Search in sources :

Example 1 with GeometricBrownian1D

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);
}
Also used : GeometricBrownian1D(org.ojalgo.random.process.GeometricBrownian1D) CalendarDate(org.ojalgo.type.CalendarDate) ArrayList(java.util.ArrayList) SimpleAsset(org.ojalgo.finance.portfolio.SimpleAsset) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) GeometricBrownianMotion(org.ojalgo.random.process.GeometricBrownianMotion) CalendarDateSeries(org.ojalgo.series.CalendarDateSeries) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 SimpleAsset (org.ojalgo.finance.portfolio.SimpleAsset)1 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)1 GeometricBrownian1D (org.ojalgo.random.process.GeometricBrownian1D)1 GeometricBrownianMotion (org.ojalgo.random.process.GeometricBrownianMotion)1 CalendarDateSeries (org.ojalgo.series.CalendarDateSeries)1 CalendarDate (org.ojalgo.type.CalendarDate)1