anaucoin commited on
Commit
a9dbf90
·
1 Parent(s): 00b63e7

remove test trades

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -45,7 +45,7 @@ class color:
45
  UNDERLINE = '\033[4m'
46
  END = '\033[0m'
47
 
48
- @st.experimental_memo
49
  def print_PL(amnt, thresh, extras = "" ):
50
  if amnt > 0:
51
  return color.BOLD + color.GREEN + str(amnt) + extras + color.END
@@ -56,7 +56,7 @@ def print_PL(amnt, thresh, extras = "" ):
56
  else:
57
  return str(amnt + extras)
58
 
59
- @st.experimental_memo
60
  def get_headers(logtype):
61
  otimeheader = ""
62
  cheader = ""
@@ -108,7 +108,7 @@ def get_headers(logtype):
108
 
109
  return otimeheader.lower(), cheader.lower(), plheader.lower(), fmat
110
 
111
- @st.experimental_memo
112
  def get_coin_info(df_coin, principal_balance,plheader):
113
  numtrades = int(len(df_coin))
114
  numwin = int(sum(df_coin[plheader] > 0))
@@ -129,13 +129,13 @@ def get_coin_info(df_coin, principal_balance,plheader):
129
 
130
  return numtrades, numwin, numloss, winrate, pfactor, cum_PL, cum_PL_perc, mean_PL, mean_PL_perc
131
 
132
- @st.experimental_memo
133
  def get_hist_info(df_coin, principal_balance,plheader):
134
  numtrades = int(len(df_coin))
135
  numwin = int(sum(df_coin[plheader] > 0))
136
  numloss = int(sum(df_coin[plheader] < 0))
137
  if numtrades != 0:
138
- winrate = int(np.round(100*numwin/numtrades,4))
139
  else:
140
  winrate = np.nan
141
 
@@ -147,7 +147,7 @@ def get_hist_info(df_coin, principal_balance,plheader):
147
  pfactor = np.nan
148
  return numtrades, numwin, numloss, winrate, pfactor
149
 
150
- @st.experimental_memo
151
  def get_rolling_stats(df, lev, otimeheader, days):
152
  max_roll = (df[otimeheader].max() - df[otimeheader].min()).days
153
 
@@ -162,13 +162,13 @@ def get_rolling_stats(df, lev, otimeheader, days):
162
  else:
163
  rolling_perc = np.nan
164
  return 100*rolling_perc
165
- @st.experimental_memo
166
  def cc_coding(row):
167
  return ['background-color: lightgrey'] * len(row) if row['Exit Date'] <= datetime.strptime('2022-12-16 00:00:00','%Y-%m-%d %H:%M:%S').date() else [''] * len(row)
168
  def ctt_coding(row):
169
  return ['background-color: lightgrey'] * len(row) if row['Exit Date'] <= datetime.strptime('2023-01-02 00:00:00','%Y-%m-%d %H:%M:%S').date() else [''] * len(row)
170
 
171
- @st.experimental_memo
172
  def my_style(v, props=''):
173
  props = 'color:red' if v < 0 else 'color:green'
174
  return props
@@ -217,18 +217,20 @@ def load_data(filename, account, exchange, otimeheader, fmat):
217
  else:
218
  newdf = pd.DataFrame([], columns=['Trade','Signal','Entry Date','Buy Price', 'Sell Price','Exit Date', 'P/L per token', 'P/L %'])
219
 
220
- if account == 'Pure Bread Test':
221
  tvdata = pd.read_csv('pb-history-old.csv',header = 0).drop('Unnamed: 0', axis=1)
 
 
222
  else:
223
  tvdata = pd.DataFrame([])
224
  if tvdata.empty:
225
  df = newdf
226
  else:
227
  df = pd.concat([tvdata, newdf], ignore_index =True)
228
- df = df.sort_values('Entry Date', ascending = True)
229
- df.index = range(len(df))
230
- df.Trade = df.index + 1
231
-
232
  dateheader = 'Date'
