From 78eeecb88cbcffa2456f847ace4d38c8d20f5677 Mon Sep 17 00:00:00 2001 From: Derek Melchin <38889814+DerekMelchin@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:01:44 -0500 Subject: [PATCH] Add draft for new historical data structure --- .../01 History Requests.html | 18 +++++ .../02 Warm Up Periods.html | 12 ++++ .../01 Getting Started/metadata.json | 12 ++++ .../02 History Requests/01 Introduction.html | 0 .../02 Flat DataFrames.html | 0 .../03 Trailing Time Periods.html | 0 .../04 Trailing Data Samples.html | 0 .../02 History Requests/05 Date Ranges.html | 0 .../02 History Requests/metadata.json | 12 ++++ .../03 History Responses/01 Introduction.html | 0 .../03 History Responses/02 DataFrames.html | 0 .../03 History Responses/03 Slices.html | 0 .../03 History Responses/04 Lists.html | 0 .../03 History Responses/metadata.json | 12 ++++ .../01 US Equities/01 Introduction.php | 0 .../01 US Equities/02 Trades.php | 0 .../01 US Equities/03 Quotes.php | 0 .../01 US Equities/04 Ticks.php | 0 .../01 US Equities/05 Slices.php | 0 .../01 US Equities/06 Splits.php | 0 .../01 US Equities/07 Dividends.php | 0 .../01 US Equities/08 Symbol Changes.php | 0 .../01 US Equities/09 Delistings.php | 0 .../01 US Equities/10 Universes.php | 0 .../01 US Equities/11 Alternative Data.php | 0 .../01 US Equities/12 Indicators.php | 0 .../01 US Equities/13 Short Availability.php | 0 .../01 US Equities/metadata.json | 12 ++++ .../05 Alternative Data/01 Introduction.php | 0 .../05 Alternative Data/02 Slices.php | 0 .../05 Alternative Data/03 Data Points.php | 0 .../05 Alternative Data/04 Universes.php | 0 .../05 Alternative Data/metadata.json | 12 ++++ .../06 Custom Data/01 Introduction.php | 0 .../06 Custom Data/02 Slices.php | 0 .../06 Custom Data/03 Data Points.php | 0 .../06 Custom Data/04 Universes.php | 0 .../06 Custom Data/metadata.json | 12 ++++ .../07 Warm Up Periods/01 Introduction.php | 1 + .../02 Set Warm Up Periods.html | 70 +++++++++++++++++++ .../03 Warm Up Vs Reality.html | 19 +++++ .../07 Warm Up Periods/04 Event Handler.html | 11 +++ .../07 Warm Up Periods/05 Limitations.html | 1 + .../07 Warm Up Periods/99 Examples.html | 11 +++ .../07 Warm Up Periods/metadata.json | 12 ++++ .../08 Rolling Window/01 Introduction.php | 1 + .../08 Rolling Window/02 Supported Types.php | 1 + .../08 Rolling Window/03 Add Data.php | 1 + .../08 Rolling Window/04 Warm Up.php | 1 + .../08 Rolling Window/05 Check Readiness.php | 1 + .../08 Rolling Window/06 Adjust Size.php | 1 + .../08 Rolling Window/07 Access Data.php | 1 + .../08 Combine with Indicators.php | 1 + .../09 Combine with Consolidators.php | 1 + .../10 Cast to Other Types.php | 1 + .../08 Rolling Window/11 Delete Data.php | 1 + .../08 Rolling Window/12 Examples.php | 1 + .../08 Rolling Window/metadata.json | 12 ++++ .../09 Common Errors/01 Introduction.html | 7 ++ 59 files changed, 258 insertions(+) create mode 100644 08 Drafts/05 Historical Data/01 Getting Started/01 History Requests.html create mode 100644 08 Drafts/05 Historical Data/01 Getting Started/02 Warm Up Periods.html create mode 100644 08 Drafts/05 Historical Data/01 Getting Started/metadata.json create mode 100644 08 Drafts/05 Historical Data/02 History Requests/01 Introduction.html create mode 100644 08 Drafts/05 Historical Data/02 History Requests/02 Flat DataFrames.html create mode 100644 08 Drafts/05 Historical Data/02 History Requests/03 Trailing Time Periods.html create mode 100644 08 Drafts/05 Historical Data/02 History Requests/04 Trailing Data Samples.html create mode 100644 08 Drafts/05 Historical Data/02 History Requests/05 Date Ranges.html create mode 100644 08 Drafts/05 Historical Data/02 History Requests/metadata.json create mode 100644 08 Drafts/05 Historical Data/03 History Responses/01 Introduction.html create mode 100644 08 Drafts/05 Historical Data/03 History Responses/02 DataFrames.html create mode 100644 08 Drafts/05 Historical Data/03 History Responses/03 Slices.html create mode 100644 08 Drafts/05 Historical Data/03 History Responses/04 Lists.html create mode 100644 08 Drafts/05 Historical Data/03 History Responses/metadata.json create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/01 Introduction.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/02 Trades.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/03 Quotes.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/04 Ticks.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/05 Slices.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/06 Splits.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/07 Dividends.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/08 Symbol Changes.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/09 Delistings.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/10 Universes.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/11 Alternative Data.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/12 Indicators.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/13 Short Availability.php create mode 100644 08 Drafts/05 Historical Data/04 Asset Classes/01 US Equities/metadata.json create mode 100644 08 Drafts/05 Historical Data/05 Alternative Data/01 Introduction.php create mode 100644 08 Drafts/05 Historical Data/05 Alternative Data/02 Slices.php create mode 100644 08 Drafts/05 Historical Data/05 Alternative Data/03 Data Points.php create mode 100644 08 Drafts/05 Historical Data/05 Alternative Data/04 Universes.php create mode 100644 08 Drafts/05 Historical Data/05 Alternative Data/metadata.json create mode 100644 08 Drafts/05 Historical Data/06 Custom Data/01 Introduction.php create mode 100644 08 Drafts/05 Historical Data/06 Custom Data/02 Slices.php create mode 100644 08 Drafts/05 Historical Data/06 Custom Data/03 Data Points.php create mode 100644 08 Drafts/05 Historical Data/06 Custom Data/04 Universes.php create mode 100644 08 Drafts/05 Historical Data/06 Custom Data/metadata.json create mode 100644 08 Drafts/05 Historical Data/07 Warm Up Periods/01 Introduction.php create mode 100644 08 Drafts/05 Historical Data/07 Warm Up Periods/02 Set Warm Up Periods.html create mode 100644 08 Drafts/05 Historical Data/07 Warm Up Periods/03 Warm Up Vs Reality.html create mode 100644 08 Drafts/05 Historical Data/07 Warm Up Periods/04 Event Handler.html create mode 100644 08 Drafts/05 Historical Data/07 Warm Up Periods/05 Limitations.html create mode 100644 08 Drafts/05 Historical Data/07 Warm Up Periods/99 Examples.html create mode 100644 08 Drafts/05 Historical Data/07 Warm Up Periods/metadata.json create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/01 Introduction.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/02 Supported Types.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/03 Add Data.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/04 Warm Up.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/05 Check Readiness.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/06 Adjust Size.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/07 Access Data.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/08 Combine with Indicators.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/09 Combine with Consolidators.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/10 Cast to Other Types.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/11 Delete Data.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/12 Examples.php create mode 100644 08 Drafts/05 Historical Data/08 Rolling Window/metadata.json create mode 100644 08 Drafts/05 Historical Data/09 Common Errors/01 Introduction.html diff --git a/08 Drafts/05 Historical Data/01 Getting Started/01 History Requests.html b/08 Drafts/05 Historical Data/01 Getting Started/01 History Requests.html new file mode 100644 index 0000000000..be0bd59ccb --- /dev/null +++ b/08 Drafts/05 Historical Data/01 Getting Started/01 History Requests.html @@ -0,0 +1,18 @@ +
Follow these steps to get some historical data:
+ +The process to creating a new project depends on if you use the Cloud Platform, Local Platform, or CLI.
+ +initialize
Initialize
method, add an asset.var spy = AddEquity("SPY");+
spy = self.add_equity('SPY')+
history
History
method with the asset's Symbol and a lookback period.var history = History(spy.Symbol, 10, Resolution.Daily);+
history = self.history(spy.symbol, 10, Resolution.DAILY)+
Follow these steps to add a warm-up period to the start of your algorithm:
+ +The process to creating a new project depends on if you use the Cloud Platform, Local Platform, or CLI.
+ +initialize
Initialize
method, call the set_warm_up
SetWarmUp
method with the warm-up duration.SetWarmUp(10, Resolution.Daily);+
self.set_warm_up(10, Resolution.DAILY)+
+You can set a warm-up period based on a period of time or a number of bars. To set a warm-up, in your algorithm's Initialize
initialize
method, call the SetWarmUp
set_warm_up
method.
// Wind time back 7 days from start +SetWarmUp(TimeSpan.FromDays(7)); + +// Feed in 100 bars before start date +SetWarmUp(100); ++
# Wind time back 7 days from start +self.set_warm_up(timedelta(7)) + +# Feed in 100 bars before start date +self.set_warm_up(100) ++
If you pass a timedelta
TimeSpan
argument, the warm-up period consists of that timedelta
TimeSpan
before the start date and pipes in data that matches the resolution of your data subscriptions.
If you pass just an integer argument, LEAN calculates the start of the warm-up period for each of your security subscriptions by using the number of bars you specify, the resolution of each security, and the trading calendar of each security. After it calculates the start time of the warm-up period for each security, it sets the earliest start time as the start of the algorithm warm-up period. For instance, in the following example, the warm-up period consists of 100 minute resolution bars for SPY and as many second resolution bars for BTCUSD that occur from the start of the SPY warm-up period to the algorithm StartDate
start_date
.
AddEquity("SPY", Resolution.Minute, fillForward: false); +AddCrypto("BTCUSD", Resolution.Second, fillForward: false); +SetWarmUp(100); ++
self.add_equity("SPY", Resolution.MINUTE, fill_forward=False) +self.add_crypto("BTCUSD", Resolution.SECOND, fill_forward=False) +self.set_warm_up(100) ++
To use a specific resolution of data for the warm-up period, pass a resolution
argument to the SetWarmUp
set_warm_up
method.
// Feed in 100 days of daily data before the start date +SetWarmUp(TimeSpan.FromDays(100), Resolution.Daily); + +// Feed in data for 100 trading days of daily data before the start date +SetWarmUp(100, Resolution.Daily);+
# Feed in 100 days of daily data before the start date +self.set_warm_up(timedelta(days=100), Resolution.DAILY) + +# Feed in data for 100 trading days before the start date +self.set_warm_up(100, Resolution.DAILY)+
If you pass a timedelta
TimeSpan
and a resolution, the warm-up period consists of the time period and resolution you set, regardless of the resolution of your data subscriptions.
If you pass an integer and a resolution, the warm-up period consists of the number of bars and resolution you set, regardless of the resolution of your data subscriptions. In this case, LEAN calculates the start of the warm-up period for each of your security subscriptions just like it does when you only pass an integer argument. After it calculates the start time of the warm-up period for each security, it sets the earliest start time as the start of the algorithm warm-up period.
If you pass a resolution argument and you registered indicators or consolidators for automatic updates, the warm-up period resolution must be less than or equal to the lowest resolution of your automatic indicators and consolidators. For instance, in the following example, the indicators use minute resolution data, so you can set the warm-up period to use tick, second, or minute resolution data.
+ +_spy = AddEquity("SPY", Resolution.Minute, fillForward: false).Symbol; +_btc = AddCrypto("BTCUSD", Resolution.Second, fillForward: false).Symbol; + +_spySma = SMA(_spy, 10); +_btcSMA = SMA(_btc, 10, Resolution.Minute); + +SetWarmUp(100, Resolution.Minute); ++
self._spy = self.add_equity("SPY", Resolution.MINUTE, fill_forward=False).symbol +self._btc = self.add_crypto("BTCUSD", Resolution.SECOND, fill_forward=False).symbol + +self._spy_sma = self.sma(self._spy, 10) +self._btc_sma = self.sma(self._btc, 10, Resolution.MINUTE) + +self.set_warm_up(100, Resolution.MINUTE) ++
You may need to distinguish warm-up data from real data. To check if the algorithm is currently in a warm up period, use the IsWarmingUp
is_warming_up
property.
// In Initialize +var emaFast = EMA("IBM", 50); +var emaSlow = EMA("IBM", 100); +SetWarmup(100); + +// In OnData: Don't run if the indicators aren't ready +if (IsWarmingUp) return; ++
# In Initialize +self._ema_fast = self.ema("IBM", 50); +self._ema_slow = self.ema("IBM", 100); +self.set_warmup(100); + +// In OnData: Don't run if the indicators aren't ready +if self.is_warming_up: return ++
The OnWarmupFinished
on_warmup_finished
event handler executes when the warm up period ends, even if you don't set a warm up period.
public override void OnWarmupFinished() +{ + // Done warming up +} ++
def on_warmup_finished(self) -> None: + pass # Done warming up+
You can't place trades during the warm-up period because they would be operating on fictional fast-forwarded data.
\ No newline at end of file diff --git a/08 Drafts/05 Historical Data/07 Warm Up Periods/99 Examples.html b/08 Drafts/05 Historical Data/07 Warm Up Periods/99 Examples.html new file mode 100644 index 0000000000..62169a494d --- /dev/null +++ b/08 Drafts/05 Historical Data/07 Warm Up Periods/99 Examples.html @@ -0,0 +1,11 @@ + diff --git a/08 Drafts/05 Historical Data/07 Warm Up Periods/metadata.json b/08 Drafts/05 Historical Data/07 Warm Up Periods/metadata.json new file mode 100644 index 0000000000..4235bc6090 --- /dev/null +++ b/08 Drafts/05 Historical Data/07 Warm Up Periods/metadata.json @@ -0,0 +1,12 @@ +{ + "type": "metadata", + "values": { + "description": "LEAN supports an automated fast-forward system called \"Warm Up\". It simulates winding back the clock from the time you deploy the algorithm.", + "keywords": "historical data, warm up, algorithmic trading", + "og:description": "LEAN supports an automated fast-forward system called \"Warm Up\". It simulates winding back the clock from the time you deploy the algorithm.", + "og:title": "Warm Up Periods - Documentation QuantConnect.com", + "og:type": "website", + "og:site_name": "Warm Up Periods - QuantConnect.com", + "og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/historical-data/warm-up-periods.png" + } +} diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/01 Introduction.php b/08 Drafts/05 Historical Data/08 Rolling Window/01 Introduction.php new file mode 100644 index 0000000000..47f45efbe2 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/01 Introduction.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/introduction.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/02 Supported Types.php b/08 Drafts/05 Historical Data/08 Rolling Window/02 Supported Types.php new file mode 100644 index 0000000000..56e5ed6527 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/02 Supported Types.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/supported-types.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/03 Add Data.php b/08 Drafts/05 Historical Data/08 Rolling Window/03 Add Data.php new file mode 100644 index 0000000000..7757b719df --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/03 Add Data.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/add-data.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/04 Warm Up.php b/08 Drafts/05 Historical Data/08 Rolling Window/04 Warm Up.php new file mode 100644 index 0000000000..eca0e33023 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/04 Warm Up.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/warm-up.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/05 Check Readiness.php b/08 Drafts/05 Historical Data/08 Rolling Window/05 Check Readiness.php new file mode 100644 index 0000000000..a1009dff68 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/05 Check Readiness.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/check-readiness.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/06 Adjust Size.php b/08 Drafts/05 Historical Data/08 Rolling Window/06 Adjust Size.php new file mode 100644 index 0000000000..f3a7c60076 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/06 Adjust Size.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/adjust-size.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/07 Access Data.php b/08 Drafts/05 Historical Data/08 Rolling Window/07 Access Data.php new file mode 100644 index 0000000000..239cb7c116 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/07 Access Data.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/access-data.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/08 Combine with Indicators.php b/08 Drafts/05 Historical Data/08 Rolling Window/08 Combine with Indicators.php new file mode 100644 index 0000000000..4e17ff885c --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/08 Combine with Indicators.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/indicators/historical-values.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/09 Combine with Consolidators.php b/08 Drafts/05 Historical Data/08 Rolling Window/09 Combine with Consolidators.php new file mode 100644 index 0000000000..78da95693d --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/09 Combine with Consolidators.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/combine-with-consolidators.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/10 Cast to Other Types.php b/08 Drafts/05 Historical Data/08 Rolling Window/10 Cast to Other Types.php new file mode 100644 index 0000000000..885cd90953 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/10 Cast to Other Types.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/cast-to-other-types.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/11 Delete Data.php b/08 Drafts/05 Historical Data/08 Rolling Window/11 Delete Data.php new file mode 100644 index 0000000000..c0bcb62860 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/11 Delete Data.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/delete-data.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/12 Examples.php b/08 Drafts/05 Historical Data/08 Rolling Window/12 Examples.php new file mode 100644 index 0000000000..fac02b1ae1 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/12 Examples.php @@ -0,0 +1 @@ + include(DOCS_RESOURCES."/rolling-window/examples.html"); ?> \ No newline at end of file diff --git a/08 Drafts/05 Historical Data/08 Rolling Window/metadata.json b/08 Drafts/05 Historical Data/08 Rolling Window/metadata.json new file mode 100644 index 0000000000..0e4e6a6327 --- /dev/null +++ b/08 Drafts/05 Historical Data/08 Rolling Window/metadata.json @@ -0,0 +1,12 @@ +{ + "type": "metadata", + "values": { + "description": "A RollingWindow is an array of a fixed-size that holds trailing data. It's more efficient to store data than to make many historical data requests.", + "keywords": "historical data, rolling window, trailing data, indicators, consolidators", + "og:description": "A RollingWindow is an array of a fixed-size that holds trailing data. It's more efficient to store data than to make many historical data requests.", + "og:title": "Rolling Window - Documentation QuantConnect.com", + "og:type": "website", + "og:site_name": "Rolling Window - QuantConnect.com", + "og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/historical-data/rolling-window.png" + } +} diff --git a/08 Drafts/05 Historical Data/09 Common Errors/01 Introduction.html b/08 Drafts/05 Historical Data/09 Common Errors/01 Introduction.html new file mode 100644 index 0000000000..9b3494f524 --- /dev/null +++ b/08 Drafts/05 Historical Data/09 Common Errors/01 Introduction.html @@ -0,0 +1,7 @@ +add Live Trading +Other data providers +Trading disabled in warm-up + Limitations of quantconnect provider +Limitations of brokerages +E.g. IB is slow and leads to timeout if we request or warm up too many symbols (e.g. options) +Indicator readiness.