Back

Python example with Futures

Is there a template to get started with Futures in Python? Thank you. 

Update Backtest








We wrote this algorithm based on the C# template.
The key is to filter the FuturesChains object found in the Slice object that arrives in the OnData event handler to find the front contract no earlier than 90 days (since in this example, we are looking to that expire date from current date):

# find contracts expiring no earlier than in 90 days
contracts = [ i for i in chain.Value \
if i.Expiry > self.Time.Date.AddDays(90) ]

# if there are contracts under those conditions,
# pick the front contract
if len(contracts) > 0:
contract = sorted(contracts, \
key=lambda x: x.Expiry, reverse=True)[0]

 

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thanks Alexandre. Is there a way to build continuous contracts from those individual contracts? Suppose you want to calculate an EMA200 on ES, you probably need to concatenate 3 contracts since they are only liquid 3 months each. How this would be done in QC? Thank you for your help.

0

At the moment, there is no way to build continous contracts, but they are definitely in our TODO list of features. Since Futures and Options support is still beta we are working on improvements and stability before adding more features.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed