mavg(n) appears to be generated starting from the beginning of the backtest period. Is there a way to get the n-Day Moving Average starting from Day 1 of the test?
mavg(n) appears to be generated starting from the beginning of the backtest period. Is there a way to get the n-Day Moving Average starting from Day 1 of the test?
Here's an example using history (which is the only way to have data "warmed up" prior to the backtest start):
import pandas as pd
from pytz import timezone
def initialize(context):
context.stocks = [sid(8554),sid(33652)]
def handle_data(context, data):
prices = history(31,'1d','price')[:-1]
print get_datetime().astimezone(timezone('US/Eastern'))
for stock in context.stocks:
print stock.symbol + ': ' + str(prices.mean()[stock])
Make sense?
Grant