Exemple #1
0
        private void priceBookFromSimulatorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Model1Container db = new Model1Container();

            //refresh listview
            listView_AllTrades.BeginUpdate();

            foreach (ListViewItem listView in listView_AllTrades.Items)
            {
                //According selected id in listview to find trade
                int   id    = Convert.ToInt32(listView.SubItems[0].Text);
                Trade trade = db.TradeSet.SingleOrDefault(x => x.Id == id);

                //Get values in this trade
                double direction;
                if (trade.IsBuy == true)
                {
                    direction = 1;
                }
                else
                {
                    direction = -1;
                }
                double quantity    = trade.Quantity;
                double marketprice = trade.Price;

                //Price product

                //Stock
                if (trade.Instrument.InstType.TypeName == "Stock")
                {
                    //Market Price
                    double s = trade.Instrument.Price.OrderByDescending(x => x.Date).First().ClosingPrice;
                    listView.SubItems.Add(Convert.ToString(s));
                    //P&L
                    listView.SubItems.Add(((s - marketprice) * direction * quantity).ToString());
                    //Delta
                    listView.SubItems.Add(Convert.ToString(direction * quantity));
                    //Gamma
                    listView.SubItems.Add(Convert.ToString(0));
                    //Vega
                    listView.SubItems.Add(Convert.ToString(0));
                    //Rho
                    listView.SubItems.Add(Convert.ToString(0));
                    //Theta
                    listView.SubItems.Add(Convert.ToString(0));
                }
                else
                {
                    //Option

                    Value value = new Value(); //Basic values about Options
                    value = GetValue(trade);

                    //European Option
                    if (trade.Instrument.InstType.TypeName == "EuropeanOption")
                    {
                        WindowsFormsApp3.European european = new WindowsFormsApp3.European();
                        //Market Price
                        listView.SubItems.Add(Convert.ToString(european.OptionPrice(value)[0]));
                        //P&L
                        listView.SubItems.Add(((european.OptionPrice(value)[0] - marketprice) * direction * quantity).ToString());
                        //Delta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * european.Delta(value)));
                        //Gamma
                        listView.SubItems.Add(Convert.ToString(direction * quantity * european.Gamma(value)));
                        //Vega
                        listView.SubItems.Add(Convert.ToString(direction * quantity * european.Vega(value)));
                        //Rho
                        listView.SubItems.Add(Convert.ToString(direction * quantity * european.Rho(value)));
                        //Theta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * european.Theta(value)));
                    }


                    //Asian Option
                    if (trade.Instrument.InstType.TypeName == "AsianOption")
                    {
                        WindowsFormsApp3.Asian asian = new WindowsFormsApp3.Asian();
                        //Market Price
                        listView.SubItems.Add(Convert.ToString(asian.OptionPrice(value)[0]));
                        //P&L
                        listView.SubItems.Add(((asian.OptionPrice(value)[0] - marketprice) * direction * quantity).ToString());
                        //Delta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * asian.Delta(value)));
                        //Gamma
                        listView.SubItems.Add(Convert.ToString(direction * quantity * asian.Gamma(value)));
                        //Vega
                        listView.SubItems.Add(Convert.ToString(direction * quantity * asian.Vega(value)));
                        //Rho
                        listView.SubItems.Add(Convert.ToString(direction * quantity * asian.Rho(value)));
                        //Theta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * asian.Theta(value)));
                    }

                    //Lookback Option
                    if (trade.Instrument.InstType.TypeName == "LookbackOption")
                    {
                        WindowsFormsApp3.Lookback lookback = new WindowsFormsApp3.Lookback();
                        //Market Price
                        listView.SubItems.Add(Convert.ToString(lookback.OptionPrice(value)[0]));
                        //P&L
                        listView.SubItems.Add(((lookback.OptionPrice(value)[0] - marketprice) * direction * quantity).ToString());
                        //Delta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * lookback.Delta(value)));
                        //Gamma
                        listView.SubItems.Add(Convert.ToString(direction * quantity * lookback.Gamma(value)));
                        //Vega
                        listView.SubItems.Add(Convert.ToString(direction * quantity * lookback.Vega(value)));
                        //Rho
                        listView.SubItems.Add(Convert.ToString(direction * quantity * lookback.Rho(value)));
                        //Theta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * lookback.Theta(value)));
                    }

                    //Digital Option
                    if (trade.Instrument.InstType.TypeName == "DigitalOption")
                    {
                        WindowsFormsApp3.Digital digital = new WindowsFormsApp3.Digital();
                        //Market Price
                        listView.SubItems.Add(Convert.ToString(digital.OptionPrice(value)[0]));
                        //P&L
                        listView.SubItems.Add(((digital.OptionPrice(value)[0] - marketprice) * direction * quantity).ToString());
                        //Delta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * digital.Delta(value)));
                        //Gamma
                        listView.SubItems.Add(Convert.ToString(direction * quantity * digital.Gamma(value)));
                        //Vega
                        listView.SubItems.Add(Convert.ToString(direction * quantity * digital.Vega(value)));
                        //Rho
                        listView.SubItems.Add(Convert.ToString(direction * quantity * digital.Rho(value)));
                        //Theta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * digital.Theta(value)));
                    }

                    //Range Option
                    if (trade.Instrument.InstType.TypeName == "RangeOption")
                    {
                        WindowsFormsApp3.Range range = new WindowsFormsApp3.Range();
                        //Market Price
                        listView.SubItems.Add(Convert.ToString(range.OptionPrice(value)[0]));
                        //P&L
                        listView.SubItems.Add(((range.OptionPrice(value)[0] - marketprice) * direction * quantity).ToString());
                        //Delta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * range.Delta(value)));
                        //Gamma
                        listView.SubItems.Add(Convert.ToString(direction * quantity * range.Gamma(value)));
                        //Vega
                        listView.SubItems.Add(Convert.ToString(direction * quantity * range.Vega(value)));
                        //Rho
                        listView.SubItems.Add(Convert.ToString(direction * quantity * range.Rho(value)));
                        //Theta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * range.Theta(value)));
                    }

                    //Barrier Option
                    if (trade.Instrument.InstType.TypeName == "BarrierOption")
                    {
                        WindowsFormsApp3.Barrier barrier = new WindowsFormsApp3.Barrier();
                        //Market Price
                        listView.SubItems.Add(Convert.ToString(barrier.OptionPrice(value)[0]));
                        //P&L
                        listView.SubItems.Add(((barrier.OptionPrice(value)[0] - marketprice) * direction * quantity).ToString());
                        //Delta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * barrier.Delta(value)));
                        //Gamma
                        listView.SubItems.Add(Convert.ToString(direction * quantity * barrier.Gamma(value)));
                        //Vega
                        listView.SubItems.Add(Convert.ToString(direction * quantity * barrier.Vega(value)));
                        //Rho
                        listView.SubItems.Add(Convert.ToString(direction * quantity * barrier.Rho(value)));
                        //Theta
                        listView.SubItems.Add(Convert.ToString(direction * quantity * barrier.Theta(value)));
                    }
                }
            }

            listView_AllTrades.EndUpdate();
            MessageBox.Show("Price succussfully");
        }
