Skip to content

Commit 822c8d0

Browse files
committed
Initial Commit
0 parents  commit 822c8d0

7 files changed

+256
-0
lines changed

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [2020] [Tanvir Khan]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn app:server

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Currency pair tracker (updates every minute)
2+
This app pulls data from Alpha Vantage Foreign Currency Intraday Trading API and does basic technical analysis. It also updates the charts on a per minute basis.
3+
4+
### Parameters For the Indicators (coder's assumptions, you are advised to use your own prudence)
5+
6+
#### Bollinger Band: 2 Standard Deviation
7+
#### MACD: n_slow=26, n_fast=12, n_sign=9
8+
#### RSI: n_period=60, Resistance and Support are put at 55 and 45 respectively
9+
10+
### Known Issues:
11+
12+
1. Due to the free API callback limit of Alpha Vantage, even if items are changed from the dropdown menus, the charts may not get updated before the 1 minute designated time. A premium subscription can be bought to have a better experience.
13+
14+
2. Data pulled from Alpha Vantage are only upto 4 decimal places, thus the charts might not be as precise as they should be.

app.py

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# importing required libraries
2+
import pandas as pd
3+
import numpy as np
4+
import dash
5+
import dash_core_components as dcc
6+
import dash_html_components as html
7+
from dash.dependencies import Input, Output, State
8+
from datetime import datetime
9+
import plotly.express as px
10+
import pandas_datareader as pdr
11+
from prophet import Prophet
12+
13+
# initiate the app
14+
app = dash.Dash()
15+
server = app.server
16+
17+
crypcode = pd.read_csv("crypcode.csv")
18+
cryp_value = crypcode["currency code"].tolist()
19+
cryp_label = crypcode["currency name"].tolist()
20+
# crypcode.head()
21+
22+
todate = datetime.today().strftime("%Y-%m-%d")
23+
firstdate = pd.to_datetime(todate, format="%Y-%m-%d") - pd.to_timedelta(
24+
365 / 4, unit="d"
25+
)
26+
27+
# read more about inline-block & flex
28+
# https://www.geeksforgeeks.org/what-is-the-difference-between-inline-flex-and-inline-block-in-css/
29+
# read more about padding and margin
30+
# https://stackoverflow.com/questions/35620419/what-is-difference-between-css-margin-and-padding
31+
32+
# format the app
33+
colors = {"background": "#222A2A", "text": "#479B55", "box": "#7F7F7F"}
34+
35+
app.layout = html.Div(
36+
children=[
37+
html.H1(
38+
"Crypto Forecast",
39+
style={
40+
"textAlign": "center",
41+
"paddingTop": "30px",
42+
"verticalAlign": "bottom",
43+
},
44+
),
45+
html.H2(
46+
"Forecast Commonly Traded Cryptocurrencies with Facebook's Prophet Procedure",
47+
style={
48+
"textAlign": "center",
49+
"paddingTop": "5px",
50+
"verticalAlign": "middle",
51+
},
52+
),
53+
# the from crypto dropdown
54+
html.Div(
55+
[
56+
html.H3("Select Crypto", style={"paddingRight": "30px"}),
57+
dcc.Dropdown(
58+
id="SelectCrypto",
59+
options=[{"label": i, "value": i} for i in cryp_value],
60+
value="BTC",
61+
clearable=False,
62+
style={
63+
"fontsize": 24,
64+
"width": 90,
65+
"color": colors["text"],
66+
}, # this style controls the text inside the dropdown
67+
),
68+
],
69+
style={ # this style controls the layout of the dropdown box
70+
"display": "inline-block",
71+
"verticalAlign": "middle",
72+
"paddingLeft": "20px",
73+
"paddingBottom": "20px",
74+
},
75+
),
76+
# the submit button
77+
html.Div(
78+
[
79+
html.Button(
80+
id="submit-button",
81+
n_clicks=0,
82+
children="Forecast",
83+
style={
84+
"fontSize": 20,
85+
"verticalAlign": "middle",
86+
"color": colors[
87+
"text"
88+
], # this style controls the text inside the submit button
89+
},
90+
)
91+
],
92+
style={
93+
"display": "inline-block",
94+
"verticalAlign": "bottom",
95+
"width": 90,
96+
# "height": 20,
97+
"paddingLeft": "7px",
98+
"paddingBottom": "20px", # this style controls the entire submit button position etc.
99+
},
100+
),
101+
# the graphs
102+
dcc.Graph(id="forecast", style={"color": colors["text"]}),
103+
],
104+
style={
105+
# "display": "inline-block",
106+
"backgroundColor": colors["background"],
107+
"color": colors["text"],
108+
# "horizontalAlign": "middle",
109+
"width": "100%",
110+
"height": "100%",
111+
"align-items": "center",
112+
# "justify-content": "center", # this style controls the entire app
113+
},
114+
)
115+
116+
# app functions
117+
@app.callback(
118+
Output(component_id="forecast", component_property="figure"),
119+
# Output(component_id="Coef_Value", component_property="figure"),
120+
# Output(component_id="Model_Evaluation", component_property="figure"),
121+
[Input("submit-button", "n_clicks")],
122+
[
123+
State("SelectCrypto", "value"),
124+
# State("amount", "value"),
125+
# State("isFlaggedSite", "value"),
126+
# State("isUnrecognizedDevice", "value"),
127+
# State("isOutsideLocation", "value"),
128+
],
129+
)
130+
131+
# start the function
132+
def CryptoForecast(n_clicks, SelectCrypto):
133+
cryptodata = pdr.get_data_yahoo(
134+
[SelectCrypto + "-" + "USD"], start=firstdate, end=todate
135+
).reset_index()
136+
cryptodata.columns = cryptodata.columns.get_level_values(0)
137+
138+
cryp_pro = cryptodata[["Date", "Close"]]
139+
cry_pro = cryp_pro.rename(columns = {"Date":"ds", "Close":"y"})
140+
141+
model = Prophet()
142+
model.fit(cryp_pro)
143+
future = model.make_future_dataframe(periods=60)
144+
forecast = m.predict(future)
145+
forecast = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]
146+
forecast = forecast.remane(columns = {"ds":"Date"})
147+
148+
plot_data = forecast.merge(crypto, on = "Date", how = "outer")
149+
150+
fig_forecast = px.scatter(
151+
plot_data,
152+
x="Date",
153+
y="Close",
154+
size="Volume",
155+
title=SelectCrypto,
156+
labels={"Date": "Date", "Close": "Closing Price"},
157+
template="plotly_dark",
158+
).update_traces(mode="lines+markers", marker=dict(color="green", opacity=0.4))
159+
160+
fig_forecast.add_trace(go.Scatter(x = plot_data["Date"], y=plot_data["yhat"], mode='lines', name = "Predicted Price"))
161+
fig_forecast.add_trace(go.Scatter(x = plot_data["Date"], y=plot_data["yhat_lower"], mode='markers', name = "Lower Band"))
162+
fig_forecast.add_trace(go.Scatter(x = plot_data["Date"], y=plot_data["yhat_upper"], mode='markers', name = "Upper Band"))
163+
164+
165+
return fig
166+
167+
168+
# launch the app
169+
if __name__ == "__main__":
170+
app.run_server(debug=False, threaded=False)

