Compare commits

...

78 Commits

Author SHA1 Message Date
Jhonathan Abreu
f4f7c1c18c Add logs to ProcessedDataProvider 2025-03-20 09:45:19 -04:00
Jhonathan Abreu
8ddf4cb390 Trigger Build 2025-03-20 09:45:18 -04:00
Jhonathan Abreu
759d7207ac Trigger Build 2025-03-20 09:45:18 -04:00
Jhonathan Abreu
aa559ce5cb Trigger Build 2025-03-20 09:45:17 -04:00
Jhonathan Abreu
c1c4501377 Trigger Build 2025-03-20 09:45:17 -04:00
Jhonathan Abreu
e6ae78ad26 Minor fix 2025-03-20 09:45:16 -04:00
Jhonathan Abreu
af5d1458d8 Minor fix 2025-03-20 09:45:16 -04:00
Jhonathan Abreu
0217ed8453 Trigger Build 2025-03-20 09:45:16 -04:00
Jhonathan Abreu
96fa97fa5c Trigger Build 2025-03-20 09:45:15 -04:00
Jhonathan Abreu
3ab160cb37 Trigger Build 2025-03-20 09:45:15 -04:00
Jhonathan Abreu
c4399d3226 Minor changes 2025-03-20 09:45:14 -04:00
Jhonathan Abreu
f399485970 Add initialize method to chain providers classes 2025-03-20 09:45:14 -04:00
Jhonathan Abreu
3f7d1bc36f Minor fix for FakeDataQueue 2025-03-20 09:45:13 -04:00
Jhonathan Abreu
c2af7028e8 Update new regression algorithms data points count 2025-03-20 09:45:13 -04:00
Jhonathan Abreu
686e93165e Add history provider as constructor argument for chain providers 2025-03-20 09:45:12 -04:00
Jhonathan Abreu
04f8bc01d9 Minor fix 2025-03-20 09:45:11 -04:00
Jhonathan Abreu
043f4c42bd Trigger Build 2025-03-20 09:45:11 -04:00
Jhonathan Abreu
82379fce2a Trigger Build 2025-03-20 09:45:10 -04:00
Jhonathan Abreu
f7529bdde2 Trigger Build 2025-03-20 09:45:10 -04:00
Jhonathan Abreu
c84fc2534e Trigger Build 2025-03-20 09:45:10 -04:00
Jhonathan Abreu
a950ef9286 Trigger Build 2025-03-20 09:45:09 -04:00
Jhonathan Abreu
f878a46408 Trigger Build 2025-03-20 09:45:09 -04:00
Jhonathan Abreu
92c0d94d51 Trigger Build 2025-03-20 09:45:08 -04:00
Jhonathan Abreu
ca09f80ec1 Trigger Build 2025-03-20 09:45:08 -04:00
Jhonathan Abreu
9808d8bb46 Trigger Build 2025-03-20 09:45:08 -04:00
Jhonathan Abreu
dacea571bb Trigger Build 2025-03-20 09:45:07 -04:00
Jhonathan Abreu
def8c78ac4 Trigger Build 2025-03-20 09:45:06 -04:00
Jhonathan Abreu
1e57102261 Trigger Build 2025-03-20 09:45:06 -04:00
Jhonathan Abreu
40ca555dbc Trigger Build 2025-03-20 09:45:05 -04:00
Jhonathan Abreu
975434a950 Minor unit test fix 2025-03-20 09:45:05 -04:00
Jhonathan Abreu
7a98c6501a Update FOPs universe file header
Removed greeks and IV columns.
Updated FOPs universe files: removed outdated columns.
2025-03-20 09:45:04 -04:00
Jhonathan Abreu
01daed7075 Minor fix for failing unit tests 2025-03-20 09:45:04 -04:00
Jhonathan Abreu
b14e287959 Improve some regression algorithms 2025-03-20 09:45:04 -04:00
Jhonathan Abreu
476ffb6742 Minor changes 2025-03-20 09:45:03 -04:00
Jhonathan Abreu
6c05df56af Throw from option universe data filters for future options
Future options IV, Open interest and greeks are not supported for future options
2025-03-20 09:45:03 -04:00
Jhonathan Abreu
83bedf703a Sort configs by internal flag
Internals go first
2025-03-20 09:45:02 -04:00
Jhonathan Abreu
341073f5f3 Update regression algorithms stats after rebase
Added HSI futures universe files
2025-03-20 09:45:02 -04:00
Jhonathan Abreu
65b5d52909 Fix: use universe data for market data in FuturesContract 2025-03-20 09:45:01 -04:00
Jhonathan Abreu
bc2cba13bb Refactor FuturesContract data handling
Forward price data from bars and ticks stored in private fields for improved memory usage
2025-03-20 09:45:01 -04:00
Jhonathan Abreu
c5fa27220c Trigger Build 2025-03-20 09:45:00 -04:00
Jhonathan Abreu
1956ff64e6 Trigger Build 2025-03-20 09:45:00 -04:00
Jhonathan Abreu
7c81de0ef7 Minor changes and cleanup 2025-03-20 09:44:59 -04:00
Jhonathan Abreu
74158721eb Remove ZipEntryName other classes and unused code
Removed ZipEntryName class and references across various files.
Removed DataQueueFuturesChainUniverseDataCollectionEnumerator and DataQueueOptionChainUniverseDataCollectionEnumerator classes.
Removed OptionChainUniverseSubscriptionEnumeratorFactory class.
Removed unused code for handling OptionChainUniverse and FuturesChainUniverse in FileSystemDataFeed.cs and LiveTradingDataFeed.cs.
Removed several test files related to enumerator factories and universe data collection.
2025-03-20 09:44:59 -04:00
Jhonathan Abreu
b4b03ddee8 Clean chain provider classes up 2025-03-20 09:44:57 -04:00
Jhonathan Abreu
935746ac62 Trigger Build 2025-03-20 09:44:56 -04:00
Jhonathan Abreu
3246695c95 Trigger Build 2025-03-20 09:44:56 -04:00
Jhonathan Abreu
c00e0f2104 Trigger Build 2025-03-20 09:44:55 -04:00
Jhonathan Abreu
3d555ab510 Trigger Build 2025-03-20 09:44:55 -04:00
Jhonathan Abreu
b1f4b8a78c Add minor fix for future options tickers parsing
Added tests
2025-03-20 09:44:54 -04:00
Jhonathan Abreu
3c850d6d79 Add base class for options and futures contracts
- Introduced `BaseContract` as an abstract base class for contracts, consolidating common properties and methods.
- Removed ISymbolInterface
2025-03-20 09:44:54 -04:00
Jhonathan Abreu
557674a178 Refactor class and interface names for clarity
Renamed `FileBasedUniverse` to `BaseChainUniverseData` and
`IFileBasedUniverse` to `IChainUniverseData`.
2025-03-20 09:44:51 -04:00
Jhonathan Abreu
fa66f348a8 Remove chain cache logic from FuturesChainUniverse 2025-03-20 09:44:49 -04:00
Jhonathan Abreu
fd0cc927a8 Remove specific constructors and indexers from Chain classes
Removed public indexers in `BaseChains` for getting or setting `BaseChain` instances by `ticker` or `Symbol`, which were used for Pythonnet compatibility.
2025-03-20 09:44:49 -04:00
Jhonathan Abreu
5031590155 Refactor data handling in BaseChain and TimeSliceFactory
- Added `AddData` method to `BaseChain` for adding market data
- Refactored `TimeSliceFactory` to use `BaseChain.AddData` method
2025-03-20 09:44:48 -04:00
Jhonathan Abreu
90cc4ca468 Changed _auxiliaryData field to lazily-initialized AuxiliaryData property 2025-03-20 09:44:48 -04:00
Jhonathan Abreu
4ab170c821 Improve resolution handling for history requests 2025-03-20 09:44:48 -04:00
Jhonathan Abreu
66baf97bb4 Add implicit conversion from FuturesContract to Symbol
Modified algorithms to use futures contract objects directly instead of accessing their Symbol property.
Removed unnecessary import statements and redundant lines in various files.
2025-03-20 09:44:47 -04:00
Jhonathan Abreu
1b431480a9 Regression algorithms updates 2025-03-20 09:44:46 -04:00
Jhonathan Abreu
cbd343824d Minor data fixes 2025-03-20 09:44:45 -04:00
Jhonathan Abreu
dbdbd38181 Reduce number of universe files in repo 2025-03-20 09:44:44 -04:00
Jhonathan Abreu
1f24fd610e Minor fixes 2025-03-20 09:44:38 -04:00
Jhonathan Abreu
c8c6eb599e Replace QCAlgorithm.FutureChainProvider usages with new FuturesChain api 2025-03-20 09:44:37 -04:00
Jhonathan Abreu
a35689731d Add regression algorithms 2025-03-20 09:44:36 -04:00
Jhonathan Abreu
2124b92acf Add regression algorithms 2025-03-20 09:44:35 -04:00
Jhonathan Abreu
9b1b7a61cc Add DataFrame property to FuturesChains class 2025-03-20 09:44:34 -04:00
Jhonathan Abreu
7c3d63a87d Add futures chains DataFrame property
Also, remove IDerivativeSecurity interface from Future
2025-03-20 09:44:32 -04:00
Jhonathan Abreu
dab65ca2d1 Minor future chains unit test improvement 2025-03-20 09:44:21 -04:00
Jhonathan Abreu
fd79251c65 Fix failing tests 2025-03-20 09:44:20 -04:00
Jhonathan Abreu
8a441263dd Fix failing tests 2025-03-20 09:44:19 -04:00
Jhonathan Abreu
10e2592d5e Fix failing tests 2025-03-20 09:44:17 -04:00
Jhonathan Abreu
e8c75c08d5 Refactor QuantBook option and future history to use new universes 2025-03-20 09:44:15 -04:00
Jhonathan Abreu
f28318ec99 Update regression algorithms stats 2025-03-20 09:44:14 -04:00
Jhonathan Abreu
4a841aab5e Add FuturesChains API to QC algorithm
Also refactor future chain provider to use the new FutureUniverse instead of zip file names
2025-03-20 09:44:10 -04:00
Jhonathan Abreu
b72adf16d2 Abstraction cleanup 2025-03-20 09:44:09 -04:00
Jhonathan Abreu
d88d30d5f6 Make Future universe selection file-based like option universe 2025-03-20 09:44:08 -04:00
Jhonathan Abreu
ba16399039 Make Future universe selection file-based like option universe 2025-03-20 09:44:04 -04:00
Jhonathan Abreu
8dde62454c Make FOPs option chains universe file based 2025-03-20 09:44:00 -04:00
Jhonathan Abreu
c881d14c4a Make FOPs selection universe file-based for backtesting 2025-03-20 09:43:59 -04:00
262 changed files with 4994 additions and 3184 deletions

