Beispiel #1
0
        public virtual void test_addVolatility_notAscendingTime()
        {
            HullWhiteOneFactorPiecewiseConstantParameters @base = HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);
            double time = 3.0;
            double vol  = 0.015;

            assertThrowsIllegalArg(() => @base.withVolatilityAdded(vol, time));
        }
Beispiel #2
0
        public virtual void test_of()
        {
            HullWhiteOneFactorPiecewiseConstantParameters test = HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);

            assertEquals(test.LastVolatility, VOLATILITY.get(VOLATILITY.size() - 1));
            assertEquals(test.MeanReversion, MEAN_REVERSION);
            assertEquals(test.Volatility, VOLATILITY);
            assertEquals(test.VolatilityTime, DoubleArray.of(0.0, 0.5, 1.0, 2.0, 5.0, 1000d));
        }
Beispiel #3
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            HullWhiteOneFactorPiecewiseConstantParameters test1 = HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);

            coverImmutableBean(test1);
            HullWhiteOneFactorPiecewiseConstantParameters test2 = HullWhiteOneFactorPiecewiseConstantParameters.of(0.02, DoubleArray.of(0.015), DoubleArray.of());

            coverBeanEquals(test1, test2);
        }
Beispiel #4
0
        public virtual void test_of_noTime()
        {
            double eta = 0.02;
            HullWhiteOneFactorPiecewiseConstantParameters test = HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, DoubleArray.of(eta), DoubleArray.of());

            assertEquals(test.LastVolatility, eta);
            assertEquals(test.MeanReversion, MEAN_REVERSION);
            assertEquals(test.Volatility, DoubleArray.of(eta));
            assertEquals(test.VolatilityTime, DoubleArray.of(0d, 1000d));
        }
Beispiel #5
0
        public virtual void test_setLastVolatility()
        {
            HullWhiteOneFactorPiecewiseConstantParameters @base = HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);
            double lastVol = 0.092;
            HullWhiteOneFactorPiecewiseConstantParameters test = @base.withLastVolatility(lastVol);

            assertEquals(test.LastVolatility, lastVol);
            assertEquals(test.MeanReversion, @base.MeanReversion);
            assertEquals(test.Volatility, DoubleArray.of(0.01, 0.011, 0.012, 0.013, lastVol));
            assertEquals(test.VolatilityTime, @base.VolatilityTime);
        }
Beispiel #6
0
        public virtual void test_setVolatility()
        {
            HullWhiteOneFactorPiecewiseConstantParameters @base = HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);
            DoubleArray newVol = DoubleArray.of(0.04, 0.012, 0.016, 0.019, 0.024);
            HullWhiteOneFactorPiecewiseConstantParameters test = @base.withVolatility(newVol);

            assertEquals(test.LastVolatility, newVol.get(newVol.size() - 1));
            assertEquals(test.MeanReversion, @base.MeanReversion);
            assertEquals(test.Volatility, newVol);
            assertEquals(test.VolatilityTime, @base.VolatilityTime);
        }
Beispiel #7
0
        public virtual void test_addVolatility()
        {
            HullWhiteOneFactorPiecewiseConstantParameters @base = HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);
            double time = 7.0;
            double vol  = 0.015;
            HullWhiteOneFactorPiecewiseConstantParameters test = @base.withVolatilityAdded(vol, time);

            assertEquals(test.LastVolatility, vol);
            assertEquals(test.MeanReversion, MEAN_REVERSION);
            assertEquals(test.Volatility, DoubleArray.of(0.01, 0.011, 0.012, 0.013, 0.014, vol));
            assertEquals(test.VolatilityTime, DoubleArray.of(0.0, 0.5, 1.0, 2.0, 5.0, 7.0, 1000d));
        }
Beispiel #8
0
        public virtual void test_priceSensitivityHullWhiteParameter()
        {
            DoubleArray computed = PRICER.priceSensitivityModelParamsHullWhite(FUTURE, RATE_PROVIDER, HW_PROVIDER);
            DoubleArray vols     = HW_PROVIDER.Parameters.Volatility;
            int         size     = vols.size();

            double[] expected = new double[size];
            for (int i = 0; i < size; ++i)
            {
                double[] volsUp = vols.toArray();
                double[] volsDw = vols.toArray();
                volsUp[i] += TOL_FD;
                volsDw[i] -= TOL_FD;
                HullWhiteOneFactorPiecewiseConstantParameters         paramsUp = HullWhiteOneFactorPiecewiseConstantParameters.of(HW_PROVIDER.Parameters.MeanReversion, DoubleArray.copyOf(volsUp), HW_PROVIDER.Parameters.VolatilityTime.subArray(1, size));
                HullWhiteOneFactorPiecewiseConstantParameters         paramsDw = HullWhiteOneFactorPiecewiseConstantParameters.of(HW_PROVIDER.Parameters.MeanReversion, DoubleArray.copyOf(volsDw), HW_PROVIDER.Parameters.VolatilityTime.subArray(1, size));
                HullWhiteOneFactorPiecewiseConstantParametersProvider provUp   = HullWhiteOneFactorPiecewiseConstantParametersProvider.of(paramsUp, HW_PROVIDER.DayCount, HW_PROVIDER.ValuationDateTime);
                HullWhiteOneFactorPiecewiseConstantParametersProvider provDw   = HullWhiteOneFactorPiecewiseConstantParametersProvider.of(paramsDw, HW_PROVIDER.DayCount, HW_PROVIDER.ValuationDateTime);
                double priceUp = PRICER.price(FUTURE, RATE_PROVIDER, provUp);
                double priceDw = PRICER.price(FUTURE, RATE_PROVIDER, provDw);
                expected[i] = 0.5 * (priceUp - priceDw) / TOL_FD;
            }
            assertTrue(DoubleArrayMath.fuzzyEquals(computed.toArray(), expected, TOL_FD));
        }
Beispiel #9
0
        public virtual void test_of_notAscendingTime1()
        {
            DoubleArray time = DoubleArray.of(0.5, 1.0, 4.0);

            assertThrowsIllegalArg(() => HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, VOLATILITY, time));
        }
Beispiel #10
0
        public virtual void test_serialization()
        {
            HullWhiteOneFactorPiecewiseConstantParameters test = HullWhiteOneFactorPiecewiseConstantParameters.of(MEAN_REVERSION, VOLATILITY, VOLATILITY_TIME);

            assertSerialization(test);
        }