Write a SQL query to extract daily portfolio values and identify assets that have exceeded their pre-defined risk limits.
Use the supplied portfolio valuation and risk limit data. Return all portfolio assets, including assets without a configured limit or with a missing valuation.
asset_code, portfolio_id, valuation_date, daily_portfolio_value, risk_limit, excess_amount, and risk_status.risk_status must identify exceeded limits, values within limits, missing values, and missing limits. Order by asset_code, portfolio_id, and valuation_date.| Column | Type | Description |
|---|---|---|
| valuation_idPK | INT | Unique valuation record identifier |
| portfolio_id | VARCHAR(20) | Portfolio identifier |
| asset_code | VARCHAR(20) | Traded asset identifier |
| valuation_date | DATE | Date of the valuation |
| market_value | NUMERIC(14,2) | Asset market value for the valuation record |
| Column | Type | Description |
|---|---|---|
| limit_idPK | INT | Unique risk limit identifier |
| asset_code | VARCHAR(20) | Asset governed by the limit |
| risk_limit | NUMERIC(14,2) | Pre-defined maximum permitted daily value |