コード例 #1
0
 /**
  * This method takes the portfolio Model and returns the investement value for the given number of
  * years after adjusting to inflation
  *
  * @param pModel
  * @return double
  */
 private double InvstSingleIteration(PortfolioModel pModel) {
   double dInvestment = pModel.getInvestment();
   for (int idx = 1; idx <= this.iRetYears; ++idx) {
     dInvestment =
         dInvestment * (1 + getGaussianReturn(pModel.getInvstReturn(), pModel.getInvstRisk()));
   }
   return dInvestment / (Math.pow((1 + pModel.getInflation()), iRetYears));
 }
コード例 #2
0
  public double[] simulatePortfolio(
      final PortfolioModel pModel, final int iYears, final int iNoOfSimulations) throws Exception {

    // validations for the input arguments
    if (pModel == null) throw new Exception(MPTContants.PROVIDE_PORTFOLIO);

    if (pModel.getInvestment() <= 0) throw new Exception(MPTContants.PROVIDE_INVSTMENT);

    if (iYears <= 0) throw new Exception(MPTContants.PROVIDE_YEARS);

    if (iNoOfSimulations <= 0) throw new Exception(MPTContants.PROVIDE_SIMULATIONS);

    this.iRetYears = iYears;
    this.simulSortedValues =
        IntStream.range(0, iNoOfSimulations)
            .parallel() // default is 3 to change default
                        // -Djava.util.concurrent.ForkJoinPool.common.parallelism=5
            .mapToDouble(k -> InvstSingleIteration(pModel))
            .sorted()
            .toArray();
    return simulSortedValues;
  }