public HestonAsian(IEnumerable <double> Tm, PayoffType type, double K, double T) { this.Tm = Tm; this.type = type; this.K = K; this.T = T; }
/// <summary> /// Initializes a new instance of the <see cref="T:HestonModel.Classes.InterfaceClasses.AsianOption"/> class. /// </summary> /// <param name="StrikePrice">Strike price.</param> /// <param name="Type">Type (Put / Call)</param> /// <param name="Maturity">Maturity</param> /// <param name="MonitoringTimes">Monitoring times</param> public AsianOption(double StrikePrice, PayoffType Type, double Maturity, IEnumerable <double> MonitoringTimes) : base(StrikePrice, Type, Maturity) { // Sanity Check if (MonitoringTimes.Any()) { double max = MonitoringTimes.Max(); if (max > Maturity) { throw new Exception("All monitoring time have to be less of equal than the maturity time"); } double min = MonitoringTimes.Min(); if (min < 0) { throw new Exception("All monitoring time have to be nonnegative"); } } else { throw new Exception("Provide at least one monitoring time for the Asian option pricing"); } _MonitoringTimes = MonitoringTimes; }
public HestonAsian() { this.Tm = new double[] { 0.75, 1.00 }; this.type = PayoffType.Call; this.K = 100; this.T = 1; }
public void Task_2_2_3() { // Variance Process Values double Kappa = 1.5768; double Theta = 0.0398; double Sigma = 0.5751; double V0 = 0.0175; double Rho = -0.5711; // Heston Model Params double InitialStockPrice = 100; double RiskFreeRate = 0.025; // Option Params double StrikePrice = 100; PayoffType Type = PayoffType.Call; double Maturity = 3; VarianceProcessParameters varParams = new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho); HestonModelParameters hestonModel = new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams); EuropeanOption euOption = new EuropeanOption(StrikePrice, Type, Maturity); EuropeanOptionFormula euFormula = new EuropeanOptionFormula(hestonModel, euOption); Assert.AreEqual(15.4793, euFormula.Price(), 1e-4); }
/// <summary> /// Initializes a new instance of the EuropeanOptionMC class. /// </summary> /// <param name="parameters">Interface holding Heston Model params.</param> /// <param name="monteCarloSimulationSettings">Interface holding Monte carlo simulation settings.</param> /// <param name="europeanOption">Interface holding European option params.</param> public EuropeanOptionMC(HestonModelParameters parameters, MonteCarloSettings monteCarloSimulationSettings, EuropeanOption europeanOption) : base(parameters, monteCarloSimulationSettings, europeanOption.Maturity) { _StrikePrice = europeanOption.StrikePrice; _Type = europeanOption.Type; }
/// <summary> /// Initializes a new instance of the European option /// </summary> /// <param name="parameters">Heston Model Parameter Object</param> /// <param name="europeanOption">European option Parameter Object</param> public EuropeanOptionFormula(HestonModelParameters parameters, EuropeanOption europeanOption) : base(parameters.InitialStockPrice, parameters.RiskFreeRate, parameters.GetVariance()) { _StrikePrice = europeanOption.StrikePrice; _Type = europeanOption.Type; _Maturity = europeanOption.Maturity; }
public static void Task2() { // Task 2 // Variance Process Values Console.WriteLine("Task 2"); double Kappa = 1.5768; double Theta = 0.0398; double Sigma = 0.5751; double V0 = 0.0175; double Rho = -0.5711; // Heston Model Params double InitialStockPrice = 100; double RiskFreeRate = 0.025; // Option Params double StrikePrice = 100; PayoffType Type = PayoffType.Call; int[] Maturity = new int[5] { 1, 2, 3, 4, 15 }; VarianceProcessParameters varParams = new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho); HestonModelParameters hestonModel = new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams); // ************Task 2.1 Print**************** System.Console.WriteLine("*********************"); HestonModelParamPrint(varParams, hestonModel); //Prepare csv var csv = new StringBuilder(); String newLine = string.Format("K, T, Price"); csv.AppendLine(newLine); for (int i = 0; i < 5; i++) { EuropeanOption euOption = new EuropeanOption(StrikePrice, Type, Maturity[i]); double price = Heston.HestonEuropeanOptionPrice(hestonModel, euOption); System.Console.WriteLine("K={0}, T={1}, C={2}", StrikePrice, Maturity[i], price); newLine = string.Format("{0}, {1}, {2}", StrikePrice, Maturity[i], price); csv.AppendLine(newLine); } //Write to csv File.WriteAllText(@"./task2.csv", csv.ToString()); System.Console.WriteLine("*********************"); System.Console.WriteLine("\n\n"); }
/// <summary> /// Initializes a new instance of the <see cref="T:HestonModel.Classes.InterfaceClasses.EuropeanOption"/> class. /// </summary> /// <param name="StrikePrice">Strike price.</param> /// <param name="Type">Option Type (Put/Call).</param> /// <param name="Maturity">Maturity.</param> public EuropeanOption(double StrikePrice, PayoffType Type, double Maturity) { // Sanity Check if (Maturity <= 0) { throw new Exception("Maturity must be a positive number."); } if (StrikePrice <= 0) { throw new Exception("Strike price must be a positive number."); } // Initialize private vars _StrikePrice = StrikePrice; _Type = Type; _Maturity = Maturity; }
public void Task_2_7_1() { // Variance Process Values double Kappa = 2; double Theta = 0.06; double Sigma = 0.4; double V0 = 0.04; double Rho = 0.5; // Heston Model Params double InitialStockPrice = 100; double RiskFreeRate = 0.1; // Option Params double StrikePrice = 100; PayoffType Type = PayoffType.Call; double Maturity = 1; List <double> MonitoringTimes = new List <double> { 0.75, 1.00 }; // MC Simulation Params int NumberOfTrials = (int)1e5; int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity); VarianceProcessParameters varParams = new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho); HestonModelParameters hestonModel = new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams); AsianOption asianOption = new AsianOption(StrikePrice, Type, Maturity, MonitoringTimes); MonteCarloSettings monteCarloSettings = new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps); AsianOptionMC asianOptionMC = new AsianOptionMC(hestonModel, monteCarloSettings, asianOption); Assert.AreEqual(13.6299, asianOptionMC.Price(1), 1e-1); }
public void Task_2_3_3() { // Variance Process Values double Kappa = 2; double Theta = 0.06; double Sigma = 0.4; double V0 = 0.04; double Rho = 0.5; // Heston Model Params double InitialStockPrice = 100; double RiskFreeRate = 0.1; // Option Params double StrikePrice = 100; PayoffType Type = PayoffType.Call; double Maturity = 3; // MC Simulation Params int NumberOfTrials = (int)1e5; int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity); VarianceProcessParameters varParams = new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho); HestonModelParameters hestonModel = new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams); EuropeanOption euOption = new EuropeanOption(StrikePrice, Type, Maturity); MonteCarloSettings monteCarloSettings = new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps); EuropeanOptionMC euOptionMC = new EuropeanOptionMC(hestonModel, monteCarloSettings, euOption); Assert.AreEqual(29.9957, euOptionMC.Price(1), 1e-1); }
public static void TaskThreadScaling() { // Variance Process Values Console.WriteLine("Task Thread Scaling"); // Variance Process Values double Kappa = 2.0; double Theta = 0.06; double Sigma = 0.4; double V0 = 0.04; double Rho = 0.5; // Heston Model Params double InitialStockPrice = 100; double RiskFreeRate = 0.1; // Option Params double StrikePrice = 100; PayoffType Type = PayoffType.Call; double Maturity = 3; VarianceProcessParameters varParams = new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho); HestonModelParameters hestonModel = new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams); // ************Task 3 Print**************** System.Console.WriteLine("*********************"); HestonModelParamPrint(varParams, hestonModel); //Prepare csv var csv = new StringBuilder(); String newLine = string.Format("Number of Trials, cores, time"); csv.AppendLine(newLine); int[] cores = new int[5] { 1, 2, 4, 8, 16 }; for (int i = 0; i < 5; i++) { // MC Simulation Params int NumberOfTrials = (int)1e6; int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity); EuropeanOption euOption = new EuropeanOption(StrikePrice, Type, Maturity); MonteCarloSettings monteCarloSettings = new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps); double priceForm = Heston.HestonEuropeanOptionPrice(hestonModel, euOption); // Create Monte Carlo EU option object EuropeanOptionMC euOptionMC = new EuropeanOptionMC(hestonModel, monteCarloSettings, euOption); var stopwatch = new Stopwatch(); stopwatch.Start(); double price = euOptionMC.Price(cores[i]); stopwatch.Stop(); long elapsed_time = stopwatch.ElapsedMilliseconds; System.Console.WriteLine("K={0}, T={1}, cores={2}, C_MC={3}, C_form={4}, time={5}", StrikePrice, Maturity, cores[i], price, priceForm, elapsed_time); newLine = string.Format("{0}, {1}, {2}", NumberOfTrials, cores[i], elapsed_time); csv.AppendLine(newLine); } //Write to csv File.WriteAllText(@"./taskThreadScaling.csv", csv.ToString()); System.Console.WriteLine("*********************"); System.Console.WriteLine("\n\n"); }
public static void Task4() { // Variance Process Values Console.WriteLine("Task 4"); // Variance Process Values double Kappa = 2.0; double Theta = 0.06; double Sigma = 0.4; double V0 = 0.04; double Rho = 0.5; // Heston Model Params double InitialStockPrice = 100; double RiskFreeRate = 0.1; // Option Params double StrikePrice = 100; PayoffType Type = PayoffType.Call; double Maturity = 1; VarianceProcessParameters varParams = new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho); HestonModelParameters hestonModel = new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams); // ************Task 4 Print**************** System.Console.WriteLine("*********************"); HestonModelParamPrint(varParams, hestonModel); EuropeanOption euOption = new EuropeanOption(StrikePrice, Type, Maturity); double priceForm = Heston.HestonEuropeanOptionPrice(hestonModel, euOption); System.Console.WriteLine("K={0}, T={1}, refPrice={2}", StrikePrice, Maturity, priceForm); //Prepare csv var csv = new StringBuilder(); String newLine = string.Format("Trials, Time Steps, relError"); csv.AppendLine(newLine); for (int i = 3; i < 5; i++) { // MC Simulation Params int NumberOfTrials = (int)Math.Pow(10, i); double[] factor = new double[3] { 0.5, 1, 2 }; for (int j = 0; j < 3; j++) { int NumberOfTimeSteps = (int)Math.Ceiling(factor[j] * 365 * Maturity); MonteCarloSettings monteCarloSettings = new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps); double price = Heston.HestonEuropeanOptionPriceMC(hestonModel, euOption, monteCarloSettings); System.Console.WriteLine("K={0}, T={1}, #Trials={2}, #TimeSteps={3}, rel_error={4}", StrikePrice, Maturity, NumberOfTrials, NumberOfTimeSteps, Math.Abs(priceForm - price) / priceForm); newLine = string.Format("{0}, {1}, {2}", NumberOfTrials, NumberOfTimeSteps, Math.Abs(priceForm - price) / priceForm); csv.AppendLine(newLine); } } //Write to csv File.WriteAllText(@"./task4.csv", csv.ToString()); System.Console.WriteLine("*********************"); System.Console.WriteLine("\n\n"); }
public static void Task3() { // Variance Process Values Console.WriteLine("Task 3"); // Variance Process Values double Kappa = 2.0; double Theta = 0.06; double Sigma = 0.4; double V0 = 0.04; double Rho = 0.5; // Heston Model Params double InitialStockPrice = 100; double RiskFreeRate = 0.1; // Option Params double StrikePrice = 100; PayoffType Type = PayoffType.Call; double[] Maturity = new double[5] { 1, 2, 3, 4, 15 }; VarianceProcessParameters varParams = new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho); HestonModelParameters hestonModel = new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams); // ************Task 3 Print**************** System.Console.WriteLine("*********************"); HestonModelParamPrint(varParams, hestonModel); //Prepare csv var csv = new StringBuilder(); String newLine = string.Format("K, T, Price, refPrice"); csv.AppendLine(newLine); for (int i = 0; i < 5; i++) { // MC Simulation Params int NumberOfTrials = (int)1e5; int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity[i]); EuropeanOption euOption = new EuropeanOption(StrikePrice, Type, Maturity[i]); MonteCarloSettings monteCarloSettings = new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps); double priceForm = Heston.HestonEuropeanOptionPrice(hestonModel, euOption); double price = Heston.HestonEuropeanOptionPriceMC(hestonModel, euOption, monteCarloSettings); System.Console.WriteLine("K={0}, T={1}, C_MC={2}, C_form={3}", StrikePrice, Maturity[i], price, priceForm); newLine = string.Format("{0}, {1}, {2}, {3}", StrikePrice, Maturity[i], price, priceForm); csv.AppendLine(newLine); } //Write to csv File.WriteAllText(@"./task3.csv", csv.ToString()); System.Console.WriteLine("*********************"); System.Console.WriteLine("\n\n"); }
public HestonEuro(PayoffType type, double K, double T) { this.type = type; this.K = K; this.T = T; }
public HestonEuro() { this.type = PayoffType.Call; this.K = 100; this.T = 1; }
public static void Task7() { // Variance Process Values Console.WriteLine("Task 7"); // Variance Process Values double Kappa = 2.0; double Theta = 0.06; double Sigma = 0.4; double V0 = 0.04; double Rho = 0.5; // Heston Model Params double InitialStockPrice = 100; double RiskFreeRate = 0.1; // Option Params double StrikePrice = 100; PayoffType Type = PayoffType.Call; double[] Maturity = new double[3] { 1, 2, 3 }; VarianceProcessParameters varParams = new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho); HestonModelParameters hestonModel = new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams); // ************Task 7 Print**************** System.Console.WriteLine("*********************"); HestonModelParamPrint(varParams, hestonModel); // Monitoring Times List <double> monTimes1 = new List <double> { 0.75, 1.00 }; List <double> monTimes2 = new List <double> { 0.25, 0.5, 0.75, 1.00, 1.25, 1.5, 1.75 }; List <double> monTimes3 = new List <double> { 1.00, 2.00, 3.00 }; List <List <double> > MonitoringTimes = new List <List <double> > { monTimes1, monTimes2, monTimes3 }; //Prepare csv var csv = new StringBuilder(); String newLine = string.Format("K, T, Price"); csv.AppendLine(newLine); for (int i = 0; i < 3; i++) { // MC Simulation Params int NumberOfTrials = (int)1e5; int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity[i]); AsianOption asianOption = new AsianOption(StrikePrice, Type, Maturity[i], MonitoringTimes[i]); MonteCarloSettings monteCarloSettings = new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps); double price = Heston.HestonAsianOptionPriceMC(hestonModel, asianOption, monteCarloSettings); System.Console.WriteLine("K={0}, T={1}, C_MC={2}", StrikePrice, Maturity[i], price); newLine = string.Format("{0}, {1}, {2}", StrikePrice, Maturity[i], price); csv.AppendLine(newLine); } //Write to csv File.WriteAllText(@"./task7.csv", csv.ToString()); System.Console.WriteLine("*********************"); System.Console.WriteLine("\n\n"); }
public AsianOptionGrading(IEnumerable <double> monitoringTimes, double timeToExpiry, double strike, PayoffType type) : base(timeToExpiry, strike, type) { MonitoringTimes = monitoringTimes; }