Example #1
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);
        }
 public InitializerViewModel()
 {
     debutTest            = DateTime.Now;
     maturity             = new DateTime(2019, 6, 7);
     plageEstimation      = 15;
     typeData             = new SimulatedDataFeedProvider();
     strike               = 8;
     periodeRebalancement = 5;
     nameOption           = "Vanilla Call";
     option               = new VanillaCall(nameOption, new Share("AIRBUS GROUP SE", "AIR FP    "), maturity, strike);
 }
Example #3
0
        private double[] computeWREVolatilityTable(double[,] returns)
        {
            SimulatedDataFeedProvider simulator = new SimulatedDataFeedProvider();
            int numberOfDaysPerYear             = simulator.NumberOfDaysPerYear;

            double[,] covarianceMatrix = computeWRECovarianceMatrix(returns);
            int size = covarianceMatrix.GetLength(0);

            double[] volatilityTable = new Double[size];
            for (int i = 0; i < size; i++)
            {
                volatilityTable[i] = Math.Sqrt(covarianceMatrix[i, i] * numberOfDaysPerYear);
            }
            return(volatilityTable);
        }
Example #4
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);
        }
Example #5
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");
        }
        public MainWindowViewModels()
        {
            StartCommand = new DelegateCommand(StartTicker, CanStartTicker);
            universeVM   = new UniverseViewModel();

            /*IOption call = Simulation.Option;
             * List<IOption> myOptionsList = new List<IOption>() { call };
             * AvailableOptions = new ObservableCollection<IOption>(myOptionsList);*/

            IDataFeedProvider        type1      = new SimulatedDataFeedProvider();
            IDataFeedProvider        type2      = new HistoricalDataFeedProvider();
            List <IDataFeedProvider> mydataList = new List <IDataFeedProvider>()
            {
                type1, type2
            };

            AvailableData = new ObservableCollection <IDataFeedProvider>(mydataList);
            graphTest     = GraphTest;
            win           = new GraphVisualization();
            /* win.Show();*/
        }
Example #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);
        }
        // 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);
                }
            }
        }
Example #9
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));
        }
Example #10
0
        public List <DataFeed> getDataSimulation()
        {
            var dataProvider = new SimulatedDataFeedProvider();

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