Invicto69 commited on
Commit
27a7d99
·
verified ·
1 Parent(s): aa8d4ac

Delete gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +0 -99
gradio_app.py DELETED
@@ -1,99 +0,0 @@
1
- import gradio as gr
2
- from indicators import SMC
3
- from utils import smc_plot_backtest, smc_ema_plot_backtest, smc_structure_plot_backtest, fetch
4
- import pandas as pd
5
-
6
- symbols = pd.read_csv('data/Ticker_List_NSE_India.csv')
7
- limits = pd.read_csv('data/yahoo_limits.csv')
8
-
9
- def run(stock, interval, period, strategy, swing_hl, ema1=9, ema2=21, cross_close=False):
10
- # Downloading ticker data.
11
- ticker = symbols[symbols['NAME OF COMPANY'] == stock]['YahooEquiv'].values[0]
12
- data = fetch(ticker, period, interval)
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
- # Plotting backtest plot based on strategy.
27
- if strategy == "Order Block":
28
- backtest_plot = smc_plot_backtest(data, 'test.html', swing_hl)
29
- if strategy == "Order Block with EMA":
30
- backtest_plot = smc_ema_plot_backtest(data, 'test.html', ema1, ema2, cross_close)
31
- if strategy == "Structure trading":
32
- backtest_plot = smc_structure_plot_backtest(data, 'test.html', swing_hl)
33
-
34
- return signal_plot, backtest_plot
35
-
36
-
37
- with gr.Blocks(fill_width=True) as app:
38
- gr.Markdown(
39
- '# Algorithmic Trading Dashboard'
40
- )
41
- stock = gr.Dropdown(symbols['NAME OF COMPANY'].unique().tolist(), label='Select Company', value=None)
42
-
43
- with gr.Row():
44
- interval = gr.Dropdown(limits['interval'].tolist(), label='Select Interval', value=None)
45
-
46
- period_list = ['1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max']
47
- period = gr.Dropdown(label = 'Select Period', choices=["max"], value="max")
48
-
49
- # Updating period based on interval
50
- def update_period(interval):
51
- limit = limits[limits['interval'] == interval]['limit'].values[0]
52
- idx = period_list.index(limit)
53
- return gr.Dropdown(period_list[:idx+1]+['max'], interactive=True, label='Select Period')
54
-
55
- interval.change(update_period, [interval], [period])
56
-
57
- with gr.Row():
58
- strategy = gr.Dropdown(['Order Block', 'Order Block with EMA', 'Structure trading'], label='Strategy', value=None)
59
- swing_hl = gr.Number(label="Swing High/Low Window Size", value=10, interactive=True)
60
-
61
- @gr.render(inputs=[strategy])
62
- def show_extra(strat):
63
- if strat == "Order Block with EMA":
64
- with gr.Row():
65
- ema1 = gr.Number(label='Fast EMA length', value=9)
66
- ema2 = gr.Number(label='Slow EMA length', value=21)
67
- cross_close = gr.Checkbox(label='Close trade on EMA crossover')
68
- input = [stock, interval, period, strategy, swing_hl, ema1, ema2, cross_close]
69
-
70
- elif strat == "Order Block" or strat == "Structure trading":
71
- input = [stock, interval, period, strategy, swing_hl]
72
- else:
73
- input = []
74
-
75
- btn.click(
76
- run,
77
- inputs=input,
78
- outputs=[signal_plot, backtest_plot]
79
- )
80
-
81
- examples = gr.Examples(
82
- examples=[
83
- ["Reliance Industries Limited", "15m", "max", "Order Block", 10],
84
- ["Reliance Industries Limited", "15m", "max", "Order Block with EMA", 10],
85
- ["Reliance Industries Limited", "15m", "max", "Structure trading", 20],
86
- ],
87
- example_labels=['Order Block', 'Order Block with EMA', 'Structure trading'],
88
- inputs=[stock, interval, period, strategy, swing_hl]
89
- )
90
-
91
- btn = gr.Button("Run")
92
-
93
- with gr.Row():
94
- signal_plot = gr.Plot(label='Signal plot')
95
-
96
- with gr.Row():
97
- backtest_plot = gr.Plot(label='Backtesting plot')
98
-
99
- app.launch(debug=True)