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)
`