Hello I was building an algorithm based on simple average and trying to validate the price.
The data below is from the log, it shows the current price and the price 5 days ago. For instance, the price on 2018-09-24 is
52.47, but when I used the data.history function to find the price of 5 days ago on 2018-10-01(5 trading days later) and it has become 52.446.
2018-09-24 12:59 record_vars:189 INFO Current Price: 52.47 5 Days Ago:51.865
2018-09-25 12:59 record_vars:189 INFO Current Price: 52.725 5 Days Ago:52.135
2018-09-26 12:59 record_vars:189 INFO Current Price: 52.485 5 Days Ago:52.441
2018-09-27 12:59 record_vars:189 INFO Current Price: 52.46 5 Days Ago:52.486
2018-09-28 12:59 record_vars:189 INFO Current Price: 52.03 5 Days Ago:52.178
2018-10-01 12:59 record_vars:189 INFO Current Price: 52.18 5 Days Ago:52.446
2018-10-02 12:59 record_vars:189 INFO Current Price: 51.78 5 Days Ago:52.48
2018-10-03 12:59 record_vars:189 INFO Current Price: 51.635 5 Days Ago:52.42
2018-10-04 12:59 record_vars:189 INFO Current Price: 50.88 5 Days Ago:52.05
2018-10-05 12:59 record_vars:189 INFO Current Price: 50.62 5 Days Ago:52.16
2018-10-08 12:59 record_vars:189 INFO Current Price: 50.46 5 Days Ago:51.79
2018-10-09 12:59 record_vars:189 INFO Current Price: 50.316 5 Days Ago:51.64
2018-10-10 12:59 record_vars:189 INFO Current Price: 49.09 5 Days Ago:50.89
2018-10-11 12:59 record_vars:189 INFO Current Price: 48.53 5 Days Ago:50.64
Here's the code I used:
context.world = data.history(sid(33486) ,fields="price", bar_count=180, frequency="1d")
log.info("Current Price: %s 5 Days Ago:%s"%(context.world[-1],context.world[-5]))
And the schedule function:
schedule_function(func=record_vars, date_rule=date_rules.every_day(),
time_rule=time_rules.market_close(hours=0,minutes=1),
half_days=True)