Exemple #2
0
        public void calculation()
        {
            label_pro.Text = "Input";

            //create objects
            RandomNumber randomnumber = new RandomNumber();
            Value        value        = new Value();

            //Define the inputs
            value.S      = Convert.ToDouble(textBoxS0.Text);
            value.K      = Convert.ToDouble(textBoxK.Text);
            value.T      = Convert.ToDouble(textBoxT.Text);
            value.R      = Convert.ToDouble(textBoxr.Text);
            value.Sigma  = Convert.ToDouble(textBoxsigma.Text);
            value.Trials = Convert.ToInt32(textBoxN.Text);
            value.N      = Convert.ToInt32(textBoxsteps.Text);
            value.Type   = Convert.ToBoolean(Radio_call.Checked);
            value.An     = Convert.ToBoolean(checkBox_An.Checked);
            value.CV     = Convert.ToBoolean(checkBox_CV.Checked);
            value.MT     = Convert.ToBoolean(checkBox_MT.Checked);

            label_pro.Text = "Reading Your Data";
            inprogress(10);

            double[,] Rn = randomnumber.Rand(value.Trials, value.N, value.MT);
            value.Rn     = Rn;

            label_pro.Text = "Creating Random Number Array";
            inprogress(20);

            //Outputs
            if (radioButton_European.Checked)
            {
                value.Rb = 0;
                value.Bt = 0;
                value.Br = 0;
                European european = new European();

                label_pro.Text    = "Calculate Price";
                textBoxPrice.Text = Convert.ToString(european.OptionPrice(value)[0]);
                inprogress(30);

                label_pro.Text  = "Calculate Std";
                textBoxStd.Text = Convert.ToString(european.OptionPrice(value)[1]);
                inprogress(40);

                label_pro.Text    = "Calculate Delta";
                textBoxDelta.Text = Convert.ToString(european.Delta(value));
                inprogress(50);

                label_pro.Text    = "Calculate Gamma";
                textBoxGamma.Text = Convert.ToString(european.Gamma(value));
                inprogress(60);

                label_pro.Text   = "Calculate Vega";
                textBoxVega.Text = Convert.ToString(european.Vega(value));
                inprogress(70);

                label_pro.Text    = "Calculate Theta";
                textBoxTheta.Text = Convert.ToString(european.Theta(value));
                inprogress(80);

                label_pro.Text  = "Calculate Rho";
                textBoxRho.Text = Convert.ToString(european.Rho(value));
                inprogress(90);
            }
            if (radioButton_Asian.Checked)
            {
                value.Rb = 0;
                value.Bt = 0;
                value.Br = 0;
                Asian asian = new Asian();

                label_pro.Text    = "Calculate Price";
                textBoxPrice.Text = Convert.ToString(asian.OptionPrice(value)[0]);
                inprogress(30);

                label_pro.Text  = "Calculate Std";
                textBoxStd.Text = Convert.ToString(asian.OptionPrice(value)[1]);
                inprogress(40);

                label_pro.Text    = "Calculate Delta";
                textBoxDelta.Text = Convert.ToString(asian.Delta(value));
                inprogress(50);

                label_pro.Text    = "Calculate Gamma";
                textBoxGamma.Text = Convert.ToString(asian.Gamma(value));
                inprogress(60);

                label_pro.Text   = "Calculate Vega";
                textBoxVega.Text = Convert.ToString(asian.Vega(value));
                inprogress(70);

                label_pro.Text    = "Calculate Theta";
                textBoxTheta.Text = Convert.ToString(asian.Theta(value));
                inprogress(80);

                label_pro.Text  = "Calculate Rho";
                textBoxRho.Text = Convert.ToString(asian.Rho(value));
                inprogress(90);
            }
            if (radioButton_Digital.Checked)
            {
                if (textBox_Rebate.Text == string.Empty)
                {
                    textBox_Rebate.BackColor = Color.Pink;
                }
                else
                {
                    value.Rb = Convert.ToDouble(textBox_Rebate.Text);
                    value.Bt = 0;
                    value.Br = 0;
                    Digital digital = new Digital();

                    label_pro.Text    = "Calculate Price";
                    textBoxPrice.Text = Convert.ToString(digital.OptionPrice(value)[0]);
                    inprogress(30);

                    label_pro.Text  = "Calculate Std";
                    textBoxStd.Text = Convert.ToString(digital.OptionPrice(value)[1]);
                    inprogress(40);

                    label_pro.Text    = "Calculate Delta";
                    textBoxDelta.Text = Convert.ToString(digital.Delta(value));
                    inprogress(50);

                    label_pro.Text    = "Calculate Gamma";
                    textBoxGamma.Text = Convert.ToString(digital.Gamma(value));
                    inprogress(60);

                    label_pro.Text   = "Calculate Vega";
                    textBoxVega.Text = Convert.ToString(digital.Vega(value));
                    inprogress(70);

                    label_pro.Text    = "Calculate Theta";
                    textBoxTheta.Text = Convert.ToString(digital.Theta(value));
                    inprogress(80);

                    label_pro.Text  = "Calculate Rho";
                    textBoxRho.Text = Convert.ToString(digital.Rho(value));
                    inprogress(90);
                }
            }
            if (radioButton_Barrier.Checked)
            {
                if (textBox_Barrier.Text == string.Empty)
                {
                    textBox_Barrier.BackColor = Color.Pink;
                }
                else
                {
                    value.Rb = 0;
                    value.Br = Convert.ToDouble(textBox_Barrier.Text);
                    if (radioButton_DO.Checked)
                    {
                        value.Bt = 0;
                    }
                    if (radioButton_UO.Checked)
                    {
                        value.Bt = 1;
                    }
                    if (radioButton_DI.Checked)
                    {
                        value.Bt = 2;
                    }
                    if (radioButton_UI.Checked)
                    {
                        value.Bt = 3;
                    }
                    Barrier barrier = new Barrier();

                    label_pro.Text    = "Calculate Price";
                    textBoxPrice.Text = Convert.ToString(barrier.OptionPrice(value)[0]);
                    inprogress(30);

                    label_pro.Text  = "Calculate Std";
                    textBoxStd.Text = Convert.ToString(barrier.OptionPrice(value)[1]);
                    inprogress(40);

                    label_pro.Text    = "Calculate Delta";
                    textBoxDelta.Text = Convert.ToString(barrier.Delta(value));
                    inprogress(50);

                    label_pro.Text    = "Calculate Gamma";
                    textBoxGamma.Text = Convert.ToString(barrier.Gamma(value));
                    inprogress(60);

                    label_pro.Text   = "Calculate Vega";
                    textBoxVega.Text = Convert.ToString(barrier.Vega(value));
                    inprogress(70);

                    label_pro.Text    = "Calculate Theta";
                    textBoxTheta.Text = Convert.ToString(barrier.Theta(value));
                    inprogress(80);

                    label_pro.Text  = "Calculate Rho";
                    textBoxRho.Text = Convert.ToString(barrier.Rho(value));
                    inprogress(90);
                }
            }
            if (radioButton_Lookback.Checked)
            {
                value.Rb = 0;
                value.Bt = 0;
                value.Br = 0;
                Lookback lookback = new Lookback();

                label_pro.Text    = "Calculate Price";
                textBoxPrice.Text = Convert.ToString(lookback.OptionPrice(value)[0]);
                inprogress(30);

                label_pro.Text  = "Calculate Std";
                textBoxStd.Text = Convert.ToString(lookback.OptionPrice(value)[1]);
                inprogress(40);

                label_pro.Text    = "Calculate Delta";
                textBoxDelta.Text = Convert.ToString(lookback.Delta(value));
                inprogress(50);

                label_pro.Text    = "Calculate Gamma";
                textBoxGamma.Text = Convert.ToString(lookback.Gamma(value));
                inprogress(60);

                label_pro.Text   = "Calculate Vega";
                textBoxVega.Text = Convert.ToString(lookback.Vega(value));
                inprogress(70);

                label_pro.Text    = "Calculate Theta";
                textBoxTheta.Text = Convert.ToString(lookback.Theta(value));
                inprogress(80);

                label_pro.Text  = "Calculate Rho";
                textBoxRho.Text = Convert.ToString(lookback.Rho(value));
                inprogress(90);
            }
            if (radioButton_Range.Checked)
            {
                value.Rb = 0;
                value.Bt = 0;
                value.Br = 0;
                Range range = new Range();

                label_pro.Text    = "Calculate Price";
                textBoxPrice.Text = Convert.ToString(range.OptionPrice(value)[0]);
                inprogress(30);

                label_pro.Text  = "Calculate Std";
                textBoxStd.Text = Convert.ToString(range.OptionPrice(value)[1]);
                inprogress(40);

                label_pro.Text    = "Calculate Delta";
                textBoxDelta.Text = Convert.ToString(range.Delta(value));
                inprogress(50);

                label_pro.Text    = "Calculate Gamma";
                textBoxGamma.Text = Convert.ToString(range.Gamma(value));
                inprogress(60);

                label_pro.Text   = "Calculate Vega";
                textBoxVega.Text = Convert.ToString(range.Vega(value));
                inprogress(70);

                label_pro.Text    = "Calculate Theta";
                textBoxTheta.Text = Convert.ToString(range.Theta(value));
                inprogress(80);

                label_pro.Text  = "Calculate Rho";
                textBoxRho.Text = Convert.ToString(range.Rho(value));
                inprogress(90);
            }
            int core_num;

            if (value.MT == true)
            {
                core_num = System.Environment.ProcessorCount;
            }
            else
            {
                core_num = 1;
            }
            TextBoxCore.Text = Convert.ToString(core_num);
        }