View File

@@ -49,7 +49,7 @@ namespace QuantConnect.Algorithm.CSharp
contractDepthOffset: 0
);
_futureContract = AddFutureContract(FutureChainProvider.GetFutureContractList(_continuousContract.Symbol, Time).First());
_futureContract = AddFutureContract(FuturesChain(_continuousContract.Symbol).First());
}
/// <summary>
@@ -115,12 +115,12 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -169,7 +169,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 2;
/// <summary>
/// Final status of the algorithm

View File

@@ -93,12 +93,12 @@ namespace QuantConnect.Algorithm.CSharp
/// <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
@@ -113,7 +113,7 @@ namespace QuantConnect.Algorithm.CSharp
{"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"},

View File

@@ -108,7 +108,7 @@ namespace QuantConnect.Algorithm.CSharp
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;
@@ -220,7 +220,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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
@@ -240,7 +240,7 @@ namespace QuantConnect.Algorithm.CSharp
{"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"},

View File

@@ -38,7 +38,7 @@ namespace QuantConnect.Algorithm.CSharp
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();
@@ -151,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 84;
public int AlgorithmHistoryDataPoints => 85;
/// <summary>
/// Final status of the algorithm

View File

@@ -18,7 +18,6 @@ using QuantConnect.Data;
using QuantConnect.Orders;
using QuantConnect.Interfaces;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Indicators;
using QuantConnect.Securities;
@@ -118,7 +117,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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
@@ -161,7 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$7100000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "2.33%"},
{"OrderListHash", "9c524830ffc7354327638142ae62acd2"}
{"OrderListHash", "04670183a0a4c9160167415aa5102499"}
};
}
}

