Invicto69 commited on
Commit
eb42f85
·
verified ·
1 Parent(s): 98d3a70

Update gradio_app.py

Browse files
Files changed (1) hide show
  1. 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
- ticker = symbols[symbols['NAME OF COMPANY'] == stock]['YahooEquiv'].values[0]
11
- data = fetch(ticker, period='1mo', interval='15m')
12
-
13
- smc_plot_backtest(data, 'test.html', swing_hl)
14
-
15
- signal_plot = SMC(data=data, swing_hl_window_sz=swing_hl).plot(show=False).update_layout(title=dict(text=ticker))
16
- backtest_plot = gr.Plot()
17
-
18
- if strategy == "SMC":
19
- backtest_plot = smc_plot_backtest(data, 'test.html', swing_hl)
20
-
21
- if strategy == "SMC with EMA":
22
- backtest_plot = smc_ema_plot_backtest(data, 'test.html', ema1, ema2, cross_close)
23
-
24
- return signal_plot, backtest_plot
25
-
26
-
27
- with gr.Blocks(fill_width=True) as app:
28
- gr.Markdown(
29
- '# Algorithmic Trading Dashboard'
30
- )
31
- stock = gr.Dropdown(symbols['NAME OF COMPANY'].unique().tolist(), label='Select Company', value=None)
32
-
33
- with gr.Row():
34
- strategy = gr.Dropdown(['SMC', 'SMC with EMA'], label='Strategy', value=None)
35
- swing_hl = gr.Number(label="Swing High/Low Window Size", value=10, interactive=True)
36
-
37
- @gr.render(inputs=[strategy])
38
- def show_extra(strat):
39
- if strat == "SMC with EMA":
40
- with gr.Row():
41
- ema1 = gr.Number(label='Fast EMA length', value=9)
42
- ema2 = gr.Number(label='Slow EMA length', value=21)
43
- cross_close = gr.Checkbox(label='Close trade on EMA crossover')
44
- input = [stock, strategy, swing_hl, ema1, ema2, cross_close]
45
-
46
- elif strat == "SMC":
47
- input = [stock, strategy, swing_hl]
48
- else:
49
- input = []
50
-
51
- btn.click(
52
- run,
53
- inputs=input,
54
- outputs=[signal_plot, backtest_plot]
55
- )
56
-
57
- btn = gr.Button("Run")
58
-
59
- with gr.Row():
60
- signal_plot = gr.Plot(label='Signal plot')
61
-
62
- with gr.Row():
63
- backtest_plot = gr.Plot(label='Backtesting plot')
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)