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 static double UpdatePortfolio(DateTime maturity, double risklessRate, DateTime date, SimulatedDataFeedProvider data, VanillaCall call, int nbDaysPerYear, double volatility) { List <DataFeed> spotList = data.GetDataFeed(call, date); // decimal spot = spotList[0].PriceList[call.UnderlyingShare.Id]; PricingResults price; price = Pricer.PriceCall(call, date, nbDaysPerYear, (double)spot, volatility); // double pricePortfolio = price.Price; double delta = price.Deltas[0]; double riskyPosition = delta; //Dictionary<string, decimal> price = datafeed.PriceList.TryGetValue(call.Name,out 0); double riskFreePosition = pricePortfolio - delta * (double)spot; while (date < maturity) { date.AddDays(1); spotList = data.GetDataFeed(call, date); // spot = spotList[0].PriceList[call.UnderlyingShare.Id]; pricePortfolio = riskyPosition * (double)spot + riskFreePosition * Math.Exp(risklessRate / 365); price = Pricer.PriceCall(call, date, nbDaysPerYear, (double)spot, volatility); // delta = price.Deltas[0]; riskyPosition = delta; riskFreePosition = pricePortfolio - delta * (double)spot; } return(riskyPosition * (double)spot + riskFreePosition * Math.Exp(risklessRate / 365)); }
public override double CalculerPrix(int jour, AbstractData donnees, double[] spot, double[,] corr, double[] vol) { Pricer pricer = new Pricer(); DateTime dateAvancee = donnees.listeDate[jour]; double prix = pricer.PriceCall((VanillaCall)this.option, dateAvancee, 365, spot[0], vol[0]).Price; return(prix); }
public override double[] CalculerDeltas(int jour, AbstractData donnees, double[] vol, double[,] corr, double[] spot) { Pricer pricer = new Pricer(); DateTime dateAvancee = donnees.listeDate[jour]; double[] deltas = pricer.PriceCall((VanillaCall)this.option, dateAvancee, 365, spot[0], vol[0]).Deltas; return(deltas); }
public Balancement(DataFeed data) { DateTime dateDebut = DateTime.Now; VanillaCall option = new VanillaCall("Vanilla Call", new Share("VanillaShare", "1"), new DateTime(2019, 12, 04), 8); var priceList = dataFeedProvider.GetDataFeed(option, dateDebut); //Je pense en fait que la fonction Pricer c'est la fonction doit être un fonction qui renvoit pricedelta et du //coup c'est la bas qu'on differencie les baskets des vanilles pricer = new Pricer(); PricingResults priceDelta = pricer.PriceCall(option, dateDebut, dataFeedProvider.NumberOfDaysPerYear, Convert.ToDouble(priceList[0].PriceList[option.UnderlyingShareIds[1]]), 0.25); Dictionary <string, double> compo = new Dictionary <string, double> { }; int i = 1; foreach (string id in option.UnderlyingShareIds) { compo[id] = priceDelta.Deltas[i]; i += 1; } // Le premier argument de portefeuille doit être le prix de l'option en 0; //Le deuxième la compo //le troisième le prix des actifs en 0 List <decimal> priceOption = new List <decimal> { Convert.ToDecimal(priceDelta.Price) }; Portfolio portfolio = new Portfolio(priceOption, compo, priceList[0].PriceList); //Traitement des données foreach (DataFeed priceAsset_t in priceList.Skip(1)) { priceDelta = pricer.PriceCall(option, dateDebut, dataFeedProvider.NumberOfDaysPerYear, Convert.ToDouble(priceAsset_t.PriceList[option.UnderlyingShareIds[1]]), 0.25); //updateCompo foreach (string id in option.UnderlyingShareIds) { compo[id] = priceDelta.Deltas[i]; i += 1; } portfolio.UpdatePortfolioValue(priceAsset_t, dataFeedProvider.NumberOfDaysPerYear, periodeRebalancement); portfolio.UpdateCompo(compo); } }
/* * Method to calculate all the pricings in between a certain date and the maturity. * * */ 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(); } List <PricingResults> listPrix = new List <PricingResults>(); List <DataFeed> listdf = new List <DataFeed>(listDataFeed); VanillaCall vanny = new VanillaCall(oName, oShares, oMaturity, oStrike); while (listdf.Count > oObservation) { calculVolatility(listdf); double listPrice = (double)listdf[oObservation].PriceList[oShares[0].Id]; oSpot[0] = listPrice; listPrix.Add(vanillaPricer.PriceCall(vanny, listdf[oObservation].Date, businessDays, oSpot[0], oVolatility[0])); vanillaPricer.PriceCall(vanny, listdf[oObservation].Date, businessDays, oSpot[0], oVolatility[0]); listdf.RemoveAt(0); } return(listPrix); }
public static void Main(string[] args) { int strike = 9; double volatility = 0.4; DateTime maturity = new DateTime(2019, 09, 04); DateTime beginDate = new DateTime(2018, 09, 04); int totalDays = DayCount.CountBusinessDays(beginDate, maturity); Share[] share = { new Share("Sfr", "1254798") }; if (share.Length == 1) { VanillaCall callOption = new VanillaCall("Vanille", share[0], maturity, strike); /* Simulated data feeds : */ SimulatedDataFeedProvider simulator = new SimulatedDataFeedProvider(); List <DataFeed> dataFeeds = simulator.GetDataFeed(callOption, beginDate); int numberOfDaysPerYear = simulator.NumberOfDaysPerYear; /* Portfolio initialisation : */ Portfolio portfolio = new Portfolio(); portfolio.PortfolioComposition = new Dictionary <String, double>(); Pricer pricer = new Pricer(); double spot = (double)dataFeeds[0].PriceList[share[0].Id]; PricingResults pricingResults = pricer.PriceCall(callOption, beginDate, totalDays, spot, volatility); double callPrice = pricingResults.Price; portfolio.FirstPortfolioValue = callPrice; portfolio.CurrentPortfolioValue = callPrice; portfolio.CurrentDate = beginDate; double previousDelta = pricingResults.Deltas[0]; portfolio.PortfolioComposition.Add(share[0].Id, previousDelta); double payoff = 0; double[] optionValue = new Double[totalDays]; double[] portfolioValue = new Double[totalDays]; optionValue[0] = callPrice; portfolioValue[0] = portfolio.CurrentPortfolioValue; int indexArrays = 1; /* Skip the first day : because it's already initialized*/ foreach (DataFeed data in dataFeeds.Skip(1)) { if (data != dataFeeds.Last()) { portfolio.updateValue(spot, data, pricer, callOption, volatility, numberOfDaysPerYear); spot = updateSpot(data, share[0]); double pricing = getPricingResult(data, callOption, pricer, volatility, numberOfDaysPerYear); /* Fill arrays of optionValue and portfolioValue */ optionValue[indexArrays] = pricing; portfolioValue[indexArrays] = portfolio.CurrentPortfolioValue; Console.WriteLine("Valeur option = " + optionValue[indexArrays]); Console.WriteLine("Valeur portefeuille = " + portfolioValue[indexArrays]); } /* For the last day : */ else { portfolio.CurrentDate = data.Date; payoff = callOption.GetPayoff(data.PriceList); } indexArrays++; } /* Partie traçage de courbes */ using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\ensimag\Desktop\WriteLines.txt")) { for (int index = 0; index < totalDays; index++) { // If the line doesn't contain the word 'Second', write the line to the file. file.WriteLine(optionValue[index]); file.WriteLine(portfolioValue[index]); } } //double valuePortfolio = (portfolio.currentPortfolioValue - payoff) / portfolio.firstPortfolioValue; //Console.WriteLine("Valeur = " + valuePortfolio); Portfolio portefolioTest = new Portfolio(); double finalportfolioValue = portfolio.updatePortfolio(pricer, callOption, dataFeeds, numberOfDaysPerYear, share[0], totalDays, volatility, beginDate); Console.WriteLine("Valeur = " + finalportfolioValue); } }
override protected PricingResults ComputePricing(int dateIndex, double[] volatility, double[,] correlation) { var pricer = new Pricer(); return(pricer.PriceCall(Vanilla, MarketDataDates[dateIndex], 365, Spots[dateIndex][0], volatility[0])); }
public PricingResults pricingResult() { Pricer pricer = new Pricer(); return(pricer.PriceCall((VanillaCall)option, date, nbJourParAn, spotPrice, 0.4)); }