use of org.ojalgo.random.process.GeometricBrownian1D in project ojAlgo-finance by optimatika.
the class MultidimensionalSimulatorTest method testStepping.
@Test
public void testStepping() {
final PrimitiveDenseStore tmpCorrelation = PrimitiveDenseStore.FACTORY.makeEye(3, 3);
final GeometricBrownianMotion tmpOrgProc1 = new SimpleAsset(0.0, 0.01, PrimitiveMath.THIRD).forecast();
final GeometricBrownianMotion tmpOrgProc2 = new SimpleAsset(0.0, 0.02, PrimitiveMath.THIRD).forecast();
final GeometricBrownianMotion tmpOrgProc3 = new SimpleAsset(0.0, 0.03, PrimitiveMath.THIRD).forecast();
TestUtils.assertEquals(0.01, tmpOrgProc1.getStandardDeviation(), 0.005);
TestUtils.assertEquals(0.02, tmpOrgProc2.getStandardDeviation(), 0.005);
TestUtils.assertEquals(0.03, tmpOrgProc3.getStandardDeviation(), 0.005);
final ArrayList<GeometricBrownianMotion> tmpProcs = new ArrayList<>();
tmpProcs.add(tmpOrgProc1);
tmpProcs.add(tmpOrgProc2);
tmpProcs.add(tmpOrgProc3);
final GeometricBrownian1D tmpGB1D = new GeometricBrownian1D(tmpCorrelation, tmpProcs);
final List<CalendarDateSeries<Double>> tmpSeries = new ArrayList<>();
tmpSeries.add(new CalendarDateSeries<Double>(CalendarDateUnit.MONTH));
tmpSeries.add(new CalendarDateSeries<Double>(CalendarDateUnit.MONTH));
tmpSeries.add(new CalendarDateSeries<Double>(CalendarDateUnit.MONTH));
CalendarDate tmpCalendarDateKey = CalendarDate.make(CalendarDateUnit.MONTH);
tmpSeries.get(0).put(tmpCalendarDateKey, tmpOrgProc1.getValue());
tmpSeries.get(1).put(tmpCalendarDateKey, tmpOrgProc2.getValue());
tmpSeries.get(2).put(tmpCalendarDateKey, tmpOrgProc3.getValue());
for (int t = 0; t < 1000; t++) {
tmpGB1D.step(1.0 / 12.0);
tmpCalendarDateKey = tmpCalendarDateKey.step(CalendarDateUnit.MONTH);
tmpSeries.get(0).put(tmpCalendarDateKey, tmpGB1D.getValue(0));
tmpSeries.get(1).put(tmpCalendarDateKey, tmpGB1D.getValue(1));
tmpSeries.get(2).put(tmpCalendarDateKey, tmpGB1D.getValue(2));
}
final GeometricBrownianMotion tmpNewProc1 = GeometricBrownianMotion.estimate(tmpSeries.get(0).asPrimitive(), 1.0 / 12.0);
final GeometricBrownianMotion tmpNewProc2 = GeometricBrownianMotion.estimate(tmpSeries.get(1).asPrimitive(), 1.0 / 12.0);
final GeometricBrownianMotion tmpNewProc3 = GeometricBrownianMotion.estimate(tmpSeries.get(2).asPrimitive(), 1.0 / 12.0);
TestUtils.assertEquals(0.01, tmpNewProc1.getStandardDeviation(), 0.005);
TestUtils.assertEquals(0.02, tmpNewProc2.getStandardDeviation(), 0.005);
TestUtils.assertEquals(0.03, tmpNewProc3.getStandardDeviation(), 0.005);
}
Aggregations