(The error I'm getting is on the samplealgo01/samplealgo/btest.py)
I have spent the last two months or so analyzing how the samplealgo01 and multiple other algorithms work. This last week I finally though I had enough information to start building my own algorithm on top of the samplealgo01. I first modified how the order are bought, I had no troubles with this. The error only occurred when I when to modify how stocks are sold. I changed the logic and ran the code but once the code started to run, I got a error that said the snapshot in btest was empty. Since I got an error, I commented out my version of how to sell and uncommented the original version and ran it again. This time the error did not occur. I was a little curious to why, so then I commented out the order.append({...}) that happens in the original sell logic, once I did that an ran the code again I got the same error as before. It looks like if I don't sell it happens.
The next thing I did was go to the beginning of where the error occur and that is here in the btest.py:
snapshot = {
symbol: df[df.index < t]
for symbol, df in price_map.items()
# sanity check to exclude stale prices
if t - df[df.index < t].index[-1] < pd.Timedelta('2 days')}
It turns out if you hide the order.append({}) in the sell logic or even modify how the sell logic works then the snapshot becomes empty because it does not pass this if statement:
if t - df[df.index < t].index[-1] < pd.Timedelta('2 days')
I would like to know why this is happening and is there a work around for it?
(The error I'm getting is on the samplealgo01/samplealgo/btest.py)
I have spent the last two months or so analyzing how the samplealgo01 and multiple other algorithms work. This last week I finally though I had enough information to start building my own algorithm on top of the samplealgo01. I first modified how the order are bought, I had no troubles with this. The error only occurred when I when to modify how stocks are sold. I changed the logic and ran the code but once the code started to run, I got a error that said the snapshot in btest was empty. Since I got an error, I commented out my version of how to sell and uncommented the original version and ran it again. This time the error did not occur. I was a little curious to why, so then I commented out the order.append({...}) that happens in the original sell logic, once I did that an ran the code again I got the same error as before. It looks like if I don't sell it happens.
The next thing I did was go to the beginning of where the error occur and that is here in the btest.py:
It turns out if you hide the order.append({}) in the sell logic or even modify how the sell logic works then the snapshot becomes empty because it does not pass this if statement:
I would like to know why this is happening and is there a work around for it?