dataframe -> df_analyzed in backtesting and edge
This commit is contained in:
parent
3208faf7ed
commit
ebb0187f40
@ -137,10 +137,10 @@ class Edge:
|
|||||||
pair_data = pair_data.sort_values(by=['date'])
|
pair_data = pair_data.sort_values(by=['date'])
|
||||||
pair_data = pair_data.reset_index(drop=True)
|
pair_data = pair_data.reset_index(drop=True)
|
||||||
|
|
||||||
dataframe = self.strategy.advise_sell(
|
df_analyzed = self.strategy.advise_sell(
|
||||||
self.strategy.advise_buy(pair_data, {'pair': pair}), {'pair': pair})[headers].copy()
|
self.strategy.advise_buy(pair_data, {'pair': pair}), {'pair': pair})[headers].copy()
|
||||||
|
|
||||||
trades += self._find_trades_for_stoploss_range(dataframe, pair, self._stoploss_range)
|
trades += self._find_trades_for_stoploss_range(df_analyzed, pair, self._stoploss_range)
|
||||||
|
|
||||||
# If no trade found then exit
|
# If no trade found then exit
|
||||||
if len(trades) == 0:
|
if len(trades) == 0:
|
||||||
@ -359,11 +359,11 @@ class Edge:
|
|||||||
# Returning a list of pairs in order of "expectancy"
|
# Returning a list of pairs in order of "expectancy"
|
||||||
return final
|
return final
|
||||||
|
|
||||||
def _find_trades_for_stoploss_range(self, dataframe, pair, stoploss_range):
|
def _find_trades_for_stoploss_range(self, df, pair, stoploss_range):
|
||||||
buy_column = dataframe['buy'].values
|
buy_column = df['buy'].values
|
||||||
sell_column = dataframe['sell'].values
|
sell_column = df['sell'].values
|
||||||
date_column = dataframe['date'].values
|
date_column = df['date'].values
|
||||||
ohlc_columns = dataframe[['open', 'high', 'low', 'close']].values
|
ohlc_columns = df[['open', 'high', 'low', 'close']].values
|
||||||
|
|
||||||
result: list = []
|
result: list = []
|
||||||
for stoploss in stoploss_range:
|
for stoploss in stoploss_range:
|
||||||
|
@ -164,19 +164,19 @@ class Backtesting:
|
|||||||
pair_data.loc[:, 'buy'] = 0 # cleanup from previous run
|
pair_data.loc[:, 'buy'] = 0 # cleanup from previous run
|
||||||
pair_data.loc[:, 'sell'] = 0 # cleanup from previous run
|
pair_data.loc[:, 'sell'] = 0 # cleanup from previous run
|
||||||
|
|
||||||
dataframe = self.strategy.advise_sell(
|
df_analyzed = self.strategy.advise_sell(
|
||||||
self.strategy.advise_buy(pair_data, {'pair': pair}), {'pair': pair})[headers].copy()
|
self.strategy.advise_buy(pair_data, {'pair': pair}), {'pair': pair})[headers].copy()
|
||||||
|
|
||||||
# To avoid using data from future, we use buy/sell signals shifted
|
# To avoid using data from future, we use buy/sell signals shifted
|
||||||
# from the previous candle
|
# from the previous candle
|
||||||
dataframe.loc[:, 'buy'] = dataframe['buy'].shift(1)
|
df_analyzed.loc[:, 'buy'] = df_analyzed['buy'].shift(1)
|
||||||
dataframe.loc[:, 'sell'] = dataframe['sell'].shift(1)
|
df_analyzed.loc[:, 'sell'] = df_analyzed['sell'].shift(1)
|
||||||
|
|
||||||
dataframe.drop(dataframe.head(1).index, inplace=True)
|
df_analyzed.drop(df_analyzed.head(1).index, inplace=True)
|
||||||
|
|
||||||
# Convert from Pandas to list for performance reasons
|
# Convert from Pandas to list for performance reasons
|
||||||
# (Looping Pandas is slow.)
|
# (Looping Pandas is slow.)
|
||||||
data[pair] = [x for x in dataframe.itertuples()]
|
data[pair] = [x for x in df_analyzed.itertuples()]
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _get_close_rate(self, sell_row, trade: Trade, sell: SellCheckTuple,
|
def _get_close_rate(self, sell_row, trade: Trade, sell: SellCheckTuple,
|
||||||
|
Loading…
Reference in New Issue
Block a user