public void NonFlatRates() { ZeroCurve myZero = new ZeroCurve(); myZero.Ratepoints = 2; myZero.MakeArrays(); myZero.SetR(0, 0.05, 1.0); myZero.SetR(1, 0.075, 2.0); //test interpolation priot to point 0 double tTime = 0.5; double val = myZero.LinInterp(tTime); Assert.IsTrue(val > 0.0499999999); Assert.IsTrue(val < 0.050000001); //test interpolation prior to point 1 tTime = 1.5; val = myZero.LinInterp(tTime); Assert.IsTrue(val > 0.062499999999); Assert.IsTrue(val < 0.06250000001); //test interpolation post point 1 tTime = 2.5; val = myZero.LinInterp(tTime); Assert.IsTrue(val > 0.07499999999); Assert.IsTrue(val < 0.0750000001); //test forward rates //test interpolation priot to point 0 double tl = 0.25; tTime = 0.5; val = myZero.ForwardRate(tl, tTime); Assert.IsTrue(val > 0.0499999999); Assert.IsTrue(val < 0.050000001); //test interpolation prior to point 1 tTime = 1.5; val = myZero.ForwardRate(tl, tTime); Assert.IsTrue(val > 0.06499999); /// 0.065 Assert.IsTrue(val < 0.065000001); //test interpolation post point 1 tTime = 2.5; val = myZero.ForwardRate(tl, tTime); ///0.077778 Assert.IsTrue(val > 0.0777777); Assert.IsTrue(val < 0.07777778); }
public void ADivSlopingZero() { DivList mydiv = new DivList(); mydiv.Divpoints = 1; mydiv.MakeArrays(); mydiv.SetD(0, 5, 0.5); ZeroCurve myZero = new ZeroCurve(); myZero.Ratepoints = 2; myZero.MakeArrays(); myZero.SetR(0, 0.075, 0.5); myZero.SetR(1, 0.05, 2); //create the tree Tree myTree = new Tree(); myTree.Gridsteps = 100; myTree.Tau = 1.0; myTree.Sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "a"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.IsTrue(prc > 10.37); //Orc pr = 10.38 Assert.IsTrue(prc < 10.39); Assert.IsTrue(prp > 9.42); //Orc pr = 9.43 Assert.IsTrue(prp < 9.44); }
public void ANoDivFlatZero() { DivList mydiv = new DivList(); mydiv.Divpoints = 1; mydiv.MakeArrays(); mydiv.SetD(0, 0.0, 1.0); ZeroCurve myZero = new ZeroCurve(); myZero.Ratepoints = 1; myZero.MakeArrays(); myZero.SetR(0, 0.05, 1.0); //create the tree Tree myTree = new Tree(); myTree.Gridsteps = 100; myTree.Tau = 1.0; myTree.Sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "a"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.IsTrue(prc > 12.33); //Orc pr = 12.34 Assert.IsTrue(prc < 12.35); Assert.IsTrue(prp > 7.98); //Orc pr = 7.99 Assert.IsTrue(prp < 8.00); }
public void EDivFlatZero() { DivList mydiv = new DivList(); mydiv.Divpoints = 1; mydiv.MakeArrays(); mydiv.SetD(0, 5, 0.5); ZeroCurve myZero = new ZeroCurve(); myZero.Ratepoints = 1; myZero.MakeArrays(); myZero.SetR(0, 0.05, 1.0); //create the tree Tree myTree = new Tree(); myTree.Gridsteps = 100; myTree.Tau = 1.0; myTree.Sig = 0.25; myTree.Spot = 100.0; //myTree.flatFlag = false; myTree.MakeGrid(myZero, mydiv); //create pricer Pricer myPrice = new Pricer(); myPrice.Strike = 100; myPrice.Payoff = "c"; myPrice.Smoothing = "y"; myPrice.Style = "e"; myPrice.MakeGrid(myTree); double prc = myPrice.Price(); myPrice.Payoff = "p"; myPrice.MakeGrid(myTree); double prp = myPrice.Price(); Assert.IsTrue(prc > 9.455); //BS pr = 9.46277 Assert.IsTrue(prc < 9.475); Assert.IsTrue(prp > 9.462); //BS pr = 9.46226 Assert.IsTrue(prp < 9.475); }