private void buttonCalibrate_Click(object sender, EventArgs e)
        {
            CalibrationForm cf = new CalibrationForm(ss);
            DialogResult r = cf.ShowDialog();
            if (r == DialogResult.OK) /** Calibration successful */
            {
                if(cf.generatedSpot!=null) curveViewer.AddCurve(new CurveViewer.Curve(cf.generatedSpot, Color.Red));
                ss = cf.ss;

                foreach (DataGridViewRow dgvr in dataGridViewFutures.Rows)
                {
                    DataGridViewCellCollection cells = dgvr.Cells;
                    double mat = (double)cells[0].Value;
                    cells[1].Value = PriceFuture(mat);
                }

                foreach (DataGridViewRow dgvr in dataGridViewOption.Rows)
                {
                    DataGridViewCellCollection cells = dgvr.Cells;
                    Option newOpt = new Option()
                    {
                        Value = (double)cells[0].Value,
                        StrikePrice = (double)cells[1].Value,
                        DaysTilExpiry = (int)cells[2].Value,
                        Type = (string)cells[3].Value,
                    };
                    cells[4].Value = PriceOption(newOpt);
                }

            }
        }
        private double PriceOption(Option o)
        {
            // price option with ss

            double price = 0.0;
            double xt = ss.Sigma_x;
            double delta = (double)7 / (double)360;
            double et = Math.Log(o.Value) - ss.Sigma_x;
            double nbWeeks = (o.DaysTilExpiry / 7);

            for (int i = 0; i < nbWeeks; i++)
            {
                double dx, de;
                dx = gr.NextGuassian();
                de = ss.P_xe * delta / dx;
                // xt = Math.Exp(-ss.K * delta) * xt + gr.NextGuassian() * delta;
                // et = ss.Mu_e * delta + et + gr.NextGuassian() * delta;
                xt += (-ss.K * xt - ss.Lambda_X) * delta + ss.Sigma_x * dx * delta;
                et += (ss.Mu_e - ss.Lambda_e) * delta + ss.Sigma_e * de * delta;
            }

            double f = Math.Exp(et + xt); // afficher

            if (o.Type == "Call")
                price = Math.Exp(-0.03/* to change.?*/* nbWeeks) * Math.Max(f - o.StrikePrice, 0);
            else
                price = Math.Exp(-0.03/* to change.?*/* nbWeeks) * Math.Max(o.StrikePrice - f, 0);
            //while (true)
            // Console.WriteLine(gr.NextGuassian());
            Console.WriteLine("f:{0}, xt:{1}, et:{2}, price:{3}", f, xt, et, price);

            return price;
            }
        private void buttonLoadOption_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TextReader tw = new StreamReader(openFileDialog1.FileName);
                while (tw.Peek() >= 0)
                {
                    string line = tw.ReadLine();
                    string[] parts = line.Split(',');
                    if (parts.Length != 4) continue;
                    try
                    {
                        Option newOpt = new Option()
                        {
                            Value = Double.Parse(parts[0], NumberStyles.AllowDecimalPoint | NumberStyles.Float),
                            StrikePrice = Double.Parse(parts[1], NumberStyles.AllowDecimalPoint | NumberStyles.Float),
                            DaysTilExpiry = Int32.Parse(parts[2]),
                            Type = parts[3],
                        };
                        dataGridViewOption.Rows.Add(new object[] { newOpt.Value, newOpt.StrikePrice, newOpt.DaysTilExpiry, newOpt.Type, PriceOption(newOpt) });
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }

                tw.Close();

            }
        }