Exemplo n.º 1
0
 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)));
 }
Exemplo n.º 2
0
        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;
                }
            }
        }