private void Button_Click(object sender, RoutedEventArgs e) { GetData(out vol, out strikeValue, out interestRate, out valueDate, out maturityDate, out riskfacorDate); way = (Way)System.Enum.Parse(typeof(Way), Way.SelectedItem.ToString()); optionType = (OptionType)System.Enum.Parse(typeof(OptionType), TypeOption.SelectedItem.ToString()); sousJacent = (Underlying)System.Enum.Parse(typeof(Underlying), sousjacent.SelectedItem.ToString()); var x = MyGreeks.SelectedItems; var z = MyGreeks.SelectedItem; listGreeks = MyGreeks.SelectedItems.Cast <GreekType>().ToList(); Data.InitMarketData(vol, interestRate, valueDate); var option = new OptionInstrument(strikeValue, maturityDate, optionType, way, sousJacent, riskfacorDate); var pricingcfg = new PricingConfiguration(listGreeks); var pricer = new Pricer(); Result.Text = pricer.Results(option, pricingcfg).Mtm.ToString(); var resultGreek = pricer.Results(option, pricingcfg).Results; if (resultGreek.Count != 0) { foreach (var result in resultGreek) { switch (result.Key) { case GreekType.Delta: ValueDelta.Text = result.Value.ToString(""); break; case GreekType.Vega: ValueVega.Text = result.Value.ToString(); break; case GreekType.Gamma: ValueGamma.Text = result.Value.ToString(); break; case GreekType.Rho: ValueRho.Text = result.Value.ToString(); break; case GreekType.Tetha: ValueTetha.Text = result.Value.ToString(); break; } } } }
public void Actual(DataTestCase testCase) { Data.InitMarketData(testCase.Vol, testCase.Rate, testCase.EvalDate); var pricingCfg = new PricingConfiguration(testCase.GreekTypes); var pricer = new Pricer(); PricingResults expectedResults = null; var actualResults = pricer.Results(testCase.Option, pricingCfg); var error = string.Empty; try { using (StreamReader file = File.OpenText(@"C:\Users\AHMED\source\repos\ConsoleApp1\ResultPricing.text")) { JsonSerializer serializer = new JsonSerializer(); expectedResults = (PricingResults)serializer.Deserialize(file, typeof(PricingResults)); } } catch (Exception e) { Assert.Fail(error = string.Format("Not Deserialize result: {0}", e.Message)); } if (actualResults.CompareResult(expectedResults)) { Assert.Pass("No regression detected"); } else { // save ecart Assert.Fail("regression detected"); } }
static void Main(string[] args) { DateTime expirationDate = DateTime.Parse("01/05/2019"); DateTime riskFactorDate = DateTime.Parse("01/09/2019"); DateTime paramDate = DateTime.Parse("01/04/2019"); var option = new OptionInstrument(60, expirationDate, OptionType.Put, Way.Sell, Underlying.Petrol, riskFactorDate); Data.InitMarketData(0.25, 0.05, paramDate); var pricingcfg = new PricingConfiguration( new List <GreekType> { GreekType.Delta, GreekType.Gamma, GreekType.Vega, GreekType.Rho, GreekType.Tetha }); var pricer = new Pricer(); var results = pricer.Results(option, pricingcfg); Console.WriteLine("Le prix de l'option :" + results.Mtm); foreach (var result in results.Results) { Console.WriteLine("La valeur de " + result.Key.ToString() + " : " + result.Value); } /*// prcing europeene option * var maturity = DateTime.Parse("01/05/2019"); * var paramDate = DateTime.Parse("01/04/2019"); * var riskFctorDate = DateTime.Parse("01/09/2019"); * var diif = (paramDate-maturity).TotalDays; * var option = new OptionInstrument(60, maturity); * var interpolator = new InterpolatorFuturePrice("CL", riskFctorDate); * var riskFator = interpolator.InterpolationBackStepProcess(); * var optionData = new OptionMarketData(riskFator, paramDate, 0.05, 0.25); * * var pricer = new OptionPricer(option, optionData,"call"); * * * var listGreeks = new List<string>() * { * "Delta", * "Vega", * "Theta", * "Rho", * "Gamma" * }; * * PrintResult print = new PrintResult(pricer,true,true,listGreeks); * print.Print(); */ // InitMarketData // Construction of Product + PricingConfiguration // Call the method Price }
public void Reference(DataTestCase testCase) { Data.InitMarketData(testCase.Vol, testCase.Rate, testCase.EvalDate); var pricingCfg = new PricingConfiguration(testCase.GreekTypes); var pricer = new Pricer(); var results = pricer.Results(testCase.Option, pricingCfg); var json = JsonConvert.SerializeObject(results, Formatting.Indented); var msg = "The reference is generated"; var isGenereted = true; try { using (StreamWriter file = File.CreateText(@"C:\Users\AHMED\source\repos\ConsoleApp1\ResultPricing.text")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, results); } } catch (Exception e) { isGenereted = false; msg = string.Format("The reference cannot be generated:{0}", e.Message); } finally { if (isGenereted == false) { Assert.Fail(msg); } else { Assert.Pass(msg); } } }