コード例 #1
0
        public void CanInterpolateFact()
        {
            var interp = new DummyPointInterpolator();
            var point  = 99.97;

            interp = new DummyPointInterpolator(point);
            Assert.Equal(point, interp.Interpolate(5, 25));
            Assert.Equal(point, interp.Interpolate(-6, 77));
            Assert.Equal(point, interp.Interpolate(0, 0));
            Assert.Equal(point, interp.Interpolate(55, 25));

            Assert.Equal(point, interp.Interpolate(55));
            Assert.Equal(point, interp.Interpolate(-55));
            Assert.Equal(point, interp.Interpolate(0));
            Assert.Equal(point, interp.Interpolate(System.Math.PI));

            Assert.Equal(0, interp.FirstDerivative(System.Math.PI));
            Assert.Equal(0, interp.SecondDerivative(System.Math.PI));

            Assert.Equal(1.0, interp.Sensitivity(System.Math.PI).First());

            var i2 = interp.Bump(66, 3.0);

            Assert.Equal(point + 3.0, i2.Interpolate(55));

            var i3 = interp.UpdateY(66, 3.0);

            Assert.Equal(3.0, i3.Interpolate(55));
        }
コード例 #2
0
        public void ExtensionFacts()
        {
            var i  = new DummyPointInterpolator(0.5);
            var xs = new double[] { 1.0, 10.0 };

            Assert.Equal(0.5, i.Average(xs));
            Assert.Equal(0.5, i.MaxY(xs));
            Assert.Equal(0.5, i.MinY(xs));
            Assert.Equal(1.0, i.Sum(xs));
            Assert.Equal(0.5, i.Many(xs)[0]);
        }
コード例 #3
0
        public void PVFacts()
        {
            var t   = 1.0;
            var k   = 0.0;
            var f   = 100.0;
            var vol = 0.32;
            var rf  = 0.05;
            var cp  = OptionType.P;

            //zero strike put is worthless
            var PV = TrinomialTree.AmericanAssetOptionPV(f, k, rf, f, t, vol, cp);

            Assert.Equal(0, PV, 10);
            PV = BinomialTree.AmericanPV(t, f, k, rf, vol, cp, rf, 100);
            Assert.Equal(0, PV, 10);
            var flatInterp    = new DummyPointInterpolator(new[] { 1.0 }, new[] { rf });
            var flatFwdInterp = new DummyPointInterpolator(new[] { 1.0 }, new[] { f });

            PV = TrinomialTree.VanillaPV(t, f, k, flatInterp, vol, cp, flatFwdInterp, 100, true);
            Assert.Equal(0, PV, 10);

            //zero strike call is worth fwd with no discounting
            cp = OptionType.C;
            PV = TrinomialTree.AmericanAssetOptionPV(f, k, rf, f, t, vol, cp);
            Assert.Equal(f, PV, 10);
            PV = BinomialTree.AmericanPV(t, f, k, rf, vol, cp, rf, 100);
            Assert.Equal(f, PV, 10);

            //OTM option with zero vol is worthless
            vol = 0.0;
            k   = f + 1.0;
            PV  = BinomialTree.AmericanPV(t, f, k, rf, vol, cp, rf, 100);
            Assert.Equal(0, PV, 10);
            PV = TrinomialTree.AmericanAssetOptionPV(f, k, rf, f, t, vol, cp);
            Assert.Equal(0, PV, 10);

            //option worth >= black in all cases for same inputs
            vol = 0.32;
            k   = f + 20;
            var PVBlack = BlackFunctions.BlackPV(f, k, rf, t, vol, cp);

            PV = BinomialTree.AmericanPV(t, f, k, rf, vol, cp, rf, 100);
            Assert.True(PV >= PVBlack);
            PV = TrinomialTree.AmericanAssetOptionPV(f, k, rf, f, t, vol, cp);
            Assert.True(PV >= PVBlack);
        }