View File

@@ -123,7 +123,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -190,12 +190,12 @@ namespace QuantConnect.Algorithm.CSharp
/// <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
@@ -233,7 +233,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "€2300000000.00"},
{"Lowest Capacity Asset", "FESX YJHOAMPYKRS5"},
{"Portfolio Turnover", "0.40%"},
{"OrderListHash", "54040d29a467becaedcf59d79323321b"}
{"OrderListHash", "ac9acc478ba1afe53993cdbb92f8ec6e"}
};
}
}

View File

@@ -176,7 +176,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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
@@ -221,5 +221,5 @@ namespace QuantConnect.Algorithm.CSharp
{"Portfolio Turnover", "0.13%"},
{"OrderListHash", "7c8700a9baa24f6f76d866e7d88cc19c"}
};
}
}
}

View File

@@ -149,7 +149,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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
@@ -169,7 +169,7 @@ namespace QuantConnect.Algorithm.CSharp
{"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"},

View File

@@ -18,8 +18,8 @@ using System;
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;
@@ -104,6 +104,16 @@ namespace QuantConnect.Algorithm.CSharp
}
}
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>
@@ -117,7 +127,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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
@@ -160,7 +170,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
{"Portfolio Turnover", "0.92%"},
{"OrderListHash", "9507abc8348ff3cb1e2a9a5f48d128a7"}
{"OrderListHash", "c0713abdc4fb059c2be797fce36e4f36"}
};
}
}

View File

@@ -136,7 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -41,7 +41,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -140,12 +140,12 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -47,7 +47,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -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
{
@@ -41,40 +36,40 @@ namespace QuantConnect.Algorithm.CSharp
/// <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"}
};
}
}

View File

@@ -149,7 +149,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -36,7 +36,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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
@@ -69,7 +69,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
{"Portfolio Turnover", "0.87%"},
{"OrderListHash", "ea6fdf3133bde7063e4fc0fa809ae260"}
{"OrderListHash", "8b8b733248a21fc717079be54b2e844c"}
};
}
}

View File

@@ -41,7 +41,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -47,7 +47,7 @@ namespace QuantConnect.Algorithm.CSharp
SetEndDate(2020, 01, 20);
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
var symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
var symbol = FuturesChain(SP500).First();
_future = AddFutureContract(symbol);
var tradableDatesCount = QuantConnect.Time.EachTradeableDayInTimeZone(_future.Exchange.Hours,
@@ -194,7 +194,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -139,7 +139,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 713371;
public long DataPoints => 162571;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -155,7 +155,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 723498;
public long DataPoints => 172698;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -120,7 +120,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 9953;
public virtual long DataPoints => 5469;
/// <summary>
/// Data Points count of the algorithm history
@@ -160,7 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$2.15"},
{"Estimated Strategy Capacity", "$100000000.00"},
{"Estimated Strategy Capacity", "$130000000.00"},
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
{"Portfolio Turnover", "41.23%"},
{"OrderListHash", "b9f8e1a0704c086944e5df07e0ab04d6"}

View File

@@ -34,6 +34,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 15813;
public override long DataPoints => 9079;
}
}

View File

