public override void Initialize() { SetStartDate(2013, 10, 7); SetEndDate(2013, 10, 11); AddEquity("SPY", Resolution.Second); // Create two custom indicators, where one of them defines WarmUpPeriod parameter _customNotWarmUp = new CustomSMA("_customNotWarmUp", 60); _customWarmUp = new CSMAWithWarmUp("_customWarmUp", 60); // Register the daily data of "SPY" to automatically update both indicators RegisterIndicator("SPY", _customWarmUp, Resolution.Minute); RegisterIndicator("SPY", _customNotWarmUp, Resolution.Minute); // Warm up _customWarmUp indicator WarmUpIndicator("SPY", _customWarmUp, Resolution.Minute); // Check _customWarmUp indicator has already been warmed up with the requested data if (!_customWarmUp.IsReady) { throw new Exception("_customWarmUp indicator was expected to be ready"); } if (_customWarmUp.Samples != 60) { throw new Exception("_customWarmUp indicator was expected to have processed 60 datapoints already"); } // Try to warm up _customNotWarmUp indicator. It's expected from LEAN to skip the warm up process // because this indicator doesn't implement IIndicatorWarmUpPeriodProvider WarmUpIndicator("SPY", _customNotWarmUp, Resolution.Minute); // Check _customNotWarmUp indicator is not ready, because the warm up process was skipped if (_customNotWarmUp.IsReady) { throw new Exception("_customNotWarmUp indicator wasn't expected to be warmed up"); } }
public override void Initialize() { SetStartDate(2013, 10, 7); SetEndDate(2013, 10, 11); AddEquity("SPY", Resolution.Second); // Create two custom indicators, where one of them defines WarmUpPeriod parameter _customNotWarmUp = new CSMANotWarmUp("_customNotWarmUp", 60); _customWarmUp = new CSMAWithWarmUp("_customWarmUp", 60); _customNotInherit = new SimpleMovingAverage("_customNotInherit", 60); // using 2nd SMA to match counterpart python algorithm ( CustomSMA + csharpIndicator ) // so that AlgorithmHistoryDataPoints are the same in both _duplicateSMA = new SimpleMovingAverage("_duplicateSMA", 60); // Register the daily data of "SPY" to automatically update both indicators RegisterIndicator("SPY", _customWarmUp, Resolution.Minute); RegisterIndicator("SPY", _customNotWarmUp, Resolution.Minute); RegisterIndicator("SPY", _customNotInherit, Resolution.Minute); RegisterIndicator("SPY", _duplicateSMA, Resolution.Minute); // Warm up _customWarmUp indicator WarmUpIndicator("SPY", _customWarmUp, Resolution.Minute); // Check _customWarmUp indicator has already been warmed up with the requested data if (!_customWarmUp.IsReady) { throw new Exception("_customWarmUp indicator was expected to be ready"); } if (_customWarmUp.Samples != 60) { throw new Exception("_customWarmUp indicator was expected to have processed 60 datapoints already"); } // Try to warm up _customNotWarmUp indicator. It's expected from LEAN to skip the warm up process // because this indicator doesn't implement IIndicatorWarmUpPeriodProvider WarmUpIndicator("SPY", _customNotWarmUp, Resolution.Minute); // Check _customNotWarmUp indicator is not ready, because the warm up process was skipped if (_customNotWarmUp.IsReady) { throw new Exception("_customNotWarmUp indicator wasn't expected to be warmed up"); } WarmUpIndicator("SPY", _customNotInherit, Resolution.Minute); // Check _customWarmUp indicator has already been warmed up with the requested data if (!_customNotInherit.IsReady) { throw new Exception("_customNotInherit indicator was expected to be ready"); } if (_customNotInherit.Samples != 60) { throw new Exception("_customNotInherit indicator was expected to have processed 60 datapoints already"); } WarmUpIndicator("SPY", _duplicateSMA, Resolution.Minute); // Check _customWarmUp indicator has already been warmed up with the requested data if (!_duplicateSMA.IsReady) { throw new Exception("_duplicateSMA indicator was expected to be ready"); } if (_duplicateSMA.Samples != 60) { throw new Exception("_duplicateSMA indicator was expected to have processed 60 datapoints already"); } }