Spaces:
Running
Running
import plotly.graph_objects as go | |
import pandas as pd | |
def create_stock_chart(stock_data, symbol): | |
"""Create an interactive stock price chart""" | |
fig = go.Figure() | |
fig.add_trace( | |
go.Candlestick( | |
x=stock_data.index, | |
open=stock_data['Open'], | |
high=stock_data['High'], | |
low=stock_data['Low'], | |
close=stock_data['Close'], | |
name=symbol | |
) | |
) | |
fig.update_layout( | |
title=f"{symbol} Stock Price", | |
yaxis_title="Price (USD)", | |
template="plotly_dark", | |
xaxis_rangeslider_visible=False | |
) | |
return fig | |
def create_metrics_table(company_info): | |
"""Create a table of key financial metrics""" | |
metrics = { | |
'Metric': [ | |
'Market Cap', 'P/E Ratio', 'Forward P/E', | |
'PEG Ratio', 'Dividend Yield', 'Beta' | |
], | |
'Value': [ | |
company_info.get('marketCap', 'N/A'), | |
company_info.get('trailingPE', 'N/A'), | |
company_info.get('forwardPE', 'N/A'), | |
company_info.get('pegRatio', 'N/A'), | |
company_info.get('dividendYield', 'N/A'), | |
company_info.get('beta', 'N/A') | |
] | |
} | |
return pd.DataFrame(metrics) | |