Spaces:
Build error
Build error
drawdown calc fixes + compound round fix
Browse files
app.py
CHANGED
|
@@ -295,24 +295,23 @@ def get_sd_df(sd_df, sd, bot_selections, dca1, dca2, dca3, dca4, dca5, dca6, fee
|
|
| 295 |
sd_df['Cumulative P/L (-)'] = sd_df['Net P/L Per Trade (-)'].cumsum()
|
| 296 |
return sd_df
|
| 297 |
|
| 298 |
-
def get_account_drawdown(trades,
|
| 299 |
max_draw = 0.0
|
| 300 |
beg = 0
|
| 301 |
fin = 0
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
for
|
| 305 |
-
|
| 306 |
-
delta = future - trades[candidate]
|
| 307 |
if max_draw > delta.min():
|
| 308 |
max_draw = min(max_draw, delta.min())
|
| 309 |
-
beg =
|
| 310 |
fin = delta.argmin()
|
| 311 |
-
max_draw_perc = max_draw/(
|
| 312 |
-
|
| 313 |
max_draw = min(max_draw, trades)
|
| 314 |
-
max_draw_perc = max_draw/(principal_balance)
|
| 315 |
-
return
|
| 316 |
|
| 317 |
def runapp() -> None:
|
| 318 |
bot_selections = "Pure Bread"
|
|
@@ -408,10 +407,10 @@ def runapp() -> None:
|
|
| 408 |
df['Compounded Return'] = df['Return Per Trade'].cumprod()
|
| 409 |
df['New Balance'] = [min(dollar_cap/lev, bal*principal_balance) for bal in df['Compounded Return']]
|
| 410 |
df['Balance used in Trade'] = np.concatenate([[principal_balance], df['New Balance'].values[:-1]])
|
| 411 |
-
df['Net P/L Per Trade'] = (df['Return Per Trade']-1)*df['Balance used in Trade']
|
| 412 |
df['Cumulative P/L'] = df['Net P/L Per Trade'].cumsum()
|
| 413 |
|
| 414 |
-
max_draw
|
| 415 |
cum_pl = df.loc[df.dropna().index[-1],'Cumulative P/L'] + principal_balance
|
| 416 |
|
| 417 |
effective_return = 100*((cum_pl - principal_balance)/principal_balance)
|
|
|
|
| 295 |
sd_df['Cumulative P/L (-)'] = sd_df['Net P/L Per Trade (-)'].cumsum()
|
| 296 |
return sd_df
|
| 297 |
|
| 298 |
+
def get_account_drawdown(trades, principal_balance):
|
| 299 |
max_draw = 0.0
|
| 300 |
beg = 0
|
| 301 |
fin = 0
|
| 302 |
+
trades = np.hstack([0.0, trades.dropna().values]) + principal_balance
|
| 303 |
+
if len(trades) > 2:
|
| 304 |
+
for ind in range(len(trades)-1):
|
| 305 |
+
delta = trades[ind+1:] - trades[ind]
|
|
|
|
| 306 |
if max_draw > delta.min():
|
| 307 |
max_draw = min(max_draw, delta.min())
|
| 308 |
+
beg = ind
|
| 309 |
fin = delta.argmin()
|
| 310 |
+
max_draw_perc = 100*max_draw/(trades[beg])
|
| 311 |
+
else:
|
| 312 |
max_draw = min(max_draw, trades)
|
| 313 |
+
max_draw_perc = 100*max_draw/(principal_balance)
|
| 314 |
+
return max_draw_perc
|
| 315 |
|
| 316 |
def runapp() -> None:
|
| 317 |
bot_selections = "Pure Bread"
|
|
|
|
| 407 |
df['Compounded Return'] = df['Return Per Trade'].cumprod()
|
| 408 |
df['New Balance'] = [min(dollar_cap/lev, bal*principal_balance) for bal in df['Compounded Return']]
|
| 409 |
df['Balance used in Trade'] = np.concatenate([[principal_balance], df['New Balance'].values[:-1]])
|
| 410 |
+
df['Net P/L Per Trade'] = drop_frac_cents((df['Return Per Trade']-1)*df['Balance used in Trade'])
|
| 411 |
df['Cumulative P/L'] = df['Net P/L Per Trade'].cumsum()
|
| 412 |
|
| 413 |
+
max_draw = get_account_drawdown(df['Cumulative P/L'], principal_balance)
|
| 414 |
cum_pl = df.loc[df.dropna().index[-1],'Cumulative P/L'] + principal_balance
|
| 415 |
|
| 416 |
effective_return = 100*((cum_pl - principal_balance)/principal_balance)
|