Esempio n. 1
0
 private void add6_Click(object sender, EventArgs e)
 {
     try
     {
         int n = 0;
         Price pri = new Price();
         List<string> inst = new List<string>();
         List<int> id = new List<int>();
         foreach (Instrument i in portfolio.Instruments)//find the id and ticker the instrument you chose
         {
             inst.Add(i.Ticker);
             id.Add(i.Id);
         }
         while (instrument6.SelectedItem.ToString() != inst[n])
             n++;
         pri.ClosingPrice = Convert.ToDouble(price6.Value);
         pri.Timestamp = DateTime.Now.ToLongDateString();
         pri.InstrumentId = Convert.ToInt16(id[n]);
         portfolio.Prices.Add(pri);
         portfolio.SaveChanges();
         MessageBox.Show("Data added successfully", "Notice");
         this.Close();
     }
     catch { MessageBox.Show("Something wrong, please check wheather the inputs are correct."); }
 }
Esempio n. 2
0
        private void testdata3()
        {
            Price p = new Price();
            p.ClosingPrice = 48;
            p.Timestamp = DateTime.Now.ToLongDateString();
            p.InstrumentId = (from i in portfolio.Instruments
                              where i.Ticker == "MSFTC50Euro"
                              select i.Id).First();
            portfolio.Prices.Add(p);
            portfolio.SaveChanges();

            Price p2 = new Price();
            p2.ClosingPrice = 49;
            p2.Timestamp = DateTime.Now.ToLongDateString();
            p2.InstrumentId = (from i in portfolio.Instruments
                               where i.Ticker == "SINAC50BARR"
                               select i.Id).First();
            portfolio.Prices.Add(p2);
            portfolio.SaveChanges();

            Price p3 = new Price();
            p3.ClosingPrice = 50;
            p3.Timestamp = DateTime.Now.ToLongDateString();
            p3.InstrumentId = (from i in portfolio.Instruments
                               join j in portfolio.InstTypes on i.InstTypeId equals j.Id
                               where j.TypeName == "Stock"
                               where i.Underlying == "MSFT"
                               select i.Id).First();
            portfolio.Prices.Add(p3);
            portfolio.SaveChanges();
        }
Esempio n. 3
0
        private void add4_Click(object sender, EventArgs e)
        {
            try
            {
                Trade tra = new Trade();
                List<string> inst = new List<string>();
                List<int> instid = new List<int>();
                string inst2 = instrument4.SelectedItem.ToString();
                var n = (from i in portfolio.Instruments
                         where i.Ticker == inst2
                         select i.Id).First();//find out the instrument id for trade

                var v = (from i in portfolio.Prices//find out the price for instrument
                         where i.InstrumentId == n
                         orderby i.Id descending
                         select i.ClosingPrice).First();

                price4.Text = v.ToString();
                foreach (Instrument i in portfolio.Instruments)
                {
                    inst.Add(i.Ticker);
                    instid.Add(i.InstTypeId);
                }
                tra.MarketPrice = 0;
                tra.IsBuy = buy4.Checked;
                tra.Quantity = Convert.ToDouble(quantity4.Value);
                tra.UnderlyingP = v;//Convert.ToDouble(underlyingprice.Value);
                tra.Price = Convert.ToDouble(tradeprice4.Value);
                tra.Timestamp = DateTime.Now.ToLongDateString();
                tra.PL = 0;

                tra.InstrumentId = Convert.ToInt16(n);
                Price p = new Price();
                p.ClosingPrice = tra.UnderlyingP;
                p.Timestamp = tra.Timestamp;
                p.InstrumentId = tra.InstrumentId;
                portfolio.Prices.Add(p);
                portfolio.SaveChanges();
                if (insttype4.Text == "Stock")//if the trade is stock, make the market price as underlying price ,delta=1 or -1
                {
                    tra.MarketPrice = tra.UnderlyingP;

                    if (tra.IsBuy == true)
                    {
                        tra.Delta = 1;
                        tra.PL = (tra.Price - (double)tra.MarketPrice)*tra.Quantity;
                    }
                    else
                    {
                        tra.Delta = -1;
                        tra.PL = ((double)tra.MarketPrice - tra.Price) * tra.Quantity;
                    }
                    tra.Gamma = 0;
                    tra.Theta = 0;
                    tra.Vega = 0;
                    tra.Rho = 0;
                }
                portfolio.Trades.Add(tra);
                portfolio.SaveChanges();
                MessageBox.Show("Data added successfully", "Notice");
                this.Close();
            }
            catch { MessageBox.Show("Something wrong, please check wheather the inputs are correct."); }
        }