use .copy() to avoid Pandas mistake. drop first row because of shifting

This commit is contained in:
Janne Sinivirta
2018-06-07 10:21:07 +03:00
parent 7f8e0ba25f
commit b4ae5a36a8
2 changed files with 11 additions and 7 deletions

View File

@@ -161,11 +161,15 @@ class Backtesting(object):
for pair, pair_data in processed.items():
pair_data['buy'], pair_data['sell'] = 0, 0 # cleanup from previous run
ticker_data = self.populate_sell_trend(self.populate_buy_trend(pair_data))[headers]
ticker_data = self.populate_sell_trend(
self.populate_buy_trend(pair_data))[headers].copy()
# to avoid using data from future, we buy/sell with signal from previous candle
ticker_data.loc[:, 'buy'] = ticker_data['buy'].shift(1)
ticker_data.loc[:, 'sell'] = ticker_data['sell'].shift(1)
ticker_data.drop(ticker_data.head(1).index, inplace=True)
# to avoid using data from future, we buy/sell with signal from previous candle, not current
ticker_data.buy = ticker_data.buy.shift(1)
ticker_data.sell = ticker_data.sell.shift(1)
ticker = [x for x in ticker_data.itertuples()]
lock_pair_until = None