shuhayas commited on
Commit
c599c59
·
verified ·
1 Parent(s): c8c1236

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import yfinance as yf
3
+ import pandas as pd
4
+ from datetime import datetime
5
+
6
+ # Set the ticker symbol
7
+ tickerSymbol = '^VIX'
8
+
9
+ # Streamlit app title
10
+ st.title('VIX Closing Prices and Moving Averages')
11
+
12
+ # Get data on this ticker
13
+ tickerData = yf.Ticker(tickerSymbol)
14
+
15
+ # Ask user to specify date range
16
+ # Convert string dates to datetime.date objects
17
+ start_date = datetime.strptime('2010-1-1', '%Y-%m-%d').date()
18
+ end_date = datetime.strptime('2020-12-31', '%Y-%m-%d').date()
19
+ date_range = st.date_input('Date range', [start_date, end_date])
20
+
21
+ # 確定ボタンを追加
22
+ if st.button('Update Chart'):
23
+ # Get the historical prices for this ticker
24
+ # We will use daily prices. Adjust the period to change the frequency of prices
25
+ tickerDf = tickerData.history(period='1d', start=date_range[0], end=date_range[1])
26
+
27
+ # Calculate moving averages
28
+ tickerDf['20_Day_MA'] = tickerDf['Close'].rolling(window=20).mean()
29
+ tickerDf['50_Day_MA'] = tickerDf['Close'].rolling(window=50).mean()
30
+
31
+ # Display chart
32
+ st.line_chart(tickerDf[['Close', '20_Day_MA', '50_Day_MA']])