233
  theader = 'Time'
234
 
@@ -329,11 +331,11 @@ def runapp() -> None:
329
  if bot_selections == "Pumpernickel":
330
  lev_cap = 5
331
  dollar_cap = 1000000000.00
332
- data = load_data('history.csv', 'Pumpernickel Test', 'Bybit Futures', otimeheader, fmat)
333
  if bot_selections == "Pure Bread":
334
  lev_cap = 5
335
  dollar_cap = 1000000000.00
336
- data = load_data('history_new.csv', 'Pure Bread Test', 'Bybit Futures', otimeheader, fmat)
337
  df = data.copy(deep=True)
338
 
339
  dateheader = 'Date'
@@ -385,7 +387,8 @@ def runapp() -> None:
385
 
386
  if no_errors:
387
  if bot_selections == "Pumpernickel":
388
- dca_map = {1: 1/3, 2: 1/3, 3: 1/3}
 
389
  df['DCA %'] = df['DCA'].map(dca_map)
390
  df['Calculated Return %'] = (df['DCA %'])*(df['Signal'].map(signal_map)*(df['Sell Price']-df['Buy Price'])/df['Buy Price']-2*fees) #accounts for fees on open and close of trade
391
  df['DCA'] = np.floor(df['DCA'].values)
@@ -409,6 +412,7 @@ def runapp() -> None:
409
  df['Compounded Return'] = df['Return Per Trade'].cumprod()
410
  df['New Balance'] = [min(dollar_cap/lev, bal*principal_balance) for bal in df['Compounded Return']]
411
  df['Balance used in Trade'] = np.concatenate([[principal_balance], df['New Balance'].values[:-1]])
 
412
  df['Net P/L Per Trade'] = drop_frac_cents((df['Return Per Trade']-1)*df['Balance used in Trade'])
413
  df['Cumulative P/L'] = df['Net P/L Per Trade'].cumsum()
414
 
@@ -562,7 +566,7 @@ def runapp() -> None:
562
  st.metric(
563
  "Max Drawdown",
564
  "",#f"{np.round(100*max_draw/principal_balance,2)/100*principal_balance:.2f}",
565
- f"{np.round(max_draw)}%",
566
  )
567
 
568
  if bot_selections == "Pumpernickel":
 
45
  UNDERLINE = '\033[4m'
46
  END = '\033[0m'
47
 
48
+ @st.cache_data
49
  def print_PL(amnt, thresh, extras = "" ):
50
  if amnt > 0:
51
  return color.BOLD + color.GREEN + str(amnt) + extras + color.END
 
56
  else:
57
  return str(amnt + extras)
58
 
59
+ @st.cache_data
60
  def get_headers(logtype):
61
  otimeheader = ""
62
  cheader = ""
 
108
 
109
  return otimeheader.lower(), cheader.lower(), plheader.lower(), fmat
110
 
111
+ @st.cache_data
112
  def get_coin_info(df_coin, principal_balance,plheader):
113
  numtrades = int(len(df_coin))
114
  numwin = int(sum(df_coin[plheader] > 0))
 
129
 
130
  return numtrades, numwin, numloss, winrate, pfactor, cum_PL, cum_PL_perc, mean_PL, mean_PL_perc
131
 
132
+ @st.cache_data
133
  def get_hist_info(df_coin, principal_balance,plheader):
134
  numtrades = int(len(df_coin))
135
  numwin = int(sum(df_coin[plheader] > 0))
136
  numloss = int(sum(df_coin[plheader] < 0))
137
  if numtrades != 0:
138
+ winrate = np.round(100*numwin/numtrades,4)
139
  else:
140
  winrate = np.nan
141
 
 
147
  pfactor = np.nan
148
  return numtrades, numwin, numloss, winrate, pfactor
149
 
150
+ @st.cache_data
151
  def get_rolling_stats(df, lev, otimeheader, days):
