David Li commited on
Commit
48283ee
·
1 Parent(s): 6ea4549

fix: try streamlit multipage

Browse files
Files changed (3) hide show
  1. app.py +0 -0
  2. pages/ta.py +89 -0
  3. requirements.txt +3 -0
app.py ADDED
File without changes
pages/ta.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import datetime
3
+ import pandas as pd
4
+ import requests
5
+ import os
6
+ import sys
7
+ from PIL import Image
8
+ from io import StringIO
9
+ from openbb_terminal.stocks.stocks_helper import load
10
+ from openbb_terminal.common.technical_analysis.volatility_view import display_bbands, display_donchian
11
+
12
+ st.write("""
13
+ # Technical Analysis Web Application
14
+ Leveraging the openbb sdk, we can build a web application to display
15
+ technical analysis graphs for any stock.
16
+ """)
17
+
18
+ st.sidebar.header('User Input Parameters')
19
+
20
+ today = datetime.date.today()
21
+ def user_input_features():
22
+ ticker = st.sidebar.text_input("Ticker", 'ZIM')
23
+ start_date = st.sidebar.text_input("Start Date", '2020-05-01')
24
+ end_date = st.sidebar.text_input("End Date", f'{today}')
25
+ # ta_range = st.sidebar.number_input("TA Range", min_value=1, max_value=50)
26
+ return ticker, start_date, end_date # , ta_range
27
+
28
+ symbol, start, end = user_input_features()
29
+
30
+
31
+ def remove_existing_file(func):
32
+ def wrapper(*args, **kwargs):
33
+ old_stdin = sys.stdin
34
+ sys.stdin = StringIO("y")
35
+ stream = os.popen('cd ~ && pwd')
36
+ root_dir = stream.read()
37
+ sample_dir = root_dir.strip()
38
+ # remove /home/codespace/OpenBBUserData/exports/bbands.png already
39
+ # get last arg as export
40
+ export = args[-1]
41
+ temp_image = os.path.join(sample_dir, "OpenBBUserData", "exports", export)
42
+ # if exists erase
43
+ if os.path.exists(temp_image):
44
+ os.remove(temp_image)
45
+ func(*args, **kwargs)
46
+ sys.stdin = old_stdin
47
+ if os.path.exists(temp_image):
48
+ return temp_image
49
+ return None
50
+ return wrapper
51
+
52
+ @remove_existing_file
53
+ @st.cache_data
54
+ def build_bbands_img(data, symbol, window=15, n_std=2, export="bbands.png"):
55
+ return display_bbands(data, symbol, window, n_std, export=export)
56
+
57
+
58
+ @remove_existing_file
59
+ @st.cache_data
60
+ def build_donchian_img(data, symbol, export="donchian.png"):
61
+ return display_donchian(data, symbol, export=export)
62
+ company_name = symbol.upper()
63
+
64
+ start = pd.to_datetime(start)
65
+ end = pd.to_datetime(end)
66
+
67
+ # Read data
68
+ data = load(symbol,start, 1440, end)
69
+ st.write(data)
70
+ # Adjusted Close Price
71
+ st.header(f"Adjusted Close Price\n {company_name}")
72
+ st.line_chart(data["Close"])
73
+
74
+ # get ta graph
75
+ bbands_img = build_bbands_img(data, symbol, 15, 2, "bbands.png")
76
+ # plot ta using open bb sdk in streamlit
77
+ st.header(f"Bollinger Bands")
78
+ #
79
+ # if bbands.png exists, display it
80
+
81
+ if bbands_img:
82
+ st.image(bbands_img, caption='Bollinger bands chart')
83
+
84
+ donchian_img = build_donchian_img(data, symbol, "donchian.png")
85
+ # plot ta using open bb sdk in streamlit
86
+ st.header(f"Donchian")
87
+
88
+ if donchian_img:
89
+ st.image(donchian_img, caption='Donchian Openbb chart')
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ openbb
2
+ streamlit
3
+ yfinance