/// <summary> /// Test method, displays a sensitivity on heston call and put prices. /// </summary> private void PutCallTest() { Console.WriteLine("Black-Sholes Calls Market Prices"); Console.WriteLine(this.callMarketPrice); Console.WriteLine("Strikes"); Console.WriteLine(this.strike); Console.WriteLine("Maturities"); Console.WriteLine(this.maturity); var x = new Vector() { 3.18344026504981, 0.0427882999286046, 0.644527074840708, -0.659960749691282, 0.0150455464938991, 0.0211747510984717 }; HestonCall hc = new HestonCall(this, x, this.s0); hc.T = .1; hc.rate = this.rate[0]; Console.WriteLine("Strike\tCall\tPut"); for (int z = 200; z < 6500; z += 1000) { hc.K = z; var call = hc.HestonCallPrice(); var put = hc.HestonPutPrice(); var callPut = hc.HestonCallPutPrice(); Console.WriteLine(z + "\t" + callPut[0] + "\t" + callPut[1]); } }
public void Test() { double k = 0.9; double tau = 2.0; double rate = 0.1; double dy = 0.07; double kappa = 2.5; double theta = 0.4; double sigma = 0.2; double s0 = 1.0; double v0 = 0.3; double rho = -0.8; // Calculates the theoretical value of the call. Vector param = new Vector(5); param[0] = kappa; param[1] = theta; param[2] = sigma; param[3] = rho; param[4] = v0; HestonCall hestonCall = new HestonCall(); double fairmatPrice = hestonCall.HestonCallPrice(param, s0, tau, k, rate, dy); double tol = 1e-9; double benchmarkPrice = 0.339537359104676; Console.WriteLine("Theoretical Benchmark Price = " + benchmarkPrice.ToString()); Console.WriteLine("Theoretical Fairmat Price = " + fairmatPrice); Assert.Less(Math.Abs(fairmatPrice - benchmarkPrice), tol); }
public void Test() { Engine.MultiThread = true; Document doc = new Document(); ProjectROV rov = new ProjectROV(doc); doc.Part.Add(rov); doc.DefaultProject.NMethods.m_UseAntiteticPaths = true; int n_sim = 50000; int n_steps = 512; double strike = 100.0; double tau = 5.0; double rate = 0.1; double dy = 0.07; ModelParameter pStrike = new ModelParameter(strike, "strike"); pStrike.VarName = "strike"; rov.Symbols.Add(pStrike); ModelParameter pRate = new ModelParameter(rate, "rfrate"); pRate.VarName = "rfrate"; rov.Symbols.Add(pRate); AFunction payoff = new AFunction(rov); payoff.VarName = "payoff"; payoff.m_IndependentVariables = 1; payoff.m_Value = (RightValue)("max(x1 - strike ; 0)"); rov.Symbols.Add(payoff); HestonProcess process = new HestonProcess(); process.r = (ModelParameter)rate; process.q = (ModelParameter)dy; process.k = (ModelParameter)2.5; process.theta = (ModelParameter)0.4; process.sigma = (ModelParameter)0.2; process.S0 = (ModelParameter)100.0; process.V0 = (ModelParameter)0.3; StochasticProcessExtendible s = new StochasticProcessExtendible(rov, process); rov.Processes.AddProcess(s); // Set the discounting. RiskFreeInfo rfi = rov.GetDiscountingModel() as RiskFreeInfo; rfi.ActualizationType = EActualizationType.RiskFree; rfi.m_deterministicRF = rate; OptionTree op = new OptionTree(rov); op.PayoffInfo.PayoffExpression = "payoff(v1a)"; op.PayoffInfo.Timing.EndingTime.m_Value = (RightValue)tau; op.PayoffInfo.European = true; rov.Map.Root = op; rov.NMethods.Technology = ETechType.T_SIMULATION; rov.NMethods.PathsNumber = n_sim; rov.NMethods.SimulationSteps = n_steps; ROVSolver solver = new ROVSolver(); solver.BindToProject(rov); solver.DoValuation(-1); if (rov.HasErrors) { Console.WriteLine(rov.m_RuntimeErrorList[0]); } Assert.IsFalse(rov.HasErrors); ResultItem price = rov.m_ResultList[0] as ResultItem; double samplePrice = price.value; double sampleDevSt = price.stdDev / Math.Sqrt((double)n_sim); // Calculates the theoretical value of the call. Vector param = new Vector(5); param[0] = process.k.V(); param[1] = process.theta.V(); param[2] = process.sigma.V(); param[3] = 0.0; param[4] = process.V0.V(); HestonCall hestonCall = new HestonCall(); double thPrice = hestonCall.HestonCallPrice(param, process.S0.V(), tau, strike, rate, dy); Console.WriteLine("Theoretical Price = " + thPrice.ToString()); Console.WriteLine("Monte Carlo Price = " + samplePrice); Console.WriteLine("Standard Deviation = " + sampleDevSt.ToString()); double tol = 4.0 * sampleDevSt; Assert.Less(Math.Abs(thPrice - samplePrice), tol); }
/// <summary> /// Test method, displays a sensitivity on heston call and put prices. /// </summary> private void PutCallTest() { Console.WriteLine("Black-Sholes Calls Market Prices"); Console.WriteLine(this.callMarketPrice); Console.WriteLine("Strikes"); Console.WriteLine(this.strike); Console.WriteLine("Maturities"); Console.WriteLine(this.maturity); var x = new Vector() {3.18344026504981, 0.0427882999286046, 0.644527074840708, -0.659960749691282, 0.0150455464938991, 0.0211747510984717}; HestonCall hc = new HestonCall(this, x, this.s0); hc.T = .1; hc.rate = this.rate[0]; Console.WriteLine("Strike\tCall\tPut"); for (int z = 200; z < 6500; z += 1000) { hc.K = z; var call = hc.HestonCallPrice(); var put = hc.HestonPutPrice(); var callPut = hc.HestonCallPutPrice(); Console.WriteLine(z + "\t" + callPut[0] + "\t" + callPut[1]); } }
public static void Main(string[] args) { int Caso = 1; if (Caso == 0) { InterestRateMarketData MData = InterestRateMarketData.FromFile("../../../TestData/InterestRatesModels/05052009-EU.xml"); CallPriceMarketData test = CallPriceMarketData.FromFile("../../../TestData/Heston/05052009-SX5E-HestonData.xml"); EquityCalibrationData CalData = new EquityCalibrationData(test, MData); Matrix CallMarketPrice = (Matrix)test.CallPrice; Vector Maturity = (Vector)test.Maturity; Vector Strike = (Vector)test.Strike; Vector DividendYield = (Vector)test.DividendYield; Vector Drift = CalData.Rate - CalData.DividendYield; Vector Rate = CalData.Rate; double u, kappa, theta, sigma, rho, v0, s0, r, q, T, K, val; u = 1.0; kappa = 19.4; theta = 0.235; sigma = 0.00500999; rho = -0.96; v0 = 0.664; s0 = 3872.15; r = -0.0867303549580581; q = 0; T = 0.50; K = 6000; Vector MatBound = new Vector(2); Vector StrikeBound = new Vector(2); MatBound[0] = 0.0; MatBound[1] = 2.0; StrikeBound[0] = 0.7; StrikeBound[1] = 1.3; Matrix Volatility = new Matrix(test.CallPrice.R, test.CallPrice.C); HestonCallOptimizationProblem HP = new HestonCallOptimizationProblem(CallMarketPrice, Maturity, Strike, Rate, DividendYield, test.S0, MatBound, StrikeBound, Volatility); Complex Cval, Cu; Cu = u - Complex.I; HestonCall hc = new HestonCall(HP); Cval = hc.phi(u, kappa, theta, sigma, rho, s0, v0, r, T); Console.WriteLine("phi1 = {0}", Cval); Cval = hc.phi(Cu, kappa, theta, sigma, rho, s0, v0, r, T); Console.WriteLine("phi2 = {0}", Cval); val = hc.IntegrandFunc(u, kappa, theta, sigma, rho, s0, v0, r, q, T, K); Console.WriteLine("IntFunc = {0}", val); Vector x = new Vector(5); x[0] = kappa; x[1] = theta; x[2] = sigma; x[3] = rho; x[4] = v0; DateTime T1, T2; TimeSpan ElapsedTime; double Time, Time2, Time3; T1 = DateTime.Now; val = hc.HestonCallPrice(x, s0, T, K, r, q); T2 = DateTime.Now; ElapsedTime = T2 - T1; Time = (double)ElapsedTime.Milliseconds; Time2 = (double)ElapsedTime.Seconds; Console.WriteLine("Price = {0}", val); Console.WriteLine("Elapsed Time = {0}", Time2 + Time / 1000); int NProve = 10; int NPassi = 1000; double val2; Random CasNum = new Random(); for (int i = 0; i < NProve; i++) { for (int j = 0; j < 5; j++) { val2 = ((double)CasNum.Next(0, NPassi)) / ((double)NPassi); x[j] = HP.Bounds.Lb[j] + (HP.Bounds.Ub[j] - HP.Bounds.Lb[j]) * val2; } Console.Write("Trial {0} x = " + x.ToString(), i + 1); T1 = DateTime.Now; val = HP.Obj(x); T2 = DateTime.Now; ElapsedTime = T2 - T1; Time = (double)ElapsedTime.Milliseconds; Time2 = (double)ElapsedTime.Seconds; Time3 = (double)ElapsedTime.Minutes; Console.WriteLine(" Time = {0}' {1}'' Val = {2}", Time3, Time2 + Time / 1000, val); } } if (Caso == 1) { TestHestonCallEstimation NewTest = new TestHestonCallEstimation(); bool Result = NewTest.Run(); } }