private void addScatterSeries(DataSeries item, PerformanceIndex index) { Volatility volatility = index.getVolatility(); ILineSeries series = chart.addScatterSeries( new double[] {volatility.getStandardDeviation()}, new double[] {index.getFinalAccumulatedPercentage()}, item.getLabel()); item.configure(series); }
@Test public void testVolatilityOfSharesHeldIsIdenticalToExcel() throws IOException { ReportingPeriod report = new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2014-07-31")); List<Exception> warnings = new ArrayList<>(); PerformanceIndex index = PerformanceIndex.forClient(client, report, warnings); assertThat(warnings, empty()); assertThat( index.getVolatility().getStandardDeviation(), closeTo(0.01251323582, 0.000001)); // excel }
private void addPortfolio(DataSeries item, Portfolio portfolio, List<Exception> warnings) { Object cacheKey = item.isPortfolioPlus() ? portfolio.getUUID() : portfolio; PerformanceIndex portfolioIndex = dataCache.get(cacheKey); if (portfolioIndex == null) { portfolioIndex = item.isPortfolioPlus() ? PerformanceIndex // .forPortfolioPlusAccount(getClient(), portfolio, getReportingPeriod(), warnings) : PerformanceIndex.forPortfolio( getClient(), portfolio, getReportingPeriod(), warnings); dataCache.put(cacheKey, portfolioIndex); } addScatterSeries(item, portfolioIndex); }
@Test public void testVolatilityIfSecurityIsSoldAndLaterBoughtDuringReportingPeriod() throws IOException { ReportingPeriod report = new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-02-20")); List<Exception> warnings = new ArrayList<>(); Security basf = client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get(); PerformanceIndex index = PerformanceIndex.forInvestment(client, basf, report, warnings); assertThat(warnings, empty()); assertThat( index.getVolatility().getStandardDeviation(), closeTo(0.0134468200485513, 0.00001)); // excel assertThat(index.getDates()[index.getDates().length - 1], is(Dates.date("2015-02-20"))); }
private PerformanceIndex getClientIndex(List<Exception> warnings) { PerformanceIndex index = dataCache.get(Client.class); if (index == null) { ReportingPeriod interval = getReportingPeriod(); index = PerformanceIndex.forClient(getClient(), interval, warnings); dataCache.put(Client.class, index); } return index; }
private void addAccount(DataSeries item, Account account, List<Exception> warnings) { PerformanceIndex accountIndex = dataCache.get(account); if (accountIndex == null) { accountIndex = PerformanceIndex.forAccount(getClient(), account, getReportingPeriod(), warnings); dataCache.put(account, accountIndex); } addScatterSeries(item, accountIndex); }
private void addSecurityBenchmark(DataSeries item, Security security, List<Exception> warnings) { PerformanceIndex securityIndex = dataCache.get(security); if (securityIndex == null) { PerformanceIndex clientIndex = getClientIndex(warnings); securityIndex = PerformanceIndex.forSecurity(clientIndex, security, warnings); dataCache.put(security, securityIndex); } addScatterSeries(item, securityIndex); }
private void addSecurityPerformance( DataSeries item, Security security, List<Exception> warnings) { PerformanceIndex securityIndex = dataCache.get(security.getUUID()); if (securityIndex == null) { securityIndex = PerformanceIndex.forInvestment(getClient(), security, getReportingPeriod(), warnings); dataCache.put(security.getUUID(), securityIndex); } addScatterSeries(item, securityIndex); }
private void addClassification( DataSeries item, Classification classification, List<Exception> warnings) { PerformanceIndex index = dataCache.get(classification); if (index == null) { index = PerformanceIndex.forClassification( getClient(), classification, getReportingPeriod(), warnings); dataCache.put(classification, index); } addScatterSeries(item, index); }
@Test public void testVolatilityIfSecurityIsSoldDuringReportingPeriod() throws IOException { ReportingPeriod report = new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-01-31")); List<Exception> warnings = new ArrayList<>(); Security basf = client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get(); PerformanceIndex index = PerformanceIndex.forInvestment(client, basf, report, warnings); assertThat(warnings, empty()); assertThat( index.getVolatility().getStandardDeviation(), closeTo(0.01371839502, 0.00001)); // excel assertThat(index.getDates()[index.getDates().length - 1], is(Dates.date("2015-01-31"))); // compare with client -> must be lower because cash has volatility of 0 PerformanceIndex clientIndex = PerformanceIndex.forClient(client, report, warnings); assertThat( clientIndex.getVolatility().getStandardDeviation(), lessThan(index.getVolatility().getStandardDeviation())); }
@Test public void testVolatilityIfBenchmarkHasNoQuotes() throws IOException { ReportingPeriod report = new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-01-31")); List<Exception> warnings = new ArrayList<>(); PerformanceIndex index = PerformanceIndex.forClient(client, report, warnings); Security sap = client.getSecurities().stream().filter(s -> "Sap AG".equals(s.getName())).findAny().get(); PerformanceIndex sapIndex = PerformanceIndex.forSecurity(index, sap, warnings); assertThat(warnings, empty()); // quotes only until December 31st assertThat(sapIndex.getDates()[sapIndex.getDates().length - 1], is(Dates.date("2014-12-31"))); assertThat( sapIndex.getVolatility().getStandardDeviation(), closeTo(0.0126152529671108, 0.00001)); // excel }