Ejemplo n.º 1
0
        /***************************************************************************
         *
         * Compute Probability of ITM for the particular displayed option
         *
         * ************************************************************************/

        public void ComputeProbITM()
        {
            if (Equity != EquityType.Option)
            {
                return;
            }
            if (iv == null || Strike == null || UnderlyingPrice == null || ExpiryDate == null)
            {
                frmPos.m_Log.Log(ErrorLevel.logERR, string.Format("ComputeProbITM unable to compute Prob ITM for {0}", Ticker));
                return;
            }
            double vol = (double)iv / Math.Sqrt(252);
            double K   = (double)Strike;
            double S   = (double)UnderlyingPrice;

            int DaysToExpire = (int)Utils.ComputeDaysToExpire(ExpiryDate);

            frmPos.m_Log.Log(ErrorLevel.logDEB, string.Format("ComputeProbITM {0}: iv: {1:F6} strike: {2:N} underlying: {3:F4} days to expiry {4} side {5}", Ticker, vol, K, S, DaysToExpire, DisplayCall()));

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

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

            if ((bool)!IfCall)
            {
                ProbITM = Phi.phi(-d2) * 100;
            }
            else
            {
                ProbITM = Phi.phi(d2) * 100;
            }

            if ((EmailNotifications & Utils.enNEAR_ITM) == Utils.enNEAR_ITM)
            {
                if (ProbITM > 30.0 && ProbITM < 50.0)
                {
                    string note = string.Format("Option {0} {1} {2} strike {3} is ITM {4:F2}", Ticker, DisplayCall(), IfSell ? "Sell" : "Buy", Strike, ProbITM);
                    EmailBrian(note, new TimeSpan(3, 0, 0));
                }
            }
            if ((EmailNotifications & Utils.enITM) == Utils.enITM)
            {
                if (ProbITM >= 50.0)
                {
                    string note = string.Format("Option {0} {1} {2} strike {3} is ITM {4:F2}", Ticker, DisplayCall(), IfSell ? "Sell" : "Buy", Strike, ProbITM);
                    EmailBrian(note, new TimeSpan(1, 0, 0));
                }
            }
        }
Ejemplo n.º 2
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);
            }
        }