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

Merged
merged 81 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
c881d14
Make FOPs selection universe file-based for backtesting
jhonabreul Dec 10, 2024
8dde624
Make FOPs option chains universe file based
jhonabreul Dec 10, 2024
ba16399
Make Future universe selection file-based like option universe
jhonabreul Dec 17, 2024
d88d30d
Make Future universe selection file-based like option universe
jhonabreul Dec 17, 2024
b72adf1
Abstraction cleanup
jhonabreul Dec 17, 2024
4a841aa
Add FuturesChains API to QC algorithm
jhonabreul Dec 18, 2024
f28318e
Update regression algorithms stats
jhonabreul Dec 18, 2024
e8c75c0
Refactor QuantBook option and future history to use new universes
jhonabreul Dec 19, 2024
10e2592
Fix failing tests
jhonabreul Dec 19, 2024
8a44126
Fix failing tests
jhonabreul Dec 19, 2024
fd79251
Fix failing tests
jhonabreul Dec 20, 2024
dab65ca
Minor future chains unit test improvement
jhonabreul Dec 20, 2024
7c3d63a
Add futures chains DataFrame property
jhonabreul Dec 20, 2024
9b1b7a6
Add DataFrame property to FuturesChains class
jhonabreul Dec 23, 2024
2124b92
Add regression algorithms
jhonabreul Dec 23, 2024
a356897
Add regression algorithms
jhonabreul Dec 24, 2024
c8c6eb5
Replace QCAlgorithm.FutureChainProvider usages with new FuturesChain api
jhonabreul Dec 24, 2024
1f24fd6
Minor fixes
jhonabreul Dec 24, 2024
dbdbd38
Reduce number of universe files in repo
jhonabreul Dec 26, 2024
cbd3438
Minor data fixes
jhonabreul Dec 27, 2024
1b43148
Regression algorithms updates
jhonabreul Dec 27, 2024
66baf97
Add implicit conversion from FuturesContract to Symbol
jhonabreul Dec 27, 2024
4ab170c
Improve resolution handling for history requests
jhonabreul Dec 27, 2024
90cc4ca
Changed _auxiliaryData field to lazily-initialized AuxiliaryData prop…
jhonabreul Dec 27, 2024
5031590
Refactor data handling in BaseChain and TimeSliceFactory
jhonabreul Dec 27, 2024
fd0cc92
Remove specific constructors and indexers from Chain classes
jhonabreul Dec 27, 2024
fa66f34
Remove chain cache logic from FuturesChainUniverse
jhonabreul Dec 27, 2024
557674a
Refactor class and interface names for clarity
jhonabreul Dec 27, 2024
3c850d6
Add base class for options and futures contracts
jhonabreul Dec 27, 2024
b1f4b8a
Add minor fix for future options tickers parsing
jhonabreul Dec 27, 2024
3d555ab
Trigger Build
jhonabreul Dec 31, 2024
c00e0f2
Trigger Build
jhonabreul Jan 2, 2025
3246695
Trigger Build
jhonabreul Jan 2, 2025
935746a
Trigger Build
jhonabreul Jan 3, 2025
b4b03dd
Clean chain provider classes up
jhonabreul Jan 6, 2025
7415872
Remove ZipEntryName other classes and unused code
jhonabreul Jan 8, 2025
7c81de0
Minor changes and cleanup
jhonabreul Jan 8, 2025
1956ff6
Trigger Build
jhonabreul Jan 8, 2025
c5fa272
Trigger Build
jhonabreul Jan 8, 2025
bc2cba1
Refactor FuturesContract data handling
jhonabreul Jan 8, 2025
65b5d52
Fix: use universe data for market data in FuturesContract
jhonabreul Jan 8, 2025
341073f
Update regression algorithms stats after rebase
jhonabreul Jan 17, 2025
83bedf7
Sort configs by internal flag
jhonabreul Jan 17, 2025
6c05df5
Throw from option universe data filters for future options
jhonabreul Jan 17, 2025
476ffb6
Minor changes
jhonabreul Jan 17, 2025
b14e287
Improve some regression algorithms
jhonabreul Jan 17, 2025
01daed7
Minor fix for failing unit tests
jhonabreul Jan 20, 2025
7a98c65
Update FOPs universe file header
jhonabreul Jan 21, 2025
975434a
Minor unit test fix
jhonabreul Jan 21, 2025
40ca555
Trigger Build
jhonabreul Jan 21, 2025
1e57102
Trigger Build
jhonabreul Jan 22, 2025
def8c78
Trigger Build
jhonabreul Jan 22, 2025
dacea57
Trigger Build
jhonabreul Jan 27, 2025
9808d8b
Trigger Build
jhonabreul Jan 27, 2025
ca09f80
Trigger Build
jhonabreul Jan 28, 2025
92c0d94
Trigger Build
jhonabreul Jan 28, 2025
f878a46
Trigger Build
jhonabreul Feb 3, 2025
a950ef9
Trigger Build
jhonabreul Feb 5, 2025
c84fc25
Trigger Build
jhonabreul Feb 5, 2025
f7529bd
Trigger Build
jhonabreul Feb 5, 2025
82379fc
Trigger Build
jhonabreul Feb 10, 2025
043f4c4
Trigger Build
jhonabreul Feb 11, 2025
04f8bc0
Minor fix
jhonabreul Feb 12, 2025
686e931
Add history provider as constructor argument for chain providers
jhonabreul Feb 12, 2025
c2af702
Update new regression algorithms data points count
jhonabreul Feb 12, 2025
3f7d1bc
Minor fix for FakeDataQueue
jhonabreul Feb 12, 2025
f399485
Add initialize method to chain providers classes
jhonabreul Feb 13, 2025
c4399d3
Minor changes
jhonabreul Feb 13, 2025
3ab160c
Trigger Build
jhonabreul Feb 13, 2025
96fa97f
Trigger Build
jhonabreul Feb 13, 2025
0217ed8
Trigger Build
jhonabreul Feb 14, 2025
af5d145
Minor fix
jhonabreul Mar 17, 2025
e6ae78a
Minor fix
jhonabreul Mar 17, 2025
c1c4501
Trigger Build
jhonabreul Mar 17, 2025
aa559ce
Trigger Build
jhonabreul Mar 18, 2025
759d720
Trigger Build
jhonabreul Mar 18, 2025
8ddf4cb
Trigger Build
jhonabreul Mar 18, 2025
f4f7c1c
Add logs to ProcessedDataProvider
jhonabreul Mar 20, 2025
029be86
Removed test logs
jhonabreul Mar 20, 2025
28f3cea
Minor fix
jhonabreul Mar 20, 2025
ed1b0db
Support downloading options and futures universe files from api data …
jhonabreul Mar 25, 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