forked from CSjiade/Stock_DashBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (40 loc) · 1.95 KB
/
Copy pathapp.py
File metadata and controls
55 lines (40 loc) · 1.95 KB
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
import streamlit as st
import yfinance as yf
from PIL import Image
import requests
from io import BytesIO
import financial
import stockchart
import backtest
if __name__ == '__main__':
st.title('Trading DashBoard')
url = 'https://g.foolcdn.com/editorial/images/602904/why-tesla-stock-is-up-today.jpg'
response = requests.get(url)
img = Image.open(BytesIO(response. content))
#Stock Overview Section
st.image(img, use_column_width=True)
st.sidebar.header('Enter your Inputs')
stock_ticker = st.sidebar.text_input("Stock Ticker", "TSM")
period_view = st.sidebar.checkbox('period')
mv_slow = st.sidebar.text_input("Moving Average (Slow)",5)
mv_fast = st.sidebar.text_input("Moving Average (Fast)",25)
rsi_period = st.sidebar.text_input("RSI (Period)",14)
stock_data = yf.Ticker(stock_ticker)
stockchart.display_stock(period_view, stock_data, rsi_period, stock_ticker.upper(), mv_fast, mv_slow)
financial.financeStatement_setup(stock_ticker.upper())
#BackTest Section
backtest_init = st.sidebar.checkbox('BackTest')
if backtest_init == True:
backtest_options = ['SMA','RSI']
execution = ["Current Day Close Price", "Next Day Open Price"]
sell_execution = ["Sell All at Next Open", "Customise Sell"]
st.sidebar.header('Backtest Strategy')
st.title("BackTest")
ticker = st.sidebar.text_input("Ticker","TSM")
stock_bt = yf.Ticker(ticker)
stock_close = stock_bt.history(period = "5d", interval = "1d")
current_price = st.sidebar.text_input( "Current Price" , "%.2f" %stock_close.Close[-1])
backtest_options = st.sidebar.selectbox("Strategies", backtest_options)
execution_type = st.sidebar.selectbox("Buy Execution Type", execution)
sell_execution_type = st.sidebar.selectbox("Sell Execution Type", sell_execution)
backtest.backtest(backtest_options, stock_bt, ticker.upper(),execution_type,sell_execution_type)