Thank you very much karen, the link you have posted is very helpful to me, however my code returns a huge difference in prices for AAPL, then i have tried to switch to another sec AA and the prices are correct, with the same code.
for example if you run this code
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline import CustomFactor
#****************************************************************
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import SimpleMovingAverage
import numpy as np
class GetPrice(CustomFactor):
inputs = [USEquityPricing.close]
window_length = 1
def compute(self, today, assets, out, prices):
#100*((current-previous)/(1.0*previous))
out[:] = prices
def initialize(context):
pipe = Pipeline()
attach_pipeline(pipe, name='my_pipeline')
last_close = GetPrice()
pipe.add(last_close, name='close price')
context.stock = sid(2)
context.returns = {}
def before_trading_start(context, data):
context.results = pipeline_output('my_pipeline')
def handle_data(context, data):
print 'data close: ', data[sid(2)].price
h = history(7,'1d','price')
print 'history close: ', h[sid(2)].iloc[-1]
print context.results
you will get exactly the close price of yesterday for AA in the Pipeline calculation and it's perfectly fine, BUT
if you change the sec id to 24 wich is AAPL you will get a very different close price like 329.720 in 01-04-2011 although data and history both returns a value of 47.33 for the same datetime.
So since my first attempt was with AAPL i was thinking that something was wrong with my code, but now the question is.. what is this strange discrpancy between AAPL close prices calculated with Pipeline?