Spaces:
Runtime error
Runtime error
anaucoin commited on
Commit ·
3208cdd
1
Parent(s): b7c477d
CT DCA updates
Browse files
app.py
CHANGED
|
@@ -160,9 +160,9 @@ def get_rolling_stats(df, lev, otimeheader, days):
|
|
| 160 |
return 100*rolling_perc
|
| 161 |
@st.experimental_memo
|
| 162 |
def cc_coding(row):
|
| 163 |
-
return ['background-color:
|
| 164 |
def ctt_coding(row):
|
| 165 |
-
return ['background-color:
|
| 166 |
|
| 167 |
@st.experimental_memo
|
| 168 |
def my_style(v, props=''):
|
|
@@ -223,11 +223,16 @@ def load_data(filename, otimeheader, fmat):
|
|
| 223 |
|
| 224 |
for exit in pd.unique(df['Exit Date']):
|
| 225 |
df_exit = df[df['Exit Date']==exit]
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
def runapp() -> None:
|
| 233 |
#st.header("Trading Bot Dashboard :bread: :moneybag:")
|
|
@@ -506,6 +511,7 @@ def runapp() -> None:
|
|
| 506 |
principal_balance = st.number_input('Starting Balance', min_value=0.00, value=1000.00, max_value= dollar_cap, step=.01)
|
| 507 |
|
| 508 |
if bot_selections == "Cinnamon Toast":
|
|
|
|
| 509 |
with st.container():
|
| 510 |
col1, col2, col3, col4 = st.columns(4)
|
| 511 |
with col1:
|
|
@@ -516,6 +522,13 @@ def runapp() -> None:
|
|
| 516 |
dca3 = st.number_input('DCA 3 Allocation', min_value=0, value=25, max_value= 100, step=1)
|
| 517 |
with col4:
|
| 518 |
dca4 = st.number_input('DCA 4 Allocation', min_value=0, value=25, max_value= 100, step=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
|
| 520 |
#hack way to get button centered
|
| 521 |
c = st.columns(9)
|
|
@@ -535,9 +548,10 @@ def runapp() -> None:
|
|
| 535 |
no_errors = False
|
| 536 |
if no_errors:
|
| 537 |
if bot_selections == "Cinnamon Toast":
|
| 538 |
-
dca_map = {1: dca1/100, 2: dca2/100, 3: dca3/100, 4: dca4/100}
|
| 539 |
df['DCA %'] = df['DCA'].map(dca_map)
|
| 540 |
df['Calculated Return %'] = df['Signal'].map(signal_map)*(df['DCA %'])*(1-fees)*((df['Sell Price']-df['Buy Price'])/df['Buy Price'] - fees) #accounts for fees on open and close of trade
|
|
|
|
| 541 |
|
| 542 |
df['Return Per Trade'] = np.nan
|
| 543 |
df['Balance used in Trade'] = np.nan
|
|
@@ -650,19 +664,24 @@ def runapp() -> None:
|
|
| 650 |
'Sell Price' : 'max',
|
| 651 |
'Net P/L Per Trade': 'mean',
|
| 652 |
'Calculated Return %' : lambda x: np.round(100*lev*x.sum(),2),
|
| 653 |
-
'DCA':
|
| 654 |
grouped_df.index = range(1, len(grouped_df)+1)
|
| 655 |
grouped_df.rename(columns={'DCA' : '# of DCAs', 'Buy Price':'Avg. Buy Price',
|
| 656 |
'Net P/L Per Trade':'Net P/L',
|
| 657 |
'Calculated Return %':'P/L %'}, inplace=True)
|
| 658 |
-
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
grouped_df = df.groupby('Exit Date').agg({'Signal':'min','Entry Date': 'min','Exit Date': 'max','Buy Price': 'mean',
|
| 660 |
'Sell Price' : 'max',
|
| 661 |
'P/L per token': 'mean',
|
| 662 |
-
'
|
| 663 |
-
'DCA':
|
| 664 |
grouped_df.index = range(1, len(grouped_df)+1)
|
| 665 |
grouped_df.rename(columns={'DCA' : '# of DCAs', 'Buy Price':'Avg. Buy Price',
|
|
|
|
| 666 |
'P/L per token':'Net P/L'}, inplace=True)
|
| 667 |
|
| 668 |
else:
|
|
@@ -690,7 +709,7 @@ def runapp() -> None:
|
|
| 690 |
.apply(coding, axis=1)\
|
| 691 |
.applymap(my_style,subset=['Net P/L'])\
|
| 692 |
.applymap(my_style,subset=['P/L %']), use_container_width=True)
|
| 693 |
-
new_title = '<div style="text-align: right;"><span style="background-color:
|
| 694 |
st.markdown(new_title, unsafe_allow_html=True)
|
| 695 |
else:
|
| 696 |
st.dataframe(grouped_df.style.format({'Avg. Buy Price': '${:.2f}', 'Sell Price': '${:.2f}', 'Net P/L':'${:.2f}', 'P/L %':'{:.2f}%'})\
|
|
|
|
| 160 |
return 100*rolling_perc
|
| 161 |
@st.experimental_memo
|
| 162 |
def cc_coding(row):
|
| 163 |
+
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)
|
| 164 |
def ctt_coding(row):
|
| 165 |
+
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)
|
| 166 |
|
| 167 |
@st.experimental_memo
|
| 168 |
def my_style(v, props=''):
|
|
|
|
| 223 |
|
| 224 |
for exit in pd.unique(df['Exit Date']):
|
| 225 |
df_exit = df[df['Exit Date']==exit]
|
| 226 |
+
if dateutil.parser.parse(str(exit)) < dateutil.parser.parse('2023-02-07 00:13:00'):
|
| 227 |
+
for i in range(len(df_exit)):
|
| 228 |
+
ind = df_exit.index[i]
|
| 229 |
+
df.loc[ind,'DCA'] = i+1
|
| 230 |
+
|
| 231 |
+
else:
|
| 232 |
+
for i in range(len(df_exit)):
|
| 233 |
+
ind = df_exit.index[i]
|
| 234 |
+
df.loc[ind,'DCA'] = i+1.1
|
| 235 |
+
return df
|
| 236 |
|
| 237 |
def runapp() -> None:
|
| 238 |
#st.header("Trading Bot Dashboard :bread: :moneybag:")
|
|
|
|
| 511 |
principal_balance = st.number_input('Starting Balance', min_value=0.00, value=1000.00, max_value= dollar_cap, step=.01)
|
| 512 |
|
| 513 |
if bot_selections == "Cinnamon Toast":
|
| 514 |
+
st.write("Choose your DCA setup (for trades before 02/07/2023)")
|
| 515 |
with st.container():
|
| 516 |
col1, col2, col3, col4 = st.columns(4)
|
| 517 |
with col1:
|
|
|
|
| 522 |
dca3 = st.number_input('DCA 3 Allocation', min_value=0, value=25, max_value= 100, step=1)
|
| 523 |
with col4:
|
| 524 |
dca4 = st.number_input('DCA 4 Allocation', min_value=0, value=25, max_value= 100, step=1)
|
| 525 |
+
st.write("Choose your DCA setup (for trades on or after 02/07/2023)")
|
| 526 |
+
with st.container():
|
| 527 |
+
col1, col2 = st.columns(2)
|
| 528 |
+
with col1:
|
| 529 |
+
dca5 = st.number_input('DCA 1 Allocation', min_value=0, value=50, max_value= 100, step=1)
|
| 530 |
+
with col2:
|
| 531 |
+
dca6 = st.number_input('DCA 2 Allocation', min_value=0, value=50, max_value= 100, step=1)
|
| 532 |
|
| 533 |
#hack way to get button centered
|
| 534 |
c = st.columns(9)
|
|
|
|
| 548 |
no_errors = False
|
| 549 |
if no_errors:
|
| 550 |
if bot_selections == "Cinnamon Toast":
|
| 551 |
+
dca_map = {1: dca1/100, 2: dca2/100, 3: dca3/100, 4: dca4/100, 1.1: dca5/100, 2.1: dca6/100}
|
| 552 |
df['DCA %'] = df['DCA'].map(dca_map)
|
| 553 |
df['Calculated Return %'] = df['Signal'].map(signal_map)*(df['DCA %'])*(1-fees)*((df['Sell Price']-df['Buy Price'])/df['Buy Price'] - fees) #accounts for fees on open and close of trade
|
| 554 |
+
df['DCA'] = np.floor(df['DCA'].values)
|
| 555 |
|
| 556 |
df['Return Per Trade'] = np.nan
|
| 557 |
df['Balance used in Trade'] = np.nan
|
|
|
|
| 664 |
'Sell Price' : 'max',
|
| 665 |
'Net P/L Per Trade': 'mean',
|
| 666 |
'Calculated Return %' : lambda x: np.round(100*lev*x.sum(),2),
|
| 667 |
+
'DCA': lambda x: int(np.floor(x.max()))})
|
| 668 |
grouped_df.index = range(1, len(grouped_df)+1)
|
| 669 |
grouped_df.rename(columns={'DCA' : '# of DCAs', 'Buy Price':'Avg. Buy Price',
|
| 670 |
'Net P/L Per Trade':'Net P/L',
|
| 671 |
'Calculated Return %':'P/L %'}, inplace=True)
|
| 672 |
+
else:
|
| 673 |
+
dca_map = {1: 25/100, 2: 25/100, 3: 25/100, 4: 25/100, 1.1: 50/100, 2.1: 50/100}
|
| 674 |
+
df['DCA %'] = df['DCA'].map(dca_map)
|
| 675 |
+
df['Calculated Return %'] = (df['DCA %'])*(1-fees)*((df['Sell Price']-df['Buy Price'])/df['Buy Price'] - fees) #accounts for fees on open and close of trade
|
| 676 |
+
|
| 677 |
grouped_df = df.groupby('Exit Date').agg({'Signal':'min','Entry Date': 'min','Exit Date': 'max','Buy Price': 'mean',
|
| 678 |
'Sell Price' : 'max',
|
| 679 |
'P/L per token': 'mean',
|
| 680 |
+
'Calculated Return %' : lambda x: np.round(100*x.sum(),2),
|
| 681 |
+
'DCA': lambda x: int(np.floor(x.max()))})
|
| 682 |
grouped_df.index = range(1, len(grouped_df)+1)
|
| 683 |
grouped_df.rename(columns={'DCA' : '# of DCAs', 'Buy Price':'Avg. Buy Price',
|
| 684 |
+
'Calculated Return %':'P/L %',
|
| 685 |
'P/L per token':'Net P/L'}, inplace=True)
|
| 686 |
|
| 687 |
else:
|
|
|
|
| 709 |
.apply(coding, axis=1)\
|
| 710 |
.applymap(my_style,subset=['Net P/L'])\
|
| 711 |
.applymap(my_style,subset=['P/L %']), use_container_width=True)
|
| 712 |
+
new_title = '<div style="text-align: right;"><span style="background-color:lightgrey;"> </span> Not Live Traded</div>'
|
| 713 |
st.markdown(new_title, unsafe_allow_html=True)
|
| 714 |
else:
|
| 715 |
st.dataframe(grouped_df.style.format({'Avg. Buy Price': '${:.2f}', 'Sell Price': '${:.2f}', 'Net P/L':'${:.2f}', 'P/L %':'{:.2f}%'})\
|