Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
WTI future moving average algo

I am a novice programmer working on extremely simple algorithms for crude oil futures. I have two concerns:

-I can not figure out how to get the 200 day moving average syntax correct. Please let me know how I can correct this.

-With my pricing data from quandl, I am pretty sure my algo is only using the settle prices from the data set. How can I incorporate the open, high, and low prices into my algorithm?

Thank you for the help in advance. I apologize for my inexperience.

` def rename_col(df):
df = df.rename(columns={'Settle': 'price'})
df = df[['price', 'sid']]
return df

def initialize(context):
fetch_csv('http://www.quandl.com/api/v1/datasets/OFDP/FUTURE_CL1.csv?&trim_start=1983-03-30&trim_end=2014-03-11&sort_order=desc',
date_column='Date',
symbol='oil',
usecols=['Settle'],
post_func=rename_col,
date_format='%Y-%m-%d'
)

context.stock = sid(3766)

def handle_data(context, data):
if 'price' in data['oil']:
record(oil_price=data['oil'].price)

price = data['oil'].price  
200mavg = data['oil'].mavg(200)  

if price < 200mavg:  
order(context.['oil'],-1)  

if price > 200mavg:
order(context.['oil'],+1)
`

1 response

Hi Nick,

Currently Quantopian only supports US stocks and ETS, but as the platform grows we hope to add additional data sources including futures. Since our database only has historical information for stocks, it cannot process the command

order(context['oil'], -1).  

It can only include a stock, which is specidied by a unique security id or a SID. See here for more information on ordering methods.

You can take a look at these previous examples which use Quandl to import data:
https://www.quantopian.com/posts/using-the-fetcher-with-quandl
https://www.quantopian.com/posts/visualizing-implied-vs-realized-volatility
https://www.quantopian.com/posts/black-litterman

Cheers,
Alisa

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.