with current_date_cte as (
select "2024-03-24"
)
select
"2024-03-24" as current_date,
{% for i in range(1,61) %}
{% set next_month = (select next_month = (select current_date + interval '1 month' *i)::date from current_date_cte) %}
CASE
WHEN start_date > LAST_DAY('{{next_month}}' - INTERVAL 1 MONTH) THEN
GREATEST(0, 1 - (DATEDIFF(start_date, LAST_DAY('{{next_month}}' - INTERVAL 1 MONTH)) /
DATEDIFF('{{next_month}}', LAST_DAY('{{next_month}}' - INTERVAL 1 MONTH))))
ELSE
GREATEST(0, IF(end_date > '{{next_month}}', 1,
(DATEDIFF(end_date, LAST_DAY('{{next_month}}' - INTERVAL 1 MONTH)) /
DATEDIFF('{{next_month}}', LAST_DAY('{{next_month}}' - INTERVAL 1 MONTH))))
END * notional_in_usd AS "{{ next_month }}"
{% endfor %}
from deal_mon limit 10;