Skip to content

Commit 5f63ef2

Browse files
committed
Use SeedInitialPrices in Examples
1 parent 080b055 commit 5f63ef2

File tree

72 files changed

+271
-722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+271
-722
lines changed

03 Writing Algorithms/01 Key Concepts/04 Multi-Asset Modeling/99 Examples.html

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h4>
1919
SetStartDate(2024, 9, 1);
2020
SetEndDate(2024, 12, 31);
2121
// Seed the last price to set the initial price of the BTCUSDT holdings.
22-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
22+
Settings.SeedInitialPrices = true;
2323

2424
// Simulate a cash Bybit account.
2525
SetBrokerageModel(BrokerageName.Bybit, AccountType.Cash);
@@ -85,12 +85,7 @@ <h4>
8585
self.set_start_date(2024, 9, 1)
8686
self.set_end_date(2024, 12, 31)
8787
# Seed the last price to set the initial price of the BTCUSDT holdings.
88-
self.set_security_initializer(
89-
BrokerageModelSecurityInitializer(
90-
self.brokerage_model,
91-
FuncSecuritySeeder(self.get_last_known_prices)
92-
)
93-
)
88+
self.settings.seed_initial_prices = True
9489

9590
# Simulate a cash Bybit account.
9691
self.set_brokerage_model(BrokerageName.BYBIT, AccountType.CASH)
@@ -154,11 +149,7 @@ <h4>
154149
SetCash(1000000);
155150
// Seed the price of each asset with its last known price to
156151
// avoid trading errors.
157-
SetSecurityInitializer(
158-
new BrokerageModelSecurityInitializer(
159-
BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)
160-
)
161-
);
152+
Settings.SeedInitialPrices = true;
162153
// Add BTCUSD spot and Future data to trade their price
163154
// discrepancies.
164155
_spot = AddCrypto("BTCUSD", market: Market.Coinbase);
@@ -230,12 +221,7 @@ <h4>
230221
self.set_cash(1_000_000)
231222
# Seed the price of each asset with its last known price to
232223
# avoid trading errors.
233-
self.set_security_initializer(
234-
BrokerageModelSecurityInitializer(
235-
self.brokerage_model,
236-
FuncSecuritySeeder(self.get_last_known_prices)
237-
)
238-
)
224+
self.settings.seed_initial_prices = True
239225
# Add BTCUSD spot and Future data to trade their price
240226
# discrepancies.
241227
self._spot = self.add_crypto("BTCUSD", market=Market.COINBASE)

03 Writing Algorithms/01 Key Concepts/06 Security Identifiers/99 Examples.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h4>
2626
SetStartDate(2024, 9, 1);
2727
SetEndDate(2024, 12, 31);
2828
// Seed the price data to allow the mapped contract to fill despite sparse data.
29-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
29+
Settings.SeedInitialPrices = true;
3030
}
3131

3232
public override void OnWarmupFinished()
@@ -72,7 +72,7 @@ <h4>
7272
self.set_start_date(2024, 9, 1)
7373
self.set_end_date(2024, 12, 31)
7474
# Seed the price data in order to allow the mapped contract to fill despite sparse data.
75-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))
75+
self.settings.seed_initial_prices = True
7676
self._last_scheduled_event = None
7777

7878
def on_warmup_finished(self) -&gt; None:

03 Writing Algorithms/02 Initialization/99 Examples.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ <h4>Example 1: Set the Data Seed</h4>
99
<pre class="csharp">// Seed with the last known price of assets to prevent $0 security price errors.
1010
public override void Initialize()
1111
{
12-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(
13-
BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
12+
Settings.SeedInitialPrices = true;
1413
}</pre>
1514
<pre class="python"># Seed with the last known price of assets to prevent $0 security price errors.
1615
def initialize(self):
17-
self.set_security_initializer(BrokerageModelSecurityInitializer(
18-
self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))</pre>
16+
self.settings.seed_initial_prices = True</pre>
1917
</div>
2018

2119
<h4>Example 2: Enable Extended Market Hours</h4>

03 Writing Algorithms/03 Securities/02 Requesting Data/99 Examples.html

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ <h4>
2929
SetStartDate(2024, 9, 1);
3030
SetEndDate(2024, 12, 31);
3131
// Seed the price of each asset with its last known price to avoid trading errors.
32-
SetSecurityInitializer(
33-
new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices))
34-
);
32+
Settings.SeedInitialPrices = true;
3533
// Add a universe of the 25 most liquid US Equities.
3634
AddUniverse(Universe.Top(25));
3735
}
@@ -78,12 +76,7 @@ <h4>
7876
self.set_start_date(2024, 9, 1)
7977
self.set_end_date(2024, 12, 31)
8078
# Seed the price of each asset with its last known price to avoid trading errors.
81-
self.set_security_initializer(
82-
BrokerageModelSecurityInitializer(
83-
self.brokerage_model,
84-
FuncSecuritySeeder(self.get_last_known_prices)
85-
)
86-
)
79+
self.settings.seed_initial_prices = True
8780
# Add a universe of the 25 most liquid US Equities.
8881
self.add_universe(self.universe.top(25))
8982

