Ready for first real test

This commit is contained in:
Aryan Singh committed 2026-07-02 00:46:34 -05:00
1 parent acddf9135f
commit b91c81ebdf
46 files changed
+34903 -26

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
import yfinance as yf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Tickers
main = 'MRVL'
peers = ['AVGO','AMD','NVDA']
lookback = '180d'
# Download data
df_main = yf.download(main, period=lookback, progress=False)
df_peers = {t: yf.download(t, period=lookback, progress=False) for t in peers}
# Technical indicators for main
for ma in [20,50,200]:
df_main[f'SMA{ma}'] = df_main['Close'].rolling(ma).mean()
# Return and volatility
df_main['Ret'] = df_main['Close'].pct_change()
df_main['Vol20'] = df_main['Ret'].rolling(20).std() * np.sqrt(252)
# Correlation with peers
corr_df = pd.DataFrame(index=df_main.index)
for t in peers:
corr_df[f'{t}_corr'] = df_main['Ret'].rolling(60).corr(df_peers[t]['Close'].pct_change())
# Plot price + MA
plt.figure(figsize=(12,6))
plt.plot(df_main['Close'], label='Close')
plt.plot(df_main['SMA20'], label='SMA20')
plt.plot(df_main['SMA50'], label='SMA50')
plt.plot(df_main['SMA200'], label='SMA200')
plt.title(f'{main} price with moving averages')
plt.legend()
plt.tight_layout()
plt.savefig('mrvl_ma.png')
# Plot volatility
plt.figure(figsize=(12,4))
plt.plot(df_main['Vol20'], label='20‑Day Vol (annualized)')
plt.title(f'{main} 20‑Day volatility')
plt.legend()
plt.tight_layout()
plt.savefig('mrvl_vol.png')
# Plot correlation heatmap
plt.figure(figsize=(8,6))
corr_vals = corr_df.mean().values
plt.bar(peers, corr_vals)
plt.title('Average 60‑day correlation of MRVL with peers')
plt.ylabel('Correlation')
plt.tight_layout()
plt.savefig('mrvl_corr.png')
print('Charts generated: mrvl_ma.png, mrvl_vol.png, mrvl_corr.png')