crypcode.csv

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
currency code,currency name
2+
BNB,Binance Coin
3+
BTC,Bitcoin
4+
BCH,Bitcoin Cash
5+
ADA,Cardano
6+
ETH,Ethereum
7+
LTC,Litecoin
8+
XMR,Monero
9+
XLM,Stellar
10+
USDT,Tether

requirements.txt

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
aiohttp==3.6.2
2+
async-timeout==3.0.1
3+
attrs==19.3.0
4+
Brotli==1.0.7
5+
certifi==2020.4.5.1
6+
chardet==3.0.4
7+
click==7.1.2
8+
dash==1.12.0
9+
dash-core-components==1.10.0
10+
dash-html-components==1.0.3
11+
dash-renderer==1.4.1
12+
dash-table==4.7.0
13+
Flask==1.1.2
14+
Flask-Compress==1.5.0
15+
future==0.18.2
16+
gunicorn==20.0.4
17+
idna==2.9
18+
itsdangerous==1.1.0
19+
Jinja2==2.11.2
20+
MarkupSafe==1.1.1
21+
multidict==4.7.5
22+
numpy==1.18.4
23+
pandas==1.0.3
24+
plotly==4.7.1
25+
python-dateutil==2.8.1
26+
pytz==2020.1
27+
requests==2.23.0
28+
retrying==1.3.3
29+
six==1.14.0
30+
ta==0.5.25
31+
urllib3==1.25.9
32+
Werkzeug==1.0.1
33+
xlrd==1.2.0
34+
yarl==1.4.2
35+
pystan==2.19.1.1
36+
pandas_datareader==0.9.0
37+
prophet==1.0.1
38+
cmdstanpy==0.9.68
39+
ujson==4.0.2

runtime.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.7.3

0 commit comments

Comments
 (0)