Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Futures and Future Options file-based universes #8480

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d7a9209
Make FOPs selection universe file-based for backtesting
jhonabreul Dec 10, 2024
dc0b080
Make FOPs option chains universe file based
jhonabreul Dec 10, 2024
067364a
Make Future universe selection file-based like option universe
jhonabreul Dec 17, 2024
7c8ba9a
Make Future universe selection file-based like option universe
jhonabreul Dec 17, 2024
6cb4808
Abstraction cleanup
jhonabreul Dec 17, 2024
7eca363
Add FuturesChains API to QC algorithm
jhonabreul Dec 18, 2024
97762ae
Update regression algorithms stats
jhonabreul Dec 18, 2024
85636e2
Refactor QuantBook option and future history to use new universes
jhonabreul Dec 19, 2024
1e1018e
Fix failing tests
jhonabreul Dec 19, 2024
5d7e21f
Fix failing tests
jhonabreul Dec 19, 2024
b0e1f3d
Fix failing tests
jhonabreul Dec 20, 2024
c3511e2
Minor future chains unit test improvement
jhonabreul Dec 20, 2024
144937b
Add futures chains DataFrame property
jhonabreul Dec 20, 2024
4f6c735
Add DataFrame property to FuturesChains class
jhonabreul Dec 23, 2024
ef33438
Add regression algorithms
jhonabreul Dec 23, 2024
296f020
Add regression algorithms
jhonabreul Dec 24, 2024
cf0a483
Replace QCAlgorithm.FutureChainProvider usages with new FuturesChain api
jhonabreul Dec 24, 2024
9482fa0
Minor fixes
jhonabreul Dec 24, 2024
f082aff
Reduce number of universe files in repo
jhonabreul Dec 26, 2024
295ac67
Minor data fixes
jhonabreul Dec 27, 2024
aa0c29f
Regression algorithms updates
jhonabreul Dec 27, 2024
822602a
Add implicit conversion from FuturesContract to Symbol
jhonabreul Dec 27, 2024
bafbdca
Improve resolution handling for history requests
jhonabreul Dec 27, 2024
6c7d8d8
Changed _auxiliaryData field to lazily-initialized AuxiliaryData prop…
jhonabreul Dec 27, 2024
96e9c21
Refactor data handling in BaseChain and TimeSliceFactory
jhonabreul Dec 27, 2024
76a8803
Remove specific constructors and indexers from Chain classes
jhonabreul Dec 27, 2024
c62c9bf
Remove chain cache logic from FuturesChainUniverse
jhonabreul Dec 27, 2024
4af52c4
Refactor class and interface names for clarity
jhonabreul Dec 27, 2024
42d57b3
Add base class for options and futures contracts
jhonabreul Dec 27, 2024
26d52f5
Add minor fix for future options tickers parsing
jhonabreul Dec 27, 2024
34a36d2
Trigger Build
jhonabreul Dec 31, 2024
3f7e140
Trigger Build
jhonabreul Jan 2, 2025
2530d84
Trigger Build
jhonabreul Jan 2, 2025
63aee50
Trigger Build
jhonabreul Jan 3, 2025
f8365b5
Clean chain provider classes up
jhonabreul Jan 6, 2025
58eba49
Remove ZipEntryName other classes and unused code
jhonabreul Jan 8, 2025
3def899
Minor changes and cleanup
jhonabreul Jan 8, 2025
768ce8c
Trigger Build
jhonabreul Jan 8, 2025
44bda96
Trigger Build
jhonabreul Jan 8, 2025
27c6a5f
Refactor FuturesContract data handling
jhonabreul Jan 8, 2025
769d901
Fix: use universe data for market data in FuturesContract
jhonabreul Jan 8, 2025
25583be
Update regression algorithms stats after rebase
jhonabreul Jan 17, 2025
e9bf5cb
Sort configs by internal flag
jhonabreul Jan 17, 2025
f0592fd
Throw from option universe data filters for future options
jhonabreul Jan 17, 2025
dc0a355
Minor changes
jhonabreul Jan 17, 2025
509406b
Improve some regression algorithms
jhonabreul Jan 17, 2025
f0c1e02
Minor fix for failing unit tests
jhonabreul Jan 20, 2025
d154bf5
Update FOPs universe file header
jhonabreul Jan 21, 2025
8252884
Minor unit test fix
jhonabreul Jan 21, 2025
89b7e25
Trigger Build
jhonabreul Jan 21, 2025
31265b4
Trigger Build
jhonabreul Jan 22, 2025
ffd02a2
Trigger Build
jhonabreul Jan 22, 2025
4103752
Trigger Build
jhonabreul Jan 27, 2025
39c25d5
Trigger Build
jhonabreul Jan 27, 2025
80a5748
Trigger Build
jhonabreul Jan 28, 2025
2b9e435
Trigger Build
jhonabreul Jan 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void Initialize()
contractDepthOffset: 0
);

