Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import plotly.graph_objs as go
|
| 4 |
+
import plotly.express as ex
|
| 5 |
+
import yfinance as yf
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pandas_ta
|
| 8 |
+
import datetime as dt
|
| 9 |
+
import streamlit as st
|
| 10 |
+
start = dt.datetime(2020, 1, 1).strftime('%Y-%m-%d')
|
| 11 |
+
end = dt.date.today()
|
| 12 |
+
|
| 13 |
+
ticker='6505.TW'
|
| 14 |
+
|
| 15 |
+
df = yf.download(ticker, start = start, end = end)
|
| 16 |
+
|
| 17 |
+
df['stoch_k'] = pandas_ta.stochrsi(close=df['Adj Close'],length=20).iloc[:,0]
|
| 18 |
+
df['stoch_d'] = pandas_ta.stochrsi(close=df['Adj Close'],length=20).iloc[:,1]
|
| 19 |
+
df['bb_lower'] = pandas_ta.bbands(close=df['Adj Close'],length=20).iloc[:,0]
|
| 20 |
+
df['bb_upper'] = pandas_ta.bbands(close=df['Adj Close'],length=20).iloc[:,2]
|
| 21 |
+
df['forward_1d'] = df['Adj Close'].pct_change(1).shift(-1)
|
| 22 |
+
|
| 23 |
+
fig=ex.line(df, x=df.index, y=['Adj Close','bb_lower','bb_upper'], title='台塑化 (6505.TW) Adj Close with Bollinger Bands')
|
| 24 |
+
fig.update_layout(title_text=f'台塑化(6505.TW) Adj Close with Bollinger Bands', title_x=0.5)
|
| 25 |
+
|
| 26 |
+
st.plotly_chart(fig, use_container_width=True)
|