// // Abstract: // Update managerVM's attributs. // // Parameters: // theDate: // DateTime where the modeling should be ran. // // estWindow: // String containing the period where the model should be ran. // // frequency: // String containing the step where portefolio is reshuffled. public void PleaseUpdateManager(DateTime theDate, string estmWindow, string frequency, IDataFeedProvider simulator, FinancialComputation opt) { StartDate = theDate; SampleNumber = Int32.Parse(estmWindow); Step = Int32.Parse(frequency); marketSimulator = simulator; option = opt; option.MarketDataDates.Clear(); var window = 20; var res = option.GenChartData(window, StartDate, Step, marketSimulator); ValPayOff = option.PayOff; ValPortfolio = res.PortfolioValue.Last().Value; Labels = GetDateSet(option.MarketDataDates); optp.Clear(); pfp.Clear(); trackingError.Clear(); for (int i = 0; i < res.OptionPrice.Count; i++) { optp.Insert(i, res.OptionPrice[i]); pfp.Insert(i, res.PortfolioValue[i].Value); trackingError.Insert(i, res.OptionPrice[i] - res.PortfolioValue[i].Value); } }
public SimulationModel(IOption option, IDataFeedProvider dataFeedProvider, DateTime dateDebut, int plageEstimation) { this.option = option ?? throw new ArgumentNullException("Option should not be null"); this.dataFeedProvider = dataFeedProvider ?? throw new ArgumentNullException("dataFeed should not be null"); if (dateDebut == null) { throw new ArgumentNullException("Beginning date should not be null"); } this.dateDebut = new DateTime(2012, 9, 10); if (plageEstimation < 2) { throw new ArgumentOutOfRangeException("Estimation duration should be upper than 2 days"); } this.plageEstimation = plageEstimation; Estimateur.dispMatrix(Estimateur.getCovMatrix(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14))); if (option.GetType().ToString().EndsWith("VanillaCall")) { Console.WriteLine("Volatilité: " + Estimateur.Volatilite(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14), new double[] { 1 }, dataFeedProvider)); } else if (option.GetType().ToString().EndsWith("BasketOption")) { Console.WriteLine("Volatilité: " + Estimateur.Volatilite(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14), ((BasketOption)option).Weights, dataFeedProvider)); } Estimateur.dispMatrix(Estimateur.getCorrMatrix(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14))); Console.WriteLine("Correlation moyenne: " + Estimateur.Correlation(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14))); }
public PortfolioManager(OptionPricer optionPricer, IDataFeedProvider dataFeedProvider) { this.dataFeedProvider = dataFeedProvider; this.optionPricer = optionPricer; results = new TrackedResults(); deltas = new double[optionPricer.Opt.UnderlyingShareIds.Length]; }
private void GetSpots(DateTime beginningTest, IDataFeedProvider simulateMarket) {//Get all the spots of the underlying asset from the debTest date to the maturity date Spots.Clear(); var firstDateMarket = simulateMarket.GetMinDate(); if (beginningTest.Date < firstDateMarket.Date) { throw new Exception("No Market data before the " + firstDateMarket.ToShortDateString()); } if (beginningTest.Date > Option.Maturity.Date) { throw new Exception("No Market data after the Maturity date (" + Option.Maturity.ToShortDateString() + ")"); } var dataFeed = simulateMarket.GetDataFeed(Option, beginningTest); if (dataFeed.Count() == 0) { throw new Exception("No Market data"); } foreach (DataFeed d in dataFeed) { var spotList = new List <double>(); foreach (string shareId in Option.UnderlyingShareIds) { spotList.Add((double)d.PriceList[shareId]); } Spots.Add(spotList.ToArray()); MarketDataDates.Add(d.Date); } PayOff = computePayOff(); }
public InitializerViewModel() { debutTest = DateTime.Now; maturity = new DateTime(2019, 6, 7); plageEstimation = 15; typeData = new SimulatedDataFeedProvider(); strike = 8; }
public Balancement(IDataFeedProvider dataFeedProvider, IOption option, DateTime dateTmpDebut, int plageEstimation, int periodeRebalancement) { var dateDebut = new DateTime(dateTmpDebut.Year, dateTmpDebut.Month, dateTmpDebut.Day); var priceList = dataFeedProvider.GetDataFeed(option, dateDebut); payoff = payOffaMaturite(option, priceList); pricer = new Pricer(); hedge = new List <decimal>(); priceOption = new List <double>(); dates = new List <DateTime>(); Dictionary <string, double> compo = new Dictionary <string, double> { }; volatilite = Estimateur.Volatilite(priceList, plageEstimation, dateDebut.AddDays(plageEstimation), option, dataFeedProvider); matrixCorrelation = Estimateur.getCorrMatrix(priceList, plageEstimation, dateDebut.AddDays(plageEstimation)); Estimateur.dispMatrix(matrixCorrelation); PricingResults priceDelta = PriceResults(option, priceList[0].PriceList, dateDebut, dataFeedProvider); int i = 0; foreach (string id in option.UnderlyingShareIds) { compo[id] = priceDelta.Deltas[i]; i += 1; } DateTime oldBalancement = dateDebut; portfolio = new Portfolio(Convert.ToDecimal(priceDelta.Price), compo, priceList[0].PriceList); priceOption.Add(priceDelta.Price); hedge.Add(portfolio.portfolioValue); dates.Add(priceList[0].Date); foreach (DataFeed priceAsset_t in priceList.Skip(1)) { if (DayCount.CountBusinessDays(oldBalancement, priceAsset_t.Date) >= periodeRebalancement || priceAsset_t == priceList.Last()) { priceDelta = PriceResults(option, priceAsset_t.PriceList, dateDebut, dataFeedProvider); priceOption.Add(priceDelta.Price); portfolio.UpdatePortfolioValue(priceAsset_t, dataFeedProvider.NumberOfDaysPerYear, oldBalancement); i = 0; foreach (string id in option.UnderlyingShareIds) { compo[id] = priceDelta.Deltas[i]; i += 1; } hedge.Add(portfolio.portfolioValue); dates.Add(priceAsset_t.Date); portfolio.UpdateLiquidity(priceAsset_t); portfolio.UpdateCompo(compo); oldBalancement = priceAsset_t.Date; } } }
// // Abstract: // Creates a new instance of FBT.ViewModel.ManagerVM with the date to start estimation // with a set estimation window and a specific frequency of reshuffle to invoke Model // // Parameters: // theDate: // The starting date to invoke modeling. // // estmWindow: // The estimated window - number of days - where the model is going to be ran // // frequency: // The frequency of reshuffle the portefolio public ManagerVM(DateTime theDate, string estmWindow, string frequency, IDataFeedProvider simulator, FinancialComputation opt) { StartDate = theDate; SampleNumber = Int32.Parse(estmWindow); Step = Int32.Parse(frequency); Labels = GetDateSet(new List <DateTime>()); marketSimulator = simulator; option = opt; optp = new ChartValues <double>(); pfp = new ChartValues <double>(); trackingError = new ChartValues <double>(); }
public SimulationModel(IOption option, IDataFeedProvider dataFeedProvider, DateTime dateDebut, int plageEstimation, int periodeRebalancement) { this.option = option; if (this.option == null) { MessageBox.Show("Option should not be null, previous option was taken"); } this.dataFeedProvider = dataFeedProvider; if (this.dataFeedProvider == null) { MessageBox.Show("dataFeed should not be null, previous datafeed was taken"); } if (dateDebut == null) { MessageBox.Show("Beginning date should not be null"); } if (dateDebut.DayOfWeek.ToString() == "Saturday" || dateDebut.DayOfWeek.ToString() == "Sunday") { MessageBox.Show("Beginning date is not a business day"); } this.dateDebut = dateDebut; if (plageEstimation < 2) { MessageBox.Show("plage estimation should be at least 2, , previous plageEstimation was taken "); } this.plageEstimation = plageEstimation; if (periodeRebalancement <= 0) { MessageBox.Show("Rebalancement period should be positive, previous periode for rebalancement was taken "); } if (option.Strike <= 0) { MessageBox.Show("Strike should be positive, previous strike was taken"); } this.balancement = new Balancement(dataFeedProvider, option, dateDebut, plageEstimation, periodeRebalancement); }
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 Volatilite(List <DataFeed> dataList, int joursDEstimation, DateTime dateActuelle, IOption option, IDataFeedProvider dataFeedProvider) { double[,] covMatrix = getCovMatrix(dataList, joursDEstimation, dateActuelle); if (option is BasketOption) { covMatrix = matrixWithWeight(covMatrix, ((BasketOption)option).Weights); } double variancePortefeuille = 0; for (int i = 0; i < covMatrix.GetLength(0); i++) { for (int j = 0; j < covMatrix.GetLength(1); j++) { variancePortefeuille += covMatrix[i, j]; } } return(Math.Sqrt(variancePortefeuille) * Math.Sqrt(dataFeedProvider.NumberOfDaysPerYear)); }
public PriceOpValPort GenChartData(int estimationWindow, DateTime beginningTest, int rebalancingStep, IDataFeedProvider simulateMarket) { GetSpots(beginningTest, simulateMarket); var priceOpt = new List <double>(); var valPort = new List <Portfolio>(); //The first datafeed considered is the one at date window var volatility = ComputeVolatility(estimationWindow, estimationWindow, rebalancingStep); var correlation = ComputeCorrelation(estimationWindow, estimationWindow); var pricingRes = ComputePricing(estimationWindow, volatility, correlation); var valPortFolio = pricingRes.Price; var deltas = pricingRes.Deltas; var initialSpots = Spots[estimationWindow]; var consideredPortfolio = new Portfolio(valPortFolio, deltas, initialSpots); priceOpt.Add(pricingRes.Price); valPort.Add(new Portfolio(consideredPortfolio)); for (var i = estimationWindow + 1; i < Spots.Count; i++) {//For each data feed except the first one pricingRes = ComputePricing(i, volatility, correlation); consideredPortfolio.UpdateValue(Spots[i]); if ((i - estimationWindow) % rebalancingStep == 0) {//if there is a rebalancing volatility = ComputeVolatility(estimationWindow, i, rebalancingStep); correlation = ComputeCorrelation(estimationWindow, i); consideredPortfolio.Deltas = pricingRes.Deltas; } consideredPortfolio.UpdateFreeRiskDelta(Spots[i]); priceOpt.Add(pricingRes.Price); valPort.Add(new Portfolio(consideredPortfolio)); } return(new PriceOpValPort(valPort, priceOpt)); }