_futureContract = AddFutureContract(FutureChainProvider.GetFutureContractList(_continuousContract.Symbol, Time).First());
_futureContract = AddFutureContract(FuturesChain(_continuousContract.Symbol).First());
}

/// <summary>
Expand Down Expand Up @@ -115,12 +115,12 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 76;
public long DataPoints => 61;

/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;

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

/// <summary>
/// Final status of the algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public override void OnData(Slice slice)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 12172;
public long DataPoints => 9922;

/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 2;

/// <summary>
/// Final status of the algorithm
Expand All @@ -113,7 +113,7 @@ public override void OnData(Slice slice)
{"Total Orders", "20"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "386219349.202%"},
{"Compounding Annual Return", "88398927.578%"},
{"Drawdown", "5.200%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public override void OnData(Slice slice)
return;
}

foreach (var chain in slice.OptionChains.Values)
foreach (var chain in slice.OptionChains.Values.OrderBy(x => x.Symbol.Underlying.ID.Date))
{
var futureInvested = false;
var optionInvested = false;
Expand Down Expand Up @@ -220,7 +220,7 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 608380;
public long DataPoints => 319494;

/// <summary>
/// Data Points count of the algorithm history
Expand All @@ -240,7 +240,7 @@ public override void OnEndOfAlgorithm()
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "347.065%"},
{"Compounding Annual Return", "309.669%"},
{"Drawdown", "0.900%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override void Initialize()
SetEndDate(2013, 10, 10);

var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
_symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
_symbol = FuturesChain(SP500).First();

// Test case: custom IndicatorBase<QuoteBar> indicator using Future unsubscribed symbol
var indicator1 = new CustomIndicator();
Expand Down Expand Up @@ -151,7 +151,7 @@ protected override decimal ComputeNextValue(QuoteBar input)
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 84;
public int AlgorithmHistoryDataPoints => 85;

/// <summary>
/// Final status of the algorithm
Expand Down
5 changes: 2 additions & 3 deletions Algorithm.CSharp/BasicTemplateContinuousFutureAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using QuantConnect.Orders;
using QuantConnect.Interfaces;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Indicators;
using QuantConnect.Securities;
Expand Down Expand Up @@ -118,7 +117,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 713375;
public long DataPoints => 162575;

/// <summary>
/// Data Points count of the algorithm history
Expand Down Expand Up @@ -161,7 +160,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
{"Estimated Strategy Capacity", "$7100000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "2.33%"},
{"OrderListHash", "9c524830ffc7354327638142ae62acd2"}
{"OrderListHash", "04670183a0a4c9160167415aa5102499"}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 2217330;
public long DataPoints => 504530;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
6 changes: 3 additions & 3 deletions Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ public override void OnEndOfAlgorithm()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 133947;
public long DataPoints => 94326;

/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 26;
public int AlgorithmHistoryDataPoints => 0;

/// <summary>
/// Final status of the algorithm
Expand Down Expand Up @@ -233,7 +233,7 @@ public override void OnEndOfAlgorithm()
{"Estimated Strategy Capacity", "€2300000000.00"},
{"Lowest Capacity Asset", "FESX YJHOAMPYKRS5"},
{"Portfolio Turnover", "0.40%"},
{"OrderListHash", "54040d29a467becaedcf59d79323321b"}
{"OrderListHash", "ac9acc478ba1afe53993cdbb92f8ec6e"}
};
}
}
4 changes: 2 additions & 2 deletions Algorithm.CSharp/BasicTemplateFutureRolloverAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void Dispose()
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1185;
public long DataPoints => 727;

/// <summary>
/// Data Points count of the algorithm history
Expand Down Expand Up @@ -221,5 +221,5 @@ public void Dispose()
{"Portfolio Turnover", "0.13%"},
{"OrderListHash", "7c8700a9baa24f6f76d866e7d88cc19c"}
};
}
}
}
4 changes: 2 additions & 2 deletions Algorithm.CSharp/BasicTemplateFuturesAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 75403;
public long DataPoints => 40308;

/// <summary>
/// Data Points count of the algorithm history
Expand All @@ -169,7 +169,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
{"Total Orders", "2700"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-99.777%"},
{"Compounding Annual Return", "-99.597%"},
{"Drawdown", "4.400%"},
{"Expectancy", "-0.724"},
{"Start Equity", "1000000"},
Expand Down
16 changes: 13 additions & 3 deletions Algorithm.CSharp/BasicTemplateFuturesDailyAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using QuantConnect.Orders;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;

Expand Down Expand Up @@ -104,6 +104,16 @@ select futuresContract
}
}

