Just run a simple algo to print the price of AAPL(data range:03/05/2018-03/06/2018).You get a wrong price when you print 03-05's date on 03-05.But you can get correct price of 03-05 on 03-06. Why? Is there any way to get correct price on the day you run.
def rebalance(context, data):
price_history = data.history(
context.security,
fields='price',
bar_count=5,
frequency='1d'
)
print price_history
====the result=====
2018-03-05 22:31
2018-02-27 00:00:00+00:00 178.34
2018-02-28 00:00:00+00:00 178.10
2018-03-01 00:00:00+00:00 174.90
2018-03-02 00:00:00+00:00 176.28
2018-03-05 00:00:00+00:00 175.85
Freq: C, Name: Equity(24 [AAPL]), dtype: float64
2018-03-06 22:31
2018-02-28 00:00:00+00:00 178.10
2018-03-01 00:00:00+00:00 174.90
2018-03-02 00:00:00+00:00 176.28
2018-03-05 00:00:00+00:00 176.83
2018-03-06 00:00:00+00:00 177.95
Freq: C, Name: Equity(24 [AAPL]), dtype: float64