public void Initialize() { _testOption = new Library.Binominal.Option { K = 100, type = 2, T = 0.25, r = 0.1, sig = 0.2 }; }
public void C9_9_7_PadeApproximation() { var opt = new Library.Binominal.Option { K = 65, type = 1, T = 0.25, r = 0.08, sig = 0.3 }; double PriceWithJR(int numSteps, int type) { opt.type = type; var steps = numSteps; var S = 60; double k = opt.T / steps; double discounting = Math.Exp(-opt.r * k); var binParams = new PadeJRStrategy(opt.sig, opt.r, k); // Factory var bn = new BinomialMethod(discounting, binParams, steps); bn.ModifyLattice(S); // Phase III: Backward Induction and compute option price var RHS = new Vector <double>(bn.BasePyramidVector()); var pay = opt.PayoffVector(RHS); return(bn.GetPrice(pay)); } double PriceWithCRR(int numSteps, int type) { opt.type = type; var steps = numSteps; var S = 60; double k = opt.T / steps; double discounting = Math.Exp(-opt.r * k); var binParams = new PadeCRRStrategy(opt.sig, opt.r, k); // Factory var bn = new BinomialMethod(discounting, binParams, steps); bn.ModifyLattice(S); // Phase III: Backward Induction and compute option price var RHS = new Vector <double>(bn.BasePyramidVector()); var pay = opt.PayoffVector(RHS); return(bn.GetPrice(pay)); } Assert.AreEqual(PriceWithCRR(100, 1), 2.1399, 0.01); Assert.AreEqual(PriceWithCRR(100, 2), 5.8527, 0.01); Assert.AreEqual(PriceWithCRR(200, 1), 2.1365, 0.01); Assert.AreEqual(PriceWithCRR(200, 2), 5.8494, 0.01); Assert.AreEqual(PriceWithJR(100, 1), 2.1386, 0.01); Assert.AreEqual(PriceWithJR(100, 2), 5.8516, 0.01); Assert.AreEqual(PriceWithJR(200, 1), 2.1344, 0.01); Assert.AreEqual(PriceWithJR(200, 2), 5.8473, 0.01); }