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 List <decimal> GetPayOff()
        {
            List <decimal> payoffs = new List <decimal>();
            int            periodeRebalancement = 1;
            var            priceList            = dataFeedProvider.GetDataFeed(option, dateDebut);

            for (var i = 1; i < priceList.Count; i += periodeRebalancement)
            {
                var     element   = priceList[i];
                decimal spotPrice = element.PriceList["1"];
                payoffs.Add(Math.Max(spotPrice - Convert.ToDecimal(Strike), 0));
            }
            return(payoffs);
        }
Exemplo n.º 3
0
        // Crée une liste de resultats (l'évolution du portefeuille de l'option sur la durée demandée)
        public List <TrackedResults> computePortfolioEvolution(DateTime testStart, DateTime testEnd,
                                                               int rebalancingPeriod, int estimationPeriod)
        {
            List <TrackedResults> res  = new List <TrackedResults>();
            List <DataFeed>       data = dataFeedProvider.GetDataFeed(optionPricer.Opt.UnderlyingShareIds, testStart,
                                                                      optionPricer.Opt.Maturity); // Données totales

            /* Calcul des portefeuilles sur toute la période */
            int             i           = 0;
            List <DataFeed> pricingData = data.GetRange(i * rebalancingPeriod, estimationPeriod);

            while (DateTime.Compare(pricingData.Last().Date, testEnd) < 0 && ((i + 1) * rebalancingPeriod + estimationPeriod) < data.Count)
            {
                int nRebalacingDays = 0;
                if (i != 0)
                {
                    nRebalacingDays = (pricingData.Last().Date - data[(i - 1) * rebalancingPeriod + estimationPeriod].Date).Days;
                }
                updateResults(pricingData, i, nRebalacingDays);
                res.Add(new TrackedResults(results));
                i++;
                pricingData = data.GetRange(i * rebalancingPeriod, estimationPeriod);
            }
            return(res);
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
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;
                }
            }
        }
Exemplo n.º 6
0
        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);
            }
        }