Fixes for OpenInterest storing (#4712)
- Fix Slice.Get OpenInterest type. Adding unit test - Fix for SecurityCache that wasn't storing OpenInterest types - Updateing regression tests to covere these usages
This commit is contained in:
@@ -19,6 +19,7 @@ AddReference("QuantConnect.Common")
|
||||
from System import *
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Data.Market import *
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
### <summary>
|
||||
@@ -48,9 +49,18 @@ class OptionOpenInterestRegressionAlgorithm(QCAlgorithm):
|
||||
if float(contract.Symbol.ID.StrikePrice) == 72.5 and \
|
||||
contract.Symbol.ID.OptionRight == OptionRight.Call and \
|
||||
contract.Symbol.ID.Date == datetime(2016, 1, 15):
|
||||
if slice.Time.date() == datetime(2014, 6, 5).date() and contract.OpenInterest != 50:
|
||||
|
||||
history = self.History(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:
|
||||
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):
|
||||
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:
|
||||
if slice.Time.date() == datetime(2014, 6, 6).date() and (contract.OpenInterest != 70 or security.OpenInterest != 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)
|
||||
|
||||
Reference in New Issue
Block a user