File size: 1,091 Bytes
c599c59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import yfinance as yf
import pandas as pd
from datetime import datetime

# Set the ticker symbol
tickerSymbol = '^VIX'

# Streamlit app title
st.title('VIX Closing Prices and Moving Averages')

# Get data on this ticker
tickerData = yf.Ticker(tickerSymbol)

# Ask user to specify date range
# Convert string dates to datetime.date objects
start_date = datetime.strptime('2010-1-1', '%Y-%m-%d').date()
end_date = datetime.strptime('2020-12-31', '%Y-%m-%d').date()
date_range = st.date_input('Date range', [start_date, end_date])

# 確定ボタンを追加
if st.button('Update Chart'):
    # Get the historical prices for this ticker
    # We will use daily prices. Adjust the period to change the frequency of prices
    tickerDf = tickerData.history(period='1d', start=date_range[0], end=date_range[1])

    # Calculate moving averages
    tickerDf['20_Day_MA'] = tickerDf['Close'].rolling(window=20).mean()
    tickerDf['50_Day_MA'] = tickerDf['Close'].rolling(window=50).mean()

    # Display chart
    st.line_chart(tickerDf[['Close', '20_Day_MA', '50_Day_MA']])