Hello! This is my first post here and I am really enjoying this site since joining last week.
My first algorithm I'm trying to develop needs access to the previous 20 close prices of the last 20 days, including volume. I looked up some previous people's questions that were similar and got some help, however I still can't quite figure it out.
I'd like it so that every day when the market opens, get the previous 20 day prices and volumes and store them in a list or array of some sort.
I've figured out that I think I'm going to need to change my Window length but that doesn't seem to fix the problem.
Here is what I have so far, any help would be greatly appreciated! Thanks!
import numpy as np
# globals for get_data batch transform decorator
R_P = 1 # refresh period in days
W_L = 2 # window length in days
def initialize(context):
context.aapl = [sid(24)]
def handle_data(context, data):
# get data
d = get_data(data,context.aapl)
if d == None:
print 'nothing happened'
return
price = d[0]
#volumes = d[1]
print price
#log.debug(prices)
#log.debug(volumes)
@batch_transform(refresh_period=R_P, window_length=W_L) # set globals R_P & W_L above
def get_data(datapanel,sids):
p = datapanel['price'].as_matrix(sids)
# v = datapanel['volume'].as_matrix(sids)
return [p]