B0843064 commited on
Commit
04eb9f3
·
1 Parent(s): 0be1578

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -1,26 +1,25 @@
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(2021, 1, 1).strftime('%Y-%m-%d')
11
- end = dt.date.today()
12
 
13
- ticker='2408.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='南亞科技 (2408.TW) Adj Close with Bollinger Bands')
24
- fig.update_layout(title_text=f'南亞科技(2408.TW) Adj Close with Bollinger Bands', title_x=0.5)
 
 
 
25
 
26
- st.plotly_chart(fig, use_container_width=True)
 
 
 
 
 
 
1
  import pandas as pd
2
+ import yfinance as yf
3
  import pandas_ta
4
  import datetime as dt
5
+
6
  start = dt.datetime(2021, 1, 1).strftime('%Y-%m-%d')
7
+ end = dt.date.today()
8
 
9
+ ticker = '2408.TW'
10
 
11
+ df = yf.download(ticker, start=start, end=end)
12
 
13
+ df['stoch_k'] = pandas_ta.stochrsi(close=df['Adj Close'], length=20).iloc[:, 0]
14
+ df['stoch_d'] = pandas_ta.stochrsi(close=df['Adj Close'], length=20).iloc[:, 1]
15
+ df['bb_lower'] = pandas_ta.bbands(close=df['Adj Close'], length=20).iloc[:, 0]
16
+ df['bb_upper'] = pandas_ta.bbands(close=df['Adj Close'], length=20).iloc[:, 2]
17
  df['forward_1d'] = df['Adj Close'].pct_change(1).shift(-1)
18
 
19
+ ax = df[['Adj Close', 'bb_lower', 'bb_upper']].plot(figsize=(12, 6), linewidth=1.5)
20
+ ax.set_title('南亞科技 (2408.TW) Adj Close with Bollinger Bands')
21
+ ax.set_xlabel('Date')
22
+ ax.set_ylabel('Price')
23
+ ax.legend(['Adj Close', 'Lower Bollinger Band', 'Upper Bollinger Band'])
24
 
25
+ plt.show()