@@ -78,7 +78,7 @@ namespace QuantConnect.Algorithm.CSharp
}
return universe.Select(x => x);
return universe;
});
_milk.SetFilter(universe =>
@@ -94,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
}
}
return universe.Select(x => x);
return universe;
});
}
@@ -184,7 +184,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 596358;
public long DataPoints => 445961;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -78,7 +78,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 19888;
public long DataPoints => 10883;
/// <summary>
/// Data Points count of the algorithm history
@@ -98,7 +98,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-99.258%"},
{"Compounding Annual Return", "-99.012%"},
{"Drawdown", "6.300%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},

View File

@@ -188,7 +188,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 396945;
public virtual long DataPoints => 159274;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -173,7 +173,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 1014;
public override long DataPoints => 483;
}
}

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 1004;
public override long DataPoints => 479;
}
}

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 1007;
public override long DataPoints => 483;
}
}

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 18850;
public override long DataPoints => 7424;
}
}

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 18844;
public override long DataPoints => 7440;
}
}

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 18846;
public override long DataPoints => 7434;
}
}

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 1127376;
public override long DataPoints => 444159;
}
}

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 1127374;
public override long DataPoints => 445123;
}
}

View File

@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 1127488;
public override long DataPoints => 444757;
}
}

View File

@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1276;
public long DataPoints => 848;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -62,7 +62,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 516622;
public long DataPoints => 70735;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -28,7 +28,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 1690;
public override long DataPoints => 1235;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
@@ -44,24 +44,24 @@ namespace QuantConnect.Algorithm.CSharp
{"Start Equity", "100000"},
{"End Equity", "107779.1"},
{"Net Profit", "7.779%"},
{"Sharpe Ratio", "3.132"},
{"Sharpe Ratio", "3.128"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "99.474%"},
{"Probabilistic Sharpe Ratio", "99.450%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.145"},
{"Beta", "0.271"},
{"Annual Standard Deviation", "0.081"},
{"Annual Variance", "0.006"},
{"Annual Variance", "0.007"},
{"Information Ratio", "-1.459"},
{"Tracking Error", "0.099"},
{"Treynor Ratio", "0.932"},
{"Treynor Ratio", "0.931"},
{"Total Fees", "$2.15"},
{"Estimated Strategy Capacity", "$150000000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "1.98%"},
{"OrderListHash", "b337ac27f46a6298dd4e9f0f04b49427"}
{"OrderListHash", "6365adfc234509e390295a150f25c295"}
};
}
}

View File

@@ -92,7 +92,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 525811;
public virtual long DataPoints => 288140;
/// <summary>
/// Data Points count of the algorithm history
@@ -124,18 +124,18 @@ namespace QuantConnect.Algorithm.CSharp
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.228"},
{"Beta", "0.108"},
{"Alpha", "0.227"},
{"Beta", "0.109"},
{"Annual Standard Deviation", "0.084"},
{"Annual Variance", "0.007"},
{"Information Ratio", "-1.122"},
{"Tracking Error", "0.112"},
{"Treynor Ratio", "2.501"},
{"Treynor Ratio", "2.49"},
{"Total Fees", "$2.15"},
{"Estimated Strategy Capacity", "$1700000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "2.01%"},
{"OrderListHash", "640ce720644ff0b580687e80105d0a92"}
{"OrderListHash", "de82efe4f019a5fa1fb79d111bf15811"}
};
}
}

View File

@@ -14,7 +14,6 @@
*/
using System.Collections.Generic;
using QuantConnect.Orders;
namespace QuantConnect.Algorithm.CSharp
{
@@ -29,7 +28,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 12251;
public override long DataPoints => 3918;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm

View File

@@ -13,13 +13,11 @@
* limitations under the License.
*/
using System;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Orders;
namespace QuantConnect.Algorithm.CSharp
{
@@ -107,7 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 4632655;
public virtual long DataPoints => 761073;
/// <summary>
/// Data Points count of the algorithm history
@@ -131,10 +129,10 @@ namespace QuantConnect.Algorithm.CSharp
{"Drawdown", "0.100%"},
{"Expectancy", "-0.678"},
{"Start Equity", "10000000"},
{"End Equity", "9988860.24"},
{"End Equity", "9988880.24"},
{"Net Profit", "-0.111%"},
{"Sharpe Ratio", "-10.413"},
{"Sortino Ratio", "-0.961"},
{"Sharpe Ratio", "-10.416"},
{"Sortino Ratio", "-0.959"},
{"Probabilistic Sharpe Ratio", "0.000%"},
{"Loss Rate", "80%"},
{"Win Rate", "20%"},
@@ -145,12 +143,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Annual Variance", "0"},
{"Information Ratio", "-1.076"},
{"Tracking Error", "0.107"},
{"Treynor Ratio", "14.588"},
{"Treynor Ratio", "14.634"},
{"Total Fees", "$19.76"},
{"Estimated Strategy Capacity", "$1300000000.00"},
{"Estimated Strategy Capacity", "$1400000000.00"},
{"Lowest Capacity Asset", "DC V5E8PHPRCHJ8|DC V5E8P9SH0U0X"},
{"Portfolio Turnover", "0.00%"},
{"OrderListHash", "7f06f736e2f1294916fb2485519021a2"}
{"OrderListHash", "67b64c13cbc4aad88111503cf7b789bc"}
};
}
}

View File

@@ -130,7 +130,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 94731;
public long DataPoints => 36213;
/// <summary>
/// Data Points count of the algorithm history
@@ -150,7 +150,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Orders", "8"},
{"Average Win", "0.69%"},
{"Average Loss", "-2.47%"},
{"Compounding Annual Return", "-99.966%"},
{"Compounding Annual Return", "-99.946%"},
{"Drawdown", "28.600%"},
{"Expectancy", "-0.680"},
{"Start Equity", "100000"},

View File

