I am a noob just testing out a very simple strategy of buying leveraged ETFs during the last two trading hours if they have moved a certain percentage.
I noticed the logs in my backtests had some big issues with the dates and prices. First the dates all seem to be off one day; the quantopian data is all one day ahead. For example, when it is actually the 6th, it generates logs as the 7th, and the I have logs Saturdays when the market is not open.
Regarding pricing data, I suspect the error is on my part, but I can't get an accurate figure for the previous day's close. I define closing price as:
close_price = data.current(context.securities[0],"close")
inside a scheduled function that runs at the end of the of the day. I log this number, and it appears to just be a random number. When I schedule the function to run at a different time (but still on the same day), the supposed closing price changes as well. Not too sure where I went wrong here, and what price I'm actually referencing.
Lastly, what is the most efficient way to get a stock's current price? I use:
current_price = data.history(context.securities[0], "price", 2, "1m").iloc[0]
But I'm sure there's a much more efficient way that I don't know.
Thanks for any feedback. I'm a complete beginner programmer, and I'm really eager to learn.