---
url: /mosaic/examples/window-frame.md
---
# Time-Based Moving Average

Moving averages of Apple stock prices, using `range` window frames that span 15 days (black) and 3 months (red) around each date.

## Specification

```py \[Python]
import vgplot as vg

aapl = vg.parquet("data/stocks.parquet", where="Symbol = 'AAPL'")

view = vg.plot(
    vg.line_y(aapl, stroke="#ccc", x="Date", y="Close"),
    vg.line_y(
        aapl,
        stroke="black",
        x="Date",
        y=vg.avg("Close", orderby="Date", range=[{"days": 15}, {"days": 15}]),
    ),
    vg.line_y(
        aapl,
        stroke="firebrick",
        x="Date",
        y=vg.avg("Close", orderby="Date", range=[{"months": 3}, {"months": 3}]),
    ),
    vg.y_label("Close"),
    vg.width(680),
    vg.height(200),
)

```
