Create an app for stock analysis with mock data. Generate mock daily price data for 5 tech stocks over the past year with standard fields (Open, Close, etc). Features: - Stock selector dropdown - Price trend charts - Basic stats (mean, volatility) - Moving averages - Volume analysis - Stock comparison Interactive elements: - Date range picker - Technical indicators - Chart type toggle Focus on clean visualization of realistic mock data.
To upload files, please first save the app
import pandas as pd
import numpy as np
def calculate_moving_averages(df, period):
"""Calculate moving averages"""
return df['Close'].rolling(window=period).mean()
def calculate_stats(df):
"""Calculate basic statistics for a stock"""
close_prices = df['Close']
returns = close_prices.pct_change().dropna()
stats = {
'Current Price': close_prices.iloc[-1],
'Mean Price': close_prices.mean(),
'Price Std': close_prices.std(),
'Daily Volatility (%)': returns.std() * 100,
'Annualized Volatility (%)': returns.std() * np.sqrt(252) * 100,
'Total Return (%)': ((close_prices.iloc[-1] / close_prices.iloc[0]) - 1) * 100,
'Max Price': close_prices.max(),
'Min Price': close_prices.min(),
'Avg Volume': df['Volume'].mean()
}
# Round numeric values
for key, value in stats.items():
if isinstance(value, (int, float)):
stats[key] = round(value, 2)
return stats
def calculate_rsi(df, period=14):
"""Calculate Relative Strength Index"""
delta = df['Close'].diff()
gain = (delta.where(delta > 0, 0)).rolling(window=period).mean()
loss = (-delta.where(delta < 0, 0)).rolling(window=period).mean()
rs = gain / loss
rsi = 100 - (100 / (1 + rs))
return rsi
def calculate_bollinger_bands(df, period=20, std_dev=2):
"""Calculate Bollinger Bands"""
sma = df['Close'].rolling(window=period).mean()
std = df['Close'].rolling(window=period).std()
upper_band = sma + (std * std_dev)
lower_band = sma - (std * std_dev)
return upper_band, lower_band, sma
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?