public double getCovariance(final int aRow, final int aCol) { final BasicMatrix tmpCovariances = myCovariances; if (tmpCovariances != null) { return tmpCovariances.doubleValue(aRow, aCol); } else { final double tmpRowRisk = this.getVolatility(aRow); final double tmpColRisk = this.getVolatility(aCol); final double tmpCorrelation = this.getCorrelation(aRow, aCol); return tmpRowRisk * tmpCorrelation * tmpColRisk; } }
public PortfolioSimulator getSimulator() { final List<GeometricBrownianMotion> tmpAssetProcesses = new ArrayList<GeometricBrownianMotion>(myComponents.size()); for (final SimpleAsset tmpAsset : myComponents) { final GeometricBrownianMotion tmpForecast = tmpAsset.forecast(); tmpForecast.setValue(tmpAsset.getWeight().doubleValue()); tmpAssetProcesses.add(tmpForecast); } return new PortfolioSimulator(myCorrelations.toPrimitiveStore(), tmpAssetProcesses); }
public SimplePortfolio(final Context aContext, final FinancePortfolio weightsPortfolio) { super(); myCorrelations = aContext.getCorrelations(); final BasicMatrix tmpCovariances = aContext.getCovariances(); final BasicMatrix tmpAssetReturns = aContext.getAssetReturns(); final List<BigDecimal> tmpWeights = weightsPortfolio.getWeights(); if ((tmpWeights.size() != myCorrelations.countRows()) || (tmpWeights.size() != myCorrelations.countColumns())) { throw new IllegalArgumentException("Input dimensions don't match!"); } myComponents = new ArrayList<SimpleAsset>(tmpWeights.size()); for (int i = 0; i < tmpWeights.size(); i++) { final double tmpMeanReturn = tmpAssetReturns.doubleValue(i, 0); final double tmpVolatilty = Math.sqrt(tmpCovariances.doubleValue(i, i)); final BigDecimal tmpWeight = tmpWeights.get(i); myComponents.add(new SimpleAsset(tmpMeanReturn, tmpVolatilty, tmpWeight)); } }
public double getCorrelation(final int aRow, final int aCol) { return myCorrelations.doubleValue(aRow, aCol); }