Beispiel #1
0
        /// <summary>
        /// Check for new splits
        /// </summary>
        /// <param name="eventArgs">The new tradable day event arguments</param>
        /// <returns>New split event if any</returns>
        public IEnumerable <BaseData> GetEvents(NewTradableDateEventArgs eventArgs)
        {
            if (_config.Symbol == eventArgs.Symbol &&
                _mapFile.HasData(eventArgs.Date))
            {
                var factor = _splitFactor;
                if (factor != null)
                {
                    var close = AuxiliaryDataEnumerator.GetRawClose(
                        eventArgs.LastBaseData?.Price ?? 0,
                        _config);
                    _splitFactor = null;
                    yield return(new Split(
                                     eventArgs.Symbol,
                                     eventArgs.Date,
                                     close,
                                     factor.Value,
                                     SplitType.SplitOccurred));
                }

                decimal splitFactor;
                if (_factorFile.HasSplitEventOnNextTradingDay(eventArgs.Date, out splitFactor))
                {
                    _splitFactor = splitFactor;
                    yield return(new Split(
                                     eventArgs.Symbol,
                                     eventArgs.Date,
                                     AuxiliaryDataEnumerator.GetRawClose(
                                         eventArgs.LastBaseData?.Price ?? 0,
                                         _config),
                                     splitFactor,
                                     SplitType.Warning));
                }
            }
        }
        /// <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;
                }
            }
        }