03 Writing Algorithms/03 Securities/03 Handling Data/99 Examples.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@
100100
SetEndDate(2024, 9, 10);
101101
// Seed the price of each asset with its last known price to
102102
// avoid trading errors.
103-
SetSecurityInitializer(
104-
new BrokerageModelSecurityInitializer(
105-
BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)
106-
)
107-
);
103+
Settings.SeedInitialPrices = true;
108104
_symbol = AddEquity("SPY", Resolution.Tick).Symbol;
109105
}
110106

@@ -147,12 +143,7 @@
147143
self.set_end_date(2024, 9, 10)
148144
# Seed the price of each asset with its last known price to
149145
# avoid trading errors.
150-
self.set_security_initializer(
151-
BrokerageModelSecurityInitializer(
152-
self.brokerage_model,
153-
FuncSecuritySeeder(self.get_last_known_prices)
154-
)
155-
)
146+
self.settings.seed_initial_prices = True
156147
self._symbol = self.add_equity('SPY', Resolution.TICK).symbol
157148

158149
def on_data(self, slice: Slice) -> None:
@@ -375,9 +366,7 @@
375366
SetStartDate(2024, 9, 1);
376367
SetEndDate(2024, 12, 31);
377368
// Seed the price of AAPL with its last known price to avoid trading errors.
378-
SetSecurityInitializer(
379-
new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices))
380-
);
369+
Settings.SeedInitialPrices = true;
381370
// Add the 7-day sentiment data for AAPL.
382371
_symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
383372
_dataset7DaySymbol = AddData&lt;BrainSentimentIndicator7Day&gt;(_symbol).Symbol;
@@ -410,12 +399,7 @@
410399
self.set_start_date(2024, 9, 1)
411400
self.set_end_date(2024, 12, 31)
412401
# Seed the price of AAPL with its last known price to avoid trading errors.
413-
self.set_security_initializer(
414-
BrokerageModelSecurityInitializer(
415-
self.brokerage_model,
416-
FuncSecuritySeeder(self.get_last_known_prices)
417-
)
418-
)
402+
self.settings.seed_initial_prices = True
419403
# Add the 7-day sentiment data for AAPL.
420404
self._symbol = self.add_equity("AAPL", Resolution.DAILY).symbol
421405
self._dataset_7day_symbol = self.add_data(BrainSentimentIndicator7Day, self._symbol).symbol

03 Writing Algorithms/03 Securities/99 Asset Classes/01 US Equity/01 Requesting Data/99 Examples.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ <h4>
7171
SetStartDate(2024, 9, 1);
7272
SetEndDate(2024, 12, 31);
7373

74-
var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
75-
AddSecurityInitializer(x =&gt; seeder.SeedSecurity(x));
74+
Settings.SeedInitialPrices = true;
7675

7776
// Add the US Equities.
7877
foreach (var ticker in "AAPL,AMZN,GOOG,META,MSFT".Split(","))
@@ -109,8 +108,7 @@ <h4>
109108
self.set_start_date(2024, 9, 1)
110109
self.set_end_date(2024, 12, 31)
111110

112-
seeder = FuncSecuritySeeder(self.get_last_known_prices)
113-
self.add_security_initializer(lambda x: seeder.seed_security(x))
111+
self.settings.seed_initial_prices = True
114112

115113
# Add the US Equities.
116114
self.signal_by_ticker = {self.add_equity(ticker, Resolution.DAILY).symbol: 1

03 Writing Algorithms/03 Securities/99 Asset Classes/02 Equity Options/01 Requesting Data/01 Universes/99 Examples.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ <h4>
124124
SetStartDate(2024, 9, 1);
125125
SetEndDate(2024, 12, 31);
126126
// Seed the price with last known price to ensure the underlying price data is available on initial option contract filtering.
127-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
127+
Settings.SeedInitialPrices = true;
128128
// Subscribe to underlying data for ATM calculation using the update underlying price.
129129
// Set data normalization mode to raw is required to ensure strike price and underlying price is comparable.
130130
_underlying = AddEquity("SPY", dataNormalizationMode: DataNormalizationMode.Raw);
@@ -172,7 +172,7 @@ <h4>
172172
self.set_start_date(2024, 9, 1)
173173
self.set_end_date(2024, 12, 31)
174174
# Seed the price with last known price to ensure the underlying price data is available on initial option contract filtering.
175-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))
175+
self.settings.seed_initial_prices = True
176176
self.underlying = self.add_equity("SPY", data_normalization_mode=DataNormalizationMode.RAW)
177177
# Subscribe to underlying data for ATM calculation using the update underlying price.
178178
# Set data normalization mode to raw is required to ensure strike price and underlying price is comparable.

