Fix Train method during warmup (#6416)
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled

- During warmup period the algorithms initial time might not be a rounded date
  value, so it's important to take into account hours/minutes. Adding
  regression algorithm reproducing and asserting issue
This commit is contained in:
Martin-Molinero
2022-06-21 10:05:27 -03:00
committed by GitHub
parent a42a53671f
commit f0b59a72fd
4 changed files with 236 additions and 7 deletions
+94 -3
View File
@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -14,6 +14,8 @@
*/
using System;
using QuantConnect.Interfaces;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
@@ -22,8 +24,9 @@ namespace QuantConnect.Algorithm.CSharp
/// <meta name="tag" content="using quantconnect" />
/// <meta name="tag" content="training" />
/// </summary>
public class TrainingExampleAlgorithm : QCAlgorithm
public class TrainingExampleAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Queue<DateTime> _trainTimes = new();
public override void Initialize()
{
SetStartDate(2013, 10, 7);
@@ -46,6 +49,94 @@ namespace QuantConnect.Algorithm.CSharp
// ML code:
// let's keep this to assert in the end of the algorithm
_trainTimes.Enqueue(Time);
}
/// <summary>
/// Let's assert the behavior of our traning schedule
/// </summary>
public override void OnEndOfAlgorithm()
{
if (_trainTimes.Count != 2)
{
throw new Exception($"Unexpected train count: {_trainTimes.Count}");
}
if (_trainTimes.Dequeue() != StartDate
|| _trainTimes.Dequeue() != new DateTime(2013, 10, 13, 8, 0, 0))
{
throw new Exception($"Unexpected train times!");
}
}
/// <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>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 56;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "-7.357"},
{"Tracking Error", "0.161"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", ""},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}
}