Spaces:
Sleeping
Sleeping
anaucoin commited on
Commit ·
9ffaaa4
1
Parent(s): d824366
raw log fix, log colors, and div by 4 err
Browse files
app.py
CHANGED
|
@@ -75,7 +75,7 @@ def my_style(v, props=''):
|
|
| 75 |
|
| 76 |
@st.experimental_memo
|
| 77 |
def cc_coding(row):
|
| 78 |
-
return ['background-color:
|
| 79 |
|
| 80 |
|
| 81 |
@st.cache(ttl=24*3600, allow_output_mutation=True)
|
|
@@ -170,7 +170,12 @@ def runapp():
|
|
| 170 |
#hack way to get button centered
|
| 171 |
c = st.columns(9)
|
| 172 |
with c[4]:
|
| 173 |
-
submitted = st.form_submit_button("Get Cookin'!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
if submitted and principal_balance * lev > dollar_cap:
|
| 176 |
lev = np.floor(dollar_cap/principal_balance)
|
|
@@ -183,11 +188,6 @@ def runapp():
|
|
| 183 |
st.error("There are no available trades matching your selections. Please try again!")
|
| 184 |
no_errors = False
|
| 185 |
if no_errors:
|
| 186 |
-
|
| 187 |
-
signal_map = {'Long': 1, 'Short':-1} # 1 for long #-1 for short
|
| 188 |
-
|
| 189 |
-
df['Calculated Return %'] = df['Signal'].map(signal_map)*(1-fees)*((df['Sell Price']-df['Buy Price'])/df['Buy Price'] - fees) #accounts for fees on open and close of trade
|
| 190 |
-
|
| 191 |
df['Return Per Trade'] = 1+df['Calculated Return %'].values
|
| 192 |
|
| 193 |
df['Compounded Return'] = df['Return Per Trade'].cumprod()
|
|
@@ -296,16 +296,18 @@ def runapp():
|
|
| 296 |
grouped_df = df.groupby('Exit Date').agg({'Signal':'min','Entry Date': 'min','Exit Date': 'max','Buy Price': 'mean',
|
| 297 |
'Sell Price' : 'max',
|
| 298 |
'P/L per token': 'mean',
|
| 299 |
-
'
|
| 300 |
grouped_df.index = range(1, len(grouped_df)+1)
|
| 301 |
grouped_df.rename(columns={'Buy Price':'Avg. Buy Price',
|
| 302 |
-
'P/L per token':'Avg. P/L per token'
|
|
|
|
|
|
|
| 303 |
st.subheader("Trade Logs")
|
| 304 |
st.dataframe(grouped_df.style.format({'Avg. Buy Price': '${:.2f}', 'Sell Price': '${:.2f}', 'Avg. P/L per token':'${:.2f}', 'P/L %':'{:.2f}%'})\
|
| 305 |
.apply(cc_coding, axis=1)\
|
| 306 |
.applymap(my_style,subset=['Avg. P/L per token'])\
|
| 307 |
.applymap(my_style,subset=['P/L %']), use_container_width=True)
|
| 308 |
-
new_title = '<div style="text-align: right;"><span style="background-color:
|
| 309 |
st.markdown(new_title, unsafe_allow_html=True)
|
| 310 |
|
| 311 |
if __name__ == "__main__":
|
|
|
|
| 75 |
|
| 76 |
@st.experimental_memo
|
| 77 |
def cc_coding(row):
|
| 78 |
+
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)
|
| 79 |
|
| 80 |
|
| 81 |
@st.cache(ttl=24*3600, allow_output_mutation=True)
|
|
|
|
| 170 |
#hack way to get button centered
|
| 171 |
c = st.columns(9)
|
| 172 |
with c[4]:
|
| 173 |
+
submitted = st.form_submit_button("Get Cookin'!")
|
| 174 |
+
|
| 175 |
+
signal_map = {'Long': 1, 'Short':-1} # 1 for long #-1 for short
|
| 176 |
+
|
| 177 |
+
df['Calculated Return %'] = df['Signal'].map(signal_map)*(1-fees)*((df['Sell Price']-df['Buy Price'])/df['Buy Price'] - fees) #accounts for fees on open and close of trade
|
| 178 |
+
|
| 179 |
|
| 180 |
if submitted and principal_balance * lev > dollar_cap:
|
| 181 |
lev = np.floor(dollar_cap/principal_balance)
|
|
|
|
| 188 |
st.error("There are no available trades matching your selections. Please try again!")
|
| 189 |
no_errors = False
|
| 190 |
if no_errors:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
df['Return Per Trade'] = 1+df['Calculated Return %'].values
|
| 192 |
|
| 193 |
df['Compounded Return'] = df['Return Per Trade'].cumprod()
|
|
|
|
| 296 |
grouped_df = df.groupby('Exit Date').agg({'Signal':'min','Entry Date': 'min','Exit Date': 'max','Buy Price': 'mean',
|
| 297 |
'Sell Price' : 'max',
|
| 298 |
'P/L per token': 'mean',
|
| 299 |
+
'Calculated Return %' : lambda x: np.round(100*x.sum(),2)})
|
| 300 |
grouped_df.index = range(1, len(grouped_df)+1)
|
| 301 |
grouped_df.rename(columns={'Buy Price':'Avg. Buy Price',
|
| 302 |
+
'P/L per token':'Avg. P/L per token',
|
| 303 |
+
'Calculated Return %':'P/L %'}, inplace=True)
|
| 304 |
+
|
| 305 |
st.subheader("Trade Logs")
|
| 306 |
st.dataframe(grouped_df.style.format({'Avg. Buy Price': '${:.2f}', 'Sell Price': '${:.2f}', 'Avg. P/L per token':'${:.2f}', 'P/L %':'{:.2f}%'})\
|
| 307 |
.apply(cc_coding, axis=1)\
|
| 308 |
.applymap(my_style,subset=['Avg. P/L per token'])\
|
| 309 |
.applymap(my_style,subset=['P/L %']), use_container_width=True)
|
| 310 |
+
new_title = '<div style="text-align: right;"><span style="background-color:lightgrey;"> </span> Backtest Data</div>'
|
| 311 |
st.markdown(new_title, unsafe_allow_html=True)
|
| 312 |
|
| 313 |
if __name__ == "__main__":
|