pep8 conversion of python algos #12 (#7954)
Python Virtual Environments / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* pep8 conversion * PEP8 updates/fixes * Update pythonnet version to 2.0.35 --------- Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
This commit is contained in:
@@ -20,42 +20,42 @@ from AlgorithmImports import *
|
||||
### <meta name="tag" content="regression test" />
|
||||
class OptionOpenInterestRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetCash(1000000)
|
||||
self.SetStartDate(2014,6,5)
|
||||
self.SetEndDate(2014,6,6)
|
||||
def initialize(self):
|
||||
self.set_cash(1000000)
|
||||
self.set_start_date(2014,6,5)
|
||||
self.set_end_date(2014,6,6)
|
||||
|
||||
option = self.AddOption("TWX")
|
||||
option = self.add_option("TWX")
|
||||
|
||||
# set our strike/expiry filter for this option chain
|
||||
option.SetFilter(-10, 10, timedelta(0), timedelta(365*2))
|
||||
option.set_filter(-10, 10, timedelta(0), timedelta(365*2))
|
||||
|
||||
# use the underlying equity as the benchmark
|
||||
self.SetBenchmark("TWX")
|
||||
self.set_benchmark("TWX")
|
||||
|
||||
def OnData(self, slice):
|
||||
if not self.Portfolio.Invested:
|
||||
for chain in slice.OptionChains:
|
||||
for contract in chain.Value:
|
||||
if float(contract.Symbol.ID.StrikePrice) == 72.5 and \
|
||||
contract.Symbol.ID.OptionRight == OptionRight.Call and \
|
||||
contract.Symbol.ID.Date == datetime(2016, 1, 15):
|
||||
def on_data(self, slice):
|
||||
if not self.portfolio.invested:
|
||||
for chain in slice.option_chains:
|
||||
for contract in chain.value:
|
||||
if float(contract.symbol.id.strike_price) == 72.5 and \
|
||||
contract.symbol.id.option_right == OptionRight.CALL and \
|
||||
contract.symbol.id.date == datetime(2016, 1, 15):
|
||||
|
||||
history = self.History(OpenInterest, contract.Symbol, timedelta(1))["openinterest"]
|
||||
history = self.history(OpenInterest, contract.symbol, timedelta(1))["openinterest"]
|
||||
if len(history.index) == 0 or 0 in history.values:
|
||||
raise ValueError("Regression test failed: open interest history request is empty")
|
||||
|
||||
security = self.Securities[contract.Symbol]
|
||||
openInterestCache = security.Cache.GetData[OpenInterest]()
|
||||
if openInterestCache == None:
|
||||
security = self.securities[contract.symbol]
|
||||
open_interest_cache = security.cache.get_data[OpenInterest]()
|
||||
if open_interest_cache == None:
|
||||
raise ValueError("Regression test failed: current open interest isn't in the security cache")
|
||||
if slice.Time.date() == datetime(2014, 6, 5).date() and (contract.OpenInterest != 50 or security.OpenInterest != 50):
|
||||
if slice.time.date() == datetime(2014, 6, 5).date() and (contract.open_interest != 50 or security.open_interest != 50):
|
||||
raise ValueError("Regression test failed: current open interest was not correctly loaded and is not equal to 50")
|
||||
if slice.Time.date() == datetime(2014, 6, 6).date() and (contract.OpenInterest != 70 or security.OpenInterest != 70):
|
||||
if slice.time.date() == datetime(2014, 6, 6).date() and (contract.open_interest != 70 or security.open_interest != 70):
|
||||
raise ValueError("Regression test failed: current open interest was not correctly loaded and is not equal to 70")
|
||||
if slice.Time.date() == datetime(2014, 6, 6).date():
|
||||
self.MarketOrder(contract.Symbol, 1)
|
||||
self.MarketOnCloseOrder(contract.Symbol, -1)
|
||||
if slice.time.date() == datetime(2014, 6, 6).date():
|
||||
self.market_order(contract.symbol, 1)
|
||||
self.market_on_close_order(contract.symbol, -1)
|
||||
|
||||
def OnOrderEvent(self, orderEvent):
|
||||
self.Log(str(orderEvent))
|
||||
def on_order_event(self, order_event):
|
||||
self.log(str(order_event))
|
||||
|
||||
Reference in New Issue
Block a user