Beispiel #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");
        }