diff --git a/Algorithm.CSharp/AddBetaIndicatorRegressionAlgorithm.cs b/Algorithm.CSharp/AddBetaIndicatorRegressionAlgorithm.cs index c12b933c77ad..bb9b00466855 100644 --- a/Algorithm.CSharp/AddBetaIndicatorRegressionAlgorithm.cs +++ b/Algorithm.CSharp/AddBetaIndicatorRegressionAlgorithm.cs @@ -44,11 +44,6 @@ public override void Initialize() _beta = B("IBM", "SPY", 3, Resolution.Daily); _sma = SMA("SPY", 3, Resolution.Daily); _lastSMAValue = 0; - - if (!_beta.IsReady) - { - throw new RegressionTestException("_beta indicator was expected to be ready"); - } } public override void OnData(Slice slice) @@ -60,7 +55,7 @@ public override void OnData(Slice slice) LimitOrder("IBM", 10, price * 0.1m); StopMarketOrder("IBM", 10, price / 0.1m); } - + if (_beta.Current.Value < 0m || _beta.Current.Value > 2.80m) { throw new RegressionTestException($"_beta value was expected to be between 0 and 2.80 but was {_beta.Current.Value}"); @@ -89,6 +84,18 @@ public override void OnOrderEvent(OrderEvent orderEvent) } } + /// + /// End of algorithm run event handler. This method is called at the end of a backtest or live trading operation. Intended for closing out logs. + /// + public override void OnEndOfAlgorithm() + { + if (!_beta.IsReady) + { + throw new RegressionTestException("Beta indicator was expected to be ready"); + } + Log($"Beta between IBM and SPY is: {_beta.Current.Value}"); + } + /// /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm. /// @@ -107,7 +114,7 @@ public override void OnOrderEvent(OrderEvent orderEvent) /// /// Data Points count of the algorithm history /// - public int AlgorithmHistoryDataPoints => 11; + public int AlgorithmHistoryDataPoints => 9; /// /// Final status of the algorithm