04-04: Stock Price Chart¶
Simulates 90-day stock price data for three companies using a random walk, then plots: all companies on one chart, a single company with 10-day moving average (high/low annotated), and a daily percentage-change bar chart. Saved as stock_chart.png.
Topics covered: np.cumprod() · np.convolve() · ax.plot() multiple lines · ax.annotate() · ax.scatter() · np.diff() · ax.bar() · plt.subplots(3,1)
Difficulty: ⭐⭐⭐ Intermediate
Requirements¶
How to Run¶
Output: stock_chart.png
Key Concepts Practised¶
| Concept | Where used |
|---|---|
np.random.normal(loc, scale) |
Simulated daily returns |
np.cumprod(1 + returns) |
Cumulative price series |
np.convolve(prices, kernel) |
Simple moving average |
ax.annotate() |
High/low price labels |
ax.scatter(..., marker="^") |
Triangle markers at extremes |
np.diff(prices) / prices[:-1] |
Daily % change |