Spaces:
Sleeping
Sleeping
File size: 1,132 Bytes
8f182cb |
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 34 35 36 37 38 39 40 41 |
import yfinance as yf
import plotly.graph_objects as go
from datetime import datetime, timedelta
class ChartUtils:
def __init__(self):
pass
def create_price_chart(self, ticker, period="6mo"):
"""Create a price chart for the ticker"""
try:
stock = yf.Ticker(ticker)
hist = stock.history(period=period)
if hist.empty:
return None
fig = go.Figure()
fig.add_trace(go.Scatter(
x=hist.index,
y=hist['Close'],
mode='lines',
name=f'{ticker} Close Price',
line=dict(color='#1f77b4', width=2)
))
fig.update_layout(
title=f'{ticker} Stock Price - Last {period}',
xaxis_title='Date',
yaxis_title='Price ($)',
hovermode='x unified',
showlegend=True,
height=400
)
return fig
except Exception as e:
return None
|