Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APR Model update #193

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ with pnl_hourly as (
hourly_pnl_pct,
hourly_rewards_pct,
hourly_total_pct,
hourly_rewards_pct as hourly_incentive_rewards_pct,
hourly_pnl_pct as hourly_performance_pct,
sum(coalesce(hourly_issuance, 0)) over (
partition by pool_id, collateral_type
order by ts
Expand Down Expand Up @@ -81,7 +83,37 @@ avg_returns as (
partition by pool_id, collateral_type
order by ts
range between interval '28 DAYS' preceding and current row
) as avg_28d_total_pct
) as avg_28d_total_pct,
avg(hourly_incentive_rewards_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '24 HOURS' preceding and current row
) as avg_24h_incentive_rewards_pct,
avg(hourly_incentive_rewards_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '7 DAYS' preceding and current row
) as avg_7d_incentive_rewards_pct,
avg(hourly_incentive_rewards_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '28 DAYS' preceding and current row
) as avg_28d_incentive_rewards_pct,
avg(hourly_performance_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '24 HOURS' preceding and current row
) as avg_24h_performance_pct,
avg(hourly_performance_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '7 DAYS' preceding and current row
) as avg_7d_performance_pct,
avg(hourly_performance_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '28 DAYS' preceding and current row
) as avg_28d_performance_pct
from pnl_hourly
),

