-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
697 lines (582 loc) · 26.5 KB
/
app.py
1
2
3
4
5
6
7
8
9
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# _oo0oo_
# o8888888o
# 88" . "88
# (| -_- |)
# 0\ = /0
# ___/`---'\___
# .' \\| |// '.
# / \\||| : |||// \
# / _||||| -:- |||||- \
# | | \\\ - /// | |
# | \_| ''\---/'' |_/ |
# \ .-\__ '-' ___/-. /
# ___'. .' /--.--\ `. .'___
# ."" '< `.___\_<|>_/___.' >' "".
# | | : `- \`.;`\ _ /`;.`/ - ` : | |
# \ \ `_. \_ __\ /__ _/ .-` / /
# =====`-.____`.___ \_____/___.-`___.-'=====
# `=---='
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Phật phù hộ, không bao giờ BUG
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from datetime import timedelta
import dash
from dash import dcc
from dash import html
import pandas as pd
import plotly.graph_objs as go
from dash.dependencies import Input, Output
from keras.models import load_model # type: ignore
from sklearn.preprocessing import MinMaxScaler
import numpy as np
app = dash.Dash()
app.title = "Cryptocurrency Price Analysis Dashboard - Cong-Dat Le (20120454)"
server = app.server
scaler=MinMaxScaler(feature_range=(0,1))
df_nse = pd.read_csv("./csvdata/BTC-USD.csv")
df_nse["Date"]=pd.to_datetime(df_nse.Date,format="%Y-%m-%d")
df_nse.index=df_nse['Date']
data=df_nse.sort_index(ascending=True,axis=0)
new_dataset=pd.DataFrame(index=range(0,len(df_nse)),columns=['Date','Close'])
for i in range(0,len(data)):
new_dataset.loc[i, "Date"] = data.iloc[i]['Date'] # Correct assignment using iloc
new_dataset.loc[i, "Close"] = data.iloc[i]["Close"]
new_dataset.index=new_dataset.Date
new_dataset.drop("Date",axis=1,inplace=True)
final_dataset=new_dataset.values
train_size = int(len(final_dataset) * 0.8)
train_data = final_dataset[:train_size, :]
valid_data = final_dataset[train_size:, :]
scaler=MinMaxScaler(feature_range=(0,1))
scaled_data=scaler.fit_transform(final_dataset)
x_train_data,y_train_data=[],[]
for i in range(60,len(train_data)):
x_train_data.append(scaled_data[i-60:i,0])
y_train_data.append(scaled_data[i,0])
x_train_data,y_train_data=np.array(x_train_data),np.array(y_train_data)
x_train_data=np.reshape(x_train_data,(x_train_data.shape[0],x_train_data.shape[1],1))
model = load_model("saved_model.keras", compile=False)
model.compile(optimizer='adam', loss='mean_squared_error')
inputs_data=new_dataset[len(new_dataset)-len(valid_data)-60:].values
inputs_data=inputs_data.reshape(-1,1)
inputs_data=scaler.transform(inputs_data)
X_test=[]
for i in range(60,inputs_data.shape[0]):
X_test.append(inputs_data[i-60:i,0])
X_test=np.array(X_test)
X_test=np.reshape(X_test,(X_test.shape[0],X_test.shape[1],1))
predicted_closing_price=model.predict(X_test)
predicted_closing_price=scaler.inverse_transform(predicted_closing_price)
train_data=new_dataset[:train_size]
valid_data=new_dataset[train_size:]
valid_data['Predictions']=predicted_closing_price
df= pd.read_csv("./csvdata/all_data.csv")
df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d')
df.set_index('Date', inplace=True)
# Create the dropdown dictionary for easy lookup
dropdown_dict = {
'BTC-USD': 'Bitcoin',
'ETH-USD': 'Ethereum',
'ADA-USD': 'Cardano',
}
# Create the stock_list from the stock_map
stock_list = [{'label': value, 'value': key} for key, value in dropdown_dict.items()]
# Make future predictions until December 2024
future_dates = pd.date_range(start=df_nse['Date'].max() + timedelta(days=1), end='2024-8-31', freq='B')
future_predictions = []
# Start with the last 60 days of data
last_60_days = scaled_data[-60:].reshape(1, 60, 1)
for date in future_dates:
predicted_price = model.predict(last_60_days)
future_predictions.append(predicted_price[0, 0])
# Add the predicted price to the input data and maintain the shape
predicted_price_reshaped = predicted_price.reshape(1, 1, 1)
last_60_days = np.append(last_60_days[:, 1:, :], predicted_price_reshaped, axis=1)
# Inverse transform the predictions to get actual prices
future_predictions = np.array(future_predictions).reshape(-1, 1)
future_predictions = scaler.inverse_transform(future_predictions)
# Create a DataFrame for future predictions
future_df = pd.DataFrame({'Date': future_dates, 'Predictions': future_predictions.flatten()})
future_df.set_index('Date', inplace=True)
def SMA(df, period=50, column="Close"):
return df[column].rolling(window=period).mean()
def EMA(df, period=50, column="Close"):
return df[column].ewm(span=period, adjust=False).mean()
def WMA(df, period=50, column="Close"):
weights = np.arange(1, period + 1)
return df[column].rolling(window=period).apply(lambda prices: np.dot(prices, weights) / weights.sum(), raw=True)
def VWMA(df, period=50, column="Close"):
volume = df["Volume"] if "Volume" in df.columns else pd.Series(np.ones(len(df)), index=df.index)
return (df[column] * volume).rolling(window=period).sum() / volume.rolling(window=period).sum()
# Hàm tổng hợp 4 đường MA
def MA(df, period=30, column="Close", ma_type="SMA"):
if ma_type == "SMA":
return SMA(df, period, column)
elif ma_type == "EMA":
return EMA(df, period, column)
elif ma_type == "WMA":
return WMA(df, period, column)
elif ma_type == "VWMA":
return VWMA(df, period, column)
else:
raise ValueError("Invalid ma_type. Use 'SMA', 'EMA', 'WMA', or 'VWMA'.")
def buy_n_sell(data, col="Close", ctypto_symbol='BTC-USD', period1=20, period2=50, period3=200, MA_type='SMA'):
df = data[data["symbolid"] == ctypto_symbol]
name = df["symbolid"].iloc[0]
df['line1'] = MA(df, period=period1, column="Close", ma_type=MA_type)
df['line2'] = MA(df, period=period2, column="Close", ma_type=MA_type)
df['line3'] = MA(df, period=period3, column="Close", ma_type=MA_type)
# Condition 1
df['Signal'] = np.where(df["line1"] > df["line2"], 1, 0)
df['Position'] = df['Signal'].diff()
df['Buy'] = np.where(df['Position'] == 1, df["Close"], np.nan)
df['Sell'] = np.where(df['Position'] == -1, df["Close"], np.nan)
# Condition 2
df['Golden_Signal'] = np.where(df["line2"] > df["line3"], 1, 0)
df['Golden_Position'] = df['Golden_Signal'].diff()
df['Golden_Buy'] = np.where(df['Golden_Position'] == 1, df["Close"], np.nan)
df['Death_Sell'] = np.where(df['Golden_Position'] == -1, df["Close"], np.nan)
# Create candlestick chart and buy/sell signals
fig = go.Figure()
# Candlestick
fig.add_trace(go.Candlestick(x=df.index,
open=df['Open'],
high=df['High'],
low=df['Low'],
close=df["Close"],
name="Close",
opacity=0.5))
# Short-term MA
fig.add_trace(go.Scatter(x=df.index,
y=df['line1'],
mode='lines',
name=f'Short-term MA {period1}',
line=dict(color='royalblue')))
# Medium-term MA
fig.add_trace(go.Scatter(x=df.index,
y=df['line2'],
mode='lines',
name=f'Medium-term MA {period2}',
line=dict(color='darkorange')))
# Long-term MA
fig.add_trace(go.Scatter(x=df.index,
y=df['line3'],
mode='lines',
name=f'Long-term MA {period3}',
line=dict(color='seagreen')))
# Buy Signal
fig.add_trace(go.Scatter(x=df.index[df['Position'] == 1],
y=df["Close"][df['Position'] == 1],
mode='markers',
marker=dict(symbol='triangle-up', color='green', size=12),
name='Buy Signal'))
# Sell Signal
fig.add_trace(go.Scatter(x=df.index[df['Position'] == -1],
y=df["Close"][df['Position'] == -1],
mode='markers',
marker=dict(symbol='triangle-down', color='red', size=12),
name='Sell Signal'))
# Golden Buy Signal
fig.add_trace(go.Scatter(x=df.index[df['Golden_Position'] == 1],
y=df["Close"][df['Golden_Position'] == 1],
mode='markers',
marker=dict(symbol='triangle-up', color='gold', size=16),
name='Golden Buy Signal',
visible='legendonly'))
# Death Sell Signal
fig.add_trace(go.Scatter(x=df.index[df['Golden_Position'] == -1],
y=df["Close"][df['Golden_Position'] == -1],
mode='markers',
marker=dict(symbol='triangle-down', color='maroon', size=16),
name='Death Sell Signal',
visible='legendonly'))
# Set layout for the chart
fig.update_layout(title=f'<b style="font-size: 20px;">Candlestick chart with Trading Signals for {name}</b>',
xaxis_title='Date',
yaxis_title="Close",
title_x=0.5,)
return fig
app.layout = html.Div([
html.H1("Cryptocurrency Price Analysis Dashboard", style={"textAlign": "center"}),
html.Div([
html.P([html.B("Developed by: "), "Cong-Dat Le"]),
html.P([html.B("Student ID: "), "20120454"]),
html.P([html.B("GitHub: "), html.A("Dat-TG", href="https://github.com/Dat-TG")])
], style={"border": "1px solid #000", "padding": "10px", "marginBottom": "50px", "textAlign": "center"}),
dcc.Tabs(id="tabs", children=[
dcc.Tab(label='Trading Signals', children=[
html.Div([
dcc.Dropdown(
id='bank-dropdown',
options= stock_list,
value='BTC-USD',
style={"width": "200px", "margin": "16px auto"},
clearable=False
),
dcc.Dropdown(
id='ma-type-dropdown',
options=[{'label': ma, 'value': ma} for ma in ['SMA', 'EMA', 'WMA', 'VWMA']],
value='SMA',
style={"width": "100px", "margin": "16px auto"},
clearable=False
),
dcc.Dropdown(
id='period1-dropdown',
options=[{'label': str(i), 'value': i} for i in [15, 20, 30]],
value=20,
style={"width": "100px", "margin": "16px auto"},
clearable=False
),
dcc.Dropdown(
id='period2-dropdown',
options=[{'label': str(i), 'value': i} for i in [50, 80, 100]],
value=50,
style={"width": "100px", "margin": "16px auto"},
clearable=False
),
dcc.Dropdown(
id='period3-dropdown',
options=[{'label': str(i), 'value': i} for i in [120, 150, 200]],
value=200,
style={"width": "100px", "margin": "16px auto"},
clearable=False
),
], style={"display": "flex", "flexDirection": "row", "flexWrap": "wrap", "justifyContent": "center"}),
dcc.Graph(id='trading-signals-chart', style={"height": "100vh"})
]),
dcc.Tab(label='Predict Cryptocurrency Price', children=[
html.Div([
dcc.Dropdown(id='stock-dropdown',
options=stock_list,
value='BTC-USD',
style={"width": "50%", "margin": "16px auto"}),
html.H2("Actual vs Predicted Closing Prices", style={"textAlign": "center"}),
dcc.Graph(
id="BTC Data",
figure={
"data": [
go.Scatter(
x=valid_data.index,
y=valid_data["Close"],
mode='lines+markers',
name='Actual',
line=dict(color='blue')
),
go.Scatter(
x=valid_data.index,
y=valid_data["Predictions"],
mode='lines+markers',
name='Predicted',
line=dict(color='red')
),
go.Scatter(
x=future_df.index,
y=future_df["Predictions"],
mode='lines+markers',
name='Future Predictions',
line=dict(color='green')
)
],
"layout": go.Layout(
title='Actual vs Predicted Closing Prices for BTC-USD',
xaxis={'title': 'Date'},
yaxis={'title': 'Closing Rate'},
legend=dict(x=0, y=1, traceorder='normal'),
hovermode='x'
)
}
),
html.H2("Actual closing price", style={"textAlign": "center"}),
dcc.Graph(
id="Actual Data AAPL",
figure={
"data": [
go.Scatter(
x=valid_data.index,
y=valid_data["Close"],
mode='markers',
name='Actual'
)
],
"layout": go.Layout(
title='Scatter plot of Actual Closing Price for BTC-USD',
xaxis={'title': 'Date'},
yaxis={'title': 'Closing Rate'}
)
}
),
html.H2("LSTM Predicted closing price", style={"textAlign": "center"}),
dcc.Graph(
id="Predicted Data AAPL",
figure={
"data": [
go.Scatter(
x=valid_data.index,
y=valid_data["Predictions"],
mode='markers',
name='Predicted'
)
],
"layout": go.Layout(
title='Scatter plot of Predicted Closing Price for BTC-USD',
xaxis={'title': 'Date'},
yaxis={'title': 'Closing Rate'}
)
}
),
html.H2("Future Predictions", style={"textAlign": "center"}),
dcc.Graph(
id="Future Predictions",
figure={
"data": [
go.Scatter(
x=future_df.index,
y=future_df["Predictions"],
mode='markers',
name='Future Predictions'
)
],
"layout": go.Layout(
title='Future Predictions of Closing Price for BTC-USD',
xaxis={'title': 'Date'},
yaxis={'title': 'Closing Rate'}
)
}
)
])
]),
dcc.Tab(label='Comparison between cryptocurrencies', children=[
html.Div([
html.H1("Stocks High vs Lows",
style={'textAlign': 'center'}),
dcc.Dropdown(id='my-dropdown',
options=stock_list,
multi=True,value=[stock_list[0]['value']],
style={"display": "block", "margin-left": "auto",
"margin-right": "auto", "width": "60%"}),
dcc.Graph(id='highlow'),
html.H1("Stocks Market Volume", style={'textAlign': 'center'}),
dcc.Dropdown(id='my-dropdown2',
options=stock_list,
multi=True,value=[stock_list[0]['value']],
style={"display": "block", "margin-left": "auto",
"margin-right": "auto", "width": "60%"}),
dcc.Graph(id='volume')
], className="container"),
])
])
])
@app.callback(
Output('trading-signals-chart', 'figure'),
[Input('bank-dropdown', 'value'),
Input('ma-type-dropdown', 'value'),
Input('period1-dropdown', 'value'),
Input('period2-dropdown', 'value'),
Input('period3-dropdown', 'value')]
)
def update_graph(crypto_symbol, ma_type, period1, period2, period3):
return buy_n_sell(df, col="Close", ctypto_symbol=crypto_symbol, period1=period1, period2=period2, period3=period3, MA_type=ma_type)
@app.callback(
[Output('BTC Data', 'figure'),
Output('Actual Data AAPL', 'figure'),
Output('Predicted Data AAPL', 'figure'),
Output('Future Predictions', 'figure')],
[Input('stock-dropdown', 'value')]
)
def update_graph(selected_stock):
# Ensure selected_stock is not None
if selected_stock is None:
# Return empty figures if selected_stock is None
return {}, {}, {}
df_stock = df[df["symbolid"] == selected_stock]
# Ensure data is sorted by index if necessary
data = df_stock.sort_index(ascending=True, axis=0)
data["Date"] = pd.to_datetime(data.index, format="%Y-%m-%d")
new_dataset = pd.DataFrame(index=range(0, len(data)), columns=['Date', 'Close'])
for i in range(0, len(data)):
new_dataset.loc[i, "Date"] = data.iloc[i]["Date"] # Correct assignment using iloc
new_dataset.loc[i, "Close"] = data.iloc[i]["Close"]
new_dataset.set_index('Date', inplace=True)
final_dataset = new_dataset.values
train_size = int(len(final_dataset) * 0.8)
train_data = final_dataset[:train_size, :]
valid_data = final_dataset[train_size:, :]
scaler = MinMaxScaler(feature_range=(0, 1))
scaled_data = scaler.fit_transform(final_dataset)
x_train_data, y_train_data = [], []
for i in range(60, len(train_data)):
x_train_data.append(scaled_data[i - 60:i, 0])
y_train_data.append(scaled_data[i, 0])
x_train_data, y_train_data = np.array(x_train_data), np.array(y_train_data)
x_train_data = np.reshape(x_train_data, (x_train_data.shape[0], x_train_data.shape[1], 1))
inputs_data = new_dataset[len(new_dataset) - len(valid_data) - 60:].values
inputs_data = inputs_data.reshape(-1, 1)
inputs_data = scaler.transform(inputs_data)
X_test = []
for i in range(60, inputs_data.shape[0]):
X_test.append(inputs_data[i - 60:i, 0])
X_test = np.array(X_test)
X_test = np.reshape(X_test, (X_test.shape[0], X_test.shape[1], 1))
predicted_closing_price = model.predict(X_test)
predicted_closing_price = scaler.inverse_transform(predicted_closing_price)
train_data = new_dataset[:train_size]
valid_data = new_dataset[train_size:]
valid_data['Predictions'] = predicted_closing_price
# Make future predictions until December 2024
future_dates = pd.date_range(start=df_stock.index.max() + timedelta(days=1), end='2024-8-31', freq='B')
future_predictions = []
# Start with the last 60 days of data
last_60_days = scaled_data[-60:].reshape(1, 60, 1)
for date in future_dates:
predicted_price = model.predict(last_60_days)
future_predictions.append(predicted_price[0, 0])
# Add the predicted price to the input data and maintain the shape
predicted_price_reshaped = predicted_price.reshape(1, 1, 1)
last_60_days = np.append(last_60_days[:, 1:, :], predicted_price_reshaped, axis=1)
# Inverse transform the predictions to get actual prices
future_predictions = np.array(future_predictions).reshape(-1, 1)
future_predictions = scaler.inverse_transform(future_predictions)
# Create a DataFrame for future predictions
future_df = pd.DataFrame({'Date': future_dates, 'Predictions': future_predictions.flatten()})
future_df.set_index('Date', inplace=True)
actual_trace = go.Scatter(
x=valid_data.index,
y=valid_data["Close"],
mode='lines+markers',
name='Actual',
line=dict(color='blue')
)
predicted_trace = go.Scatter(
x=valid_data.index,
y=valid_data["Predictions"],
mode='lines+markers',
name='Predicted',
line=dict(color='red')
)
future_trace = go.Scatter(
x=future_df.index,
y=future_df["Predictions"],
mode='lines+markers',
name='Future Predictions',
line=dict(color='green')
)
actual_scatter_trace = go.Scatter(
x=valid_data.index,
y=valid_data["Close"],
mode='markers',
name='Actual'
)
predicted_scatter_trace = go.Scatter(
x=valid_data.index,
y=valid_data["Predictions"],
mode='markers',
name='Predicted'
)
future_scatter_trace = go.Scatter(
x=future_df.index,
y=future_df["Predictions"],
mode='markers',
name='Future Predictions'
)
figure1 = {
"data": [actual_trace, predicted_trace, future_trace],
"layout": go.Layout(
title=f'Actual vs Predicted Closing Prices for {selected_stock}',
xaxis={'title': 'Date'},
yaxis={'title': 'Closing Rate'},
legend=dict(x=0, y=1, traceorder='normal'),
hovermode='x'
)
}
figure2 = {
"data": [actual_scatter_trace],
"layout": go.Layout(
title=f'Scatter plot of Actual Closing Price for {selected_stock}',
xaxis={'title': 'Date'},
yaxis={'title': 'Closing Rate'}
)
}
figure3 = {
"data": [predicted_scatter_trace],
"layout": go.Layout(
title=f'Scatter plot of Predicted Closing Price for {selected_stock}',
xaxis={'title': 'Date'},
yaxis={'title': 'Closing Rate'}
)
}
figure4 = {
"data": [future_scatter_trace],
"layout": go.Layout(
title=f'Future Predictions of Closing Price for {selected_stock}',
xaxis={'title': 'Date'},
yaxis={'title': 'Closing Rate'}
)
}
return figure1, figure2, figure3, figure4
@app.callback(Output('highlow', 'figure'),
[Input('my-dropdown', 'value')])
def update_graph(selected_dropdown):
dropdown = dropdown_dict
trace1 = []
trace2 = []
for stock in selected_dropdown:
trace1.append(
go.Scatter(x=df[df["symbolid"] == stock].index,
y=df[df["symbolid"] == stock]["High"],
mode='lines', opacity=0.7,
name=f'High {dropdown[stock]}',textposition='bottom center'))
trace2.append(
go.Scatter(x=df[df["symbolid"] == stock].index,
y=df[df["symbolid"] == stock]["Low"],
mode='lines', opacity=0.6,
name=f'Low {dropdown[stock]}',textposition='bottom center'))
traces = [trace1, trace2]
data = [val for sublist in traces for val in sublist]
figure = {'data': data,
'layout': go.Layout(colorway=["#5E0DAC", '#FF4F00', '#375CB1',
'#FF7400', '#FFF400', '#FF0056'],
height=600,
title=f"High and Low Prices for {', '.join(str(dropdown[i]) for i in selected_dropdown)} Over Time",
xaxis={"title":"Date",
'rangeselector': {'buttons': list([{'count': 1, 'label': '1M',
'step': 'month',
'stepmode': 'backward'},
{'count': 6, 'label': '6M',
'step': 'month',
'stepmode': 'backward'},
{'step': 'all'}])},
'rangeslider': {'visible': True}, 'type': 'date'},
yaxis={"title":"Price (USD)"})}
return figure
@app.callback(Output('volume', 'figure'),
[Input('my-dropdown2', 'value')])
def update_graph(selected_dropdown_value):
dropdown = dropdown_dict
trace1 = []
for stock in selected_dropdown_value:
trace1.append(
go.Scatter(x=df[df["symbolid"] == stock].index,
y=df[df["symbolid"] == stock]["Volume"],
mode='lines', opacity=0.7,
name=f'Volume {dropdown[stock]}', textposition='bottom center'))
traces = [trace1]
data = [val for sublist in traces for val in sublist]
figure = {'data': data,
'layout': go.Layout(colorway=["#5E0DAC", '#FF4F00', '#375CB1',
'#FF7400', '#FFF400', '#FF0056'],
height=600,
title=f"Market Volume for {', '.join(str(dropdown[i]) for i in selected_dropdown_value)} Over Time",
xaxis={"title":"Date",
'rangeselector': {'buttons': list([{'count': 1, 'label': '1M',
'step': 'month',
'stepmode': 'backward'},
{'count': 6, 'label': '6M',
'step': 'month',
'stepmode': 'backward'},
{'step': 'all'}])},
'rangeslider': {'visible': True}, 'type': 'date'},
yaxis={"title":"Transactions Volume"})}
return figure
if __name__=='__main__':
app.run_server(debug=True)