示例#1
0
        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));
        }
示例#2
0
        /*
         * 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);
        }
示例#3
0
        public override List <DataFeed> genereData(DateTime debut)
        {
            var dataFeedCalc       = new List <DataFeed>();
            IDataFeedProvider data = new SimulatedDataFeedProvider();

            dataFeedCalc   = data.GetDataFeed(this.option.option, debut);
            this.donnees   = dataFeedCalc;
            this.listeDate = new List <DateTime>();
            var dates = new List <DateTime>();

            for (var dt = debut; dt <= option.option.Maturity; dt = dt.AddDays(1))
            {
                this.listeDate.Add(dt);
            }
            return(dataFeedCalc);
        }
示例#4
0
        public void getDataSimul()
        {
            Console.WriteLine("debut de la generation de data");

            var               dataFeedCalc = new List <DataFeed>();
            DateTime          dateDebut    = new DateTime(2010, 1, 1);
            DateTime          dateFin      = new DateTime(2009, 1, 1);
            Share             action1      = new Share("accordId", "accordId");
            VanillaCall       vanille1     = new VanillaCall("accordId", action1, dateDebut, 10);
            IDataFeedProvider data         = new SimulatedDataFeedProvider();

            dataFeedCalc = data.GetDataFeed(vanille1, dateFin);
            Console.WriteLine(dataFeedCalc[0].Date);
            Console.WriteLine(dataFeedCalc[0].PriceList.ToString());
            decimal a = 10;

            dataFeedCalc[50].PriceList.TryGetValue("accordId", out a);
            Console.WriteLine(a);
            Console.WriteLine("fin");
        }
示例#5
0
        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);
            }
        }
示例#6
0
        public List <DataFeed> GetDataFeeds(IOption option, DateTime from)
        {
            SimulatedDataFeedProvider simulateur = new SimulatedDataFeedProvider();

            return(simulateur.GetDataFeed(option, from));
        }
示例#7
0
        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);
        }
示例#8
0
        // 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);
                }
            }
        }
示例#9
0
        public List <DataFeed> getDataSimulation()
        {
            var dataProvider = new SimulatedDataFeedProvider();

            return(dataProvider.GetDataFeed(Option, DateDebut));
        }