@@ -91,7 +91,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 872;
public long DataPoints => 852;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -94,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 54138;
public long DataPoints => 19043;
/// <summary>
/// Data Points count of the algorithm history
@@ -114,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-99.310%"},
{"Compounding Annual Return", "-98.880%"},
{"Drawdown", "4.400%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},

View File

@@ -100,7 +100,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 13586;
public virtual long DataPoints => 91;
/// </summary>
/// Data Points count of the algorithm history

View File

@@ -54,7 +54,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 41467;
public override long DataPoints => 92;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm

View File

@@ -94,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 32073;
public virtual long DataPoints => 16313;
/// </summary>
/// Data Points count of the algorithm history

View File

@@ -57,7 +57,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 103818;
public override long DataPoints => 51933;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm

View File

@@ -90,7 +90,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 18492;
public long DataPoints => 11768;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -117,7 +117,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 2;
/// <summary>
/// Final status of the algorithm

View File

@@ -205,7 +205,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -170,7 +170,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -181,7 +181,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -0,0 +1,127 @@
/*
* 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;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.OptionChain(Symbol)"/> method
/// to get a future option chain.
/// </summary>
public class FutureOptionChainFullDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _optionContract;
public override void Initialize()
{
SetStartDate(2020, 1, 6);
SetEndDate(2020, 1, 6);
var futureContract = AddFutureContract(
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 3, 20)),
Resolution.Minute).Symbol;
_optionContract = OptionChain(futureContract)
// Get contracts expiring within 4 months
.Where(contractData => contractData.Expiry - Time <= TimeSpan.FromDays(120))
// Get the contract with the latest expiration date, highest strike and lowest price
.OrderByDescending(x => x.Expiry)
.ThenByDescending(x => x.Strike)
.ThenBy(x => x.LastPrice)
.First();
AddFutureOptionContract(_optionContract);
}
public override void OnData(Slice slice)
{
// Do some trading with the selected contract for sample purposes
if (!Portfolio.Invested)
{
SetHoldings(_optionContract, 0.5);
}
else
{
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>
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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1817;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 1;
/// <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 Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "450"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "65398.86"},
{"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", "$34601.14"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES XCZJLCGM383O|ES XCZJLC9NOB29"},
{"Portfolio Turnover", "112.25%"},
{"OrderListHash", "f18259d04c2d899e7162b88e10239eb8"}
};
}
}

View File

@@ -0,0 +1,147 @@
/*
* 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;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.OptionChains(IEnumerable{Symbol})"/> method
/// to get multiple future option chains.
/// </summary>
public class FutureOptionChainsMultipleFullDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _esOptionContract;
private Symbol _gcOptionContract;
public override void Initialize()
{
SetStartDate(2020, 1, 6);
SetEndDate(2020, 1, 6);
SetCash(100000);
var esFutureContract = AddFutureContract(
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 3, 20)),
Resolution.Minute).Symbol;
var gcFutureContract = AddFutureContract(
QuantConnect.Symbol.CreateFuture(Futures.Metals.Gold, Market.COMEX, new DateTime(2020, 4, 28)),
Resolution.Minute).Symbol;
var chains = OptionChains([esFutureContract, gcFutureContract]);
_esOptionContract = GetContract(chains, esFutureContract);
_gcOptionContract = GetContract(chains, gcFutureContract);
AddFutureOptionContract(_esOptionContract);
AddFutureOptionContract(_gcOptionContract);
}
private Symbol GetContract(OptionChains chains, Symbol underlying)
{
return chains
.Where(kvp => kvp.Key.Underlying == underlying)
.Select(kvp => kvp.Value)
.Single()
// Get contracts expiring within 5 months
.Where(contractData => contractData.Expiry - Time <= TimeSpan.FromDays(120))
// Get the contract with the latest expiration date, highest strike and lowest price
.OrderByDescending(x => x.Expiry)
.ThenByDescending(x => x.Strike)
.ThenBy(x => x.LastPrice)
.First();
}
public override void OnData(Slice slice)
{
// Do some trading with the selected contract for sample purposes
if (!Portfolio.Invested)
{
SetHoldings(_esOptionContract, 0.25);
SetHoldings(_gcOptionContract, 0.25);
}
else
{
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>
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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1819;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 2;
/// <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 Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "450"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "80983.36"},
{"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", "$19016.64"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES XCZJLCGM383O|ES XCZJLC9NOB29"},
{"Portfolio Turnover", "49.52%"},
{"OrderListHash", "9b39296a82d51d51fa1df02aad39d804"}
};
}
}

View File

@@ -124,7 +124,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public virtual int AlgorithmHistoryDataPoints => 0;
public virtual int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -73,7 +73,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 0;
public override int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -51,6 +51,11 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public override long DataPoints => 1817;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>

View File

@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 24379;
public long DataPoints => 13942;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -206,7 +206,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -179,7 +179,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -190,7 +190,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -173,7 +173,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -187,7 +187,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -172,7 +172,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -80,7 +80,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 51429;
public long DataPoints => 23079;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -26,8 +26,8 @@ using QuantConnect.Securities.Future;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Continuous Futures Regression algorithm.
/// Asserting the behavior of stop market order <see cref="StopMarketOrder"/> in extended market hours
/// Continuous Futures Regression algorithm.
/// Asserting the behavior of stop market order <see cref="StopMarketOrder"/> in extended market hours
/// <seealso cref="Data.UniverseSelection.UniverseSettings.ExtendedMarketHours"/>
/// </summary>
public class FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
@@ -43,6 +43,12 @@ namespace QuantConnect.Algorithm.CSharp
Schedule.On(DateRules.EveryDay(), TimeRules.At(19, 0), () =>
{
// Don't place orders at the end of the last date, the market-on-stop order won't have time to fill
if (Time.Date == EndDate.Date.AddDays(-1))
{
return;
}
MarketOrder(_SP500EMini.Mapped, 1);
_ticket = StopMarketOrder(_SP500EMini.Mapped, -1, _SP500EMini.Price * 1.1m);
});
@@ -113,7 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all time slices of algorithm
/// </summary>
public long DataPoints => 75961;
public long DataPoints => 41486;
/// <summary>
/// Data Points count of the algorithm history
@@ -133,7 +139,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Orders", "10"},
{"Average Win", "0%"},
{"Average Loss", "-0.02%"},
{"Compounding Annual Return", "-6.736%"},
{"Compounding Annual Return", "-6.419%"},
{"Drawdown", "0.100%"},
{"Expectancy", "-1"},
{"Start Equity", "100000"},

View File

@@ -0,0 +1,131 @@
/*
* 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.Data.UniverseSelection;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm testing history requests for <see cref="FutureUniverse"/> type work as expected
/// and return the same data as the futures chain provider.
/// </summary>
public class FutureUniverseHistoryRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
public override void Initialize()
{
SetStartDate(2013, 10, 11);
SetEndDate(2013, 10, 11);
var future = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute).Symbol;
var historicalFuturesData = History<FutureUniverse>(future, 3, Resolution.Daily).ToList();
if (historicalFuturesData.Count != 3)
{
throw new RegressionTestException($"Expected 3 futures chains from history request, " +
$"but got {historicalFuturesData.Count}");
}
foreach (var historyFutureUniverse in historicalFuturesData)
{
var date = historyFutureUniverse.EndTime;
var chain = FutureChainProvider.GetFutureContractList(future, date).ToList();
if (chain.Count == 0)
{
throw new RegressionTestException($"No futures in chain on {date}");
}
if (chain.Count != historyFutureUniverse.Data.Count)
{
throw new RegressionTestException($"Expected {chain.Count} futures in chain on {date}, " +
$"but got {historyFutureUniverse.Data.Count}");
}
for (var i = 0; i < chain.Count; i++)
{
if (historyFutureUniverse.Data[i].Symbol != chain[i])
{
throw new RegressionTestException($"Missing future contract {chain[i]} on {date}");
}
}
}
}
/// <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, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 2735;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 6;
/// <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 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%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,133 @@
/*
* 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;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.FuturesChain(Symbol, bool)"/>
/// method to get a future chain.
/// </summary>
public class FuturesChainFullDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _futureContract;
public override void Initialize()
{
SetStartDate(2013, 10, 7);
SetEndDate(2013, 10, 7);
var future = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute).Symbol;
var chain = FuturesChain(future);
foreach (var contract in chain)
{
if (contract.BidPrice == 0 && contract.AskPrice == 0 && contract.Volume == 0)
{
throw new RegressionTestException("FuturesChain() returned contract with no data.");
}
}
_futureContract = chain
// Get contracts expiring within 6 months
.Where(contractData => contractData.Expiry - Time <= TimeSpan.FromDays(180))
// Get the contract with the latest expiration date, and lowest price
.OrderByDescending(x => x.Expiry)
.ThenBy(x => x.LastPrice)
.First();
AddFutureContract(_futureContract);
}
public override void OnData(Slice slice)
{
// Do some trading with the selected contract for sample purposes
if (!Portfolio.Invested)
{
SetHoldings(_futureContract, 0.5);
}
else
{
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>
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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 4083;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 1;
/// <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 Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "450"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "50272.1"},
{"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", "$8290.40"},
{"Estimated Strategy Capacity", "$13000.00"},
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
{"Portfolio Turnover", "639698.49%"},
{"OrderListHash", "312461917700d86df1b5c43e1e7ec0eb"}
};
}
}

View File

@@ -0,0 +1,140 @@
/*
* 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;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.FuturesChains(IEnumerable{Symbol}, bool)"/>
/// method to get multiple futures chains.
/// </summary>
public class FuturesChainsMultipleFullDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _esFutureContract;
private Symbol _gcFutureContract;
public override void Initialize()
{
SetStartDate(2013, 10, 7);
SetEndDate(2013, 10, 7);
var esFuture= AddFuture(Futures.Indices.SP500EMini).Symbol;
var gcFuture = AddFuture(Futures.Metals.Gold).Symbol;
var chains = FuturesChains([esFuture, gcFuture]);
_esFutureContract = GetContract(chains, esFuture);
_gcFutureContract = GetContract(chains, gcFuture);
AddFutureContract(_esFutureContract);
AddFutureContract(_gcFutureContract);
}
private Symbol GetContract(FuturesChains chains, Symbol canonical)
{
return chains
.Where(kvp => kvp.Key == canonical)
.Select(kvp => kvp.Value)
.Single()
// Get contracts expiring within 6 months
.Where(contractData => contractData.Expiry - Time <= TimeSpan.FromDays(180))
// Get the contract with the latest expiration date, and lowest price
.OrderByDescending(x => x.Expiry)
.ThenBy(x => x.LastPrice)
.First();
}
public override void OnData(Slice slice)
{
// Do some trading with the selected contract for sample purposes
if (!Portfolio.Invested)
{
SetHoldings(_esFutureContract, 0.25);
SetHoldings(_gcFutureContract, 0.25);
}
else
{
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>
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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 8184;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 2;
/// <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 Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "900"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "57108.26"},
{"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", "$5701.74"},
{"Estimated Strategy Capacity", "$19000.00"},
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
{"Portfolio Turnover", "432921.78%"},
{"OrderListHash", "c75de8eb115be82a0ec2afaec8d034ff"}
};
}
}

View File

@@ -62,7 +62,7 @@ namespace QuantConnect.Algorithm.CSharp
var future = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
_contractSymbol = FutureChainProvider.GetFutureContractList(future, Time).OrderBy(x => x.ID.Date).FirstOrDefault();
_contractSymbol = FuturesChain(future).OrderBy(x => x.ID.Date).First();
_future = AddFutureContract(_contractSymbol);
_future.Holdings.SetHoldings(1600, 1 * OrderSide);
@@ -180,7 +180,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -89,7 +89,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 268275;
public long DataPoints => 24508;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -113,7 +113,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 3631;
public long DataPoints => 2197;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -185,7 +185,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 126811;
public virtual long DataPoints => 101119;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -31,7 +31,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 177;
public override long DataPoints => 174;
/// <summary>
/// Data Points count of the algorithm history
@@ -74,7 +74,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "HSI VL6DN7UV65S9"},
{"Portfolio Turnover", "1590.77%"},
{"OrderListHash", "42cd8e3b58361b181c911a603f69d2f7"}
{"OrderListHash", "ca159879e35579b71717638fe2a6844c"}
};
}
}

View File

@@ -161,7 +161,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 823;
public virtual long DataPoints => 652;
/// <summary>
/// Data Points count of the algorithm history
@@ -204,7 +204,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$120000000.00"},
{"Lowest Capacity Asset", "HSI VL6DN7UV65S9"},
{"Portfolio Turnover", "7099.25%"},
{"OrderListHash", "174bdb031f17212dc9d92372f4fb75c2"}
{"OrderListHash", "da41f273d264b6b1fec2cfa106f3b446"}
};
}
}

View File

@@ -129,7 +129,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1432;
public long DataPoints => 968;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -101,7 +101,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1432;
public long DataPoints => 968;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -93,7 +93,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1490;
public long DataPoints => 1026;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -186,7 +186,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1575349;
public long DataPoints => 454077;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -48,7 +48,7 @@ namespace QuantConnect.Algorithm.CSharp
contractDepthOffset: 0,
extendedMarketHours: true
);
_futureContract = AddFutureContract(FutureChainProvider.GetFutureContractList(_continuousContract.Symbol, Time).First(), extendedMarketHours: true);
_futureContract = AddFutureContract(FuturesChain(_continuousContract.Symbol).First(), extendedMarketHours: true);
}
public override void OnWarmupFinished()
@@ -113,12 +113,12 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 82372;
public long DataPoints => 52987;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -103,7 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <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

View File

@@ -43,7 +43,7 @@ namespace QuantConnect.Algorithm.CSharp
contractDepthOffset: 0,
extendedMarketHours: true
);
_futureContract = AddFutureContract(FutureChainProvider.GetFutureContractList(_continuousContract.Symbol, Time).First(),
_futureContract = AddFutureContract(FuturesChain(_continuousContract.Symbol).First(),
extendedMarketHours: true);
}
public override void OnData(Slice slice)
@@ -90,12 +90,12 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 82372;
public long DataPoints => 52987;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -92,12 +92,12 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 2794076;
public long DataPoints => 526055;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 252;
public int AlgorithmHistoryDataPoints => 232;
/// <summary>
/// Final status of the algorithm

View File

@@ -90,7 +90,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public virtual int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm

View File

@@ -158,7 +158,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -165,7 +165,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm

View File

@@ -99,7 +99,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 7322;
public long DataPoints => 5072;
/// <summary>
/// Data Points count of the algorithm history

View File

@@ -151,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 21665;
public long DataPoints => 14920;
/// <summary>
/// Data Points count of the algorithm history
@@ -171,7 +171,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "-1.34%"},
{"Compounding Annual Return", "-97.000%"},
{"Compounding Annual Return", "-95.782%"},
{"Drawdown", "2.600%"},
{"Expectancy", "-1"},
{"Start Equity", "1000000"},

View File

@@ -229,8 +229,8 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$1100000.00"},
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
{"Portfolio Turnover", "549.26%"},
{"Most Traded Security", "IBM"},
{"Most Traded Security Trade Count", "63"},
{"Most Traded Security", "IBM"},
{"OrderListHash", "8dd77e35338a81410a5b68dc8345f402"}
};
}

View File

@@ -137,7 +137,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 21683;
public virtual long DataPoints => 14938;
/// <summary>
/// Data Points count of the algorithm history
@@ -157,7 +157,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "130.234%"},
{"Compounding Annual Return", "112.304%"},
{"Drawdown", "1.400%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},

View File

@@ -36,6 +36,6 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 28892;
public override long DataPoints => 19892;
}
}

View File

@@ -75,7 +75,8 @@ namespace QuantConnect.Algorithm.Framework.Selection
protected override FutureFilterUniverse Filter(FutureFilterUniverse filter)
{
// Remove duplicated keys
return filter.Contracts(FilterByOpenInterest(filter.DistinctBy(x => x).ToDictionary(x => x, x => _marketHoursDatabase.GetEntry(x.ID.Market, x, x.ID.SecurityType))));
return filter.Contracts(FilterByOpenInterest(
filter.DistinctBy(x => x).ToDictionary(x => x.Symbol, x => _marketHoursDatabase.GetEntry(x.ID.Market, x, x.ID.SecurityType))));
}
/// <summary>

View File

@@ -46,9 +46,7 @@ class AddFutureOptionSingleOptionChainSelectedInUniverseFilterRegressionAlgorith
if expiry is None or symbol is None:
raise AssertionError("Expected a single Option contract in the chain, found 0 contracts")
enumerator = option_contracts.get_enumerator()
while enumerator.move_next():
self.expected_symbols_received.append(enumerator.current.symbol)
self.expected_symbols_received.extend([x.symbol for x in option_contracts])
return option_contracts
@@ -74,7 +72,7 @@ class AddFutureOptionSingleOptionChainSelectedInUniverseFilterRegressionAlgorith
if self.invested or not has_option_quote_bars:
return
for chain in data.option_chains.values():
for chain in sorted(data.option_chains.values(), key=lambda chain: chain.symbol.underlying.id.date):
future_invested = False
option_invested = False

View File

@@ -54,6 +54,12 @@ class BasicTemplateFuturesDailyAlgorithm(QCAlgorithm):
elif all(x.exchange.hours.is_open(self.time, True) for x in self.securities.values() if x.invested):
self.liquidate()
def on_securities_changed(self, changes: SecurityChanges) -> None:
if len(changes.removed_securities) > 0 and \
self.portfolio.invested and \
all(x.exchange.hours.is_open(self.time, True) for x in self.securities.values() if x.invested):
self.liquidate()
def get_resolution(self):
return Resolution.DAILY

View File

@@ -25,7 +25,7 @@ class ConsolidateRegressionAlgorithm(QCAlgorithm):
self.set_end_date(2020, 1, 20)
SP500 = Symbol.create(Futures.Indices.SP_500_E_MINI, SecurityType.FUTURE, Market.CME)
symbol = self.future_chain_provider.get_future_contract_list(SP500, self.start_date)[0]
symbol = list(self.futures_chain(SP500))[0]
self._future = self.add_future_contract(symbol)
tradable_dates_count = len(list(Time.each_tradeable_day_in_time_zone(self._future.exchange.hours,

View File

@@ -0,0 +1,46 @@
# 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.
from AlgorithmImports import *
### <summary>
### Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.OptionChain(Symbol)"/> method
### to get a future option chain.
### </summary>
class FutureOptionChainFullDataRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2020, 1, 6)
self.set_end_date(2020, 1, 6)
future_contract = self.add_future_contract(
Symbol.create_future(Futures.Indices.SP_500_E_MINI, Market.CME, datetime(2020, 3, 20)),
Resolution.MINUTE).symbol
option_chain = self.option_chain(future_contract, flatten=True)
# Demonstration using data frame:
df = option_chain.data_frame
# Get contracts expiring within 4 months, with the latest expiration date, highest strike and lowest price
contracts = df.loc[(df.expiry <= self.time + timedelta(days=120))]
contracts = contracts.sort_values(['expiry', 'strike', 'lastprice'], ascending=[False, False, True])
self._option_contract = contracts.index[0]
self.add_future_option_contract(self._option_contract)
def on_data(self, data):
# Do some trading with the selected contract for sample purposes
if not self.portfolio.invested:
self.set_holdings(self._option_contract, 0.5)
else:
self.liquidate()

View File

@@ -0,0 +1,62 @@
# 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.
from AlgorithmImports import *
### <summary>
### Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.OptionChains(IEnumerable{Symbol})"/> method
### to get multiple future option chains.
### </summary>
class FutureOptionChainsMultipleFullDataRegressionAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2020, 1, 6)
self.set_end_date(2020, 1, 6)
es_future_contract = self.add_future_contract(
Symbol.create_future(Futures.Indices.SP_500_E_MINI, Market.CME, datetime(2020, 3, 20)),
Resolution.MINUTE).symbol
gc_future_contract = self.add_future_contract(
Symbol.create_future(Futures.Metals.GOLD, Market.COMEX, datetime(2020, 4, 28)),
Resolution.MINUTE).symbol
chains = self.option_chains([es_future_contract, gc_future_contract], flatten=True)
self._es_option_contract = self.get_contract(chains, es_future_contract)
self._gc_option_contract = self.get_contract(chains, gc_future_contract)
self.add_future_option_contract(self._es_option_contract)
self.add_future_option_contract(self._gc_option_contract)
def get_contract(self, chains: OptionChains, underlying: Symbol) -> Symbol:
df = chains.data_frame
# Index by the requested underlying, by getting all data with canonicals which underlying is the requested underlying symbol:
canonicals = df.index.get_level_values('canonical')
condition = [canonical for canonical in canonicals if canonical.underlying == underlying]
contracts = df.loc[condition]
# Get contracts expiring within 4 months, with the latest expiration date, highest strike and lowest price
contracts = contracts.loc[(df.expiry <= self.time + timedelta(days=120))]
contracts = contracts.sort_values(['expiry', 'strike', 'lastprice'], ascending=[False, False, True])
return contracts.index[0][1]
def on_data(self, data):
# Do some trading with the selected contract for sample purposes
if not self.portfolio.invested:
self.set_holdings(self._es_option_contract, 0.25)
self.set_holdings(self._gc_option_contract, 0.25)
else:
self.liquidate()

Some files were not shown because too many files have changed in this diff Show More