public override void OnSecuritiesChanged(SecurityChanges changes)
{
if (changes.RemovedSecurities.Count > 0 &&
Portfolio.Invested &&
Securities.Values.Where(x => x.Invested).All(x => x.Exchange.Hours.IsOpen(Time, true)))
{
Liquidate();
}
}

/// <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 @@ -117,7 +127,7 @@ select futuresContract
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 12474;
public virtual long DataPoints => 5861;

/// <summary>
/// Data Points count of the algorithm history
Expand Down Expand Up @@ -160,7 +170,7 @@ select futuresContract
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
{"Portfolio Turnover", "0.92%"},
{"OrderListHash", "9507abc8348ff3cb1e2a9a5f48d128a7"}
{"OrderListHash", "c0713abdc4fb059c2be797fce36e4f36"}
};
}
}
2 changes: 1 addition & 1 deletion Algorithm.CSharp/BasicTemplateFuturesFrameworkAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public override IEnumerable<IPortfolioTarget> CreateTargets(QCAlgorithm algorith
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 57759;
public virtual long DataPoints => 24883;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BasicTemplateFuturesFrameworkWithExtendedMarketAlgorithm : BasicTem
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 163416;
public override long DataPoints => 70262;

/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
Expand Down
4 changes: 2 additions & 2 deletions Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ public override void OnOrderEvent(OrderEvent orderEvent)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 48690;
public virtual long DataPoints => 25316;

/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public virtual int AlgorithmHistoryDataPoints => 5305;
public virtual int AlgorithmHistoryDataPoints => 6075;

/// <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 class BasicTemplateFuturesHistoryWithExtendedMarketHoursAlgorithm : Basic
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 147771;
public override long DataPoints => 76063;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
31 changes: 13 additions & 18 deletions Algorithm.CSharp/BasicTemplateFuturesHourlyAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
*
*/

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

namespace QuantConnect.Algorithm.CSharp
{
Expand All @@ -41,40 +36,40 @@ public class BasicTemplateFuturesHourlyAlgorithm : BasicTemplateFuturesDailyAlgo
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 87292;
public override long DataPoints => 25312;

/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "716"},
{"Total Orders", "718"},
{"Average Win", "0.03%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-1.716%"},
{"Compounding Annual Return", "-1.720%"},
{"Drawdown", "1.700%"},
{"Expectancy", "-0.770"},
{"Start Equity", "1000000"},
{"End Equity", "982718.38"},
{"Net Profit", "-1.728%"},
{"Sharpe Ratio", "-8.845"},
{"Sortino Ratio", "-5.449"},
{"End Equity", "982676.58"},
{"Net Profit", "-1.732%"},
{"Sharpe Ratio", "-8.877"},
{"Sortino Ratio", "-5.476"},
{"Probabilistic Sharpe Ratio", "0.000%"},
{"Loss Rate", "96%"},
{"Win Rate", "4%"},
{"Profit-Loss Ratio", "4.89"},
{"Profit-Loss Ratio", "4.90"},
{"Alpha", "-0.018"},
{"Beta", "-0.002"},
{"Annual Standard Deviation", "0.002"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.483"},
{"Information Ratio", "-1.484"},
{"Tracking Error", "0.089"},
{"Treynor Ratio", "9.102"},
{"Total Fees", "$1634.12"},
{"Treynor Ratio", "9.171"},
{"Total Fees", "$1638.42"},
{"Estimated Strategy Capacity", "$8000.00"},
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
{"Portfolio Turnover", "20.10%"},
{"OrderListHash", "aa7e574f86b70428ca0afae381be80ba"}
{"Portfolio Turnover", "20.14%"},
{"OrderListHash", "dedcc487d64e2f601990fc70393c89ed"}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 224662;
public long DataPoints => 117079;

/// <summary>
/// Data Points count of the algorithm history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BasicTemplateFuturesWithExtendedMarketDailyAlgorithm : BasicTemplat
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 14182;
public override long DataPoints => 5965;

/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
Expand Down Expand Up @@ -69,7 +69,7 @@ public class BasicTemplateFuturesWithExtendedMarketDailyAlgorithm : BasicTemplat
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
{"Portfolio Turnover", "0.87%"},
{"OrderListHash", "ea6fdf3133bde7063e4fc0fa809ae260"}
{"OrderListHash", "8b8b733248a21fc717079be54b2e844c"}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BasicTemplateFuturesWithExtendedMarketHourlyAlgorithm : BasicTempla
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 228941;
public override long DataPoints => 67924;

/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
Expand Down
Loading
Loading