BlackRock's Aladdin risk analytics workflow needs a time-series view of recent asset performance. Given daily closing prices and an in-scope asset set, write a PostgreSQL query that calculates each asset's daily return and rolling 30-calendar-day average return.
BLK_CORE where is_in_scope = TRUE.LAG partitioned by asset.NULL for its daily return and rolling average.| Column | Type | Description |
|---|---|---|
| asset_idPK | INT | Unique asset identifier |
| ticker | VARCHAR(12) | Trading symbol |
| asset_name | VARCHAR(100) | Asset name |
| portfolio_code | VARCHAR(30) | Portfolio membership code |
| is_in_scope | BOOLEAN | Whether the asset is included in the analysis |
| Column | Type | Description |
|---|---|---|
| price_idPK | INT | Unique price observation identifier |
| asset_id | INT | References assets.asset_id |
| price_date | DATE | Closing-price date |
| close_price | NUMERIC(12,4) | Closing price |