Expand Down Expand Up @@ -112,6 +144,20 @@ apr_calculations as (
avg_returns.avg_24h_rewards_pct * 24 * 365 as apr_24h_rewards,
avg_returns.avg_7d_rewards_pct * 24 * 365 as apr_7d_rewards,
avg_returns.avg_28d_rewards_pct * 24 * 365 as apr_28d_rewards,
-- incentive rewards pnls
avg_returns.avg_24h_incentive_rewards_pct
* 24
* 365 as apr_24h_incentive_rewards,
avg_returns.avg_7d_incentive_rewards_pct
* 24
* 365 as apr_7d_incentive_rewards,
avg_returns.avg_28d_incentive_rewards_pct
* 24
* 365 as apr_28d_incentive_rewards,
-- performance pnls
avg_returns.avg_24h_performance_pct * 24 * 365 as apr_24h_performance,
avg_returns.avg_7d_performance_pct * 24 * 365 as apr_7d_performance,
avg_returns.avg_28d_performance_pct * 24 * 365 as apr_28d_performance,
-- underlying yields
coalesce(yr.apr_24h_underlying, 0) as apr_24h_underlying,
coalesce(yr.apr_7d_underlying, 0) as apr_7d_underlying,
Expand Down Expand Up @@ -141,6 +187,22 @@ apy_calculations as (
(power(1 + apr_24h_rewards / 8760, 8760) - 1) as apy_24h_rewards,
(power(1 + apr_7d_rewards / 8760, 8760) - 1) as apy_7d_rewards,
(power(1 + apr_28d_rewards / 8760, 8760) - 1) as apy_28d_rewards,
(
power(1 + apr_24h_incentive_rewards / 8760, 8760) - 1
) as apy_24h_incentive_rewards,
(
power(1 + apr_7d_incentive_rewards / 8760, 8760) - 1
) as apy_7d_incentive_rewards,
(
power(1 + apr_28d_incentive_rewards / 8760, 8760) - 1
) as apy_28d_incentive_rewards,
(
power(1 + apr_24h_performance / 8760, 8760) - 1
) as apy_24h_performance,
(power(1 + apr_7d_performance / 8760, 8760) - 1) as apy_7d_performance,
(
power(1 + apr_28d_performance / 8760, 8760) - 1
) as apy_28d_performance,
(power(1 + apr_24h_underlying / 8760, 8760) - 1) as apy_24h_underlying,
(power(1 + apr_7d_underlying / 8760, 8760) - 1) as apy_7d_underlying,
(power(1 + apr_28d_underlying / 8760, 8760) - 1) as apy_28d_underlying
Expand Down Expand Up @@ -179,6 +241,18 @@ select
apy_7d_rewards,
apr_28d_rewards,
apy_28d_rewards,
apr_24h_incentive_rewards,
apy_24h_incentive_rewards,
apr_7d_incentive_rewards,
apy_7d_incentive_rewards,
apr_28d_incentive_rewards,
apy_28d_incentive_rewards,
apr_24h_performance,
apy_24h_performance,
apr_7d_performance,
apy_7d_performance,
apr_28d_performance,
apy_28d_performance,
apr_24h_underlying,
apy_24h_underlying,
apr_7d_underlying,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,30 @@ models:
data_type: numeric
- name: apy_28d_rewards
data_type: numeric
- name: apr_24h_incentive_rewards
data_type: numeric
- name: apy_24h_incentive_rewards
data_type: numeric
- name: apr_7d_incentive_rewards
data_type: numeric
- name: apy_7d_incentive_rewards
data_type: numeric
- name: apr_28d_incentive_rewards
data_type: numeric
- name: apy_28d_incentive_rewards
data_type: numeric
- name: apr_24h_performance
data_type: numeric
- name: apy_24h_performance
data_type: numeric
- name: apr_7d_performance
data_type: numeric
- name: apy_7d_performance
data_type: numeric
- name: apr_28d_performance
data_type: numeric
- name: apy_28d_performance
data_type: numeric
- name: apr_24h_underlying
data_type: numeric
- name: apy_24h_underlying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ with pnl_hourly as (
rewards_usd,
liquidation_rewards_usd,
hourly_pnl_pct,
hourly_incentive_rewards_pct,
hourly_performance_pct,
hourly_rewards_pct,
hourly_total_pct,
sum(coalesce(hourly_issuance, 0)) over (
Expand Down Expand Up @@ -86,7 +88,37 @@ avg_returns as (
partition by pool_id, collateral_type
order by ts
range between interval '28 DAYS' preceding and current row
) as avg_28d_total_pct
) as avg_28d_total_pct,
avg(hourly_incentive_rewards_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '24 HOURS' preceding and current row
) as avg_24h_incentive_rewards_pct,
avg(hourly_incentive_rewards_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '7 DAYS' preceding and current row
) as avg_7d_incentive_rewards_pct,
avg(hourly_incentive_rewards_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '28 DAYS' preceding and current row
) as avg_28d_incentive_rewards_pct,
avg(hourly_performance_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '24 HOURS' preceding and current row
) as avg_24h_performance_pct,
avg(hourly_performance_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '7 DAYS' preceding and current row
) as avg_7d_performance_pct,
avg(hourly_performance_pct) over (
partition by pool_id, collateral_type
order by ts
range between interval '28 DAYS' preceding and current row
) as avg_28d_performance_pct
from pnl_hourly
),

Expand Down Expand Up @@ -119,6 +151,20 @@ apr_calculations as (
avg_returns.avg_24h_rewards_pct * 24 * 365 as apr_24h_rewards,
avg_returns.avg_7d_rewards_pct * 24 * 365 as apr_7d_rewards,
avg_returns.avg_28d_rewards_pct * 24 * 365 as apr_28d_rewards,
-- incentive rewards pnls
avg_returns.avg_24h_incentive_rewards_pct
* 24
* 365 as apr_24h_incentive_rewards,
avg_returns.avg_7d_incentive_rewards_pct
* 24
* 365 as apr_7d_incentive_rewards,
avg_returns.avg_28d_incentive_rewards_pct
* 24
* 365 as apr_28d_incentive_rewards,
-- performance pnls
avg_returns.avg_24h_performance_pct * 24 * 365 as apr_24h_performance,
avg_returns.avg_7d_performance_pct * 24 * 365 as apr_7d_performance,
avg_returns.avg_28d_performance_pct * 24 * 365 as apr_28d_performance,
-- underlying yields
coalesce(yr.apr_24h_underlying, 0) as apr_24h_underlying,
coalesce(yr.apr_7d_underlying, 0) as apr_7d_underlying,
Expand Down Expand Up @@ -148,6 +194,22 @@ apy_calculations as (
(power(1 + apr_24h_rewards / 8760, 8760) - 1) as apy_24h_rewards,
(power(1 + apr_7d_rewards / 8760, 8760) - 1) as apy_7d_rewards,
(power(1 + apr_28d_rewards / 8760, 8760) - 1) as apy_28d_rewards,
(
power(1 + apr_24h_incentive_rewards / 8760, 8760) - 1
) as apy_24h_incentive_rewards,
(
power(1 + apr_7d_incentive_rewards / 8760, 8760) - 1
) as apy_7d_incentive_rewards,
(
power(1 + apr_28d_incentive_rewards / 8760, 8760) - 1
) as apy_28d_incentive_rewards,
(
power(1 + apr_24h_performance / 8760, 8760) - 1
) as apy_24h_performance,
(power(1 + apr_7d_performance / 8760, 8760) - 1) as apy_7d_performance,
(
power(1 + apr_28d_performance / 8760, 8760) - 1
) as apy_28d_performance,
(power(1 + apr_24h_underlying / 8760, 8760) - 1) as apy_24h_underlying,
(power(1 + apr_7d_underlying / 8760, 8760) - 1) as apy_7d_underlying,
(power(1 + apr_28d_underlying / 8760, 8760) - 1) as apy_28d_underlying
Expand Down Expand Up @@ -188,6 +250,18 @@ select
apy_7d_rewards,
apr_28d_rewards,
apy_28d_rewards,
apr_24h_incentive_rewards,
apy_24h_incentive_rewards,
apr_7d_incentive_rewards,
apy_7d_incentive_rewards,
apr_28d_incentive_rewards,
apy_28d_incentive_rewards,
apr_24h_performance,
apy_24h_performance,
apr_7d_performance,
apy_7d_performance,
apr_28d_performance,
apy_28d_performance,
apr_24h_underlying,
apy_24h_underlying,
apr_7d_underlying,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,29 @@ hourly_returns as (
0
)
) / pnl.collateral_value
end as hourly_total_pct
end as hourly_total_pct,
case
when pnl.collateral_value = 0 then 0
else (coalesce(
rewards.rewards_usd,
0
) - coalesce(
rewards.liquidation_rewards_usd,
0
)) / pnl.collateral_value
end as hourly_incentive_rewards_pct,
case
when pnl.collateral_value = 0 then 0
else (
coalesce(
rewards.liquidation_rewards_usd,
0
) + pnl.hourly_pnl + coalesce(
iss.hourly_issuance,
0
)
) / pnl.collateral_value
end as hourly_performance_pct
from
hourly_pnl as pnl
left join hourly_rewards as rewards
Expand Down Expand Up @@ -285,6 +307,8 @@ select
liquidation_rewards_usd,
hourly_pnl_pct,
hourly_rewards_pct,
hourly_total_pct
hourly_total_pct,
hourly_incentive_rewards_pct,
hourly_performance_pct
from
hourly_returns
40 changes: 40 additions & 0 deletions transformers/synthetix/models/marts/base/mainnet/core/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,30 @@ models:
data_type: numeric
- name: apy_28d_rewards
data_type: numeric
- name: apr_24h_incentive_rewards
data_type: numeric
- name: apy_24h_incentive_rewards
data_type: numeric
- name: apr_7d_incentive_rewards
data_type: numeric
- name: apy_7d_incentive_rewards
data_type: numeric
- name: apr_28d_incentive_rewards
data_type: numeric
- name: apy_28d_incentive_rewards
data_type: numeric
- name: apr_24h_performance
data_type: numeric
- name: apy_24h_performance
data_type: numeric
- name: apr_7d_performance
data_type: numeric
- name: apy_7d_performance
data_type: numeric
- name: apr_28d_performance
data_type: numeric
- name: apy_28d_performance
data_type: numeric
- name: apr_24h_underlying
data_type: numeric
- name: apy_24h_underlying
Expand Down Expand Up @@ -613,6 +637,22 @@ models:
data_type: numeric
tests:
- not_null
- name: hourly_incentive_rewards_pct
description: "Hourly incentive rewards (%)"
data_type: numeric
tests:
- not_null
- dbt_utils.accepted_range:
min_value: 0
inclusive: true
- name: hourly_performance_pct
description: "Hourly performance (%)"
data_type: numeric
tests:
- not_null
- dbt_utils.accepted_range:
min_value: 0
inclusive: true
- name: fct_pool_rewards_pool_hourly_base_mainnet
columns:
- name: ts
Expand Down
Loading