Skip to content

Commit

Permalink
Fix regression test for Beta indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
JosueNina committed Dec 16, 2024
1 parent 834cff7 commit 630838f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Algorithm.CSharp/AddBetaIndicatorRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}");
Expand Down Expand Up @@ -89,6 +84,18 @@ public override void OnOrderEvent(OrderEvent orderEvent)
}
}

/// <summary>
/// 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.
/// </summary>
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}");
}

/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
Expand All @@ -107,7 +114,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 11;
public int AlgorithmHistoryDataPoints => 9;

/// <summary>
/// Final status of the algorithm
Expand Down

0 comments on commit 630838f

Please sign in to comment.