03 Writing Algorithms/03 Securities/99 Asset Classes/02 Equity Options/01 Requesting Data/02 Individual Contracts/02 Create Subscriptions.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@
145145
<p>If you subscribe to an Option contract with <code class="csharp">AddOptionContract</code><code class="python">add_option_contract</code>, you'll need to wait until the next <code>Slice</code> to receive data and trade the contract. To trade the contract in the same time step you subscribe to the contract, set the current price of the contract in a <a href='/docs/v2/writing-algorithms/initialization#07-Set-Security-Initializer'>security initializer</a>.</p>
146146
147147
<div class="section-example-container">
148-
<pre class="csharp">var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
149-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, seeder));</pre>
150-
<pre class="python">seeder = FuncSecuritySeeder(self.get_last_known_prices)
151-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, seeder))</pre>
148+
<pre class="csharp">Settings.SeedInitialPrices = true;</pre>
149+
<pre class="python">self.settings.seed_initial_prices = True</pre>
152150
</div>
153151
154152
<h4>Supported Assets</h4>

03 Writing Algorithms/03 Securities/99 Asset Classes/02 Equity Options/01 Requesting Data/02 Individual Contracts/99 Examples.html

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h4>
1818
SetStartDate(2024, 9, 1);
1919
SetEndDate(2024, 12, 31);
2020
// Seed the security price to ensure the retrieval of the ATM calls at the initial filtering.
21-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
21+
Settings.SeedInitialPrices = true;
2222
// Set the data normalization mode as raw for option strike-price comparability.
2323
_aapl = AddEquity("AAPL", dataNormalizationMode: DataNormalizationMode.Raw).Symbol;
2424

@@ -77,7 +77,7 @@ <h4>
7777
self.set_end_date(2024, 12, 31)
7878
self._chain = pd.DataFrame()
7979
# Seed the security price to ensure the retrieval of the ATM calls at the initial filtering.
80-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))
80+
self.settings.seed_initial_prices = True
8181
# Set the data normalization mode as raw for option strike-price comparability.
8282
self.aapl = self.add_equity("AAPL", data_normalization_mode=DataNormalizationMode.RAW).symbol
8383

@@ -143,7 +143,7 @@ <h4>
143143
SetStartDate(2024, 9, 1);
144144
SetEndDate(2024, 12, 31);
145145
// Seed the underlying security price to ensure accurate filtering for puts of $5 above/below current market price.
146-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
146+
Settings.SeedInitialPrices = true;
147147
// Set the data normalization mode as raw for option strike-price comparability.
148148
_spy = AddEquity("SPY", dataNormalizationMode: DataNormalizationMode.Raw).Symbol;
149149

@@ -204,7 +204,7 @@ <h4>
204204
self.set_end_date(2024, 12, 27)
205205
self.legs = []
206206
# Seed the underlying security price to ensure accurate filtering for puts of $5 above/below current market price.
207-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))
207+
self.settings.seed_initial_prices = True
208208
# Set the data normalization mode as raw for option strike-price comparability.
209209
self.spy = self.add_equity("SPY", data_normalization_mode=DataNormalizationMode.RAW).symbol
210210

