Exemple #1
0
        /***************************************************************
         *
         * ComputeProbITM for given option
         *
         * ************************************************************/

        private void ComputeProbITM(OptionInfo opt)
        {
            if (opt.ImpliedVolatility == null)
            {
                m_Log.Log(ErrorLevel.logERR, string.Format("BESTSTRANGLE ComputeProbITM unable to compute Prob ITM for {0}, strike {1}", opt.Ticker, opt.Strike.ToString()));
                return;
            }
            double vol = (double)opt.ImpliedVolatility / Math.Sqrt(365);
            double K   = opt.Strike;
            double S   = opt.UndPrice;

            /* If the underlying price is 0
             * ----------------------------
             * then fetch the last price from the database. This sometimes happens off-hours for some
             * reason.... the underlying price is not returned */

            if (S == 0.0)
            {
                m_Log.Log(ErrorLevel.logERR, string.Format("BESTSTRANGLE ComputeProbITM underlying strike price is undefined. {0}, strike {1}", opt.Ticker, opt.Strike.ToString()));
                return;
            }

//            DateTime Expires = DateTime.ParseExact (opt.Expiry, "yyyyMMdd", CultureInfo.InvariantCulture);
            DateTime Expires      = opt.Expiry;
            int      DaysToExpire = (Expires - DateTime.Now).Days;

            double variance = vol * vol;
            double d2       = Math.Log(S / K, Math.E);

            d2 += -variance / 2 * DaysToExpire;
            d2 /= vol;
            d2 /= Math.Sqrt(DaysToExpire);

            if (!opt.IfCall)
            {
                opt.ProbITM = Phi.phi(-d2);
            }
            else
            {
                opt.ProbITM = Phi.phi(d2);
            }
        }
Exemple #2
0
        /************************************************************
         *
         * Cell value has changed
         *
         * *********************************************************/

        private void dgvBestStrangle_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            OptionInfo opt = (OptionInfo)dgvBestStrangle.Rows[e.RowIndex].DataBoundItem;

            if (e.ColumnIndex == colbsSTRIKE)
            {
                foreach (var o in m_Options)
                {
                    if ((opt.IfCall == o.IfCall) && opt.Strike == o.Strike)
                    {
                        opt.Price = o.Price;
                        opt.Delta = o.Delta;
                        opt.BuyingPowerReduction = ComputeBuyingPowerReduction((double)o.UndPrice, (double)o.Strike, (double)o.Price);
                        ComputeProbITM(opt);
                        dgvBestStrangle.InvalidateRow(e.RowIndex);
                        break;
                    }
                }
            }
        }
Exemple #3
0
        /************************************************************
        *
        * tbBsTargetMargin_Validated
        *
        * **********************************************************/

        private void tbBsTargetMargin_Validated(object sender, EventArgs e)
        {
            double bpr = 0;

            foreach (DataGridViewRow r in dgvBestStrangle.Rows)
            {
                OptionInfo opt = (OptionInfo)r.DataBoundItem;
                if (opt.BuyingPowerReduction > bpr)
                {
                    bpr = opt.BuyingPowerReduction;
                }
            }
            int no_contracts = (int)Math.Round(m_iTargetMargin / bpr);

            foreach (DataGridViewRow r in dgvBestStrangle.Rows)
            {
                OptionInfo opt = (OptionInfo)r.DataBoundItem;
                opt.NoContracts = no_contracts;
                dgvBestStrangle.InvalidateCell(r.Cells[colbsNOCONTRACTS]);
            }
        }