File size: 2,331 Bytes
48283ee
 
 
 
bfde9fc
6d5a213
6315f57
b18d21e
c9b1a7c
007a952
c9b1a7c
007a952
48283ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bfde9fc
 
 
 
48283ee
caf9102
91f9814
48283ee
b8ad215
48283ee
 
caf9102
45b74b6
48283ee
b8ad215
48283ee
 
 
 
 
 
 
 
 
 
 
 
fba7a0d
 
 
 
 
 
 
b8ad215
fba7a0d
48283ee
bfde9fc
48283ee
 
 
 
 
 
fba7a0d
b8ad215
48283ee
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
import streamlit as st
import datetime
import pandas as pd
import requests
import random
import os
from PIL import Image
from pages.utils.util import remove_existing_file
from openbb_terminal.sdk import openbb
from openbb.stocks import load
from openbb.ta import bbands_chart, donchian_chart
# from openbb_terminal.common.technical_analysis.volatility_view import display_bbands, display_donchian

st.write("""
# Technical Analysis Web Application
Leveraging the openbb sdk, we can build a web application to display 
technical analysis graphs for any stock.
""")

st.sidebar.header('User Input Parameters')

today = datetime.date.today()
def user_input_features():
    ticker = st.sidebar.text_input("Ticker", 'ZIM')
    start_date = st.sidebar.text_input("Start Date", '2020-05-01')
    end_date = st.sidebar.text_input("End Date", f'{today}')
    # ta_range = st.sidebar.number_input("TA Range", min_value=1, max_value=50)
    return ticker, start_date, end_date # , ta_range

symbol, start, end = user_input_features()


# append random int to file name to avoid caching
rand_int = str(random.randint(1, 500000))
ran_bbands_name = f"bbands-{rand_int}.png"
ran_donchian_name = f"donchian-{rand_int}.png"

# @remove_existing_file
@st.experimental_memo
def build_bbands_img(data, symbol, window=15, n_std=2, export="bbands.png"):
    return bbands_chart(data, symbol, window, n_std, external_axes=True)


# @remove_existing_file
@st.experimental_memo
def build_donchian_img(data, symbol, export="donchian.png"):
    return donchian_chart(data,symbol, external_axes=True)
company_name = symbol.upper()

start = pd.to_datetime(start)
end = pd.to_datetime(end)

# Read data 
data = load(symbol,start, 1440, end)
st.write(data)
# Adjusted Close Price
st.header(f"Adjusted Close Price\n {company_name}")
st.line_chart(data["Close"])


donchian_img = build_donchian_img(data, symbol, ran_donchian_name)
# plot ta using open bb sdk in streamlit
st.header(f"Donchian")


if donchian_img:
    st.plotly_chart(donchian_img, use_container_width=True)

# get ta graph
bbands_img = build_bbands_img(data, symbol, 15, 2, ran_bbands_name)
# plot ta using open bb sdk in streamlit
st.header(f"Bollinger Bands")
# 
# if bbands.png exists, display it

if bbands_img:
    print(bbands_img)
    st.plotly_chart(bbands_img, use_container_width=True)