Fix bug in bt-analysis when multiple trades sell at the same time
This commit is contained in:
parent
d711b8c0e9
commit
2ae398913d
@ -157,7 +157,8 @@ def create_cum_profit(df: pd.DataFrame, trades: pd.DataFrame, col_name: str) ->
|
|||||||
:param trades: DataFrame containing trades (requires columns close_time and profitperc)
|
:param trades: DataFrame containing trades (requires columns close_time and profitperc)
|
||||||
:return: Returns df with one additional column, col_name, containing the cumulative profit.
|
:return: Returns df with one additional column, col_name, containing the cumulative profit.
|
||||||
"""
|
"""
|
||||||
df[col_name] = trades.set_index('close_time')['profitperc'].cumsum()
|
# Use groupby/sum().cumsum() to avoid errors when multiple trades sold at the same candle.
|
||||||
|
df[col_name] = trades.groupby('close_time')['profitperc'].sum().cumsum()
|
||||||
# Set first value to 0
|
# Set first value to 0
|
||||||
df.loc[df.iloc[0].name, col_name] = 0
|
df.loc[df.iloc[0].name, col_name] = 0
|
||||||
# FFill to get continuous
|
# FFill to get continuous
|
||||||
|
Loading…
Reference in New Issue
Block a user