Post

๐Ÿ“– Day 5 โ€“ Financial Statistics

Rolling Statistics: Moving Average

This day I explored rolling statistics in Pandas, applied to financial time series; this lets me smooth data and analyzing volatility trends.

Main Goals:

  • Calculate moving averages (in this work 7 days) of closing prices.
  • Calculate standard deviation (volatility), so the risk of each asset.
  • Plot: first plots of daily returns and rolling metrics

Step by Step

๐Ÿ“ Step 1: Download of data Matrix with assets and volumes as per previous works (closing prices and volumes of IWM, GLD, IGOV).

๐Ÿ“ Step 2: Calculated .pct_change(), 7-day moving average, and rolling std.

๐Ÿ“ Step 3: Plotted returns, moving averages, and volatility together, comparing the performances of each asset.

Challenges / Insights

  • Learned how .rolling(window) works.
  • Discovered how to layer multiple plots on the same figure (ax=plt.gca()).
  • Saw how volatility clusters can appear visually.

Code Snippet

```python
returns = close.pct_change().dropna()
mov_avg = close.rolling(window=7).mean()
std = close.rolling(window=7).std()

returns.plot(figsize=(10,6), title="Daily Returns")
mov_avg.plot(figsize=(10,6), title="7-Day Moving Average")
std.plot(ax=plt.gca())
plt.show()
  
```

Plots

Daily Returns

Returns of the assets.

MA

Moving Average.

Next Step

๐Ÿ‘‰ Correlation analysis between assets.

Youโ€™ll find my projects here:

This post is licensed under CC BY 4.0 by the author.