Dear all,
I cannot seem to execute simple examples on spyder IDE, most probably because I would need to load the run_algo.py at some point.
Could anyone let me know how this could be done ?
Here is the zipline/quantopian code I used, that runs OK with run_algo.py
from zipline.api import order_target, record, symbol
from collections import deque as moving_window
import numpy as np
def initialize(context):
context.short_window = moving_window(maxlen=100)
context.long_window = moving_window(maxlen=300)
def handle_data(context, data):
# save price to window
context.short_window.append(data[symbol('AAPL')].price)
context.long_window.append(data[symbol('AAPL')].price)
# compute averages
short_mavg = np.mean(context.short_window)
long_mavg = np.mean(context.long_window)
# trading logic
if short_mavg > long_mavg:
order_target(symbol('AAPL'),100)
elif short_mavg < long_mavg:
order_target(symbol('AAPL'),0)
# save values for later inspection
record(AAPL=data[symbol('AAPL')].price,
short_mavg=short_mavg,
long_mavg=long_mavg)