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-3; 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 = 100000; int n_steps = 256; double strike = 90.0; double tau = 2.0; double rate = 0.1; double dy = 0.07; ModelParameter pStrike = new ModelParameter(strike, "strike"); pStrike.VarName = "strike"; rov.Symbols.Add(pStrike); AFunction payoff = new AFunction(rov); payoff.VarName = "payoff"; payoff.m_IndependentVariables = 1; payoff.m_Value = (RightValue)("max(x1 - strike ; 0)"); rov.Symbols.Add(payoff); AFunction zrfunc = new AFunction(rov); zrfunc.VarName = "zr"; zrfunc.m_IndependentVariables = 1; zrfunc.m_Value = (RightValue)rate; rov.Symbols.Add(zrfunc); AFunction dyfunc = new AFunction(rov); dyfunc.VarName = "dy"; dyfunc.m_IndependentVariables = 1; dyfunc.m_Value = (RightValue)dy; rov.Symbols.Add(dyfunc); HestonExtendedProcess process = new HestonExtendedProcess(); 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; process.zrReference = (ModelParameter)"@zr"; process.dyReference = (ModelParameter)"@dy"; double discount = Math.Exp(-rate * tau); 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 = 0.0; 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 = discount * 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 theoreticalPrice = hestonCall.HestonCallPrice(param, process.S0.V(), tau, strike, rate, dy); Console.WriteLine("Theoretical Price = " + theoreticalPrice.ToString()); Console.WriteLine("Monte Carlo Price = " + samplePrice); Console.WriteLine("Standard Deviation = " + sampleDevSt.ToString()); double tol = 4.0 * sampleDevSt; Assert.Less(Math.Abs(theoreticalPrice - samplePrice), tol); }