Пример #1
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            double t = double.Parse(TextBox3.Text);
            int H = int.Parse(TextBox4.Text);
            int size = 4;
            double[] spot = new double[] {  100, 100, 100, 100 };
            double[] sigma = new double[] { 0.2, 0.2, 0.2, 0.2 };
            double r = 0.05;
            double[] coeff = new double[] { .25, .25, .25, .25 };
            double[] rho = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
            double T = 6;
            int N = 6;
            int M = 50000;

            WrapperClass wc = new WrapperClass();
            double K = 0.0;
            wc.getDelta(t, size, spot, K, sigma, r, coeff, rho, T, N, H, M);

            Label4.Text = Math.Round(wc.getDelta(), 4).ToString();
            Label5.Text = Math.Round(wc.getICD(), 4).ToString();
            Label6.Text = Math.Round(wc.getDeltaBS(), 4).ToString();
        }
Пример #2
0
        protected void Hedge(object sender, EventArgs e)
        {
            //Affichage de la courbe associée au portefeuille

            DateTime DateDeb = DateTime.Parse(datepicker.Text.ToString());
            DateTime DateFin = DateTime.Parse(datepicker2.Text.ToString());
            TimeSpan difference = DateFin.Date - DateDeb.Date ;

            double rebalancement  = double.Parse(estimate_time.Text.ToString());
            WrapperClass wrap = new WrapperClass(4,60);
            AccesBD acces = new AccesDB.AccesBD();
            acces.DeleteCompo(new DateTime(2000, 1, 1), new DateTime(2010, 4, 28));
            //acces.getAssetSpot("FTSE", DateDeb, DateDeb);
            AfficheBD affiche = new AffichageBD.AfficheBD();
            double[] spot = new double[4];

            //On fait l'approximation que tout les spots commençent à la même date et on ne tient pas compte des paramètres pour le moment
            ComputeParam cp = new ComputeParam();
            cp.param(400,DateDeb.AddDays(-300));
            double[] sigma = new double[4];
            double[] rho = new double[16];
            for (int i = 0; i<4; i++){
                sigma[i] = cp.Volatility[i];
                for (int j = 0 ; j < 4; j++){
                    rho[i*4+j] = cp.Corel[i,j];
                }
            }
            double[] coeff = new double[4];
            double[][] past = new double[4][];
            for (int i = 0; i<4; i++){
                coeff[i] = 0.25;
            }

            String Date = datepicker.Text.ToString();
            DateTime Datee = DateDeb;
            Chart1.Titles.Add("Composition du portefeuille de couverture");
            Chart1.Legends.Add(new Legend("Valeur du portefeuille"));
            Chart1.Legends.Add(new Legend("Valeur du produit"));
            Chart1.Series[0].Name = "Valeur du portefeuille";
            Chart1.Series[1].Name = "Valeur du produit";
            DateTime previousDate = DateDeb;

            int pas = (difference.Days) / (int)rebalancement+1;

            DateTime DateFinBD = new DateTime(1,1,1);
            spot = acces.getLastSpot(ref DateFinBD);

            bool firstPas = true;
            int taille = ((((DateFin.Date - DateDeb.Date).Days) / pas) + 1);
            while ((DateFin.CompareTo(DateDeb) > 0 && acces.getCurrentValLiq(DateDeb)!=0) || firstPas)
            {
                firstPas = false;
                past[0] = acces.getAssetSpot("FTSE", DateDeb, Datee,pas);
                past[1] = acces.getAssetSpot("S&P", DateDeb, Datee,pas);
                past[2] = acces.getAssetSpot("NIKKEI", DateDeb, Datee,pas);
                past[3] = acces.getAssetSpot("EUROSTOXX", DateDeb, Datee,pas);
                double[] realPast = new double[past[0].Length * 4];
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < past[0].Length; j++)
                    {
                        realPast[i * past[0].Length + j] = past[i][j];
                    }
                }

                double risk = acces.getCurrentRisk(previousDate);
                double riskfree = acces.getCurrentRiskFree(previousDate);
                double[] tmpDelta = acces.getDelta(previousDate);

                //Traitement du cas où la date de départ est celle de début du produit
                //Changer le Past en tableaux bidimmensionnels !!
                wrap.computePortfolio(past[0].Length, 4, 30, 1000, (int)rebalancement, ((DateFin.Date - Datee.Date).Days) / 365.0, (DateDeb-Datee).Days/365.0, 0.05, sigma, rho, coeff, realPast);
                acces.Insert(DateDeb, wrap.getPrice(), wrap.getDelta(), wrap.getRiskFree(), wrap.getRisk());
                //Affichage du portefeuille
                if (wrap.getPrice() != 0)
                {
                    Chart1.Series[0].Points.AddXY(DateDeb, wrap.getRisk() + wrap.getRiskFree());
                    Chart1.Series[1].Points.AddXY(DateDeb, wrap.getPrice());
                }
                //Chart1.Series[1].Points.AddXY(DateDeb, risk + riskfree);
                previousDate = DateDeb;
                DateDeb = DateDeb.AddDays(pas);
            }
            string[,] toolti = acces.extractData(DateTime.Parse(datepicker.Text.ToString()), DateTime.Parse(datepicker2.Text.ToString()));
            for (int i = 0; i < Chart1.Series[0].Points.Count; i++)
            {
                Chart1.Series[0].Points[i].ToolTip = string.Format("Date = {0}, Valeur Portefeuille = {1}", toolti[2,i], Math.Round(double.Parse(toolti[1,i]),2));
                Chart1.Series[1].Points[i].ToolTip = string.Format("Date = {0}, Valeur Liquidative = {1}", toolti[2, i], Math.Round(double.Parse(toolti[0, i]), 2));
            }

            Affichage.Style.Add(HtmlTextWriterStyle.Display, "inline");
        }