Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
64398ab
Add SeedInitialPrices algorithm setting
jhonabreul Oct 16, 2025
0678de3
Update regression algorithms
jhonabreul Oct 16, 2025
30c19e2
Update regression algorithms
jhonabreul Oct 17, 2025
1286294
Update regression algorithms
jhonabreul Oct 17, 2025
accbfe0
Refactor default securities seeding
jhonabreul Oct 20, 2025
ef1c6cf
Minor fix
jhonabreul Oct 20, 2025
749cbe0
Minro fixes
jhonabreul Oct 21, 2025
dd914d0
Cleanup
jhonabreul Oct 21, 2025
08f77e9
Updated and add regression algorithms
jhonabreul Oct 31, 2025
83326ed
Address peer review
jhonabreul Nov 3, 2025
18b2340
Centralize logic to get last known data for multiple securities
jhonabreul Nov 3, 2025
5b36d04
Some cleanup
jhonabreul Nov 4, 2025
8227415
Minor build fix
jhonabreul Nov 4, 2025
04b2a38
Minor fixes
jhonabreul Nov 4, 2025
9a8e93c
More logic centralization
jhonabreul Nov 4, 2025
95babff
Some more cleanup
jhonabreul Nov 4, 2025
5844dd0
Cleanup
jhonabreul Nov 4, 2025
7810d06
Update regression algorithms and minor fixes
jhonabreul Nov 5, 2025
8d3a04d
Update regression algorithms
jhonabreul Nov 5, 2025
af04924
Minor fix
jhonabreul Nov 5, 2025
f418cd4
More minor fixes
jhonabreul Nov 6, 2025
9172d74
Update regression algorithms
jhonabreul Nov 6, 2025
7c09024
Cleanup
jhonabreul Nov 6, 2025
b5cb461
Minor test fix
jhonabreul Nov 6, 2025
d9a5da8
Address peer review
jhonabreul Nov 6, 2025
614a89d
Minor fix and performance improvement
jhonabreul Nov 7, 2025
f62b275
Fix to seed open interest data
jhonabreul Nov 7, 2025
5f6627c
Minor test fixes
jhonabreul Nov 7, 2025
ee7b11c
Address peer review
jhonabreul Nov 10, 2025
37f8b8c
Minor change
jhonabreul Nov 11, 2025
4639ebe
Minor revert
jhonabreul Nov 12, 2025
bb894d5
Minor fixes and improvements
jhonabreul Nov 17, 2025
f5c5ff0
Disable initial seeding by default
jhonabreul Nov 17, 2025
b597244
Minor fixes
jhonabreul Nov 17, 2025
843df2f
Cleanup
jhonabreul Nov 17, 2025
a74e79f
Cleanup
jhonabreul Nov 17, 2025
3677a7f
Minor fix
jhonabreul Nov 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Algorithm.CSharp/AddBetaIndicatorNewAssetsRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -107,7 +107,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 77;
public int AlgorithmHistoryDataPoints => 26;

/// <summary>
/// Final status of the algorithm
Expand All @@ -122,18 +122,18 @@ public override void OnOrderEvent(OrderEvent orderEvent)
{"Total Orders", "436"},
{"Average Win", "0.28%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "1.926%"},
{"Compounding Annual Return", "1.925%"},
{"Drawdown", "1.000%"},
{"Expectancy", "1.650"},
{"Expectancy", "1.649"},
{"Start Equity", "10000.00"},
{"End Equity", "10411.11"},
{"Net Profit", "4.111%"},
{"End Equity", "10410.99"},
{"Net Profit", "4.110%"},
{"Sharpe Ratio", "0.332"},
{"Sortino Ratio", "0.313"},
{"Probabilistic Sharpe Ratio", "74.084%"},
{"Loss Rate", "90%"},
{"Win Rate", "10%"},
{"Profit-Loss Ratio", "25.26"},
{"Profit-Loss Ratio", "25.25"},
{"Alpha", "0.003"},
{"Beta", "0.001"},
{"Annual Standard Deviation", "0.01"},
Expand All @@ -146,7 +146,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
{"Lowest Capacity Asset", "BTCUSD 2XR"},
{"Portfolio Turnover", "2.22%"},
{"Drawdown Recovery", "139"},
{"OrderListHash", "9fce77ef8817cf0159897fc64d01f5e9"}
{"OrderListHash", "896ecc92440d51ed26644aac5b8706e4"}
};
}
}
137 changes: 137 additions & 0 deletions Algorithm.CSharp/AutomaticSeedBaseRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

using System.Collections.Generic;
using System.Linq;
using QuantConnect.Interfaces;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Data.Market;
using QuantConnect.Securities;

namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm asserting that security are automatically seeded by default
/// </summary>
public abstract class AutomaticSeedBaseRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
protected virtual bool ShouldHaveTradeData { get; }
protected virtual bool ShouldHaveQuoteData { get; }
protected virtual bool ShouldHaveOpenInterestData { get; }

