How to Simulate a Portfolio in Python
What happens if you invest in 3 stocks?
Let’s simulate it with random returns:
import numpy as np
portfolio = {
"AAPL": 0.4,
"MSFT": 0.3,
"TSLA": 0.3
}
np.random.seed(0)
returns = {ticker: np.random.normal(0.01, 0.03, 12) for ticker in portfolio}
total = 1000
for i in range(12): # 12 months
monthly_return = sum(returns[ticker][i] * weight for ticker, weight in portfolio.items())
total *= (1 + monthly_return)
print(f"Portfolio value after 1 year: ${round(total, 2)}")
👉 Simulates realistic volatility
🎯 Add in a plot for bonus ✨

