Updates Futures and Options template python algorithms

Updates BasicTemplateFuturesAlgorithm.py andBasicTemplateOptionsAlgorithm.py to use python datetime/timedelta instead of C# DateTime/TimeSpan.
This commit is contained in:
AlexCatarino
2017-05-26 01:17:35 +01:00
parent 4eb80e78e9
commit 7bb331dfad
2 changed files with 6 additions and 6 deletions
@@ -20,7 +20,7 @@ from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Securities import *
from datetime import timedelta
class BasicTemplateFuturesAlgorithm(QCAlgorithm):
'''This example demonstrates how to add futures for a given underlying.
@@ -34,17 +34,17 @@ It also shows how you can inspect the futures chain to pick a specific contract
# Subscribe and set our expiry filter for the futures chain
futureES = self.AddFuture(Futures.Indices.SP500EMini)
futureES.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
futureES.SetFilter(timedelta(0), timedelta(182))
futureGC = self.AddFuture(Futures.Metals.Gold)
futureGC.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
futureGC.SetFilter(timedelta(0), timedelta(182))
def OnData(self,slice):
if not self.Portfolio.Invested:
for chain in slice.FutureChains:
# Get contracts expiring no earlier than in 90 days
contracts = filter(lambda x: x.Expiry > self.Time.Date.AddDays(90), chain.Value)
contracts = filter(lambda x: x.Expiry > self.Time + timedelta(90), chain.Value)
# if there is any contract, trade the front contract
if len(contracts) == 0: continue
@@ -19,7 +19,7 @@ AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from datetime import timedelta
class BasicTemplateOptionsAlgorithm(QCAlgorithm):
'''This example demonstrates how to add options for a given underlying equity security.
@@ -36,7 +36,7 @@ It also shows how you can inspect the option chain to pick a specific option con
self.symbol = option.Symbol
# set our strike/expiry filter for this option chain
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180))
option.SetFilter(-2, +2, timedelta(0), timedelta(180))
# use the underlying equity as the benchmark
self.SetBenchmark(equity.Symbol)