Beispiel #1
0
        private void selectedTradeDeleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //delete button
            Model1Container db = new Model1Container();

            foreach (ListViewItem i in listView_AllTrades.SelectedItems)
            {
                listView_AllTrades.Items.Remove(i);
                db.TradeSet.Remove((from j in db.TradeSet where j.Id.ToString() == i.Text select j).FirstOrDefault());
                db.SaveChanges();
            }
        }
        private void button_OK_Click(object sender, EventArgs e)
        {
            //add historical price
            Model1Container db = new Model1Container();

            if (comboBox_Product.Text == String.Empty || textBox_ClosingPrice.Text == String.Empty)
            {
                MessageBox.Show("You don't input all values");
            }
            else
            {
                db.PriceSet.Add(new Price()
                {
                    ClosingPrice = Convert.ToDouble(textBox_ClosingPrice.Text),
                    Date         = DateTime.Now,
                    Instrument   = db.InstrumentSet.FirstOrDefault(x => x.Ticker == comboBox_Product.Text)
                });
                db.SaveChanges();
                MessageBox.Show("Add historical price successfully!");
            }
        }
        private void button_OK_Click(object sender, EventArgs e)
        {
            //add trade
            Model1Container db = new Model1Container();

            if (textBox_Quantity.Text == String.Empty || textBox_Price.Text == String.Empty || comboBox_Instrument.Text == String.Empty)
            {
                MessageBox.Show("You don't input all values");
            }
            else
            {
                db.TradeSet.Add(new Trade()
                {
                    IsBuy      = radioButton_Buy.Checked,
                    Quantity   = Convert.ToDouble(textBox_Quantity.Text),
                    Price      = Convert.ToDouble(textBox_Price.Text),
                    Timestamp  = DateTime.Now,
                    Instrument = db.InstrumentSet.FirstOrDefault(x => x.Ticker == comboBox_Instrument.Text)
                });
                db.SaveChanges();
                MessageBox.Show("Add trade successfully!");
            }
        }
        private void button_OK_Click(object sender, EventArgs e)
        {
            //add instrument
            Model1Container db = new Model1Container();

            if (textBox_CompanyName.Text == String.Empty || textBox_Ticker.Text == String.Empty || textBox_Exchange.Text == String.Empty)
            {
                MessageBox.Show("You don't input all values");
            }
            else
            {
                //add stock
                if (comboBox_InstType.Text == "Stock")
                {
                    db.InstrumentSet.Add(new Instrument()
                    {
                        CompanyName = textBox_CompanyName.Text,
                        Ticker      = textBox_Ticker.Text,
                        Exchange    = textBox_Exchange.Text,
                        InstType    = db.InstTypeSet.FirstOrDefault(x => x.TypeName == "Stock")
                    });
                    MessageBox.Show("Add Stock successfully!");
                }
                //add digital option
                else if (comboBox_InstType.Text == "DigitalOption")
                {
                    db.InstrumentSet.Add(new Instrument()
                    {
                        CompanyName = textBox_CompanyName.Text,
                        Ticker      = textBox_Ticker.Text,
                        Exchange    = textBox_Exchange.Text,
                        Underlying  = comboBox_Underlying.Text,
                        Strike      = Convert.ToDouble(textBox_Strike.Text),
                        Tenor       = Convert.ToDouble(textBox_Tenor.Text),
                        IsCall      = radioButton_Call.Checked,
                        Rebate      = Convert.ToDouble(textBox_Rebate.Text),
                        InstType    = db.InstTypeSet.FirstOrDefault(x => x.TypeName == "DigitalOption")
                    });
                    MessageBox.Show("Add DigitalOption successfully!");
                }
                //add barrier option
                else if (comboBox_InstType.Text == "BarrierOption")
                {
                    db.InstrumentSet.Add(new Instrument()
                    {
                        CompanyName = textBox_CompanyName.Text,
                        Ticker      = textBox_Ticker.Text,
                        Exchange    = textBox_Exchange.Text,
                        Underlying  = comboBox_Underlying.Text,
                        Strike      = Convert.ToDouble(textBox_Strike.Text),
                        Tenor       = Convert.ToDouble(textBox_Tenor.Text),
                        IsCall      = radioButton_Call.Checked,
                        Barrier     = Convert.ToDouble(textBox_Barrier.Text),
                        BarrierType = comboBox_BarrierType.Text,
                        InstType    = db.InstTypeSet.FirstOrDefault(x => x.TypeName == "BarrierOption")
                    });
                    MessageBox.Show("Add BarrierOption successfully!");
                }
                //add other option
                else
                {
                    db.InstrumentSet.Add(new Instrument()
                    {
                        CompanyName = textBox_CompanyName.Text,
                        Ticker      = textBox_Ticker.Text,
                        Exchange    = textBox_Exchange.Text,
                        Underlying  = comboBox_Underlying.Text,
                        Strike      = Convert.ToDouble(textBox_Strike.Text),
                        Tenor       = Convert.ToDouble(textBox_Tenor.Text),
                        IsCall      = radioButton_Call.Checked,
                        InstType    = db.InstTypeSet.FirstOrDefault(x => x.TypeName == comboBox_Underlying.Text)
                    });
                    MessageBox.Show("Add Option successfully!");
                }
            }

            db.SaveChanges();
        }
        private void button_Go_Click(object sender, EventArgs e)
        {
            Model1Container db = new Model1Container();

            //InstTypeSet
            db.InstTypeSet.Add(new InstType()
            {
                TypeName = "Stock"
            });
            db.InstTypeSet.Add(new InstType()
            {
                TypeName = "EuropeanOption"
            });
            db.InstTypeSet.Add(new InstType()
            {
                TypeName = "AsianOption"
            });
            db.InstTypeSet.Add(new InstType()
            {
                TypeName = "LookbackOption"
            });
            db.InstTypeSet.Add(new InstType()
            {
                TypeName = "DigitalOption"
            });
            db.InstTypeSet.Add(new InstType()
            {
                TypeName = "RangeOption"
            });
            db.InstTypeSet.Add(new InstType()
            {
                TypeName = "BarrierOption"
            });

            //Interest Rate
            db.InterestRateSet.Add(new InterestRate()
            {
                Tenor = 0.5,
                Rate  = 0.04
            });
            db.InterestRateSet.Add(new InterestRate()
            {
                Tenor = 1,
                Rate  = 0.05
            });
            db.InterestRateSet.Add(new InterestRate()
            {
                Tenor = 1.5,
                Rate  = 0.06
            });
            db.InterestRateSet.Add(new InterestRate()
            {
                Tenor = 2,
                Rate  = 0.07
            });
            db.InterestRateSet.Add(new InterestRate()
            {
                Tenor = 2.5,
                Rate  = 0.08
            });
            db.InterestRateSet.Add(new InterestRate()
            {
                Tenor = 3,
                Rate  = 0.09
            });

            //Instrument
            db.InstrumentSet.Add(new Instrument()
            {
                CompanyName = "OPM Company",
                Ticker      = "OPMSK",
                Exchange    = "NASDAQ",
                InstTypeId  = 1
            });

            //Trade
            db.TradeSet.Add(new Trade()
            {
                IsBuy        = true,
                Quantity     = 100,
                Price        = 50,
                Timestamp    = System.DateTime.Now,
                InstrumentId = 1
            });

            //Historical Price
            db.PriceSet.Add(new Price()
            {
                Date         = System.DateTime.Today,
                ClosingPrice = 50,
                InstrumentId = 1
            });

            db.SaveChanges();

            MessageBox.Show("Add stock data to SQL successfully!");
        }
        private void button_GoOption_Click(object sender, EventArgs e)
        {
            Model1Container db = new Model1Container();

            //European Option
            //Instrument
            db.InstrumentSet.Add(new Instrument()
            {
                CompanyName = "OPM Company",
                Ticker      = "OPMEO",
                Exchange    = "NASDAQ",
                Underlying  = "OPMSK",
                Strike      = 50,
                Tenor       = 1,
                IsCall      = true,
                InstTypeId  = 2
            });

            //Trade
            db.TradeSet.Add(new Trade()
            {
                IsBuy        = true,
                Quantity     = 100,
                Price        = 12,
                Timestamp    = System.DateTime.Now,
                InstrumentId = 2
            });


            //Asian Option
            //Instrument
            db.InstrumentSet.Add(new Instrument()
            {
                CompanyName = "OPM Company",
                Ticker      = "OPMAO",
                Exchange    = "NASDAQ",
                Underlying  = "OPMSK",
                Strike      = 50,
                Tenor       = 1,
                IsCall      = true,
                InstTypeId  = 3
            });

            //Trade
            db.TradeSet.Add(new Trade()
            {
                IsBuy        = true,
                Quantity     = 100,
                Price        = 6,
                Timestamp    = System.DateTime.Now,
                InstrumentId = 3
            });


            //Lookback Option
            //Instrument
            db.InstrumentSet.Add(new Instrument()
            {
                CompanyName = "OPM Company",
                Ticker      = "OPMLO",
                Exchange    = "NASDAQ",
                Underlying  = "OPMSK",
                Strike      = 50,
                Tenor       = 1,
                IsCall      = true,
                InstTypeId  = 4
            });

            //Trade
            db.TradeSet.Add(new Trade()
            {
                IsBuy        = true,
                Quantity     = 100,
                Price        = 21,
                Timestamp    = System.DateTime.Now,
                InstrumentId = 4
            });

            //Digital Option
            //Instrument
            db.InstrumentSet.Add(new Instrument()
            {
                CompanyName = "OPM Company",
                Ticker      = "OPMDO",
                Exchange    = "NASDAQ",
                Underlying  = "OPMSK",
                Strike      = 50,
                Tenor       = 1,
                IsCall      = true,
                Rebate      = 5,
                InstTypeId  = 5
            });

            //Trade
            db.TradeSet.Add(new Trade()
            {
                IsBuy        = true,
                Quantity     = 100,
                Price        = 3,
                Timestamp    = System.DateTime.Now,
                InstrumentId = 5
            });


            //Range Option
            //Instrument
            db.InstrumentSet.Add(new Instrument()
            {
                CompanyName = "OPM Company",
                Ticker      = "OPMRO",
                Exchange    = "NASDAQ",
                Underlying  = "OPMSK",
                Strike      = 50,
                Tenor       = 1,
                IsCall      = true,
                InstTypeId  = 6
            });

            //Trade
            db.TradeSet.Add(new Trade()
            {
                IsBuy        = true,
                Quantity     = 100,
                Price        = 35,
                Timestamp    = System.DateTime.Now,
                InstrumentId = 6
            });

            //Barrier Option
            //Instrument
            db.InstrumentSet.Add(new Instrument()
            {
                CompanyName = "OPM Company",
                Ticker      = "OPMBO",
                Exchange    = "NASDAQ",
                Underlying  = "OPMSK",
                Strike      = 50,
                Tenor       = 1,
                IsCall      = true,
                Barrier     = 40,
                BarrierType = "Down and out",
                InstTypeId  = 7
            });

            //Trade
            db.TradeSet.Add(new Trade()
            {
                IsBuy        = true,
                Quantity     = 100,
                Price        = 9,
                Timestamp    = System.DateTime.Now,
                InstrumentId = 7
            });

            db.SaveChanges();

            MessageBox.Show("Add option data to SQL successfully!");
        }