CREATE MATERIALIZED VIEW insights.benchmark_twrr_by_currency_mv
WITH (
backfill_order=FIXED(olap.assets_dm -> olap.basket_index_benchmark_constituents_ft)
) AS
SELECT
c.benchmark_id,
c.fact_date,
ad.issue_currency_code AS currency_code,
SUM(a.daily_subperiod_return * c.weight) AS daily_subperiod_return
FROM olap.basket_index_benchmark_constituents_ft AS c
JOIN insights.asset_twrr_mv AS a
ON a.asset_id = c.asset_id AND a.fact_date = c.fact_date
JOIN olap.assets_dm AS ad
ON ad.asset_id = c.asset_id
WHERE
c.disabled_at IS NULL AND NOT a.daily_subperiod_return IS NULL
GROUP BY
c.benchmark_id,
c.fact_date,
ad.issue_currency_code