public override void OnSecuritiesChanged(SecurityChanges changes)
{
var gotTrades = false;
var gotQuotes = false;
var gotOpenInterest = false;

foreach (var addedSecurity in changes.AddedSecurities.Where(x => !x.Symbol.IsCanonical() || x.Symbol.SecurityType == SecurityType.Future))
{
if (addedSecurity.Price == 0)
{
throw new RegressionTestException("Security was not seeded");
}

if (!addedSecurity.HasData)
{
throw new RegressionTestException("Security does not have TradeBar or QuoteBar or OpenInterest data");
}

gotTrades |= addedSecurity.Cache.GetData<TradeBar>() != null;
gotQuotes |= addedSecurity.Cache.GetData<QuoteBar>() != null;
gotOpenInterest |= addedSecurity.Cache.GetData<OpenInterest>() != null;
}

if (changes.AddedSecurities.Count > 0)
{
if (ShouldHaveTradeData && !gotTrades)
{
throw new RegressionTestException("No contract had TradeBar data");
}

if (ShouldHaveQuoteData && !gotQuotes)
{
throw new RegressionTestException("No contract had QuoteBar data");
}

if (ShouldHaveOpenInterestData && !gotOpenInterest)
{
throw new RegressionTestException("No contract had OpenInterest data");
}
}
}

/// <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 List<Language> Languages { get; } = new() { Language.CSharp };

/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public abstract long DataPoints { get; }

/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public abstract int AlgorithmHistoryDataPoints { get; }

/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;

/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "100000"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino 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", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", ""},
{"Portfolio Turnover", "0%"},
{"Drawdown Recovery", "0"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}
2 changes: 1 addition & 1 deletion Algorithm.CSharp/BasicSetAccountCurrencyAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override void OnData(Slice slice)
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 120;
public int AlgorithmHistoryDataPoints => 15;

/// <summary>
/// Final status of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void SetAccountCurrency()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 120;
public int AlgorithmHistoryDataPoints => 15;

/// <summary>
/// Final status of the algorithm
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.CSharp/BasicTemplateCryptoAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 240;
public int AlgorithmHistoryDataPoints => 35;

/// <summary>
/// Final status of the algorithm
Expand All @@ -220,7 +220,7 @@ public override void OnEndOfAlgorithm()
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "31588.24"},
{"Start Equity", "31592.84"},
{"End Equity", "30866.71"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/BasicTemplateFuturesAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 340;
public int AlgorithmHistoryDataPoints => 354;

/// <summary>
/// Final status of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 340;
public int AlgorithmHistoryDataPoints => 354;

/// <summary>
/// Final status of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void Initialize()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 28;
public override int AlgorithmHistoryDataPoints => 5;

/// <summary>
/// Final status of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void Initialize()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 28;
public override int AlgorithmHistoryDataPoints => 5;

/// <summary>
/// Final status of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void Initialize()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 28;
public override int AlgorithmHistoryDataPoints => 5;

/// <summary>
/// Final status of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void Initialize()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 28;
public override int AlgorithmHistoryDataPoints => 5;

/// <summary>
/// Final status of the algorithm
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.CSharp/BybitCryptoFuturesRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 60;
public int AlgorithmHistoryDataPoints => 10;

/// <summary>
/// Final status of the algorithm
Expand All @@ -244,7 +244,7 @@ public override void OnEndOfAlgorithm()
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100285.86"},
{"Start Equity", "100285.85"},
{"End Equity", "100285.26"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.CSharp/BybitCryptoRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 60;
public int AlgorithmHistoryDataPoints => 10;

/// <summary>
/// Final status of the algorithm
Expand All @@ -153,7 +153,7 @@ public override void OnEndOfAlgorithm()
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "117171.12"},
{"Start Equity", "117170.74"},
{"End Equity", "117244.52"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public override BaseData Reader(SubscriptionDataConfig config, string line, Date
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 60;
public int AlgorithmHistoryDataPoints => 10;

/// <summary>
/// Final status of the algorithm
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.CSharp/CancelOpenOrdersRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 120;
public int AlgorithmHistoryDataPoints => 20;

/// <summary>
/// Final status of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public override void Initialize()
_aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
UniverseSettings.Resolution = Resolution.Minute;

// Let's disable initial price seeding, the algorithm will wait until both equity
// and options are added an have prices to do the tests, we don't want the equity
// having prices before the options are added.
Settings.SeedInitialPrices = false;

SetStartDate(2014, 06, 04);
// TWX is selected the 4th and 5th and aapl after that.
// If the algo ends on the 6th, TWX subscriptions will not be removed before OnEndOfAlgorithm is called:
Expand Down
Loading
Loading