Invicto69 commited on
Commit
aa8d4ac
·
verified ·
1 Parent(s): 39110be

Delete pages

Browse files
Files changed (2) hide show
  1. pages/complete_backtest.py +0 -55
  2. pages/dashboard.py +0 -106
pages/complete_backtest.py DELETED
@@ -1,55 +0,0 @@
1
- import streamlit as st
2
- import pandas as pd
3
- from streamlit.components import v1 as components
4
- from utils import complete_test
5
-
6
- def complete_backtest():
7
- st.title("Evaluate Strategy")
8
-
9
- limits = pd.read_csv('data/yahoo_limits.csv')
10
- period_list = ['1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max']
11
-
12
- c1, c2 = st.columns(2)
13
- with c1:
14
- # Select strategy
15
- strategy = st.selectbox("Select Strategy", ['Order Block', 'Order Block with EMA', 'Structure trading'], index=2)
16
- with c2:
17
- # Swing High/Low window size
18
- swing_hl = st.number_input("Swing High/Low Window Size", min_value=1, value=10)
19
-
20
- c1, c2 = st.columns(2)
21
- with c1:
22
- # Select interval
23
- interval = st.selectbox("Select Interval", limits['interval'].tolist(), index=3)
24
- with c2:
25
- # Update period options based on interval
26
- limit = limits[limits['interval'] == interval]['limit'].values[0]
27
- idx = period_list.index(limit)
28
- period_options = period_list[:idx + 1] + ['max']
29
- period = st.selectbox("Select Period", period_options, index=3)
30
-
31
- # EMA parameters if "Order Block with EMA" is selected
32
- if strategy == "Order Block with EMA":
33
- c1, c2, c3 = st.columns(3)
34
- with c1:
35
- ema1 = st.number_input("Fast EMA Length", min_value=1, value=9)
36
- with c2:
37
- ema2 = st.number_input("Slow EMA Length", min_value=1, value=21)
38
- with c3:
39
- cross_close = st.checkbox("Close trade on EMA crossover", value=False)
40
- else:
41
- ema1, ema2, cross_close = None, None, None
42
-
43
- # Button to run the analysis
44
- if st.button("Run"):
45
- st.session_state.results = complete_test(strategy, period, interval, swing_hl=swing_hl, ema1=ema1, ema2=ema2, cross_close=cross_close)
46
-
47
- if "results" in st.session_state:
48
- cols = ['stock', 'Start', 'End', 'Return [%]', 'Equity Final [$]', 'Buy & Hold Return [%]', '# Trades', 'Win Rate [%]', 'Best Trade [%]', 'Worst Trade [%]', 'Avg. Trade [%]']
49
- df = st.dataframe(st.session_state.results, hide_index=True, column_order=cols, on_select="rerun", selection_mode="single-row")
50
- if df.selection.rows:
51
- row = df.selection.rows
52
- plot = st.session_state.results['plot'].values[row]
53
- components.html(plot[0], height=1067)
54
-
55
- complete_backtest()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/dashboard.py DELETED
@@ -1,106 +0,0 @@
1
- import pandas as pd
2
- import streamlit as st
3
- import os
4
- import random
5
- from bokeh.io import output_file, save
6
- from bokeh.plotting import figure
7
- from streamlit.components import v1 as components
8
-
9
- from indicators import SMC
10
- from utils import fetch, smc_plot_backtest, smc_ema_plot_backtest, smc_structure_plot_backtest
11
-
12
- def use_file_for_bokeh(chart: figure, chart_height=1067):
13
- # Function used to replace st.boken_chart, because streamlit doesn't support bokeh v3
14
- file_name = f'bokeh_graph_{random.getrandbits(8)}.html'
15
- output_file(file_name)
16
- save(chart)
17
- with open(file_name, 'r', encoding='utf-8') as f:
18
- html = f.read()
19
- os.remove(file_name)
20
- components.html(html, height=chart_height)
21
-
22
- st.bokeh_chart = use_file_for_bokeh
23
-
24
- def algorithmic_trading_dashboard():
25
- # Load data
26
- symbols = pd.read_csv('data/Ticker_List_NSE_India.csv')
27
- limits = pd.read_csv('data/yahoo_limits.csv')
28
-
29
- # Dropdown options
30
- period_list = ['1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max']
31
-
32
- # Input fields on the main page
33
- st.title("Algorithmic Trading Dashboard")
34
-
35
- # Select stock
36
- stock = st.selectbox("Select Company", symbols['NAME OF COMPANY'].unique(), index=None)
37
-
38
- c1, c2 = st.columns(2)
39
-
40
- with c1:
41
- # Select interval
42
- interval = st.selectbox("Select Interval", limits['interval'].tolist(), index=3)
43
-
44
- with c2:
45
- # Update period options based on interval
46
- limit = limits[limits['interval'] == interval]['limit'].values[0]
47
- idx = period_list.index(limit)
48
- period_options = period_list[:idx + 1] + ['max']
49
- period = st.selectbox("Select Period", period_options, index=3)
50
-
51
- c1, c2 = st.columns(2)
52
-
53
- with c1:
54
- # Select strategy
55
- strategy = st.selectbox("Select Strategy", ['Order Block', 'Order Block with EMA', 'Structure trading'], index=2)
56
-
57
- with c2:
58
- # Swing High/Low window size
59
- swing_hl = st.number_input("Swing High/Low Window Size", min_value=1, value=10)
60
-
61
- # EMA parameters if "Order Block with EMA" is selected
62
- if strategy == "Order Block with EMA":
63
- c1, c2, c3 = st.columns(3)
64
- with c1:
65
- ema1 = st.number_input("Fast EMA Length", min_value=1, value=9)
66
- with c2:
67
- ema2 = st.number_input("Slow EMA Length", min_value=1, value=21)
68
- with c3:
69
- cross_close = st.checkbox("Close trade on EMA crossover", value=False)
70
-
71
- # Button to run the analysis
72
- if st.button("Run"):
73
- # Fetch ticker data
74
- ticker = symbols[symbols['NAME OF COMPANY'] == stock]['YahooEquiv'].values[0]
75
- data = fetch(ticker, period, interval)
76
-
77
- # Generate signal plot based on strategy
78
- if strategy == "Order Block" or strategy == "Order Block with EMA":
79
- signal_plot = (
80
- SMC(data=data, swing_hl_window_sz=swing_hl)
81
- .plot(order_blocks=True, swing_hl=True, show=False)
82
- .update_layout(title=dict(text=ticker))
83
- )
84
- else:
85
- signal_plot = (
86
- SMC(data=data, swing_hl_window_sz=swing_hl)
87
- .plot(swing_hl_v2=True, structure=True, show=False)
88
- .update_layout(title=dict(text=ticker))
89
- )
90
-
91
- # Generate backtest plot
92
- if strategy == "Order Block":
93
- backtest_plot = smc_plot_backtest(data, 'test.html', swing_hl)
94
- elif strategy == "Order Block with EMA":
95
- backtest_plot = smc_ema_plot_backtest(data, 'test.html', ema1, ema2, cross_close)
96
- elif strategy == "Structure trading":
97
- backtest_plot = smc_structure_plot_backtest(data, 'test.html', swing_hl)
98
-
99
- # Display plots
100
- st.write("### Signal Plot")
101
- st.plotly_chart(signal_plot, width=1200)
102
-
103
- st.write("### Backtesting Plot")
104
- st.bokeh_chart(backtest_plot)
105
-
106
- algorithmic_trading_dashboard()