public PricingResults PriceResults(IOption option, Dictionary <string, decimal> priceMarket, DateTime dateDebut, IDataFeedProvider dataFeedProvider) { Pricer pricer = new Pricer(); int length = priceMarket.Count; double[] spot = new double[length]; for (int i = 0; i < spot.Length; i++) { spot[i] = (double)priceMarket.ElementAt(i).Value; } if (option is VanillaCall) { VanillaCall optionVanilla = (VanillaCall)option; PricingResults priceDelta = pricer.PriceCall(optionVanilla, dateDebut, dataFeedProvider.NumberOfDaysPerYear, spot[0], volatilite); return(priceDelta); } else { BasketOption optionBasket = (BasketOption)option; double[] volatilities = new double[optionBasket.Weights.Length]; for (int i = 0; i < optionBasket.Weights.Length; i++) { volatilities[i] = volatilite; } PricingResults priceDelta = pricer.PriceBasket(optionBasket, dateDebut, dataFeedProvider.NumberOfDaysPerYear, spot, volatilities, matrixCorrelation); return(priceDelta); } }
public List <PricingResults> pricingUntilMaturity(List <DataFeed> listDataFeed) { if (oName.Equals(null) || oShares.Equals(null) || oMaturity == null || oStrike.Equals(null) || listDataFeed.Count == 0) { throw new NullReferenceException(); // TODO pls check if correct } List <PricingResults> listPrix = new List <PricingResults>(); List <DataFeed> listdf = new List <DataFeed>(listDataFeed); //This line wad added. oSpot = new double[oShares.Length]; BasketOption bask_o = new BasketOption(oName, oShares, oWeights, oMaturity, oStrike); while (listdf.Count > oObservation) { calculVolatility(listdf); for (int myShare = 0; myShare < oShares.Length; myShare++) { oSpot[myShare] = (double)listdf[oObservation].PriceList[oShares[myShare].Id]; } PricingResults pr = basketPricer.PriceBasket(bask_o, listdf[oObservation].Date, businessDays, oSpot, oVolatility, matriceCorr); if (listPrix.Count > 0) { var prev = listPrix.Last(); if (Math.Abs(prev.Price - pr.Price) > 3.5) { var i = 0; } } listPrix.Add(pr); listdf.RemoveAt(0); } return(listPrix); }
public static void Main(string[] args) { // header Console.WriteLine("***********************"); Console.WriteLine("* Test Load Data *"); Console.WriteLine("***********************"); var HistoricalData = new HistoricalDataProvider(); DateTime from = new DateTime(2010, 01, 01); DateTime maturity = new DateTime(2010, 04, 12); Share share1 = new Share("ACCOR SA", "AC FP"); Share share2 = new Share("CREDIT AGRICOLE SA", "ACA FP"); Share[] underlyingShares = new Share[] { share1, share2 }; double[] weights = new double[] { 0.3, 0.7 }; double strike = 7000; IOption option = new BasketOption("panier", underlyingShares, weights, maturity, strike); List <DataFeed> lst = HistoricalData.GetDataFeeds(option, from); foreach (DataFeed element in lst) { Console.WriteLine("\n\n" + element.Date.ToString() + "\n" + string.Join(",", element.PriceList.Select(kv => kv.Key + "=" + kv.Value).ToArray())); } Console.WriteLine("**************End of Loading****************"); String[] id = lst[0].PriceList.Keys.ToArray(); Console.WriteLine("les ids : " + id[0] + " et " + id[1]); Console.ReadKey(true); }
public static void Main(string[] args) { var simulatedData = new SimulatedDataProvider(); DateTime from = new DateTime(2018, 09, 04); Share share1 = new Share("vod.l", "vod.l"); Share share2 = new Share("ftse", "ftse"); string nameBasket = "Basket"; double strikeBasket = 9; Share[] sharesBasket = { share1, share2 }; Double[] weights = { 0.3, 0.7 }; DateTime maturityBasket = new DateTime(2019, 09, 04); BasketOption optionBasket = new BasketOption(nameBasket, sharesBasket, weights, maturityBasket, strikeBasket); PortfolioBasket portfolioBasket = new PortfolioBasket(); int totalDays = DayCount.CountBusinessDays(from, maturityBasket); double[] volatility = new double[2]; volatility[0] = 0.4; volatility[1] = 0.4; double[,] correlationMatrix = new double[2, 2]; correlationMatrix[0, 0] = 1; correlationMatrix[1, 1] = 0.1; correlationMatrix[0, 1] = 1; correlationMatrix[1, 0] = 0.1; double valeur = portfolioBasket.PortfolioValue(optionBasket, sharesBasket, totalDays, volatility, correlationMatrix, from); Console.WriteLine("Valeur Gain normalisée = " + valeur); }
/* * Renvoie la liste des prix des données simulées * @VanilaCallName: nom de l'option * @underlyingShares: tableau des sous-jacents * @weight: poids des sous-jacents dans le portefeuille * @startDate: date de début de la simulation * @endTime: date de fin de la simulation * @strike: valeur du strike de l'option * */ public List <DataFeed> getForwardListDataField(String VanillaCallName, Share[] underlyingShares, double[] weight, DateTime startDate, DateTime endTime, double strike) { SimulatedDataFeedProvider simulvalues = new SimulatedDataFeedProvider(); DataGestion dg = new DataGestion(); int p = dg.numberOfAssets(); IOption optionData = new BasketOption(VanillaCallName, underlyingShares, weight, endTime, strike); List <DataFeed> retMarket = simulvalues.GetDataFeed(optionData, startDate);//TODO : check this line return(retMarket); }
//CreateBasket public Basket CreateBasket(BasketOption baskOption) { CustomerManagement cstMng = new CustomerManagement(db); Basket basket = new Basket { Customer = cstMng.FindCustomerById(baskOption.CustomerId) }; db.Baskets.Add(basket); db.SaveChanges(); return(basket); }
//Create Basket public Basket CreateBasket(BasketOption baskOption) { CustomerManagement castMangr = new CustomerManagement(db); Basket basket = new Basket { Customer = castMangr.FindCustomerById(baskOption.CustomerId) }; // db.Database.EnsureCreated(); db.Baskets.Add(basket); db.SaveChanges(); return(basket); }
private void StartTicker() { List <Share> selectedShares = new List <Share>(); foreach (var comp in AvailableShares) { if (comp.IsSelected) { selectedShares.Add(new Share(comp.Name, comp.Id)); } } int length = selectedShares.Count; Share[] sharesTab = new Share[length]; for (int i = 0; i < sharesTab.Length; i++) { sharesTab[i] = selectedShares[i]; } if ((selectedOptions == "vanillaCall" || UniverseVM.Initializer.Option is VanillaCall) && length == 1) { VanillaCall vanillaCall = new VanillaCall(UniverseVM.Initializer.NameOption, sharesTab[0], UniverseVM.Initializer.Maturity, UniverseVM.Initializer.Strike); universeVM.Simulation = new SimulationModel(vanillaCall, universeVM.Initializer.TypeData, UniverseVM.Initializer.DebutTest, UniverseVM.Initializer.PlageEstimation, UniverseVM.Initializer.PeriodeRebalancement); } else if (selectedOptions == "basketOption" && length > 1) { Random aleatoire = new Random(); double[] weights = new double[length]; for (int i = 0; i < length; i++) { weights[i] = (double)1 / length; } BasketOption basketOption = new BasketOption(UniverseVM.Initializer.NameOption, sharesTab, weights, UniverseVM.Initializer.Maturity, UniverseVM.Initializer.Strike); universeVM.Simulation = new SimulationModel(basketOption, universeVM.Initializer.TypeData, UniverseVM.Initializer.DebutTest, UniverseVM.Initializer.PlageEstimation, UniverseVM.Initializer.PeriodeRebalancement); } else { MessageBox.Show("Vanilla Call supports only one share, and basket options supports at least two shares, previous option was taken"); } universeVM.UnderlyingUniverse = new Universe(universeVM.Simulation, universeVM.GraphVM.Graph); if (win != null) { win.Close(); } graphTest = universeVM.UnderlyingUniverse.Graph; win = new GraphVisualization(); win.Show(); TickerStarted = false; }
public static void Main(string[] args) { // header var simulatedData = new SimulatedDataProvider(); DateTime from = new DateTime(2018, 09, 04); DateTime maturity = new DateTime(2019, 09, 04); string name = "VanillaCall"; double strike = 7000; Share underlying = new Share("vod.l", "vod.l"); IOption option = new VanillaCall(name, underlying, maturity, strike); var lst = simulatedData.GetDataFeeds(option, from); Console.WriteLine("************************************"); Console.WriteLine("* Test Simulation CallVanille *"); Console.WriteLine("************************************"); foreach (DataFeed element in lst) { Console.WriteLine("\n\n\n\n" + element.Date.ToString() + "\n" + string.Join(",", element.PriceList.Select(kv => kv.Key + "=" + kv.Value).ToArray())); } Console.WriteLine("**************End of simulation Vanille****************"); Share share1 = new Share("vod.l", "vod.l"); Share share2 = new Share("ftse", "ftse"); string nameBasket = "Basket"; double strikeBasket = 7000; Share[] sharesBasket = { share1, share2 }; Double[] weights = { 0.3, 0.7 }; DateTime maturityBasket = new DateTime(2019, 09, 04); IOption optionBasket = new BasketOption(nameBasket, sharesBasket, weights, maturityBasket, strikeBasket); List <DataFeed> simulationBasket = simulatedData.GetDataFeeds(optionBasket, from); Console.WriteLine("\n\n\n\n"); Console.WriteLine("************************************"); Console.WriteLine("* Test Simulation BasketOption *"); Console.WriteLine("************************************"); foreach (DataFeed element in simulationBasket) { Console.WriteLine("\n\n\n\n" + element.Date.ToString() + "\n" + string.Join(",", element.PriceList.Select(kv => kv.Key + "=" + kv.Value).ToArray())); } Console.WriteLine("**************End of simulation BasketOption****************"); String[] id = simulationBasket[0].PriceList.Keys.ToArray(); Console.WriteLine("Basket ID : " + id[0] + " et " + id[1]); Console.WriteLine("Basket : " + simulationBasket[0].PriceList.Keys.ToString()); Console.WriteLine("Vanille : " + lst[0].PriceList.Count); Console.WriteLine("Vanille dates : " + lst.Count); Console.ReadKey(true); }
public IOption constructOption() { IOption option = null; if ((userInput.Weights == null) || userInput.Weights.Sum() != 1) { throw new ArgumentException("The sum of the weights must equal 1"); } if (DateTime.Compare(userInput.StartDate, userInput.Maturity) >= 0) { throw new ArgumentException("The start date must be shorter than maturity"); } List <Share> underlyingsShares = new List <Share>(); foreach (string underlyingId in userInput.UnderlyingsIds) { String underlyingName = ShareTools.GetShareName(underlyingId); underlyingsShares.Add(new Share(underlyingName, underlyingId)); } if (userInput.OptionType.Equals("VanillaCall")) { if (underlyingsShares.Count > 1) { throw new ArgumentException("You have to choose only one underlying share for the Vanilla call"); } option = new VanillaCall(userInput.NameOption, underlyingsShares[0], userInput.Maturity, userInput.Strike); } else if (userInput.OptionType.Equals("BasketOption")) { if (userInput.Weights.Length == 1) { throw new ArgumentException("You have to choose multiple underlying shares for the Basket option"); } option = new BasketOption(userInput.NameOption, underlyingsShares.ToArray(), userInput.Weights, userInput.Maturity, userInput.Strike); } else { throw new ArgumentException("Unkown OptionType " + userInput.OptionType); } return(option); }
private void StartTicker() { //universeVM = new UniverseViewModel(); BasketOption basketOption = new BasketOption("Basket", new Share[] { new Share("CREDIT AGRICOLE SA", "ACA FP "), new Share("AIR LIQUIDE SA", "AI FP "), new Share("AIRBUS GROUP SE", "AIR FP ") }, new double[] { 0.2, 0.2, 0.5, 0.1 }, UniverseVM.Initializer.Maturity, UniverseVM.Initializer.Strike); VanillaCall vanillaCall = new VanillaCall("Vanilla Call", new Share("AIRBUS GROUP SE", "AIR FP "), UniverseVM.Initializer.Maturity, UniverseVM.Initializer.Strike); universeVM.Simulation = new SimulationModel(basketOption, new HistoricalDataFeedProvider(), UniverseVM.Initializer.DebutTest, UniverseVM.Initializer.PlageEstimation); universeVM.UnderlyingUniverse = new Universe(universeVM.Simulation, universeVM.GraphVM.Graph); if (win != null) { win.Close(); } graphTest = universeVM.UnderlyingUniverse.Graph; win = new GraphVisualization(); win.Show(); TickerStarted = false; }
public static void Main(string[] args) { var simulatedData = new SimulatedDataProvider(); DateTime from = new DateTime(2010, 01, 01); Share share1 = new Share("vod.l", "vod.l"); Share share2 = new Share("ftse", "ftse"); Share share3 = new Share("sfr", "sfr"); Share share4 = new Share("sx5e", "sx5e"); string nameBasket = "Basket"; double strikeBasket = 7000; Share[] sharesBasket = { share1, share2, share3, share4 }; Double[] weights = { 0.2, 0.5, 0.2, 0.1 }; DateTime maturityBasket = new DateTime(2151, 01, 20); IOption optionBasket = new BasketOption(nameBasket, sharesBasket, weights, maturityBasket, strikeBasket); List <DataFeed> simulationBasket = simulatedData.GetDataFeeds(optionBasket, from); ParametersEstimation parameters = new ParametersEstimation(simulationBasket, new DateTime(2150, 01, 20), 15000); var correlationMatrix = parameters.Correlation; int Size = correlationMatrix.GetLength(0); Console.WriteLine("\n \n \n La matrice de correlation est : \n "); for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { Console.Write(correlationMatrix[i, j] + new string(' ', 30 - correlationMatrix[i, j].ToString().Length)); } Console.Write("\n"); } var volatilityTable = parameters.Volatility; Console.WriteLine("\n \n \n la volatilite est : \n "); for (int i = 0; i < Size; i++) { Console.WriteLine(volatilityTable[i]); } Console.ReadKey(true); }
public static void RunBasketCRUD() { //connect to the DB using CrmDbContext db = new CrmDbContext(); //to using to xrisomopioume anti gia to dispose (disconnect apo vasi) ProductOption prOpt = new ProductOption { ProductName = "apples", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); //Console.WriteLine(basket.BasketProducts[0], Product.ProductName); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product.ProductName)); }
public List <FinancialComputation> InitAvailableOptions(string filename) { var res = new List <FinancialComputation>(); var sousJacentVanilla0 = new Share("AC", "AC FP "); var maturityVanilla0 = new DateTime(2014, 9, 25); var vanilla0 = new VanillaCall("simu vanilla AC", sousJacentVanilla0, maturityVanilla0, 25); res.Add(new VanillaComputation(vanilla0)); var sousJacentVanilla1 = new Share("AC", "AC FP "); var maturityVanilla1 = new DateTime(2011, 9, 25); var vanilla1 = new VanillaCall("vanilla AC", sousJacentVanilla1, maturityVanilla1, 25); res.Add(new VanillaComputation(vanilla1)); var sousJacentVanilla2 = new Share("BN", "BN FP "); var maturityVanilla2 = new DateTime(2011, 9, 6); var vanilla2 = new VanillaCall("vanilla BN", sousJacentVanilla2, maturityVanilla2, 45); res.Add(new VanillaComputation(vanilla2)); var sousJacentVanilla3 = new Share("CAP", "CAP FP "); var maturityVanilla3 = new DateTime(2011, 9, 6); var vanilla3 = new VanillaCall("vanilla CAP", sousJacentVanilla3, maturityVanilla3, 35); res.Add(new VanillaComputation(vanilla3)); var sousJacentBasket1 = new Share("AC", "AI FP "); var sousJacentBasket2 = new Share("ACA", "CAP FP "); var sousJacentBasket3 = new Share("EDF", "BN FP "); var maturityBasket = new DateTime(2013, 6, 11); var basket = new BasketOption("basket AI CAP BN", new Share[] { sousJacentBasket1, sousJacentBasket2, sousJacentBasket3 }, new double[] { 0.3, 0.3, 0.4 }, maturityBasket, 9); res.Add(new BasketComputation(basket)); return(res); }
public static void Main(string[] args) { Share share1 = new Share("vodName", "vod.l"); Share share2 = new Share("ftse", "ftse"); string[] shareNames = new string[2] { "vodName", "ftseName" }; string nameBasket = "Basket"; double strikeBasket = 9; Share[] sharesBasket = { share1, share2 }; Double[] weights = { 0.3, 0.7 }; DateTime maturityBasket = new DateTime(2019, 09, 04); BasketOption optionBasket = new BasketOption(nameBasket, sharesBasket, weights, maturityBasket, strikeBasket); BasketOption optionBasket2 = new BasketOption("BASKETTT", sharesBasket, weights, maturityBasket, strikeBasket); VanillaCall optionVanille = new VanillaCall("Vanille", sharesBasket[0], maturityBasket, strikeBasket); VanillaCall optionVanille2 = new VanillaCall("Vanille2", sharesBasket[0], maturityBasket, strikeBasket); JsonHandler jsonHandle = new JsonHandler(); jsonHandle.SaveOption(optionVanille); jsonHandle.SaveOption(optionVanille); jsonHandle.SaveOption(optionVanille2); jsonHandle.SaveOption(optionBasket); jsonHandle.SaveOption(optionBasket2); jsonHandle.SaveOption(optionBasket); jsonHandle.SaveOption(optionBasket); jsonHandle.LoadOptions(); List <VanillaCall> listOptions = jsonHandle.ListVanillaCalls; List <BasketOption> listBasket = jsonHandle.ListBasketOptions; }
static void Main() { CustomerOption custOpt = new CustomerOption { FirstName = "Maria", LastName = "Pentagiotissa", Address = "Athens", Email = "*****@*****.**", }; using CrmDbContext db = new CrmDbContext(); CustomerManagement custMangr = new CustomerManagement(db); // testing the creation of a customer Customer customer = custMangr.CreateCustomer(custOpt); Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); //testing reading a customer customer = custMangr.FindCustomerById(2); if (customer != null) { Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); } //testing updating CustomerOption custChangingAddress = new CustomerOption { Address = "Lamia" }; customer = custMangr.Update(custChangingAddress, 1); Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); //testing deletion bool result = custMangr.DeleteCustomerById(2); Console.WriteLine($"Result = {result}"); customer = custMangr.FindCustomerById(2); if (customer != null) { Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); } else { Console.WriteLine("not found"); } ProductOption prOpt = new ProductOption { Name = "mila", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = 1, ProductId = 1 }; BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product.Name)); }
public void testEuroTwoValues() { // Testing two-asset European basket options... /* * Data from: * Excel spreadsheet www.maths.ox.ac.uk/~firth/computing/excel.shtml * and * "Option pricing formulas", E.G. Haug, McGraw-Hill 1998 pag 56-58 * European two asset max basket options */ BasketOptionTwoData[] values = { // basketType, optionType, strike, s1, s2, q1, q2, r, t, v1, v2, rho, result, tol // data from http://www.maths.ox.ac.uk/~firth/computing/excel.shtml new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.90, 10.898, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.70, 8.483, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.50, 6.844, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.30, 5.531, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.10, 4.413, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.50, 0.70, 0.00, 4.981, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.50, 0.30, 0.00, 4.159, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.50, 0.10, 0.00, 2.597, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.50, 0.10, 0.50, 4.030, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.90, 17.565, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.70, 19.980, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.50, 21.619, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.30, 22.932, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.10, 24.049, 1.1e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 80.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.30, 16.508, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 80.0, 80.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.30, 8.049, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 80.0, 120.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.30, 30.141, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 100.0, 120.0, 120.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.30, 42.889, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.90, 11.369, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.70, 12.856, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.50, 13.890, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.30, 14.741, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.10, 15.485, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 0.50, 0.30, 0.30, 0.10, 11.893, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 0.25, 0.30, 0.30, 0.10, 8.881, 1.0e-3), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 2.00, 0.30, 0.30, 0.10, 19.268, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.90, 7.339, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.70, 5.853, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.50, 4.818, 1.0e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.30, 3.967, 1.1e-3), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Put, 100.0, 100.0, 100.0, 0.00, 0.00, 0.05, 1.00, 0.30, 0.30, 0.10, 3.223, 1.0e-3), // basketType, optionType, strike, s1, s2, q1, q2, r, t, v1, v2, rho, result, tol // data from "Option pricing formulas" VB code + spreadsheet new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 98.0, 100.0, 105.0, 0.00, 0.00, 0.05, 0.50, 0.11, 0.16, 0.63, 4.8177, 1.0e-4), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 98.0, 100.0, 105.0, 0.00, 0.00, 0.05, 0.50, 0.11, 0.16, 0.63, 11.6323, 1.0e-4), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 98.0, 100.0, 105.0, 0.00, 0.00, 0.05, 0.50, 0.11, 0.16, 0.63, 2.0376, 1.0e-4), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Put, 98.0, 100.0, 105.0, 0.00, 0.00, 0.05, 0.50, 0.11, 0.16, 0.63, 0.5731, 1.0e-4), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Call, 98.0, 100.0, 105.0, 0.06, 0.09, 0.05, 0.50, 0.11, 0.16, 0.63, 2.9340, 1.0e-4), new BasketOptionTwoData(BasketType.MinBasket, Option.Type.Put, 98.0, 100.0, 105.0, 0.06, 0.09, 0.05, 0.50, 0.11, 0.16, 0.63, 3.5224, 1.0e-4), // data from "Option pricing formulas", E.G. Haug, McGraw-Hill 1998 pag 58 new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Call, 98.0, 100.0, 105.0, 0.06, 0.09, 0.05, 0.50, 0.11, 0.16, 0.63, 8.0701, 1.0e-4), new BasketOptionTwoData(BasketType.MaxBasket, Option.Type.Put, 98.0, 100.0, 105.0, 0.06, 0.09, 0.05, 0.50, 0.11, 0.16, 0.63, 1.2181, 1.0e-4), /* "Option pricing formulas", E.G. Haug, McGraw-Hill 1998 pag 59-60 * Kirk approx. for a european spread option on two futures*/ new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.20, 0.20, -0.5, 4.7530, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.20, 0.20, 0.0, 3.7970, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.20, 0.20, 0.5, 2.5537, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.25, 0.20, -0.5, 5.4275, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.25, 0.20, 0.0, 4.3712, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.25, 0.20, 0.5, 3.0086, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.20, 0.25, -0.5, 5.4061, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.20, 0.25, 0.0, 4.3451, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.1, 0.20, 0.25, 0.5, 2.9723, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.20, 0.20, -0.5, 10.7517, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.20, 0.20, 0.0, 8.7020, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.20, 0.20, 0.5, 6.0257, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.25, 0.20, -0.5, 12.1941, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.25, 0.20, 0.0, 9.9340, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.25, 0.20, 0.5, 7.0067, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.20, 0.25, -0.5, 12.1483, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.20, 0.25, 0.0, 9.8780, 1.0e-3), new BasketOptionTwoData(BasketType.SpreadBasket, Option.Type.Call, 3.0, 122.0, 120.0, 0.0, 0.0, 0.10, 0.5, 0.20, 0.25, 0.5, 6.9284, 1.0e-3) }; DayCounter dc = new Actual360(); Date today = Date.Today; SimpleQuote spot1 = new SimpleQuote(0.0); SimpleQuote spot2 = new SimpleQuote(0.0); SimpleQuote qRate1 = new SimpleQuote(0.0); YieldTermStructure qTS1 = Utilities.flatRate(today, qRate1, dc); SimpleQuote qRate2 = new SimpleQuote(0.0); YieldTermStructure qTS2 = Utilities.flatRate(today, qRate2, dc); SimpleQuote rRate = new SimpleQuote(0.0); YieldTermStructure rTS = Utilities.flatRate(today, rRate, dc); SimpleQuote vol1 = new SimpleQuote(0.0); BlackVolTermStructure volTS1 = Utilities.flatVol(today, vol1, dc); SimpleQuote vol2 = new SimpleQuote(0.0); BlackVolTermStructure volTS2 = Utilities.flatVol(today, vol2, dc); //double mcRelativeErrorTolerance = 0.01; //double fdRelativeErrorTolerance = 0.01; for (int i = 0; i < values.Length; i++) { PlainVanillaPayoff payoff = new PlainVanillaPayoff(values[i].type, values[i].strike); Date exDate = today + (int)(values[i].t * 360 + 0.5); Exercise exercise = new EuropeanExercise(exDate); spot1.setValue(values[i].s1); spot2.setValue(values[i].s2); qRate1.setValue(values[i].q1); qRate2.setValue(values[i].q2); rRate.setValue(values[i].r); vol1.setValue(values[i].v1); vol2.setValue(values[i].v2); IPricingEngine analyticEngine = null; GeneralizedBlackScholesProcess p1 = null, p2 = null; switch (values[i].basketType) { case BasketType.MaxBasket: case BasketType.MinBasket: p1 = new BlackScholesMertonProcess(new Handle <Quote>(spot1), new Handle <YieldTermStructure>(qTS1), new Handle <YieldTermStructure>(rTS), new Handle <BlackVolTermStructure>(volTS1)); p2 = new BlackScholesMertonProcess(new Handle <Quote>(spot2), new Handle <YieldTermStructure>(qTS2), new Handle <YieldTermStructure>(rTS), new Handle <BlackVolTermStructure>(volTS2)); analyticEngine = new StulzEngine(p1, p2, values[i].rho); break; case BasketType.SpreadBasket: p1 = new BlackProcess(new Handle <Quote>(spot1), new Handle <YieldTermStructure>(rTS), new Handle <BlackVolTermStructure>(volTS1)); p2 = new BlackProcess(new Handle <Quote>(spot2), new Handle <YieldTermStructure>(rTS), new Handle <BlackVolTermStructure>(volTS2)); analyticEngine = new KirkEngine((BlackProcess)p1, (BlackProcess)p2, values[i].rho); break; default: Utils.QL_FAIL("unknown basket type"); break; } List <StochasticProcess1D> procs = new List <StochasticProcess1D> { p1, p2 }; Matrix correlationMatrix = new Matrix(2, 2, values[i].rho); for (int j = 0; j < 2; j++) { correlationMatrix[j, j] = 1.0; } StochasticProcessArray process = new StochasticProcessArray(procs, correlationMatrix); //IPricingEngine mcEngine = MakeMCEuropeanBasketEngine<PseudoRandom, Statistics>(process) // .withStepsPerYear(1) // .withSamples(10000) // .withSeed(42); //IPricingEngine fdEngine = new Fd2dBlackScholesVanillaEngine(p1, p2, values[i].rho, 50, 50, 15); BasketOption basketOption = new BasketOption(basketTypeToPayoff(values[i].basketType, payoff), exercise); // analytic engine basketOption.setPricingEngine(analyticEngine); double calculated = basketOption.NPV(); double expected = values[i].result; double error = Math.Abs(calculated - expected); if (error > values[i].tol) { REPORT_FAILURE_2("value", values[i].basketType, payoff, exercise, values[i].s1, values[i].s2, values[i].q1, values[i].q2, values[i].r, today, values[i].v1, values[i].v2, values[i].rho, values[i].result, calculated, error, values[i].tol); } // // fd engine // basketOption.setPricingEngine(fdEngine); // calculated = basketOption.NPV(); // double relError = relativeError(calculated, expected, expected); // if (relError > mcRelativeErrorTolerance ) // { // REPORT_FAILURE_2("FD value", values[i].basketType, payoff, // exercise, values[i].s1, values[i].s2, // values[i].q1, values[i].q2, values[i].r, // today, values[i].v1, values[i].v2, values[i].rho, // values[i].result, calculated, relError, // fdRelativeErrorTolerance); // } //// mc engine //basketOption.setPricingEngine(mcEngine); //calculated = basketOption.NPV(); //relError = relativeError(calculated, expected, values[i].s1); //if (relError > mcRelativeErrorTolerance ) //{ // REPORT_FAILURE_2("MC value", values[i].basketType, payoff, // exercise, values[i].s1, values[i].s2, // values[i].q1, values[i].q2, values[i].r, // today, values[i].v1, values[i].v2, values[i].rho, // values[i].result, calculated, relError, // mcRelativeErrorTolerance); //} } }
public double PortfolioValue(BasketOption optionBasket, Share[] sharesBasket, int totalDays, double[] volatility, double[,] correlationMatrix, DateTime beginDate) { this.basket = optionBasket; SimulatedDataFeedProvider simulator = new SimulatedDataFeedProvider(); List <DataFeed> simulationBasket = simulator.GetDataFeed(optionBasket, beginDate); int numberDaysPerYear = simulator.NumberOfDaysPerYear; int size = sharesBasket.Length; // Number of Shares double[] spotsPrev = new double[size]; // Array that will stock the spots values of the last rebalancing spotsPrev = fillSpots(simulationBasket[0], sharesBasket, size); // We initialize the array with the spots of the first day of analysis /* Calculation of the option price and the initial composition of the portfolio */ Pricer pricer = new Pricer(); PricingResults pricesResults = pricer.PriceBasket(optionBasket, beginDate, numberDaysPerYear, spotsPrev, volatility, correlationMatrix); double priceBasket = pricesResults.Price; double[] deltaPrev = new double[size]; deltaPrev = pricesResults.Deltas; double cashRiskFreePrev = priceBasket - dotArrays(deltaPrev, spotsPrev, size); this.portfolioValue = priceBasket; this.basketPriceInit = priceBasket; int index = 0; double[] delta = new double[size]; double[] spots = new double[size]; double cashRiskFree = 0; double variationCashRisk = 0; double freeRate = 0; double cashRisk = 0; DateTime today; double[] optionValue = new double[totalDays]; double[] portfolioValue = new double[totalDays]; double payoff = 0; /* Arrays used for the plot */ optionValue[0] = pricesResults.Price; portfolioValue[0] = this.portfolioValue; foreach (DataFeed data in simulationBasket) { if (index != 0 && index != totalDays) { cashRisk = 0; variationCashRisk = 0; today = data.Date; /* Update spots */ spots = fillSpots(data, sharesBasket, size); /* Update priceResults */ pricesResults = pricer.PriceBasket(optionBasket, today, numberDaysPerYear, spots, volatility, correlationMatrix); /* Update deltas */ delta = pricesResults.Deltas; /* Update cashRisk */ cashRisk = dotArrays(delta, spots, size); variationCashRisk = dotArrays(minusArrays(deltaPrev, delta, size), spots, size); freeRate = RiskFreeRateProvider.GetRiskFreeRateAccruedValue(1 / numberDaysPerYear); /* Update cashRiskFree */ cashRiskFree = variationCashRisk + cashRiskFreePrev * freeRate; /* Update portfolioValue */ this.portfolioValue = cashRiskFree + cashRisk; /* Memorize the delta and the cashRiskFree calculated for the next balancing */ deltaPrev = delta; cashRiskFreePrev = cashRiskFree; optionValue[index] = pricesResults.Price; portfolioValue[index] = this.portfolioValue; } else if (index == totalDays) { payoff = optionBasket.GetPayoff(data.PriceList); } index++; } /* Partie traçage de courbes */ using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\ensimag\Desktop\PortfolioBasketOption.txt")) { for (int i = 0; i < totalDays; i++) { // If the line doesn't contain the word 'Second', write the line to the file. file.WriteLine(optionValue[i]); file.WriteLine(portfolioValue[i]); } } return((this.portfolioValue - payoff) / this.basketPriceInit); }
public PortfolioBasket(double portfolioValue, BasketOption basket) { this.portfolioValue = portfolioValue; this.basketPriceInit = portfolioValue; this.basket = basket; }
// Action déclenché à l'appui sur le bouton start private void StartTicker() { // Déclaration des paramètres DateTime maturity = new DateTime(2014, 12, 20); DateTime initialDate = new DateTime(2013, 1, 20); DateTime estimationDate = new DateTime(); int windowLength = 10; int numberOfDaysPerYear = 0; double strike = 0; List<Share> shareList = new List<Share>(); List<DataFeed> dataFeedList = new List<DataFeed>(); if (SelectedOption == "Vanilla Call") { if (Simulated) { // ----------- Vanilla Call donnees simulees -------- // Parametrage strike = 8; estimationDate = Utilities.getEstimationDateForSimulatedData(initialDate, windowLength); shareList.Add(new Share("BNP PARIBAS", "BNP FP")); // Creation de l'option Option option = new VanillaCall("Vanilla Call", shareList.ToArray(), maturity, strike); // Récupération des donnes simulées IDataFeedProvider data = new SimulatedDataFeedProvider(); dataFeedList = data.GetDataFeed(option, estimationDate); numberOfDaysPerYear = data.NumberOfDaysPerYear; // Fournisseur de composition du portefeuille de réplication CompositionProvider compositionProvider = new VanillaCompositionProvider(option); // Main partagé sharedMain(option, compositionProvider, dataFeedList, shareList, initialDate, strike, maturity, windowLength, numberOfDaysPerYear, Simulated); } else { // ----------- Vanilla Call donnees historiques -------- strike = 35; estimationDate = Utilities.getEstimationDateForHistoricalData(initialDate, windowLength); shareList.Add(new Share("BNP PARIBAS", "BNP FP")); Option option = new VanillaCall("Vanilla Call", shareList.ToArray(), maturity, strike); IDataFeedProvider data = new HistoricalDataFeedProvider("historicalData", 365); dataFeedList = data.GetDataFeed(option, estimationDate); numberOfDaysPerYear = data.NumberOfDaysPerYear; CompositionProvider compositionProvider = new VanillaCompositionProvider(option); sharedMain(option, compositionProvider, dataFeedList, shareList, initialDate, strike, maturity, windowLength, numberOfDaysPerYear, Simulated); } } else if (SelectedOption == "Basket Option") { if (Simulated) { // ----------- Basket option donnees simulees -------- strike = 8; estimationDate = Utilities.getEstimationDateForSimulatedData(initialDate, windowLength); shareList.Add(new Share("BNP PARIBAS", "BNP FP")); shareList.Add(new Share("ACCOR SA", "ALO FP")); double[] weights = { 0.3, 0.7 }; Option option = new BasketOption("Basket option", shareList.ToArray(), weights, maturity, strike); IDataFeedProvider data = new SimulatedDataFeedProvider(); dataFeedList = data.GetDataFeed(option, estimationDate); numberOfDaysPerYear = data.NumberOfDaysPerYear; CompositionProvider compositionProvider = new BasketCompositionProvider(option); sharedMain(option, compositionProvider, dataFeedList, shareList, initialDate, strike, maturity, windowLength, numberOfDaysPerYear, Simulated); } else { // ----------- Basket option donnees historiques -------- strike = 35; estimationDate = Utilities.getEstimationDateForHistoricalData(initialDate, windowLength); shareList.Add(new Share("BNP PARIBAS", "BNP FP")); shareList.Add(new Share("ACCOR SA", "ALO FP")); double[] weights = { 0.3, 0.7 }; Option option = new BasketOption("Basket option", shareList.ToArray(), weights, maturity, strike); IDataFeedProvider data = new HistoricalDataFeedProvider("historicalData", 365); dataFeedList = data.GetDataFeed(option, estimationDate); numberOfDaysPerYear = data.NumberOfDaysPerYear; CompositionProvider compositionProvider = new BasketCompositionProvider(option); sharedMain(option, compositionProvider, dataFeedList, shareList, initialDate, strike, maturity, windowLength, numberOfDaysPerYear, Simulated); } } }
public static void Main() { //CustomerOption custOpt = new CustomerOption //{ // FirstName = "Tester222", // LastName = "Test", // Address = "TestCity", // Email = "*****@*****.**", //}; using CrmAppDbContext db = new CrmAppDbContext(); CustomerManagement custMangr = new CustomerManagement(db); ////testing the creation of a customer //Customer customer = custMangr.CreateCustomer(custOpt); //Console.WriteLine( //$"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing reading a customer //customer = custMangr.FindCustomerById(2); //if (customer != null) // Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing updating //CustomerOption custChangingAddress = new CustomerOption //{ // Address = "Lamia" //}; //customer = custMangr.Update(custChangingAddress, 1); //Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing deletion //bool result = custMangr.DeleteCustomerById(2); //Console.WriteLine($"Result = {result}"); //customer = custMangr.FindCustomerById(2); //if (customer != null) //{ // Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); //} //else //{ // Console.WriteLine("not found"); //} ProductOption prOpt = new ProductOption { Name = "portokalia", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 5 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; //System.NullReferenceException BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach( baskProduct => Console.WriteLine( db.BasketProducts .Include(b => b.Product) .Where(b => b.Id == baskProduct.Id) .First() .Product.Name) ); Console.ReadLine(); }
public static string eqInstSpreadOptionMonteCarlo( [ExcelArgument(Description = "id of option to be constructed ")] string ObjectId, [ExcelArgument(Description = "Option type (Call/Put) ")] string optype, [ExcelArgument(Description = "Spot price leg 1")] double spot1, [ExcelArgument(Description = "Spot price leg 2")] double spot2, [ExcelArgument(Description = "Strike price ")] double stirkeprice, [ExcelArgument(Description = "Expiry Date ")] DateTime exdate, [ExcelArgument(Description = "Risk free rate ")] double riskfreerate, [ExcelArgument(Description = "Black-Scholes Vol for leg 1 ")] double vol1, [ExcelArgument(Description = "Black-Scholes Vol for leg 2 ")] double vol2, [ExcelArgument(Description = "correlation between leg 1 and leg 2 ")] double corr, [ExcelArgument(Description = "DayCounter ")] string daycounter, [ExcelArgument(Description = "Calendar ")] string calendar, [ExcelArgument(Description = "Pseudorandom (pr) or lowdiscrepancy (ld) ")] string traits, [ExcelArgument(Description = "trigger ")] object trigger) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); try { if (exdate == DateTime.MinValue) { throw new Exception("Date must not be empty. "); } if (ExcelUtil.isNull(daycounter)) { daycounter = "ACTUAL365"; } if (ExcelUtil.isNull(calendar)) { calendar = "NYC"; } if (ExcelUtil.isNull(traits)) { traits = "pr"; } Option.Type optiontype; if (optype.ToUpper() == "CALL") { optiontype = Option.Type.Call; } else if (optype.ToUpper() == "PUT") { optiontype = Option.Type.Put; } else { throw new Exception("Unknow option type"); } EliteQuant.Calendar cal = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar); EliteQuant.DayCounter dc = EliteQuant.EQConverter.ConvertObject <EliteQuant.DayCounter>(daycounter); EliteQuant.Date maturitydate = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(exdate); EliteQuant.Date today = EliteQuant.Settings.instance().getEvaluationDate(); EliteQuant.Date settlementdate = today; // T+2 if (maturitydate.serialNumber() <= today.serialNumber()) { throw new Exception("Option already expired."); } YieldTermStructureHandle rTSH = new YieldTermStructureHandle( new FlatForward(settlementdate, riskfreerate, dc)); BlackVolTermStructureHandle flatVolTSH1 = new BlackVolTermStructureHandle( new BlackConstantVol(settlementdate, cal, vol1, dc)); BlackVolTermStructureHandle flatVolTSH2 = new BlackVolTermStructureHandle( new BlackConstantVol(settlementdate, cal, vol2, dc)); Quote qh1 = new SimpleQuote(spot1); Quote qh2 = new SimpleQuote(spot2); QuoteHandle s1 = new QuoteHandle(qh1); QuoteHandle s2 = new QuoteHandle(qh2); BlackProcess p1 = new BlackProcess(s1, rTSH, flatVolTSH1); BlackProcess p2 = new BlackProcess(s2, rTSH, flatVolTSH2); StochasticProcessVector spv = new StochasticProcessVector(2); spv.Add(p1); spv.Add(p2); Matrix corrmtrx = new Matrix(2, 2); corrmtrx.set(0, 0, 1.0); corrmtrx.set(1, 1, 1.0); corrmtrx.set(0, 1, corr); corrmtrx.set(1, 0, corr); StochasticProcessArray spa = new StochasticProcessArray(spv, corrmtrx); PricingEngine engine = new MCEuropeanBasketEngine(spa, traits, 100, 1, false, true, 5000, 1e-6); Payoff payoff1 = new PlainVanillaPayoff(optiontype, stirkeprice); Payoff payoff2 = new SpreadBasketPayoff(payoff1); Exercise exercise = new EuropeanExercise(maturitydate); BasketOption bo = new BasketOption(payoff2, exercise); bo.setPricingEngine(engine); // Store the option and return its id string id = "OPTION@" + ObjectId; OHRepository.Instance.storeObject(id, bo, callerAddress); id += "#" + (String)DateTime.Now.ToString(@"HH:mm:ss"); return(id); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return("#EQ_ERR!"); } }
public BasketComputation(BasketOption b) : base(b) { Basket = b; }
public BasketOptionPricer(BasketOption opt) : base(opt) { }
public static object eqInstGetOptionGreeks( [ExcelArgument(Description = "id of option ")] string ObjectId, [ExcelArgument(Description = "Greek type ")] string gtype, [ExcelArgument(Description = "Option type (VANILLA or MULTIASSET)")] string otype, [ExcelArgument(Description = "trigger ")] object trigger) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); try { Xl.Range rng = ExcelUtil.getActiveCellRange(); if (ExcelUtil.isNull(gtype)) { gtype = "NPV"; } if (ExcelUtil.isNull(otype)) { otype = "VANILLA"; } if (otype == "VANILLA") { VanillaOption option = OHRepository.Instance.getObject <VanillaOption>(ObjectId); switch (gtype.ToUpper()) { case "NPV": return(option.NPV()); case "DELTA": return(option.delta()); case "GAMMA": return(option.gamma()); case "VEGA": return(option.vega()); case "THETA": return(option.theta()); case "RHO": return(option.rho()); default: return(0); } } else if (otype == "MULTIASSET") { BasketOption option = OHRepository.Instance.getObject <BasketOption>(ObjectId); switch (gtype.ToUpper()) { case "NPV": return(option.NPV()); case "DELTA": return(option.delta()); case "GAMMA": return(option.gamma()); case "VEGA": return(option.vega()); case "THETA": return(option.theta()); case "RHO": return(option.rho()); default: return(0); } } else { return("Unknown option type"); } } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return("#EQ_ERR!"); } }
static void Main2() { CustomerOption custOpt = new CustomerOption { FirstName = "John", LastName = "XCV", Adress = "Thessaloniki", Email = "*****@*****.**", }; using CrmDbContext db = new CrmDbContext(); CustomerManagement custMngr = new CustomerManagement(db); Customer customer = custMngr.CreateCustomer(custOpt); Console.WriteLine($"Id={customer.Id} Name={customer.FirstName} Adress={customer.Adress}"); Customer cx = custMngr.FindCustomerById(2); Console.WriteLine($"Id={cx.Id} Name={cx.FirstName} Adress={cx.Adress}"); CustomerOption custChangingAdress = new CustomerOption { Adress = "Lamia" }; Customer c2 = custMngr.Update(custChangingAdress, 1); Console.WriteLine($"Id={c2.Id} Name={c2.FirstName} Adress={c2.Adress}"); bool result = custMngr.DeleteCustomerById(2); Console.WriteLine($"Result={result}"); Customer cx2 = custMngr.FindCustomerById(2); if (cx2 != null) { Console.WriteLine($"Id={cx2.Id} Name={cx2.FirstName} Adress={cx2.Adress}"); } else { Console.WriteLine("Not found"); } ProductOption prOpt = new ProductOption { Name = "apples", Price = 1.20m, Quantity = 10 }; ProductManagement prodMngr = new ProductManagement(db); Product product = prodMngr.CreateProduct(prOpt); BasketManagement baskMngr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMngr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; BasketProduct baskProd = baskMngr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product)); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BasketOption obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }