From 171e06b6a8cc21f0bf027de44004a8164020a939 Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Fri, 20 Sep 2024 17:37:18 +0200 Subject: [PATCH 1/2] [CoW AMM] 10k growth for HODL strategy --- .../10k_growth/daily_rebalancing_4055484.sql | 4 +- .../profitability/10k_growth/hodl_4086902.sql | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 cowamm/profitability/10k_growth/hodl_4086902.sql diff --git a/cowamm/profitability/10k_growth/daily_rebalancing_4055484.sql b/cowamm/profitability/10k_growth/daily_rebalancing_4055484.sql index eeb92c29..e7cdc74b 100644 --- a/cowamm/profitability/10k_growth/daily_rebalancing_4055484.sql +++ b/cowamm/profitability/10k_growth/daily_rebalancing_4055484.sql @@ -1,7 +1,7 @@ -- Computes the balances and current value of a counterfactual portfolio that invests 10k evenly into two tokens and re-balances once a day to keep a 50:50 exposure -- Parameters --- {{token_a}} - either token of the desired uni pool --- {{token_b}} - other token of the desired uni pool +-- {{token_a}} - either token +-- {{token_b}} - other token -- {{start}} - date as of which the analysis should run -- Note: not using a simpler recursive approach due to Dune's recursion depth limitation. diff --git a/cowamm/profitability/10k_growth/hodl_4086902.sql b/cowamm/profitability/10k_growth/hodl_4086902.sql new file mode 100644 index 00000000..d95a2e36 --- /dev/null +++ b/cowamm/profitability/10k_growth/hodl_4086902.sql @@ -0,0 +1,42 @@ +-- Computes the balances and current value of a counterfactual portfolio that invests 10k evenly into two tokens and holds them +-- Parameters +-- {{token_a}} - either token +-- {{token_b}} - other token +-- {{start}} - date as of which the analysis should run + +-- limit the relevant date range +with date_series as ( + select t.day + from + unnest(sequence( + date(timestamp '{{start}}'), + date(now()) + )) t (day) --noqa: AL01 +), + +starting_balance as ( + select + 5000 / p1.price_close as token_a_start, + 5000 / p2.price_close as token_b_start + from prices.usd_daily as p1 + inner join prices.usd_daily as p2 + on + p1.day = p2.day + and p1.day = date(timestamp '{{start}}') + and p1.contract_address = {{token_a}} + and p2.contract_address = {{token_b}} +) + +select + ds.day, + token_a_start * p1.price_close + token_b_start * p2.price_close as current_value_of_investment +from starting_balance, date_series as ds +inner join prices.usd_daily as p1 + on + ds.day = p1.day + and p1.contract_address = {{token_a}} +inner join prices.usd_daily as p2 + on + ds.day = p2.day + and p2.contract_address = {{token_b}} +order by 1 desc From 9c0b1e0b7aa9223d904771caddbfd6ee9ffbdb9a Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Wed, 2 Oct 2024 16:03:53 +0200 Subject: [PATCH 2/2] , join -> cross join --- cowamm/profitability/10k_growth/hodl_4086902.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cowamm/profitability/10k_growth/hodl_4086902.sql b/cowamm/profitability/10k_growth/hodl_4086902.sql index d95a2e36..838406af 100644 --- a/cowamm/profitability/10k_growth/hodl_4086902.sql +++ b/cowamm/profitability/10k_growth/hodl_4086902.sql @@ -30,7 +30,8 @@ starting_balance as ( select ds.day, token_a_start * p1.price_close + token_b_start * p2.price_close as current_value_of_investment -from starting_balance, date_series as ds +from starting_balance +cross join date_series as ds inner join prices.usd_daily as p1 on ds.day = p1.day