示例#1
0
        /// <summary>
        /// Метод для передачи на вход серии опционов и также в явном виде на вход передаётся разрешение на выполнение дельта-хеджа
        /// </summary>
        public double Execute(double price, double rawDelta, IOptionSeries optSer, bool permissionToWork, int barNum)
        {
            if ((optSer == null) || (optSer.UnderlyingAsset == null))
            {
                return(Constants.NaN);
            }

            int len = m_context.BarsCount;

            if (len <= 0)
            {
                return(Constants.NaN);
            }

            if (len <= barNum)
            {
                string msg = String.Format("[{0}] (BarsCount <= barNum)! BarsCount:{1}; barNum:{2}",
                                           GetType().Name, m_context.BarsCount, barNum);
                m_context.Log(msg, MessageType.Info, true);
                barNum = len - 1;
            }
            ISecurity under   = optSer.UnderlyingAsset;
            DateTime  now     = under.Bars[barNum].Date;
            var       strikes = optSer.GetStrikes();
            double    res     = CommonExecute(m_variableId + "_rawDeltas", now, true, true, false, barNum,
                                              new object[]
            {
                price, rawDelta, under.Tick, optSer.ExpirationDate, under.Symbol,
                under.FinInfo.LastUpdate, under.SecurityDescription, permissionToWork,
                strikes, under.LotTick
            });

            return(res);
        }
示例#2
0
        public double Execute(IOptionSeries optSer, int barNumber)
        {
            double res = Execute(optSer.UnderlyingAsset, barNumber);

            foreach (var strike in optSer.GetStrikes())
            {
                double comm = Execute(strike.Security, barNumber);
                res += comm;
            }

            return(res);
        }
        /// <summary>
        /// Метод под флаг TemplateTypes.OPTION_SERIES, чтобы подключаться к источнику-серии
        /// </summary>
        public double Execute(IOptionSeries optSer, int barNumber)
        {
            double res = Execute(optSer.UnderlyingAsset, barNumber);

            if (barNumber < m_context.BarsCount - 1)
            {
                return(res);
            }

            double accum = 0;

            foreach (IOptionStrike strike in optSer.GetStrikes())
            {
                ISecurity sec = strike.Security;
                accum += Execute(sec, barNumber);
            }

            return(res + accum);
        }
示例#4
0
        /// <summary>
        /// Обработчик под тип входных данных OPTION_SERIES
        /// </summary>
        public IList <Double2> Execute(IOptionSeries optSer)
        {
            List <Double2> res = new List <Double2>();

            IOptionStrike[] strikes = (from strike in optSer.GetStrikes()
                                       orderby strike.Strike ascending
                                       select strike).ToArray();
            for (int j = 0; j < strikes.Length; j++)
            {
                IOptionStrike sInfo = strikes[j];
                if ((sInfo.FinInfo == null) || (!sInfo.FinInfo.TheoreticalPrice.HasValue))
                {
                    continue;
                }

                double optPx = sInfo.FinInfo.TheoreticalPrice.Value;
                optPx *= m_multPx;
                optPx += m_addPx * sInfo.Security.SecurityDescription.GetTick(sInfo.FinInfo.TheoreticalPrice.Value);

                res.Add(new Double2(sInfo.Strike, optPx));
            }

            return(res);
        }
示例#5
0
        public InteractiveSeries Execute(IOptionSeries optSer, int barNum)
        {
            int barsCount = ContextBarsCount;

            if ((barNum < barsCount - 1) || (optSer == null))
            {
                return(Constants.EmptySeries);
            }

            int      lastBarIndex   = optSer.UnderlyingAsset.Bars.Count - 1;
            DateTime now            = optSer.UnderlyingAsset.Bars[Math.Min(barNum, lastBarIndex)].Date;
            bool     wasInitialized = HandlerInitializedToday(now);

            IOptionStrike[]  options = optSer.GetStrikes().ToArray();
            PositionsManager posMan  = PositionsManager.GetManager(m_context);

            //if (Context.Runtime.IsAgentMode)
            //{
            // PROD-6089 - Если мы в режиме агента, значит все инструменты уже ISecurityRt
            //    SortedList<DateTime, IOrder> sortedOrders = new SortedList<DateTime, IOrder>(s_comparer);
            //}

            SortedList <DateTime, IPosition> sortedPos = new SortedList <DateTime, IPosition>(s_comparer);

            if (m_countFutures)
            {
                ReadOnlyCollection <IPosition> futPositions = posMan.GetActiveForBar(optSer.UnderlyingAsset);
                if (futPositions.Count > 0)
                {
                    for (int j = 0; j < futPositions.Count; j++)
                    {
                        IPosition pos = futPositions[j];
                        AddSafely(sortedPos, pos);
                    }
                }
            }

            for (int m = 0; m < options.Length; m++)
            {
                IOptionStrike optStrike = options[m];
                ReadOnlyCollection <IPosition> optPositions = posMan.GetActiveForBar(optStrike.Security);
                if (optPositions.Count > 0)
                {
                    for (int j = 0; j < optPositions.Count; j++)
                    {
                        IPosition pos = optPositions[j];
                        AddSafely(sortedPos, pos);
                    }
                }
            }

            int counter = 0;
            List <InteractiveObject> controlPoints = new List <InteractiveObject>();

            foreach (var node in sortedPos)
            {
                InteractivePointActive ip = new InteractivePointActive();
                ip.IsActive = true;
                //ip.DragableMode = DragableMode.None;
                ip.DateTime = node.Key;
                ip.ValueX   = 0; // все одинаковые 'страйки' имеют
                ip.ValueY   = PrepareValue(node, barNum, m_displayMode);
                ip.Tooltip  = PrepareTooltip(node, barNum, m_displayMode);

                controlPoints.Add(new InteractiveObject(ip));

                counter++;
                if (counter >= m_maxPositions)
                {
                    break;
                }
            }

            InteractiveSeries res = new InteractiveSeries(); // Здесь правильно делать new

            // Задаю свойство для отображения
            switch (m_displayMode)
            {
            case PositionGridDisplayMode.Px:
            case PositionGridDisplayMode.Qty:
                res.DisplayProperty.Name = nameof(IInteractivePointLight.ValueY);
                break;

            default:
                res.DisplayProperty.Name = nameof(InteractivePointActive.Tooltip);
                break;
            }
            res.ControlPoints = new ReadOnlyCollection <InteractiveObject>(controlPoints);

            SetHandlerInitialized(now);

            return(res);
        }
示例#6
0
        public Double2N Execute(IOptionSeries source)
        {
            var strikes = source != null?source.GetStrikes() : new IOptionStrike[0];

            return(CalculateInternal(strikes));
        }
示例#7
0
        public IList <Double2> Execute(IOptionSeries source, IReadOnlyList <InteractiveObject> data)
        {
            var strikes = source.GetStrikes().ToArray();

            return(Calculate(strikes, data));
        }
示例#8
0
        public IList <Double2> Execute(IOptionSeries source, InteractiveSeries data)
        {
            var strikes = source.GetStrikes().ToArray();

            return(Calculate(strikes, data.ControlPoints));
        }