152
  max_roll = (df[otimeheader].max() - df[otimeheader].min()).days
153
 
 
162
  else:
163
  rolling_perc = np.nan
164
  return 100*rolling_perc
165
+ @st.cache_data
166
  def cc_coding(row):
167
  return ['background-color: lightgrey'] * len(row) if row['Exit Date'] <= datetime.strptime('2022-12-16 00:00:00','%Y-%m-%d %H:%M:%S').date() else [''] * len(row)
168
  def ctt_coding(row):
169
  return ['background-color: lightgrey'] * len(row) if row['Exit Date'] <= datetime.strptime('2023-01-02 00:00:00','%Y-%m-%d %H:%M:%S').date() else [''] * len(row)
170
 
171
+ @st.cache_data
172
  def my_style(v, props=''):
173
  props = 'color:red' if v < 0 else 'color:green'
174
  return props
 
217
  else:
218
  newdf = pd.DataFrame([], columns=['Trade','Signal','Entry Date','Buy Price', 'Sell Price','Exit Date', 'P/L per token', 'P/L %'])
219
 
220
+ if account == 'Pure Bread':
221
  tvdata = pd.read_csv('pb-history-old.csv',header = 0).drop('Unnamed: 0', axis=1)
222
+ elif account == 'Pumpernickel':
223
+ tvdata = pd.read_csv('pn-history-old.csv',header = 0).drop('Unnamed: 0', axis=1)
224
  else:
225
  tvdata = pd.DataFrame([])
226
  if tvdata.empty:
227
  df = newdf
228
  else:
229
  df = pd.concat([tvdata, newdf], ignore_index =True)
230
+ df = df.sort_values('Entry Date', ascending = True)
231
+ df.index = range(len(df))
232
+ df.Trade = df.index + 1
233
+
234
  dateheader = 'Date'
235
  theader = 'Time'
236
 
 
331
  if bot_selections == "Pumpernickel":
332
  lev_cap = 5
333
  dollar_cap = 1000000000.00
334
+ data = load_data('history.csv', 'Pumpernickel', 'Bybit Futures', otimeheader, fmat)
335
  if bot_selections == "Pure Bread":
336
  lev_cap = 5
337
  dollar_cap = 1000000000.00
338
+ data = load_data('history.csv', 'Pure Bread', 'Bybit Futures', otimeheader, fmat)
339
  df = data.copy(deep=True)
340
 
341
  dateheader = 'Date'
 
387
 
388
  if no_errors:
389
  if bot_selections == "Pumpernickel":
390
+ dca_map = {1: 1/5, 2: 1/5, 3: 1/5, 4: 1/5, 5: 1/5} #for unequal dca amounts
391
+ signal_map = {'Long': 1, 'Short':-1}
392
  df['DCA %'] = df['DCA'].map(dca_map)
393
  df['Calculated Return %'] = (df['DCA %'])*(df['Signal'].map(signal_map)*(df['Sell Price']-df['Buy Price'])/df['Buy Price']-2*fees) #accounts for fees on open and close of trade
394
  df['DCA'] = np.floor(df['DCA'].values)
 
412
  df['Compounded Return'] = df['Return Per Trade'].cumprod()
413
  df['New Balance'] = [min(dollar_cap/lev, bal*principal_balance) for bal in df['Compounded Return']]
414
  df['Balance used in Trade'] = np.concatenate([[principal_balance], df['New Balance'].values[:-1]])
415
+
416
  df['Net P/L Per Trade'] = drop_frac_cents((df['Return Per Trade']-1)*df['Balance used in Trade'])
417
  df['Cumulative P/L'] = df['Net P/L Per Trade'].cumsum()
418
 
 
566
  st.metric(
567
  "Max Drawdown",
568
  "",#f"{np.round(100*max_draw/principal_balance,2)/100*principal_balance:.2f}",
569
+ f"{np.round(max_draw,2)}%",
570
  )
571
 
572
  if bot_selections == "Pumpernickel":