Beispiel #1
0
        public void RebalancementVanillaCallATM()
        {
            double ratio = 0;
            double compteur = 0;

            for (int i = 0; i < 200; i++)
            {
                DateTime date = DateTime.Now;
                PricingLibrary.FinancialProducts.Share Action = new PricingLibrary.FinancialProducts.Share("test", "01");
                PricingLibrary.FinancialProducts.Share[] tabAction = { Action };

                PricingLibrary.FinancialProducts.VanillaCall Call = new PricingLibrary.FinancialProducts.VanillaCall("test", tabAction, date, 10.0);
                DateTime dateStart = new DateTime(2014, 9, 9, 0, 0, 0);

                OptionManager optionCompute = new OptionManager(Call, dateStart, date, 30, true);
                ComputeResults.computeResults(optionCompute);



                double firstValue = optionCompute.HedgingPortfolioValue[0];
                double lastValue = optionCompute.HedgingPortfolioValue[optionCompute.HedgingPortfolioValue.Count - 1];
                double payoff = optionCompute.Payoff[optionCompute.Payoff.Count - 1];

                double ratioTmp = Math.Abs(payoff - lastValue) / firstValue;
                ratio += ratioTmp;
                compteur += 1;
            }

            ratio = ratio / compteur;
            Console.WriteLine(ratio);
        }
Beispiel #2
0
        /*** Test for data simulation ***/
        /* Print all loaded values 
         * for one share between two dates */
        public void TestLoadedData()
        {
            DateTime date = DateTime.Now;
            PricingLibrary.FinancialProducts.Share Action = new PricingLibrary.FinancialProducts.Share("ALO FP", "ALO FP");
            PricingLibrary.FinancialProducts.Share[] tabAction = { Action };
            PricingLibrary.FinancialProducts.VanillaCall Call = new PricingLibrary.FinancialProducts.VanillaCall("ALO FP", tabAction, date, 30.0);

            DateTime date1 = new DateTime(2015, 6, 1, 0, 0, 0);

            ShareHisto myShareHisto = new ShareHisto(date1, date, Call);

            myShareHisto.loadingSQL();

            foreach (PricingLibrary.Utilities.MarketDataFeed.DataFeed d in myShareHisto.Data)
            {
                foreach (KeyValuePair<string, decimal> t in d.PriceList)
                {
                    Console.WriteLine("Date : " + d.Date);
                    Console.WriteLine("    "  + t.Key + "   " + t.Value);
                }
            }

        }
        private void ExtractComponents()
        {
            // On test les différents paramètres, si ils ne sont pas bons on fait apparaitre un pop-up
            double sommePoids = 0.0;
            int nbAction = 0;
            foreach (var comp in ComponentInfoList)
            {
                if (comp.IsSelected)
                {
                    if (comp.Poids < 0.0)
                    {
                        System.Windows.Forms.MessageBox.Show("ERREUR : Les poids doivent être positif");
                        return;
                    }
                    sommePoids += comp.Poids;
                    nbAction += 1;
                }
            }
            if (sommePoids != 1.0)
            {
                System.Windows.Forms.MessageBox.Show("ERREUR : La somme des poids doit être égale à 1 ");
                return;
            }

            PricingLibrary.FinancialProducts.Share[] tabShare = new PricingLibrary.FinancialProducts.Share[nbAction];
            double[] tabWeight = new double[nbAction];

            if (tailleFenetre < 0)
            {
                System.Windows.Forms.MessageBox.Show("ERREUR : La taille de la fenetre doit être superieure à 0 ");
                return;
            }

            if (maturite.Subtract(dateDebut).Days < tailleFenetre)
            {
                System.Windows.Forms.MessageBox.Show("ERREUR : La taille de la fenetre ne doit pas être plus grande que l'écart entre la maturite et la date de début ");
                return;
            }

            if (tailleFenetre < nbAction)
            {
                System.Windows.Forms.MessageBox.Show("ERREUR : La taille de la fenetre doit être un entier au minimum égale au nombre de sous jacent ");
                return;
            }
            if ((1 < nbAction)&&(typeOption.Equals("Vanilla Call")))
            {
                System.Windows.Forms.MessageBox.Show("ERREUR : Un Vanilla Call ne peut avoir qu'un sous-jacent ");
                return;
            }


            // On utilise maintenant nb action comme index
            nbAction = 0;
            foreach (var comp in ComponentInfoList)
            {
                if (comp.IsSelected)
                {
                    PricingLibrary.FinancialProducts.Share share = new PricingLibrary.FinancialProducts.Share(comp.Name, comp.Name);
                    tabShare[nbAction] = share;
                    tabWeight[nbAction] = comp.Poids;
                    nbAction += 1;
                }
            }



            if (strikePrice < 0)
            {
                System.Windows.Forms.MessageBox.Show("ERREUR : Le strike doit être positif");
                return;
            }

            TimeSpan diff = maturite.Subtract(dateDebut);
            if (diff.Days < 0)
            {
                System.Windows.Forms.MessageBox.Show("ERREUR : La date de debut doit etre avant la maturite ");
                return;
            }


            if (!typeDonnees.Equals("Simulées") && !typeDonnees.Equals("Historiques"))
            {
                System.Windows.Forms.MessageBox.Show("ERREUR Type de données : Choisir l'une des deux possibilités ");
                return;
            }
            bool simule;
            if (typeDonnees.Equals("Simulées")) {
                simule = true;
            } else {
                simule = false;
            }

            PricingLibrary.FinancialProducts.IOption option;
            if (typeOption.Equals("Vanilla Call"))
            {
                option = new PricingLibrary.FinancialProducts.VanillaCall("call", tabShare, maturite, strikePrice);
            }
            else
            {
                option = new PricingLibrary.FinancialProducts.BasketOption("basket", tabShare, tabWeight, maturite, strikePrice);
            }

            ////////////////////////////////////////////////////////////////////////////

            // On calcule le portefeuilles de couverture de l'option
            OptionManager optionCompute = new OptionManager(option,dateDebut,maturite,tailleFenetre,simule);
            ComputeResults.computeResults(optionCompute);

            // On trace les graphes
            LineSeries courbe = tabToSeries(optionCompute.OptionPrice, optionCompute.dateTime);
            LineSeries courbe2 = tabToSeries(optionCompute.HedgingPortfolioValue, optionCompute.dateTime);

            this.MyModel.Series.Clear();
            this.MyModel.Axes.Clear();

            double min = Math.Min(optionCompute.OptionPrice.Min(),optionCompute.HedgingPortfolioValue.Min())-0.1;
            double max = Math.Max(optionCompute.OptionPrice.Max(), optionCompute.HedgingPortfolioValue.Max())+0.1;
            SetUpModel(min, max, optionCompute.dateTime.Min());

            courbe.Title = "Prix de l'option";
            courbe2.Title = "Valeur Portefeuille de Couverture";
            this.MyModel.Series.Add(courbe);
            this.MyModel.Series.Add(courbe2);

            // On met à jour les graphes
            this.MyModel.InvalidatePlot(true);
            this.MyModel.PlotView.InvalidatePlot(true);

        }