Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Algorithm.Python/BasicTemplateIndexDailyAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License

import datetime
from AlgorithmImports import *

class BasicTemplateIndexDailyAlgorithm(QCAlgorithm):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def initialize(self):
self.spx = self.add_index("SPX", Resolution.MINUTE).symbol

# Select an index option expiring ITM, and adds it to the algorithm.
self.spx_option = list(self.option_chain(self.spx))
self.spx_option = [i for i in self.spx_option if i.id.strike_price <= 3200 and i.id.option_right == OptionRight.CALL and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option = list(sorted(self.spx_option, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option, Resolution.MINUTE).symbol
self.spx_options = list(self.option_chain(self.spx))
self.spx_options = [i for i in self.spx_options if i.id.strike_price <= 3200 and i.id.option_right == OptionRight.CALL and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option_contract = list(sorted(self.spx_options, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option_contract, Resolution.MINUTE).symbol

self.expected_option_contract = Symbol.create_option(self.spx, Market.USA, OptionStyle.EUROPEAN, OptionRight.CALL, 3200, datetime(2021, 1, 15))
if self.spx_option != self.expected_option_contract:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def initialize(self):
self.spx = spx.symbol

# Select a index option call expiring ITM, and adds it to the algorithm.
self.spx_option = list(self.option_chain(self.spx))
self.spx_option = [i for i in self.spx_option if i.id.strike_price <= 3200 and i.id.option_right == OptionRight.CALL and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option = list(sorted(self.spx_option, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option, Resolution.MINUTE)
self.spx_options = list(self.option_chain(self.spx))
self.spx_options = [i for i in self.spx_options if i.id.strike_price <= 3200 and i.id.option_right == OptionRight.CALL and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option_contract = list(sorted(self.spx_options, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option_contract, Resolution.MINUTE)

self.spx_option.price_model = OptionPriceModels.black_scholes()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def initialize(self):
self.spx = self.add_index("SPX", Resolution.MINUTE).symbol

# Select a index option call expiring OTM, and adds it to the algorithm.
self.spx_option = list(self.option_chain(self.spx))
self.spx_option = [i for i in self.spx_option if i.id.strike_price >= 4250 and i.id.option_right == OptionRight.CALL and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option = list(sorted(self.spx_option, key=lambda x: x.id.strike_price))[0]
self.spx_option = self.add_index_option_contract(self.spx_option, Resolution.MINUTE).symbol
self.spx_options = list(self.option_chain(self.spx))
self.spx_options = [i for i in self.spx_options if i.id.strike_price >= 4250 and i.id.option_right == OptionRight.CALL and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option_contract = list(sorted(self.spx_options, key=lambda x: x.id.strike_price))[0]
self.spx_option = self.add_index_option_contract(self.spx_option_contract, Resolution.MINUTE).symbol

self.expected_contract = Symbol.create_option(
self.spx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def initialize(self):
self.spx = self.add_index("SPX", Resolution.MINUTE).symbol

# Select a index option expiring ITM, and adds it to the algorithm.
self.spx_option = list(self.option_chain(self.spx))
self.spx_option = [i for i in self.spx_option if i.id.strike_price >= 4200 and i.id.option_right == OptionRight.PUT and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option = list(sorted(self.spx_option, key=lambda x: x.id.strike_price))[0]
self.spx_option = self.add_index_option_contract(self.spx_option, Resolution.MINUTE).symbol
self.spx_options = list(self.option_chain(self.spx))
self.spx_options = [i for i in self.spx_options if i.id.strike_price >= 4200 and i.id.option_right == OptionRight.PUT and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option_contract = list(sorted(self.spx_options, key=lambda x: x.id.strike_price))[0]
self.spx_option = self.add_index_option_contract(self.spx_option_contract, Resolution.MINUTE).symbol

self.expected_contract = Symbol.create_option(self.spx, Market.USA, OptionStyle.EUROPEAN, OptionRight.PUT, 4200, datetime(2021, 1, 15))
if self.spx_option != self.expected_contract:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def initialize(self):
self.spx = self.add_index("SPX", Resolution.MINUTE).symbol

# Select a index option call expiring OTM, and adds it to the algorithm.
self.spx_option = list(self.option_chain(self.spx))
self.spx_option = [i for i in self.spx_option if i.id.strike_price <= 3200 and i.id.option_right == OptionRight.PUT and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option = list(sorted(self.spx_option, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option, Resolution.MINUTE).symbol
self.spx_options = list(self.option_chain(self.spx))
self.spx_options = [i for i in self.spx_options if i.id.strike_price <= 3200 and i.id.option_right == OptionRight.PUT and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option_contract = list(sorted(self.spx_options, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option_contract, Resolution.MINUTE).symbol

self.expected_contract = Symbol.create_option(
self.spx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def initialize(self):
self.spx = self.add_index("SPX", Resolution.MINUTE).symbol

# Select a index option expiring ITM, and adds it to the algorithm.
self.spx_option = list(self.option_chain(self.spx))
self.spx_option = [i for i in self.spx_option if i.id.strike_price >= 4250 and i.id.option_right == OptionRight.CALL and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option = list(sorted(self.spx_option, key=lambda x: x.id.strike_price))[0]
self.spx_option = self.add_index_option_contract(self.spx_option, Resolution.MINUTE).symbol
self.spx_options = list(self.option_chain(self.spx))
self.spx_options = [i for i in self.spx_options if i.id.strike_price >= 4250 and i.id.option_right == OptionRight.CALL and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option_contract = list(sorted(self.spx_options, key=lambda x: x.id.strike_price))[0]
self.spx_option = self.add_index_option_contract(self.spx_option_contract, Resolution.MINUTE).symbol

self.expected_contract = Symbol.create_option(self.spx, Market.USA, OptionStyle.EUROPEAN, OptionRight.CALL, 4250, datetime(2021, 1, 15))
if self.spx_option != self.expected_contract:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def initialize(self):
self.spx = self.add_index("SPX", Resolution.MINUTE).symbol

# Select a index option expiring ITM, and adds it to the algorithm.
self.spx_option = list(self.option_chain(self.spx))
self.spx_option = [i for i in self.spx_option if i.id.strike_price <= 4200 and i.id.option_right == OptionRight.PUT and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option = list(sorted(self.spx_option, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option, Resolution.MINUTE).symbol
self.spx_options = list(self.option_chain(self.spx))
self.spx_options = [i for i in self.spx_options if i.id.strike_price <= 4200 and i.id.option_right == OptionRight.PUT and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option_contract = list(sorted(self.spx_options, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option_contract, Resolution.MINUTE).symbol

self.expected_contract = Symbol.create_option(self.spx, Market.USA, OptionStyle.EUROPEAN, OptionRight.PUT, 4200, datetime(2021, 1, 15))
if self.spx_option != self.expected_contract:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def initialize(self):
self.spx = self.add_index("SPX", Resolution.MINUTE).symbol

# Select a index option expiring ITM, and adds it to the algorithm.
self.spx_option = list(self.option_chain(self.spx))
self.spx_option = [i for i in self.spx_option if i.id.strike_price <= 3200 and i.id.option_right == OptionRight.PUT and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option = list(sorted(self.spx_option, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option, Resolution.MINUTE).symbol
self.spx_options = list(self.option_chain(self.spx))
self.spx_options = [i for i in self.spx_options if i.id.strike_price <= 3200 and i.id.option_right == OptionRight.PUT and i.id.date.year == 2021 and i.id.date.month == 1]
self.spx_option_contract = list(sorted(self.spx_options, key=lambda x: x.id.strike_price, reverse=True))[0]
self.spx_option = self.add_index_option_contract(self.spx_option_contract, Resolution.MINUTE).symbol

self.expected_contract = Symbol.create_option(self.spx, Market.USA, OptionStyle.EUROPEAN, OptionRight.PUT, 3200, datetime(2021, 1, 15))
if self.spx_option != self.expected_contract:
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/OpenInterestFuturesRegressionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def on_data(self,data):
if self.transactions.orders_count == 0 and data.has_data:
matched = list(filter(lambda s: not (s.id.date in self.expected_expiry_dates) and not s.is_canonical(), data.keys()))
if len(matched) != 0:
raise AssertionError(f"{len(matched)}/{len(slice.keys)} were unexpected expiry date(s): " + ", ".join(list(map(lambda x: x.id.date, matched))))
raise AssertionError(f"{len(matched)}/{len(slice.keys())} were unexpected expiry date(s): " + ", ".join(list(map(lambda x: x.id.date, matched))))

for symbol in data.keys():
self.market_order(symbol, 1)
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/ScikitLearnLinearRegressionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def trade(self):
thod_buy = 0.001 # threshold of slope to buy
thod_liquidate = -0.001 # threshold of slope to liquidate

for holding in self.portfolio.Values:
for holding in self.portfolio.values():
slope = self.slopes[holding.symbol]
# liquidate when slope smaller than thod_liquidate
if holding.invested and slope < thod_liquidate:
Expand Down
2 changes: 1 addition & 1 deletion Algorithm.Python/TensorFlowNeuralNetworkAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def trade(self) -> None:
Enter or exit positions based on relationship of the open price of the current bar and the prices defined by the machine learning model.
Liquidate if the open price is below the sell price and buy if the open price is above the buy price
'''
for holding in self.portfolio.Values:
for holding in self.portfolio.values():
if holding.symbol not in self.current_slice.bars:
return

Expand Down
Loading