VIX-FIN / app.py
shuhayas's picture
Create app.py
c599c59 verified
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']])