Back to Community
Why the price data is different?
API

In different trade date, why I can't get the same price data which bind with a specified date?
Here is my simple code:
def initialize(context):
context.rs_ref_stock = sid(19656)

def before_trading_start(context, data):
#get XLF close price
xlf_price_history = data.history(sid(19656), ['close'], 3, '1d')
log.info("\n" + str(xlf_price_history))

Output:
2017-06-15 20:45 before_trading_start:10 INFO
close
2017-06-12 00:00:00+00:00 24.345
2017-06-13 00:00:00+00:00 24.455
2017-06-14 00:00:00+00:00 24.500
2017-06-16 20:45 before_trading_start:10 INFO
close
2017-06-13 00:00:00+00:00 24.361690
2017-06-14 00:00:00+00:00 24.406518
2017-06-15 00:00:00+00:00 24.306900
End of logs.

1 response

The reason is XLF declared a dividend on 06-16-2017 (see https://us.spdrs.com/en/resources/distributions/index.seam?ticker=XLF ).

The dividend was $0.093059 per share effective on the ex-date of 06-16-2017. Prices on Quantopian (and other data sources) are split AND dividend adjusted. A dividend looks exactly like a stock split when adjusting historical prices. One could argue when exactly to apply that adjustment but after the ex-dividend date the stock would be worth less because one doesn't have the rights to the dividend. Conversely, the stock before that date was worth more. The price difference is exactly equal to the dividend. (Take a look at http://www.investopedia.com/terms/a/adjusted_closing_price.asp for more info)

This is what the price data above is reflecting. After 06-16-2017, all the prices before that date are reduced by the dividend amount. (The resulting prices agree to 3 decimal places).