@@ -348,11 +348,7 @@ <h4>
348348
SetEndDate(2024, 9, 7);
349349
SetCash(1000000000);
350350
// Seed the price of each asset with its last known price to avoid trading errors.
351-
SetSecurityInitializer(
352-
new BrokerageModelSecurityInitializer(
353-
BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)
354-
)
355-
);
351+
Settings.SeedInitialPrices = true;
356352
// Set the data normalization mode as raw for option strike-price comparability.
357353
_spy = AddEquity("SPY", dataNormalizationMode: DataNormalizationMode.Raw).Symbol;
358354
}
@@ -402,12 +398,7 @@ <h4>
402398
self.set_end_date(2024, 9, 7)
403399
self.set_cash(1000000000)
404400
# Seed the price of each asset with its last known price to avoid trading errors.
405-
self.set_security_initializer(
406-
BrokerageModelSecurityInitializer(
407-
self.brokerage_model,
408-
FuncSecuritySeeder(self.get_last_known_prices)
409-
)
410-
)
401+
self.settings.seed_initial_prices = True
411402
# Set the data normalization mode as raw for option strike-price comparability.
412403
self.spy = self.add_equity("SPY", data_normalization_mode=DataNormalizationMode.RAW).symbol
413404
# Set OTM threshold for wheel strategy profit margin.
@@ -469,7 +460,7 @@ <h4>
469460
UniverseSettings.Asynchronous = true;
470461
UniverseSettings.MinimumTimeInUniverse = TimeSpan.Zero;
471462
// Seed the security price to ensure the underlying price data is ready at the initial filtering
472-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
463+
Settings.SeedInitialPrices = true;
473464
// Set the data normalization mode as raw for option strike-price comparability
474465
var spy = AddEquity("SPY", dataNormalizationMode: DataNormalizationMode.Raw).Symbol;
475466
// Set up a OptionChainManager to filter the contracts based on latest data by request
@@ -594,7 +585,7 @@ <h4>
594585
self.universe_settings.asynchronous = True
595586
self.universe_settings.minimum_time_in_universe = timedelta(minutes=0)
596587
# Seed the security price to ensure the underlying price data is ready at the initial filtering
597-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))
588+
self.settings.seed_initial_prices = True
598589
# Set the data normalization mode as raw for option strike-price comparability
599590
spy = self.add_equity("SPY", data_normalization_mode=DataNormalizationMode.RAW).symbol
600591
# Set up a OptionChainManager to filter the contracts based on latest data by request

03 Writing Algorithms/03 Securities/99 Asset Classes/02 Equity Options/02 Handling Data/99 Examples.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h4>
3131
SetEndDate(2024, 12, 31);
3232

3333
// Seed the price with last known price to ensure the underlying price data is available on initial option contract filtering.
34-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
34+
Settings.SeedInitialPrices = true;
3535
// Subscribe to underlying data for ATM calculation using the update underlying price.
3636
// Set data normalization mode to raw is required to ensure strike price and underlying price is comparable.
3737
_spy = AddEquity("SPY", dataNormalizationMode: DataNormalizationMode.Raw).Symbol;
@@ -78,7 +78,7 @@ <h4>
7878
self.contracts = []
7979

8080
# Seed the price with last known price to ensure the underlying price data is available on initial option contract filtering.
81-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))
81+
self.settings.seed_initial_prices = True
8282
# Subscribe to underlying data for ATM calculation using the update underlying price.
8383
# Set data normalization mode to raw is required to ensure strike price and underlying price is comparable.
8484
self.spy = self.add_equity("SPY", data_normalization_mode=DataNormalizationMode.RAW).symbol
@@ -137,7 +137,7 @@ <h4>
137137
SetEndDate(2024, 12, 31);
138138

139139
// Seed the price with last known price to ensure the underlying price data is available on initial option contract filtering.
140-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
140+
Settings.SeedInitialPrices = true;
141141
// Subscribe to underlying data for ATM calculation using the update underlying price.
142142
// Set data normalization mode to raw is required to ensure strike price and underlying price is comparable.
143143
var spy = AddEquity("SPY", dataNormalizationMode: DataNormalizationMode.Raw).Symbol;
@@ -167,7 +167,7 @@ <h4>
167167
self.set_end_date(2024, 12, 31)
168168

169169
# Seed the price with last known price to ensure the underlying price data is available on initial option contract filtering.
170-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))
170+
self.settings.seed_initial_prices = True
171171
# Subscribe to underlying data for ATM calculation using the update underlying price.
172172
# Set data normalization mode to raw is required to ensure strike price and underlying price is comparable.
173173
spy = self.add_equity("SPY", data_normalization_mode=DataNormalizationMode.RAW).symbol
@@ -212,7 +212,7 @@ <h4>
212212
SetEndDate(2024, 12, 31);
213213

214214
// Seed the price with last known price to ensure the underlying price data is available on initial option contract filtering.
215-
SetSecurityInitializer(new BrokerageModelSecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
215+
Settings.SeedInitialPrices = true;
216216
// Subscribe to underlying data for ATM calculation using the update underlying price.
217217
// Set data normalization mode to raw is required to ensure strike price and underlying price is comparable.
218218
var spy = AddEquity("SPY", dataNormalizationMode: DataNormalizationMode.Raw).Symbol;
@@ -241,7 +241,7 @@ <h4>
241241
self.set_end_date(2024, 12, 31)
242242

243243
# Seed the price with last known price to ensure the underlying price data is available on initial option contract filtering.
244-
self.set_security_initializer(BrokerageModelSecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))
244+
self.settings.seed_initial_prices = True
245245
# Subscribe to underlying data for ATM calculation using the update underlying price.
246246
# Set data normalization mode to raw is required to ensure strike price and underlying price is comparable.
247247
spy = self.add_equity("SPY", data_normalization_mode=DataNormalizationMode.RAW).symbol

0 commit comments

Comments
 (0)