Ejemplo n.º 1
0
        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">Slice object keyed by symbol containing the stock data</param>
        public override void OnData(Slice data)
        {
            if (!Portfolio.Invested)
            {
                SetHoldings(_googl, 1);
            }

            if (data.Bars.ContainsKey(_googl))
            {
                var googlData = data.Bars[_googl];

                // Assert our volume matches what we expected
                if (_expectedRawPrices.Current != googlData.Close)
                {
                    // Our values don't match lets try and give a reason why
                    var dayFactor        = _factorFile.GetPriceScaleFactor(googlData.Time);
                    var probableRawPrice = googlData.Close / dayFactor; // Undo adjustment

                    if (_expectedRawPrices.Current == probableRawPrice)
                    {
                        throw new Exception($"Close price was incorrect; it appears to be the adjusted value");
                    }
                    else
                    {
                        throw new Exception($"Close price was incorrect; Data may have changed.");
                    }
                }

                // Move to our next expected value
                _expectedRawPrices.MoveNext();
            }
        }
Ejemplo n.º 2
0
        private static decimal GetScaleFactor(FactorFile factorFile, DataNormalizationMode mode, DateTime date)
        {
            switch (mode)
            {
            case DataNormalizationMode.Raw:
                return(1);

            case DataNormalizationMode.TotalReturn:
            case DataNormalizationMode.SplitAdjusted:
                return(factorFile.GetSplitFactor(date));

            case DataNormalizationMode.Adjusted:
                return(factorFile.GetPriceScaleFactor(date));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// For backwards adjusted data the price is adjusted by a scale factor which is a combination of splits and dividends.
        /// This backwards adjusted price is used by default and fed as the current price.
        /// </summary>
        /// <param name="date">Current date of the backtest.</param>
        private void UpdateScaleFactors(DateTime date)
        {
            switch (_config.DataNormalizationMode)
            {
            case DataNormalizationMode.Raw:
                return;

            case DataNormalizationMode.TotalReturn:
            case DataNormalizationMode.SplitAdjusted:
                _config.PriceScaleFactor = _factorFile.GetSplitFactor(date);
                break;

            case DataNormalizationMode.Adjusted:
                _config.PriceScaleFactor = _factorFile.GetPriceScaleFactor(date);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }