/// <summary>
        /// Check for dividends and returns them
        /// </summary>
        /// <param name="eventArgs">The new tradable day event arguments</param>
        /// <returns>New Dividend event if any</returns>
        public IEnumerable <BaseData> GetEvents(NewTradableDateEventArgs eventArgs)
        {
            if (_config.Symbol == eventArgs.Symbol &&
                _mapFile.HasData(eventArgs.Date))
            {
                if (_priceFactorRatio != null)
                {
                    var close = AuxiliaryDataEnumerator.GetRawClose(
                        eventArgs.LastBaseData?.Price ?? 0,
                        _config);
                    var baseData = Dividend.Create(
                        _config.Symbol,
                        eventArgs.Date,
                        close,
                        _priceFactorRatio.Value
                        );
                    // let the config know about it for normalization
                    _config.SumOfDividends += baseData.Distribution;
                    _priceFactorRatio       = null;

                    yield return(baseData);
                }

                // check the factor file to see if we have a dividend event tomorrow
                decimal priceFactorRatio;
                if (_factorFile.HasDividendEventOnNextTradingDay(eventArgs.Date, out priceFactorRatio))
                {
                    _priceFactorRatio = priceFactorRatio;
                }
            }
        }
        /// <summary>
        /// Check for dividends and emit them into the aux data queue
        /// </summary>
        private void CheckForDividend(DateTime date)
        {
            if (_priceFactorRatio != null)
            {
                var close    = GetRawClose();
                var dividend = new Dividend(_config.Symbol, date, close, _priceFactorRatio.Value);
                // let the config know about it for normalization
                _config.SumOfDividends += dividend.Distribution;
                _auxiliaryData.Enqueue(dividend);
                _priceFactorRatio = null;
            }

            // check the factor file to see if we have a dividend event tomorrow
            decimal priceFactorRatio;

            if (_factorFile.HasDividendEventOnNextTradingDay(date, out priceFactorRatio))
            {
                _priceFactorRatio = priceFactorRatio;
            }
        }
示例#3
0
        /// <summary>
        /// Check for dividends and returns them
        /// </summary>
        /// <param name="eventArgs">The new tradable day event arguments</param>
        /// <returns>New Dividend event if any</returns>
        public IEnumerable <BaseData> GetEvents(NewTradableDateEventArgs eventArgs)
        {
            if (_config.Symbol == eventArgs.Symbol &&
                _mapFile.HasData(eventArgs.Date))
            {
                if (_priceFactorRatio != null)
                {
                    if (_referencePrice == 0)
                    {
                        throw new InvalidOperationException($"Zero reference price for {_config.Symbol} dividend at {eventArgs.Date}");
                    }

                    var baseData = Dividend.Create(
                        _config.Symbol,
                        eventArgs.Date,
                        _referencePrice,
                        _priceFactorRatio.Value
                        );
                    // let the config know about it for normalization
                    _config.SumOfDividends += baseData.Distribution;
                    _priceFactorRatio       = null;
                    _referencePrice         = 0;

                    yield return(baseData);
                }

                // check the factor file to see if we have a dividend event tomorrow
                decimal priceFactorRatio;
                decimal referencePrice;
                if (_factorFile.HasDividendEventOnNextTradingDay(eventArgs.Date, out priceFactorRatio, out referencePrice))
                {
                    _priceFactorRatio = priceFactorRatio;
                    _referencePrice   = referencePrice;
                }
            }
        }