Update gradio_app.py
Browse files- gradio_app.py +75 -64
gradio_app.py
CHANGED
@@ -1,65 +1,76 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from data_fetcher import fetch
|
3 |
-
from indicators import SMC
|
4 |
-
from strategies import smc_plot_backtest, smc_ema_plot_backtest
|
5 |
-
import pandas as pd
|
6 |
-
|
7 |
-
symbols = pd.read_csv('data/Ticker_List_NSE_India.csv')
|
8 |
-
|
9 |
-
def run(stock, strategy, swing_hl, ema1, ema2, cross_close):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
app.launch(debug=True)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from data_fetcher import fetch
|
3 |
+
from indicators import SMC
|
4 |
+
from strategies import smc_plot_backtest, smc_ema_plot_backtest, smc_structure_backtest
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
symbols = pd.read_csv('data/Ticker_List_NSE_India.csv')
|
8 |
+
|
9 |
+
def run(stock, strategy, swing_hl, ema1, ema2, cross_close):
|
10 |
+
# Downloading ticker data.
|
11 |
+
ticker = symbols[symbols['NAME OF COMPANY'] == stock]['YahooEquiv'].values[0]
|
12 |
+
data = fetch(ticker, period='1mo', interval='15m')
|
13 |
+
|
14 |
+
# Plotting signal plot based on strategy.
|
15 |
+
if strategy == "Order Block" or strategy == "Order Block with EMA":
|
16 |
+
signal_plot = (SMC(data=data, swing_hl_window_sz=swing_hl).
|
17 |
+
plot(order_blocks=True, swing_hl=True, show=False).
|
18 |
+
update_layout(title=dict(text=ticker)))
|
19 |
+
else:
|
20 |
+
signal_plot = (SMC(data=data, swing_hl_window_sz=swing_hl).
|
21 |
+
plot(swing_hl_v2=True, structure=True, show=False).
|
22 |
+
update_layout(title=dict(text=ticker)))
|
23 |
+
|
24 |
+
backtest_plot = gr.Plot()
|
25 |
+
|
26 |
+
|
27 |
+
# Plotting backtest plot based on strategy.
|
28 |
+
if strategy == "Order Block":
|
29 |
+
backtest_plot = smc_plot_backtest(data, 'test.html', swing_hl)
|
30 |
+
if strategy == "Order Block with EMA":
|
31 |
+
backtest_plot = smc_ema_plot_backtest(data, 'test.html', ema1, ema2, cross_close)
|
32 |
+
if strategy == "Structure trading":
|
33 |
+
backtest_plot = smc_structure_backtest(data, 'test.html', swing_hl)
|
34 |
+
|
35 |
+
return signal_plot, backtest_plot
|
36 |
+
|
37 |
+
|
38 |
+
with gr.Blocks(fill_width=True) as app:
|
39 |
+
gr.Markdown(
|
40 |
+
'# Algorithmic Trading Dashboard'
|
41 |
+
)
|
42 |
+
stock = gr.Dropdown(symbols['NAME OF COMPANY'].unique().tolist(), label='Select Company', value=None)
|
43 |
+
|
44 |
+
with gr.Row():
|
45 |
+
strategy = gr.Dropdown(['Order Block', 'Order Block with EMA', 'Structure trading'], label='Strategy', value=None)
|
46 |
+
swing_hl = gr.Number(label="Swing High/Low Window Size", value=10, interactive=True)
|
47 |
+
|
48 |
+
@gr.render(inputs=[strategy])
|
49 |
+
def show_extra(strat):
|
50 |
+
if strat == "Order Block with EMA":
|
51 |
+
with gr.Row():
|
52 |
+
ema1 = gr.Number(label='Fast EMA length', value=9)
|
53 |
+
ema2 = gr.Number(label='Slow EMA length', value=21)
|
54 |
+
cross_close = gr.Checkbox(label='Close trade on EMA crossover')
|
55 |
+
input = [stock, strategy, swing_hl, ema1, ema2, cross_close]
|
56 |
+
|
57 |
+
elif strat == "Order Block" or strat == "Structure trading":
|
58 |
+
input = [stock, strategy, swing_hl]
|
59 |
+
else:
|
60 |
+
input = []
|
61 |
+
|
62 |
+
btn.click(
|
63 |
+
run,
|
64 |
+
inputs=input,
|
65 |
+
outputs=[signal_plot, backtest_plot]
|
66 |
+
)
|
67 |
+
|
68 |
+
btn = gr.Button("Run")
|
69 |
+
|
70 |
+
with gr.Row():
|
71 |
+
signal_plot = gr.Plot(label='Signal plot')
|
72 |
+
|
73 |
+
with gr.Row():
|
74 |
+
backtest_plot = gr.Plot(label='Backtesting plot')
|
75 |
+
|
76 |
app.launch(debug=True)
|