diff --git a/bancor_research/bancor_simulator/v3/spec/network.py b/bancor_research/bancor_simulator/v3/spec/network.py index 15e1c193..6445903f 100644 --- a/bancor_research/bancor_simulator/v3/spec/network.py +++ b/bancor_research/bancor_simulator/v3/spec/network.py @@ -13,13 +13,17 @@ from bancor_research import DEFAULT, PandasDataFrame, read_price_feeds, pd -def toDecimal(percent: str): +def to_decimal(percent: str): return Decimal(percent[:-1]) / 100 -def userAmount(state: State, tkn_name: str, user_name: str, amount: str): - if amount.endswith("%"): - return get_user_balance(state, user_name, tkn_name) * toDecimal(amount) +def get_user_amount(state: State, tkn_name: str, user_name: str, amount: Any): + if str(amount).endswith("%"): + return ( + get_user_balance(state, user_name, tkn_name) + * Decimal(str(amount)[:-1]) + / 100 + ) return Decimal(amount) @@ -74,7 +78,7 @@ def __init__( whitelisted_tokens = { k: { - "trading_fee": toDecimal(v["trading_fee"]), + "trading_fee": to_decimal(v["trading_fee"]), "bnt_funding_limit": Decimal(v["bnt_funding_limit"]), } for k, v in whitelisted_tokens.items() @@ -92,9 +96,9 @@ def __init__( whitelisted_tokens=whitelisted_tokens, usernames=[], cooldown_time=cooldown_time, - network_fee=toDecimal(network_fee), + network_fee=to_decimal(network_fee), bnt_min_liquidity=Decimal(bnt_min_liquidity), - withdrawal_fee=toDecimal(withdrawal_fee), + withdrawal_fee=to_decimal(withdrawal_fee), ) # initialize bnt @@ -187,10 +191,10 @@ def deposit( Top level logic for deposit actions. """ state = self.get_state(copy_type="initial", timestamp=timestamp) - state, tkn_name, user_name = validate_input( - state, tkn_name, user_name, timestamp + tkn_amt = get_user_amount(state, tkn_name, user_name, tkn_amt) + state, tkn_name, tkn_amt, user_name = validate_input( + state, tkn_name, tkn_amt, user_name, timestamp ) - tkn_amt = userAmount(state, tkn_name, user_name, tkn_amt) if tkn_name == "bnt": state = deposit_bnt( state=state, tkn_name=tkn_name, tkn_amt=tkn_amt, user_name=user_name @@ -223,13 +227,10 @@ def trade( Main logic for trade actions. """ state = self.get_state(copy_type="initial", timestamp=timestamp) - state, source_token, user_name = validate_input( - state, source_token, user_name, timestamp + tkn_amt = get_user_amount(state, source_token, user_name, tkn_amt) + state, source_token, tkn_amt, user_name = validate_input( + state, source_token, tkn_amt, user_name, timestamp ) - state, target_token, user_name = validate_input( - state, target_token, user_name, timestamp - ) - tkn_amt = userAmount(state, source_token, user_name, tkn_amt) state = process_trade( state, tkn_amt, source_token, target_token, user_name, timestamp ) @@ -255,10 +256,10 @@ def begin_cooldown( Begin the withdrawal cooldown operation. """ state = self.get_state(copy_type="initial", timestamp=timestamp) - state, tkn_name, user_name = validate_input( - state, tkn_name, user_name, timestamp + tkn_amt = get_user_amount(state, tkn_name, user_name, tkn_amt) + state, tkn_name, tkn_amt, user_name = validate_input( + state, tkn_name, tkn_amt, user_name, timestamp ) - tkn_amt = userAmount(state, tkn_name, user_name, tkn_amt) state, id_number = begin_withdrawal_cooldown( state, tkn_amt, tkn_name, user_name ) @@ -518,7 +519,7 @@ def burn_pool_tokens( state, tkn_name, user_name = validate_input( state, tkn_name, user_name, timestamp ) - tkn_amt = userAmount(state, tkn_name, user_name, tkn_amt) + tkn_amt = get_user_amount(state, tkn_name, user_name, tkn_amt) if tkn_name != "bnt": state.decrease_pooltoken_balance(tkn_name, tkn_amt) state.decrease_user_balance( @@ -582,7 +583,7 @@ def join_standard_rewards_program( state, tkn_name, user_name = validate_input( state, tkn_name, user_name, timestamp ) - tkn_amt = userAmount(state, tkn_name, user_name, tkn_amt) + tkn_amt = get_user_amount(state, tkn_name, user_name, tkn_amt) state = join_standard_reward_program( state=state, user_name=user_name, @@ -611,7 +612,7 @@ def leave_standard_rewards_program( state, tkn_name, user_name = validate_input( state, tkn_name, user_name, timestamp ) - tkn_amt = userAmount(state, tkn_name, user_name, tkn_amt) + tkn_amt = get_user_amount(state, tkn_name, user_name, tkn_amt) state = leave_standard_reward_program( state=state, user_name=user_name, @@ -695,7 +696,7 @@ def set_trading_fee( """ state = self.get_state(copy_type="initial", timestamp=timestamp) state, tkn_name, user_name = validate_input(state, tkn_name, "", timestamp) - value = toDecimal(percent) + value = to_decimal(percent) state.set_trading_fee(tkn_name, value) self.next_transaction(state) handle_logging( @@ -715,7 +716,7 @@ def set_network_fee( """ state = self.get_state(copy_type="initial", timestamp=timestamp) state, tkn_name, user_name = validate_input(state, tkn_name, "", timestamp) - value = toDecimal(percent) + value = to_decimal(percent) state.set_network_fee(tkn_name, value) self.next_transaction(state) handle_logging( @@ -735,7 +736,7 @@ def set_withdrawal_fee( """ state = self.get_state(copy_type="initial", timestamp=timestamp) state, tkn_name, user_name = validate_input(state, tkn_name, "", timestamp) - value = toDecimal(percent) + value = to_decimal(percent) state.set_withdrawal_fee(tkn_name, value) self.next_transaction(state) handle_logging( @@ -755,7 +756,7 @@ def set_bnt_funding_limit( """ state = self.get_state(copy_type="initial", timestamp=timestamp) state, tkn_name, user_name = validate_input(state, tkn_name, "", timestamp) - value = toDecimal(amount) + value = to_decimal(amount) state.set_bnt_funding_limit(tkn_name, value) self.next_transaction(state) handle_logging( diff --git a/bancor_research/scenario_generator/agents.py b/bancor_research/scenario_generator/agents.py index 7787eb20..d75b0397 100644 --- a/bancor_research/scenario_generator/agents.py +++ b/bancor_research/scenario_generator/agents.py @@ -3,16 +3,23 @@ # Licensed under the MIT LICENSE. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------------------------------- """Mesa Agent-based implementations of the Bancor protocol.""" +from decimal import Decimal +from typing import Tuple import mesa +from bancor_research.bancor_simulator.v3.spec import get_prices, State, get_bnt_trading_liquidity, \ + get_tkn_trading_liquidity, get_trading_fee, get_user_balance, get_is_trading_enabled, get_network_fee, get_ema_rate, \ + get_spot_rate, get_vault_balance, get_pooltoken_balance, get_staked_balance, get_external_protection_vault, \ + get_protocol_wallet_balance, get_vortex_balance, get_bnt_funding_limit, get_bnbnt_rate, get_max_bnt_deposit, \ + get_user_pending_withdrawals from bancor_research.bancor_simulator.v3.spec.actions import ( unpack_withdrawal_cooldown, vortex_burner, ) from bancor_research.bancor_simulator.v3.spec.network import BancorDapp -from bancor_research.bancor_simulator.v3.simulation.random_walk import RandomWalker -from bancor_research.bancor_simulator.v3.simulation.utils import ( +from bancor_research.scenario_generator.monte_carlo import MonteCarlo +from bancor_research.scenario_generator.utils import ( trade_tkn_to_ema, trade_bnt_to_ema, process_arbitrage_trade, @@ -26,7 +33,7 @@ ) -class Trader(RandomWalker): +class Trader(MonteCarlo): """ Represents a Bancor dapp user (trader and/or arbitrageur). Subclass to Mesa Agent """ @@ -267,9 +274,8 @@ def perform_random_ema_force_trade(self): return self def get_random_tkn_names(self, state: State) -> Tuple[str, str]: - tokens = state.whitelisted_tokens - source_tkn = self.random.choice(tokens) - target_tkn = self.random.choice([tkn for tkn in tokens if tkn != source_tkn]) + tokens = [tkn for tkn in state.whitelisted_tokens] + source_tkn, target_tkn = self.random.sample(tokens, 2) return source_tkn, target_tkn def get_average_trading_fee(self): @@ -328,7 +334,7 @@ def step(self): self.transact() -class LP(RandomWalker): +class LP(MonteCarlo): """ Represents a Bancor dapp liquidity provider. Subclass to Mesa Agent """ @@ -432,7 +438,7 @@ def get_random_bnt_funding_limit(self, bnt_funding_amt: Decimal) -> Decimal: def set_random_trading_fee(self): state = self.protocol.v3.global_state for i in range(self.random.randint(1, 3)): - tkn_name = self.random.choice(state.whitelisted_tokens) + tkn_name = self.random.choice([tkn for tkn in state.whitelisted_tokens]) trading_fee = get_trading_fee(state, tkn_name) trading_fee = self.get_random_trading_fee(trading_fee) state.set_trading_fee(tkn_name, trading_fee) @@ -441,7 +447,7 @@ def set_random_trading_fee(self): def set_random_network_fee(self): state = self.protocol.v3.global_state - tkn_name = self.random.choice(state.whitelisted_tokens) + tkn_name = self.random.choice([tkn for tkn in state.whitelisted_tokens]) network_fee = get_network_fee(state, tkn_name) network_fee = self.get_random_network_fee(network_fee) state.set_network_fee(tkn_name, network_fee) @@ -451,7 +457,7 @@ def set_random_network_fee(self): def set_random_withdrawal_fee(self): state = self.protocol.v3.global_state withdrawal_fee = state.withdrawal_fee - tkn_name = self.random.choice(state.whitelisted_tokens) + tkn_name = self.random.choice([tkn for tkn in state.whitelisted_tokens]) withdrawal_fee = self.get_random_withdrawal_fee(withdrawal_fee) state.set_withdrawal_fee(tkn_name, withdrawal_fee) self.protocol.v3.set_state(state) @@ -459,7 +465,7 @@ def set_random_withdrawal_fee(self): def set_random_bnt_funding_limit(self): state = self.protocol.v3.global_state - tkn_name = self.random.choice(state.whitelisted_tokens) + tkn_name = self.random.choice([tkn for tkn in state.whitelisted_tokens]) bnt_funding_limit = get_bnt_funding_limit(state, tkn_name) updated_bnt_funding_limit = self.get_random_bnt_funding_limit(bnt_funding_limit) state.set_bnt_funding_limit(tkn_name, updated_bnt_funding_limit) @@ -467,9 +473,9 @@ def set_random_bnt_funding_limit(self): return self def perform_random_enable_trading(self): - self.protocol.v3.dao_msig_init_pools( - self.protocol.v3.global_state.whitelisted_tokens, "bnt" - ) + state = self.protocol.v3.global_state + for tkn in [tkn for tkn in state.whitelisted_tokens]: + self.protocol.v3.enable_trading(tkn) return self def get_random_withdrawal_amt(self, tkn_name: str) -> Decimal: @@ -497,9 +503,8 @@ def get_random_amt(self, amt: Decimal) -> Decimal: return Decimal(self.random.uniform(float(min_amt), float(max_amt))) def get_random_tkn_names(self, state: State) -> Tuple[str, str]: - tokens = state.whitelisted_tokens - source_tkn = self.random.choice(tokens) - target_tkn = self.random.choice([tkn for tkn in tokens if tkn != source_tkn]) + tokens = [tkn for tkn in state.whitelisted_tokens] + source_tkn, target_tkn = self.random.sample(tokens, 2) return source_tkn, target_tkn def is_protocol_bnbnt_healthy( @@ -554,7 +559,7 @@ def create_random_autocompounding_rewards(self): timestamp = state.timestamp start_time = 1 + timestamp - tkn_name = self.random.choice(state.whitelisted_tokens) + tkn_name = self.random.choice([tkn for tkn in state.whitelisted_tokens]) distribution_type = self.random.choice(["flat", "exp"]) if distribution_type == "flat": @@ -769,7 +774,7 @@ def perform_random_withdrawal(self): state = self.protocol.v3.global_state timestamp = state.timestamp user_name = self.random.choice(state.usernames) - tkn_name = self.random.choice(state.whitelisted_tokens) + tkn_name = self.random.choice([tkn for tkn in state.whitelisted_tokens]) pending_withdrawals = get_user_pending_withdrawals(state, user_name, tkn_name) if len(pending_withdrawals) > 0: id_number = self.random.choice(pending_withdrawals) @@ -965,10 +970,8 @@ def __init__( self.v3 = BancorDapp( price_feeds=price_feeds, whitelisted_tokens=whitelisted_tokens, - trading_fee=trading_fee, network_fee=network_fee, withdrawal_fee=withdrawal_fee, - bnt_funding_limit=bnt_funding_limit, bnt_min_liquidity=bnt_min_liquidity, ) diff --git a/bancor_research/scenario_generator/batch_run.py b/bancor_research/scenario_generator/batch_run.py index 5333d27d..1f89141f 100644 --- a/bancor_research/scenario_generator/batch_run.py +++ b/bancor_research/scenario_generator/batch_run.py @@ -22,6 +22,13 @@ """ import os +import mesa +from bancor_research.scenario_generator.constants import SIMULATION_MAX_STEPS, SIMULATION_OUTPUT_PATH + +from bancor_research.scenario_generator.model import BancorSimulation + +from bancor_research.bancor_simulator.v3.spec import * + # Add any desired parameters to sweep below. br_params = { "trading_fee": [ diff --git a/bancor_research/scenario_generator/constants.py b/bancor_research/scenario_generator/constants.py index b5e6849d..e99b418c 100644 --- a/bancor_research/scenario_generator/constants.py +++ b/bancor_research/scenario_generator/constants.py @@ -4,6 +4,11 @@ # -------------------------------------------------------------------------------------------------------------------- """Simulation constants and default state variables.""" from decimal import Decimal +from bancor_research import DEFAULT +DEFAULT_TRADING_FEE = DEFAULT.TRADING_FEE +DEFAULT_BNT_FUNDING_LIMIT = DEFAULT.BNT_FUNDING_LIMIT +DEFAULT_NETWORK_FEE = DEFAULT.NETWORK_FEE +DEFAULT_WITHDRAWAL_FEE = DEFAULT.WITHDRAWAL_FEE SIMULATION_TARGET_TVL: Decimal = Decimal("160000000") SIMULATION_TARGET_TRADE_VOLUME: Decimal = Decimal("20000000") @@ -13,6 +18,25 @@ SIMULATION_TARGET_NUM_WITHDRAWALS_PER_DAY: int = 200 SIMULATION_NUM_TRADERS = 2 SIMULATION_NUM_LPs = 2 -SIMULATION_WHITELISTED_TOKENS = ["tkn", "bnt"] + + +SIMULATION_WHITELISTED_TOKENS = { + "eth": { + "trading_fee": DEFAULT_TRADING_FEE, + "bnt_funding_limit": DEFAULT_BNT_FUNDING_LIMIT, + }, + "link": { + "trading_fee": DEFAULT_TRADING_FEE, + "bnt_funding_limit": DEFAULT_BNT_FUNDING_LIMIT, + }, + "tkn": { + "trading_fee": DEFAULT_TRADING_FEE, + "bnt_funding_limit": DEFAULT_BNT_FUNDING_LIMIT, + }, + "wbtc": { + "trading_fee": DEFAULT_TRADING_FEE, + "bnt_funding_limit": DEFAULT_BNT_FUNDING_LIMIT, + }, +} SIMULATION_MAX_STEPS = 100 -SIMULATION_OUTPUT_PATH: str = "data/simulation_output.csv" +SIMULATION_OUTPUT_PATH: str = "examples/studies/limit_max_on_curve_liquidity/data/simulation_output.csv" diff --git a/bancor_research/scenario_generator/model.py b/bancor_research/scenario_generator/model.py index 2c6ccd0b..0e2c059c 100644 --- a/bancor_research/scenario_generator/model.py +++ b/bancor_research/scenario_generator/model.py @@ -2,20 +2,20 @@ # -------------------------------------------------------------------------------------------------------------------- # Licensed under the MIT LICENSE. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------------------------------- -"""Main Bancor Simulation module interface.""" - +"""Main Bancor Simulation module interface. +If you want to perform a parameter sweep, call batch_run.py instead of run.py. +For details see batch_run.py in the same directory as run.py. +""" import mesa import itertools from decimal import Decimal -from mesa.datacollection import DataCollector -from pydantic.types import Any -from bancor_research.bancor_simulator.v3.simulation.agents import Trader, LP, Protocol +from bancor_research.scenario_generator.agents import Protocol, Trader, LP -""" -If you want to perform a parameter sweep, call batch_run.py instead of run.py. -For details see batch_run.py in the same directory as run.py. -""" +from bancor_research.bancor_simulator.v3.spec import * +from bancor_research.scenario_generator.constants import * +from mesa.datacollection import DataCollector +from pydantic.types import Any def track_params(model): @@ -53,22 +53,22 @@ class BancorSimulation(mesa.Model): max_steps = SIMULATION_MAX_STEPS def __init__( - self, - height=grid_h, - width=grid_w, - init_traders=SIMULATION_NUM_TRADERS, - init_lps=SIMULATION_NUM_LPs, - whale_threshold=SIMULATION_WHALE_THRESHOLD, - trading_fee=float(DEFAULT_TRADING_FEE), - network_fee=float(DEFAULT_NETWORK_FEE), - withdrawal_fee=float(DEFAULT_WITHDRAWAL_FEE), - whitelisted_tokens=None, - target_tvl=SIMULATION_TARGET_TVL, - price_feeds=DEFAULT_PRICE_FEEDS, - bnt_funding_limit=float(DEFAULT_BNT_FUNDING_LIMIT), - bnt_min_liquidity=float(DEFAULT_BNT_MIN_LIQUIDITY), - *args: Any, - **kwargs: Any + self, + height=grid_h, + width=grid_w, + init_traders=SIMULATION_NUM_TRADERS, + init_lps=SIMULATION_NUM_LPs, + whale_threshold=SIMULATION_WHALE_THRESHOLD, + trading_fee=float(DEFAULT_TRADING_FEE), + network_fee=float(DEFAULT_NETWORK_FEE), + withdrawal_fee=float(DEFAULT_WITHDRAWAL_FEE), + whitelisted_tokens=None, + target_tvl=SIMULATION_TARGET_TVL, + price_feeds=DEFAULT_PRICE_FEEDS, + bnt_funding_limit=float(DEFAULT_BNT_FUNDING_LIMIT), + bnt_min_liquidity=float(DEFAULT_BNT_MIN_LIQUIDITY), + *args: Any, + **kwargs: Any ): if whitelisted_tokens is None: diff --git a/bancor_research/scenario_generator/random_walk.py b/bancor_research/scenario_generator/monte_carlo.py similarity index 87% rename from bancor_research/scenario_generator/random_walk.py rename to bancor_research/scenario_generator/monte_carlo.py index 6ea3efb2..e5645a38 100644 --- a/bancor_research/scenario_generator/random_walk.py +++ b/bancor_research/scenario_generator/monte_carlo.py @@ -4,15 +4,15 @@ # -------------------------------------------------------------------------- """ -Generalized behavior for random walking, one grid cell at a time. +Generalized behavior for monte carlo simulation """ import mesa -class RandomWalker(mesa.Agent): +class MonteCarlo(mesa.Agent): """ - Class implementing random walker methods in a generalized manner. + Class implementing monte carlo methods in a generalized manner. """ grid = None diff --git a/bancor_research/scenario_generator/run.py b/bancor_research/scenario_generator/run.py index 1350945c..1a06b4dc 100644 --- a/bancor_research/scenario_generator/run.py +++ b/bancor_research/scenario_generator/run.py @@ -1,3 +1,4 @@ -from bancor_research.bancor_simulator.v3.simulation.server import server +# coding=utf-8 +from bancor_research.scenario_generator.server import server server.launch() diff --git a/bancor_research/scenario_generator/server.py b/bancor_research/scenario_generator/server.py index d47cdb22..5b52333e 100644 --- a/bancor_research/scenario_generator/server.py +++ b/bancor_research/scenario_generator/server.py @@ -3,8 +3,16 @@ # Licensed under the MIT LICENSE. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------------------------------- """Sets up the interactive visualization server for the Mesa Agent-based simulation.""" +from decimal import Decimal + +import mesa +from bancor_research.scenario_generator.constants import * # The colors here are taken from Matplotlib's tab10 palette +from bancor_research.scenario_generator.model import BancorSimulation + +from bancor_research.scenario_generator.agents import Trader, LP + RICH_COLOR = "#2ca02c" # Green POOR_COLOR = "#d62728" # Red MID_COLOR = "#1f77b4" # Blue diff --git a/bancor_research/scenario_generator/utils.py b/bancor_research/scenario_generator/utils.py index bfe637bb..9984df47 100644 --- a/bancor_research/scenario_generator/utils.py +++ b/bancor_research/scenario_generator/utils.py @@ -3,6 +3,8 @@ # Licensed under the MIT LICENSE. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------------------------------- """Simulation utility functions.""" +from decimal import Decimal +from typing import Tuple def trade_tkn_to_ema( diff --git a/examples/simulation-example.ipynb b/examples/simulation-example.ipynb index 9b855037..2fe2ba40 100644 --- a/examples/simulation-example.ipynb +++ b/examples/simulation-example.ipynb @@ -14,6 +14,7 @@ "name": "stdout", "output_type": "stream", "text": [ + "zsh:1: command not found: python\n" ] } diff --git a/examples/studies/ahp/Analytical Hierarchy Process.png b/examples/studies/ahp/Analytical Hierarchy Process.png new file mode 100644 index 00000000..32adcc9d Binary files /dev/null and b/examples/studies/ahp/Analytical Hierarchy Process.png differ diff --git a/examples/studies/ahp/ahp-example.ipynb b/examples/studies/ahp/ahp-example.ipynb new file mode 100644 index 00000000..5a0746b7 --- /dev/null +++ b/examples/studies/ahp/ahp-example.ipynb @@ -0,0 +1,1251 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# AHPy\n", + "\n", + "**AHPy** is an implementation of the Analytic Hierarchy Process ([AHP](https://en.wikipedia.org/wiki/Analytic_hierarchy_process)), a method used to structure, synthesize and evaluate the elements of a decision problem. Developed by [Thomas Saaty](http://www.creativedecisions.org/about/ThomasLSaaty.php) in the 1970s, AHP's broad use in fields well beyond that of operational research is a testament to its simple yet powerful combination of psychology and mathematics.\n", + "\n", + "

\n", + "\"bancor3\"\n", + "

" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 994, + "outputs": [], + "source": [ + "from fractions import Fraction\n", + "import itertools\n", + "import random\n", + "import pandas as pd\n", + "import ahpy" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "source": [ + "### The following code demonstrates how to arrive at a decision matrix such as that shown below." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 1029, + "outputs": [ + { + "data": { + "text/plain": " Unnamed: 0 Fees Resources Deficit Alignment \\\n0 Remove BNT from pools Proposal 0.346 0.45 0.318 0.222 \n1 Airswap Proposal 0.269 0.40 0.273 0.259 \n2 USDT liquidity Proposal 0.192 0.05 0.227 0.259 \n3 Enable deposits Proposal 0.192 0.10 0.182 0.259 \n\n Risk Total \n0 0.222 1.558 \n1 0.185 1.386 \n2 0.259 0.987 \n3 0.333 1.066 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Unnamed: 0FeesResourcesDeficitAlignmentRiskTotal
0Remove BNT from pools Proposal0.3460.450.3180.2220.2221.558
1Airswap Proposal0.2690.400.2730.2590.1851.386
2USDT liquidity Proposal0.1920.050.2270.2590.2590.987
3Enable deposits Proposal0.1920.100.1820.2590.3331.066
\n
" + }, + "execution_count": 1029, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pd.read_csv('ahp_example.csv')" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 995, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Simulated survey takers (could be only the task force or volunteers or the entire dao survey respondents)\n", + "dao_survey_respondents = {\n", + " 'Mark': [],\n", + " 'Rick': [],\n", + " 'Stefan': [],\n", + " 'Tyler': []\n", + "}" + ] + }, + { + "cell_type": "markdown", + "source": [ + "### " + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 996, + "outputs": [ + { + "data": { + "text/plain": "[('Airswap Proposal', 'USDT liquidity Proposal'),\n ('Airswap Proposal', 'Remove BNT from pools Proposal'),\n ('Airswap Proposal', 'Enable deposits Proposal'),\n ('USDT liquidity Proposal', 'Remove BNT from pools Proposal'),\n ('USDT liquidity Proposal', 'Enable deposits Proposal'),\n ('Remove BNT from pools Proposal', 'Enable deposits Proposal')]" + }, + "execution_count": 996, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Alternative recovery proposals\n", + "alternatives = (\n", + " 'Airswap Proposal',\n", + " 'USDT liquidity Proposal',\n", + " 'Remove BNT from pools Proposal',\n", + " 'Enable deposits Proposal'\n", + ")\n", + "alternatives_pairs = list(itertools.combinations(alternatives, 2))\n", + "alternatives_pairs" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 997, + "outputs": [], + "source": [ + "# Simulated survey takers with randomized responses for demonstration\n", + "def simulate_dao_survey(alternatives_pairs, survey, results={}, response={}):\n", + " for alternative in alternatives_pairs:\n", + " for comparison in survey:\n", + " importance = random.randint(1, 9)\n", + " results[comparison] = importance\n", + " return [float(Fraction(results[alternatives_pairs[i][0]], results[alternatives_pairs[i][1]])) for i in range(len(alternatives_pairs))]" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### Pairwise survey questions using a standardized ranking system such the [fundamental scale](https://en.wikipedia.org/wiki/Analytic_hierarchy_process_–_car_example)" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 998, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 1.4,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 0.7777777777777778,\n ('Airswap Proposal', 'Enable deposits Proposal'): 1.4,\n ('USDT liquidity Proposal',\n 'Remove BNT from pools Proposal'): 0.5555555555555556,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 1.0,\n ('Remove BNT from pools Proposal', 'Enable deposits Proposal'): 1.8}" + }, + "execution_count": 998, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fees_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "fees_comparisons = dict(zip(alternatives_pairs, fees_values))\n", + "fees_comparisons" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 999, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 8.0,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 0.8888888888888888,\n ('Airswap Proposal', 'Enable deposits Proposal'): 4.0,\n ('USDT liquidity Proposal',\n 'Remove BNT from pools Proposal'): 0.1111111111111111,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 0.5,\n ('Remove BNT from pools Proposal', 'Enable deposits Proposal'): 4.5}" + }, + "execution_count": 999, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "resources_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "resources_comparisons = dict(zip(alternatives_pairs, resources_values))\n", + "resources_comparisons" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1000, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 1.2,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 0.8571428571428571,\n ('Airswap Proposal', 'Enable deposits Proposal'): 1.5,\n ('USDT liquidity Proposal',\n 'Remove BNT from pools Proposal'): 0.7142857142857143,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 1.25,\n ('Remove BNT from pools Proposal', 'Enable deposits Proposal'): 1.75}" + }, + "execution_count": 1000, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "deficit_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "deficit_comparisons = dict(zip(alternatives_pairs, deficit_values))\n", + "deficit_comparisons" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1001, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 1.0,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 1.1666666666666667,\n ('Airswap Proposal', 'Enable deposits Proposal'): 1.0,\n ('USDT liquidity Proposal',\n 'Remove BNT from pools Proposal'): 1.1666666666666667,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 1.0,\n ('Remove BNT from pools Proposal',\n 'Enable deposits Proposal'): 0.8571428571428571}" + }, + "execution_count": 1001, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "alignment_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "alignment_comparisons = dict(zip(alternatives_pairs, alignment_values))\n", + "alignment_comparisons" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1002, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 0.8,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 0.4444444444444444,\n ('Airswap Proposal', 'Enable deposits Proposal'): 0.5,\n ('USDT liquidity Proposal',\n 'Remove BNT from pools Proposal'): 0.5555555555555556,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 0.625,\n ('Remove BNT from pools Proposal', 'Enable deposits Proposal'): 1.125}" + }, + "execution_count": 1002, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "legal_risk_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "legal_risk_comparisons = dict(zip(alternatives_pairs, legal_risk_values))\n", + "legal_risk_comparisons\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1003, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 0.3333333333333333,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 3.0,\n ('Airswap Proposal', 'Enable deposits Proposal'): 1.0,\n ('USDT liquidity Proposal', 'Remove BNT from pools Proposal'): 9.0,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 3.0,\n ('Remove BNT from pools Proposal',\n 'Enable deposits Proposal'): 0.3333333333333333}" + }, + "execution_count": 1003, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lp_alienation_risk_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "lp_alienation_risk_comparisons = dict(zip(alternatives_pairs, lp_alienation_risk_values))\n", + "lp_alienation_risk_comparisons\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1004, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 8.0,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 4.0,\n ('Airswap Proposal', 'Enable deposits Proposal'): 2.0,\n ('USDT liquidity Proposal', 'Remove BNT from pools Proposal'): 0.5,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 0.25,\n ('Remove BNT from pools Proposal', 'Enable deposits Proposal'): 0.5}" + }, + "execution_count": 1004, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reputational_risk_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "reputational_risk_comparisons = dict(zip(alternatives_pairs, reputational_risk_values))\n", + "reputational_risk_comparisons\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1005, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 3.0,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 3.0,\n ('Airswap Proposal', 'Enable deposits Proposal'): 1.5,\n ('USDT liquidity Proposal', 'Remove BNT from pools Proposal'): 1.0,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 0.5,\n ('Remove BNT from pools Proposal', 'Enable deposits Proposal'): 0.5}" + }, + "execution_count": 1005, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "security_risk_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "security_risk_comparisons = dict(zip(alternatives_pairs, security_risk_values))\n", + "security_risk_comparisons\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1006, + "outputs": [ + { + "data": { + "text/plain": "{('Airswap Proposal', 'USDT liquidity Proposal'): 0.7142857142857143,\n ('Airswap Proposal', 'Remove BNT from pools Proposal'): 0.8333333333333334,\n ('Airswap Proposal', 'Enable deposits Proposal'): 0.5555555555555556,\n ('USDT liquidity Proposal',\n 'Remove BNT from pools Proposal'): 1.1666666666666667,\n ('USDT liquidity Proposal', 'Enable deposits Proposal'): 0.7777777777777778,\n ('Remove BNT from pools Proposal',\n 'Enable deposits Proposal'): 0.6666666666666666}" + }, + "execution_count": 1006, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "risk_values = simulate_dao_survey(alternatives_pairs, alternatives)\n", + "risk_comparisons = dict(zip(alternatives_pairs, risk_values))\n", + "risk_comparisons" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### Use the AHPy library to calculate comparison values." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 1007, + "outputs": [], + "source": [ + "comparisons=[]" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1008, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"Fees\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.346,\n", + " \"Airswap Proposal\": 0.269,\n", + " \"USDT liquidity Proposal\": 0.192,\n", + " \"Enable deposits Proposal\": 0.192\n", + " },\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.346,\n", + " \"Airswap Proposal\": 0.269,\n", + " \"USDT liquidity Proposal\": 0.192,\n", + " \"Enable deposits Proposal\": 0.192\n", + " },\n", + " \"local_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.346,\n", + " \"Airswap Proposal\": 0.269,\n", + " \"USDT liquidity Proposal\": 0.192,\n", + " \"Enable deposits Proposal\": 0.192\n", + " },\n", + " \"consistency_ratio\": 0.0\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " Remove BNT from pools Proposal Airswap Proposal \\\nFees 0.346 0.269 \n\n USDT liquidity Proposal Enable deposits Proposal \nFees 0.192 0.192 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Remove BNT from pools ProposalAirswap ProposalUSDT liquidity ProposalEnable deposits Proposal
Fees0.3460.2690.1920.192
\n
" + }, + "execution_count": 1008, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fees = ahpy.Compare('Fees', fees_comparisons, precision=3)\n", + "report = fees.report(show=True)\n", + "fees_df = pd.DataFrame(fees.target_weights, index=['Fees'])\n", + "comparisons.append(fees_df)\n", + "fees_df" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1009, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"Resources\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.45,\n", + " \"Airswap Proposal\": 0.4,\n", + " \"Enable deposits Proposal\": 0.1,\n", + " \"USDT liquidity Proposal\": 0.05\n", + " },\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.45,\n", + " \"Airswap Proposal\": 0.4,\n", + " \"Enable deposits Proposal\": 0.1,\n", + " \"USDT liquidity Proposal\": 0.05\n", + " },\n", + " \"local_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.45,\n", + " \"Airswap Proposal\": 0.4,\n", + " \"Enable deposits Proposal\": 0.1,\n", + " \"USDT liquidity Proposal\": 0.05\n", + " },\n", + " \"consistency_ratio\": 0.0\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " Remove BNT from pools Proposal Airswap Proposal \\\nResources 0.45 0.4 \n\n Enable deposits Proposal USDT liquidity Proposal \nResources 0.1 0.05 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Remove BNT from pools ProposalAirswap ProposalEnable deposits ProposalUSDT liquidity Proposal
Resources0.450.40.10.05
\n
" + }, + "execution_count": 1009, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "resources = ahpy.Compare('Resources', resources_comparisons, precision=3)\n", + "report = resources.report(show=True)\n", + "resources_df = pd.DataFrame(resources.target_weights, index=['Resources'])\n", + "comparisons.append(resources_df)\n", + "resources_df" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1010, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"Deficit\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.318,\n", + " \"Airswap Proposal\": 0.273,\n", + " \"USDT liquidity Proposal\": 0.227,\n", + " \"Enable deposits Proposal\": 0.182\n", + " },\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.318,\n", + " \"Airswap Proposal\": 0.273,\n", + " \"USDT liquidity Proposal\": 0.227,\n", + " \"Enable deposits Proposal\": 0.182\n", + " },\n", + " \"local_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.318,\n", + " \"Airswap Proposal\": 0.273,\n", + " \"USDT liquidity Proposal\": 0.227,\n", + " \"Enable deposits Proposal\": 0.182\n", + " },\n", + " \"consistency_ratio\": 0.0\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " Remove BNT from pools Proposal Airswap Proposal \\\nDeficit 0.318 0.273 \n\n USDT liquidity Proposal Enable deposits Proposal \nDeficit 0.227 0.182 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Remove BNT from pools ProposalAirswap ProposalUSDT liquidity ProposalEnable deposits Proposal
Deficit0.3180.2730.2270.182
\n
" + }, + "execution_count": 1010, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "deficit = ahpy.Compare('Deficit', deficit_comparisons, precision=3)\n", + "report = deficit.report(show=True)\n", + "deficit_df = pd.DataFrame(deficit.target_weights, index=['Deficit'])\n", + "comparisons.append(deficit_df)\n", + "deficit_df" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1011, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"Alignment\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {\n", + " \"Airswap Proposal\": 0.259,\n", + " \"USDT liquidity Proposal\": 0.259,\n", + " \"Enable deposits Proposal\": 0.259,\n", + " \"Remove BNT from pools Proposal\": 0.222\n", + " },\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"Airswap Proposal\": 0.259,\n", + " \"USDT liquidity Proposal\": 0.259,\n", + " \"Enable deposits Proposal\": 0.259,\n", + " \"Remove BNT from pools Proposal\": 0.222\n", + " },\n", + " \"local_weights\": {\n", + " \"Airswap Proposal\": 0.259,\n", + " \"USDT liquidity Proposal\": 0.259,\n", + " \"Enable deposits Proposal\": 0.259,\n", + " \"Remove BNT from pools Proposal\": 0.222\n", + " },\n", + " \"consistency_ratio\": 0.0\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " Airswap Proposal USDT liquidity Proposal \\\nAlignment 0.259 0.259 \n\n Enable deposits Proposal Remove BNT from pools Proposal \nAlignment 0.259 0.222 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Airswap ProposalUSDT liquidity ProposalEnable deposits ProposalRemove BNT from pools Proposal
Alignment0.2590.2590.2590.222
\n
" + }, + "execution_count": 1011, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "alignment = ahpy.Compare('Alignment', alignment_comparisons, precision=3)\n", + "report = alignment.report(show=True)\n", + "alignment_df = pd.DataFrame(alignment.target_weights, index=['Alignment'])\n", + "comparisons.append(alignment_df)\n", + "alignment_df" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1012, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"Legal Risk\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.346,\n", + " \"Enable deposits Proposal\": 0.308,\n", + " \"USDT liquidity Proposal\": 0.192,\n", + " \"Airswap Proposal\": 0.154\n", + " },\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.346,\n", + " \"Enable deposits Proposal\": 0.308,\n", + " \"USDT liquidity Proposal\": 0.192,\n", + " \"Airswap Proposal\": 0.154\n", + " },\n", + " \"local_weights\": {\n", + " \"Remove BNT from pools Proposal\": 0.346,\n", + " \"Enable deposits Proposal\": 0.308,\n", + " \"USDT liquidity Proposal\": 0.192,\n", + " \"Airswap Proposal\": 0.154\n", + " },\n", + " \"consistency_ratio\": 0.0,\n", + " \"random_index\": \"Donegan & Dodd\",\n", + " \"count\": 4,\n", + " \"names\": [\n", + " \"Airswap Proposal\",\n", + " \"USDT liquidity Proposal\",\n", + " \"Remove BNT from pools Proposal\",\n", + " \"Enable deposits Proposal\"\n", + " ]\n", + " },\n", + " \"children\": null,\n", + " \"comparisons\": {\n", + " \"count\": 6,\n", + " \"input\": {\n", + " \"Airswap Proposal, USDT liquidity Proposal\": 0.8,\n", + " \"Airswap Proposal, Remove BNT from pools Proposal\": 0.4444444444444444,\n", + " \"Airswap Proposal, Enable deposits Proposal\": 0.5,\n", + " \"USDT liquidity Proposal, Remove BNT from pools Proposal\": 0.5555555555555556,\n", + " \"USDT liquidity Proposal, Enable deposits Proposal\": 0.625,\n", + " \"Remove BNT from pools Proposal, Enable deposits Proposal\": 1.125\n", + " },\n", + " \"computed\": null\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " Remove BNT from pools Proposal Enable deposits Proposal \\\nLegal Risk 0.346 0.308 \n\n USDT liquidity Proposal Airswap Proposal \nLegal Risk 0.192 0.154 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Remove BNT from pools ProposalEnable deposits ProposalUSDT liquidity ProposalAirswap Proposal
Legal Risk0.3460.3080.1920.154
\n
" + }, + "execution_count": 1012, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "legal_risk = ahpy.Compare('Legal Risk', legal_risk_comparisons, precision=3)\n", + "report = legal_risk.report(show=True, verbose=True)\n", + "legal_risk_df = pd.DataFrame(legal_risk.target_weights, index=['Legal Risk'])\n", + "# comparisons.append(legal_risk_df)\n", + "legal_risk_df\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1013, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"Reputational Risk\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {\n", + " \"Airswap Proposal\": 0.533,\n", + " \"Enable deposits Proposal\": 0.267,\n", + " \"Remove BNT from pools Proposal\": 0.133,\n", + " \"USDT liquidity Proposal\": 0.067\n", + " },\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"Airswap Proposal\": 0.533,\n", + " \"Enable deposits Proposal\": 0.267,\n", + " \"Remove BNT from pools Proposal\": 0.133,\n", + " \"USDT liquidity Proposal\": 0.067\n", + " },\n", + " \"local_weights\": {\n", + " \"Airswap Proposal\": 0.533,\n", + " \"Enable deposits Proposal\": 0.267,\n", + " \"Remove BNT from pools Proposal\": 0.133,\n", + " \"USDT liquidity Proposal\": 0.067\n", + " },\n", + " \"consistency_ratio\": 0.0,\n", + " \"random_index\": \"Donegan & Dodd\",\n", + " \"count\": 4,\n", + " \"names\": [\n", + " \"Airswap Proposal\",\n", + " \"USDT liquidity Proposal\",\n", + " \"Remove BNT from pools Proposal\",\n", + " \"Enable deposits Proposal\"\n", + " ]\n", + " },\n", + " \"children\": null,\n", + " \"comparisons\": {\n", + " \"count\": 6,\n", + " \"input\": {\n", + " \"Airswap Proposal, USDT liquidity Proposal\": 8.0,\n", + " \"Airswap Proposal, Remove BNT from pools Proposal\": 4.0,\n", + " \"Airswap Proposal, Enable deposits Proposal\": 2.0,\n", + " \"USDT liquidity Proposal, Remove BNT from pools Proposal\": 0.5,\n", + " \"USDT liquidity Proposal, Enable deposits Proposal\": 0.25,\n", + " \"Remove BNT from pools Proposal, Enable deposits Proposal\": 0.5\n", + " },\n", + " \"computed\": null\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " Airswap Proposal Enable deposits Proposal \\\nReputational Risk 0.533 0.267 \n\n Remove BNT from pools Proposal USDT liquidity Proposal \nReputational Risk 0.133 0.067 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Airswap ProposalEnable deposits ProposalRemove BNT from pools ProposalUSDT liquidity Proposal
Reputational Risk0.5330.2670.1330.067
\n
" + }, + "execution_count": 1013, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reputational_risk = ahpy.Compare('Reputational Risk', reputational_risk_comparisons, precision=3)\n", + "report = reputational_risk.report(show=True, verbose=True)\n", + "reputational_risk_df = pd.DataFrame(reputational_risk.target_weights, index=['Reputational Risk'])\n", + "# comparisons.append(reputational_risk_df)\n", + "reputational_risk_df\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1014, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"LP Alienation Risk\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {\n", + " \"USDT liquidity Proposal\": 0.562,\n", + " \"Airswap Proposal\": 0.188,\n", + " \"Enable deposits Proposal\": 0.188,\n", + " \"Remove BNT from pools Proposal\": 0.062\n", + " },\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"USDT liquidity Proposal\": 0.562,\n", + " \"Airswap Proposal\": 0.188,\n", + " \"Enable deposits Proposal\": 0.188,\n", + " \"Remove BNT from pools Proposal\": 0.062\n", + " },\n", + " \"local_weights\": {\n", + " \"USDT liquidity Proposal\": 0.562,\n", + " \"Airswap Proposal\": 0.188,\n", + " \"Enable deposits Proposal\": 0.188,\n", + " \"Remove BNT from pools Proposal\": 0.062\n", + " },\n", + " \"consistency_ratio\": 0.0,\n", + " \"random_index\": \"Donegan & Dodd\",\n", + " \"count\": 4,\n", + " \"names\": [\n", + " \"Airswap Proposal\",\n", + " \"USDT liquidity Proposal\",\n", + " \"Remove BNT from pools Proposal\",\n", + " \"Enable deposits Proposal\"\n", + " ]\n", + " },\n", + " \"children\": null,\n", + " \"comparisons\": {\n", + " \"count\": 6,\n", + " \"input\": {\n", + " \"Airswap Proposal, USDT liquidity Proposal\": 0.3333333333333333,\n", + " \"Airswap Proposal, Remove BNT from pools Proposal\": 3.0,\n", + " \"Airswap Proposal, Enable deposits Proposal\": 1.0,\n", + " \"USDT liquidity Proposal, Remove BNT from pools Proposal\": 9.0,\n", + " \"USDT liquidity Proposal, Enable deposits Proposal\": 3.0,\n", + " \"Remove BNT from pools Proposal, Enable deposits Proposal\": 0.3333333333333333\n", + " },\n", + " \"computed\": null\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " USDT liquidity Proposal Airswap Proposal \\\nLP Alienation Risk 0.562 0.188 \n\n Enable deposits Proposal Remove BNT from pools Proposal \nLP Alienation Risk 0.188 0.062 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
USDT liquidity ProposalAirswap ProposalEnable deposits ProposalRemove BNT from pools Proposal
LP Alienation Risk0.5620.1880.1880.062
\n
" + }, + "execution_count": 1014, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "lp_alienation_risk = ahpy.Compare('LP Alienation Risk', lp_alienation_risk_comparisons, precision=3)\n", + "report = lp_alienation_risk.report(show=True, verbose=True)\n", + "lp_alienation_risk_df = pd.DataFrame(lp_alienation_risk.target_weights, index=['LP Alienation Risk'])\n", + "# comparisons.append(lp_alienation_risk_df)\n", + "lp_alienation_risk_df\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1015, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"Security Risk\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {\n", + " \"Airswap Proposal\": 0.429,\n", + " \"Enable deposits Proposal\": 0.286,\n", + " \"USDT liquidity Proposal\": 0.143,\n", + " \"Remove BNT from pools Proposal\": 0.143\n", + " },\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"Airswap Proposal\": 0.429,\n", + " \"Enable deposits Proposal\": 0.286,\n", + " \"USDT liquidity Proposal\": 0.143,\n", + " \"Remove BNT from pools Proposal\": 0.143\n", + " },\n", + " \"local_weights\": {\n", + " \"Airswap Proposal\": 0.429,\n", + " \"Enable deposits Proposal\": 0.286,\n", + " \"USDT liquidity Proposal\": 0.143,\n", + " \"Remove BNT from pools Proposal\": 0.143\n", + " },\n", + " \"consistency_ratio\": 0.0,\n", + " \"random_index\": \"Donegan & Dodd\",\n", + " \"count\": 4,\n", + " \"names\": [\n", + " \"Airswap Proposal\",\n", + " \"USDT liquidity Proposal\",\n", + " \"Remove BNT from pools Proposal\",\n", + " \"Enable deposits Proposal\"\n", + " ]\n", + " },\n", + " \"children\": null,\n", + " \"comparisons\": {\n", + " \"count\": 6,\n", + " \"input\": {\n", + " \"Airswap Proposal, USDT liquidity Proposal\": 3.0,\n", + " \"Airswap Proposal, Remove BNT from pools Proposal\": 3.0,\n", + " \"Airswap Proposal, Enable deposits Proposal\": 1.5,\n", + " \"USDT liquidity Proposal, Remove BNT from pools Proposal\": 1.0,\n", + " \"USDT liquidity Proposal, Enable deposits Proposal\": 0.5,\n", + " \"Remove BNT from pools Proposal, Enable deposits Proposal\": 0.5\n", + " },\n", + " \"computed\": null\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " Airswap Proposal Enable deposits Proposal \\\nSecurity Risk 0.429 0.286 \n\n USDT liquidity Proposal Remove BNT from pools Proposal \nSecurity Risk 0.143 0.143 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Airswap ProposalEnable deposits ProposalUSDT liquidity ProposalRemove BNT from pools Proposal
Security Risk0.4290.2860.1430.143
\n
" + }, + "execution_count": 1015, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "security_risk = ahpy.Compare('Security Risk', security_risk_comparisons, precision=3)\n", + "report = security_risk.report(show=True, verbose=True)\n", + "security_risk_df = pd.DataFrame(security_risk.target_weights, index=['Security Risk'])\n", + "# comparisons.append(security_risk_df)\n", + "security_risk_df" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1016, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"name\": \"Risk\",\n", + " \"global_weight\": 1.0,\n", + " \"local_weight\": 1.0,\n", + " \"target_weights\": {},\n", + " \"elements\": {\n", + " \"global_weights\": {\n", + " \"Enable deposits Proposal\": 0.333,\n", + " \"USDT liquidity Proposal\": 0.259,\n", + " \"Remove BNT from pools Proposal\": 0.222,\n", + " \"Airswap Proposal\": 0.185\n", + " },\n", + " \"local_weights\": {\n", + " \"Enable deposits Proposal\": 0.333,\n", + " \"USDT liquidity Proposal\": 0.259,\n", + " \"Remove BNT from pools Proposal\": 0.222,\n", + " \"Airswap Proposal\": 0.185\n", + " },\n", + " \"consistency_ratio\": 0.0,\n", + " \"random_index\": \"Donegan & Dodd\",\n", + " \"count\": 4,\n", + " \"names\": [\n", + " \"Airswap Proposal\",\n", + " \"USDT liquidity Proposal\",\n", + " \"Remove BNT from pools Proposal\",\n", + " \"Enable deposits Proposal\"\n", + " ]\n", + " },\n", + " \"children\": {\n", + " \"count\": 4,\n", + " \"names\": [\n", + " \"Legal Risk\",\n", + " \"Reputational Risk\",\n", + " \"LP Alienation Risk\",\n", + " \"Security Risk\"\n", + " ]\n", + " },\n", + " \"comparisons\": {\n", + " \"count\": 6,\n", + " \"input\": {\n", + " \"Airswap Proposal, USDT liquidity Proposal\": 0.7142857142857143,\n", + " \"Airswap Proposal, Remove BNT from pools Proposal\": 0.8333333333333334,\n", + " \"Airswap Proposal, Enable deposits Proposal\": 0.5555555555555556,\n", + " \"USDT liquidity Proposal, Remove BNT from pools Proposal\": 1.1666666666666667,\n", + " \"USDT liquidity Proposal, Enable deposits Proposal\": 0.7777777777777778,\n", + " \"Remove BNT from pools Proposal, Enable deposits Proposal\": 0.6666666666666666\n", + " },\n", + " \"computed\": null\n", + " }\n", + "}\n" + ] + }, + { + "data": { + "text/plain": " Enable deposits Proposal USDT liquidity Proposal \\\nRisk 0.333 0.259 \n\n Remove BNT from pools Proposal Airswap Proposal \nRisk 0.222 0.185 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Enable deposits ProposalUSDT liquidity ProposalRemove BNT from pools ProposalAirswap Proposal
Risk0.3330.2590.2220.185
\n
" + }, + "execution_count": 1016, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "risk = ahpy.Compare('Risk', risk_comparisons, precision=3)\n", + "risk.add_children([legal_risk, reputational_risk, lp_alienation_risk, security_risk])\n", + "report = risk.report(show=True, verbose=True)\n", + "risk_df = pd.DataFrame(report['elements']['global_weights'], index=['Risk'])\n", + "comparisons.append(risk_df)\n", + "risk_df" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1017, + "outputs": [ + { + "data": { + "text/plain": " Remove BNT from pools Proposal Airswap Proposal \\\nFees 0.346 0.269 \nResources 0.450 0.400 \nDeficit 0.318 0.273 \nAlignment 0.222 0.259 \nRisk 0.222 0.185 \n\n USDT liquidity Proposal Enable deposits Proposal \nFees 0.192 0.192 \nResources 0.050 0.100 \nDeficit 0.227 0.182 \nAlignment 0.259 0.259 \nRisk 0.259 0.333 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Remove BNT from pools ProposalAirswap ProposalUSDT liquidity ProposalEnable deposits Proposal
Fees0.3460.2690.1920.192
Resources0.4500.4000.0500.100
Deficit0.3180.2730.2270.182
Alignment0.2220.2590.2590.259
Risk0.2220.1850.2590.333
\n
" + }, + "execution_count": 1017, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "comparisons_df = pd.concat(comparisons)\n", + "comparisons_df" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1018, + "outputs": [ + { + "data": { + "text/plain": " Fees Resources Deficit Alignment Risk\nRemove BNT from pools Proposal 0.346 0.45 0.318 0.222 0.222\nAirswap Proposal 0.269 0.40 0.273 0.259 0.185\nUSDT liquidity Proposal 0.192 0.05 0.227 0.259 0.259\nEnable deposits Proposal 0.192 0.10 0.182 0.259 0.333", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
FeesResourcesDeficitAlignmentRisk
Remove BNT from pools Proposal0.3460.450.3180.2220.222
Airswap Proposal0.2690.400.2730.2590.185
USDT liquidity Proposal0.1920.050.2270.2590.259
Enable deposits Proposal0.1920.100.1820.2590.333
\n
" + }, + "execution_count": 1018, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "comparisons_df.T" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1019, + "outputs": [], + "source": [ + "totals = [\n", + " comparisons_df.T.iloc[0].sum(),\n", + " comparisons_df.T.iloc[1].sum(),\n", + " comparisons_df.T.iloc[2].sum(),\n", + " comparisons_df.T.iloc[3].sum(),\n", + "]\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1020, + "outputs": [ + { + "data": { + "text/plain": " Fees Resources Deficit Alignment Risk \\\nRemove BNT from pools Proposal 0.346 0.45 0.318 0.222 0.222 \nAirswap Proposal 0.269 0.40 0.273 0.259 0.185 \nUSDT liquidity Proposal 0.192 0.05 0.227 0.259 0.259 \nEnable deposits Proposal 0.192 0.10 0.182 0.259 0.333 \n\n Total \nRemove BNT from pools Proposal 1.558 \nAirswap Proposal 1.386 \nUSDT liquidity Proposal 0.987 \nEnable deposits Proposal 1.066 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
FeesResourcesDeficitAlignmentRiskTotal
Remove BNT from pools Proposal0.3460.450.3180.2220.2221.558
Airswap Proposal0.2690.400.2730.2590.1851.386
USDT liquidity Proposal0.1920.050.2270.2590.2590.987
Enable deposits Proposal0.1920.100.1820.2590.3331.066
\n
" + }, + "execution_count": 1020, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "comparisons_df=comparisons_df.T\n", + "comparisons_df['Total']=totals\n", + "comparisons_df" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1022, + "outputs": [ + { + "data": { + "text/plain": "Index(['Remove BNT from pools Proposal', 'Airswap Proposal',\n 'USDT liquidity Proposal', 'Enable deposits Proposal'],\n dtype='object')" + }, + "execution_count": 1022, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "comparisons_df.index" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1025, + "outputs": [ + { + "data": { + "text/plain": "(0.9989999999999999, 1.0000000000000002, 1.0)" + }, + "execution_count": 1025, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "comparisons_df['Fees'].sum(),comparisons_df['Resources'].sum(),comparisons_df['Deficit'].sum()" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 1028, + "outputs": [], + "source": [ + "comparisons_df.to_csv('ahp_example.csv')" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/examples/studies/ahp/ahp_example.csv b/examples/studies/ahp/ahp_example.csv new file mode 100644 index 00000000..c0b37d38 --- /dev/null +++ b/examples/studies/ahp/ahp_example.csv @@ -0,0 +1,5 @@ +,Fees,Resources,Deficit,Alignment,Risk,Total +Remove BNT from pools Proposal,0.346,0.45,0.318,0.222,0.222,1.558 +Airswap Proposal,0.269,0.4,0.273,0.259,0.185,1.3860000000000001 +USDT liquidity Proposal,0.192,0.05,0.227,0.259,0.259,0.987 +Enable deposits Proposal,0.192,0.1,0.182,0.259,0.333,1.066 diff --git a/examples/studies/join_tables.ipynb b/examples/studies/join_tables.ipynb new file mode 100644 index 00000000..7de689ed --- /dev/null +++ b/examples/studies/join_tables.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"code","source":["total_liquidity = spark.sql('select * from default.events_poolcollection_totalliquidityupdated_csv')\n\n# convert to python\ntotal_liquidity = total_liquidity.toPandas()\n\n# convert to date\ntotal_liquidity['date'] = total_liquidity['time'].dt.date\n\n# sort by timestamp\ntotal_liquidity = total_liquidity.sort_values('time', ascending=False)\n\n# drop all but the last timestamp\ntotal_liquidity = total_liquidity.drop_duplicates(subset=['date', 'poolSymbol'])\n\n# keep only what we need\ntotal_liquidity = total_liquidity[['date', 'poolSymbol', 'liquidity_real', 'stakedBalance_real', 'poolTokenSupply_real']]\n\n#cleanup\ntotal_liquidity = total_liquidity.rename({'poolSymbol':'targetSymbol'}, axis=1)\ntotal_liquidity"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"169b59db-3107-4a7f-a46c-e48d17450614"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
/databricks/spark/python/pyspark/sql/pandas/utils.py:79: UserWarning: The conversion of DecimalType columns is inefficient and may take a long time. Column names: [liquidity, stakedBalance, poolTokenSupply] If those columns are not necessary, you may consider dropping them or converting to primitive types before the conversion.\n warnings.warn(\nOut[65]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
/databricks/spark/python/pyspark/sql/pandas/utils.py:79: UserWarning: The conversion of DecimalType columns is inefficient and may take a long time. Column names: [liquidity, stakedBalance, poolTokenSupply] If those columns are not necessary, you may consider dropping them or converting to primitive types before the conversion.\n warnings.warn(\nOut[65]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymbolliquidity_realstakedBalance_realpoolTokenSupply_real
74482022-07-31ocean6.912618e+056.843423e+056.843039e+05
74472022-07-31link1.953899e+063.559284e+063.545272e+06
74422022-07-31usdc1.545114e+062.700176e+062.693568e+06
74412022-07-31aave8.895992e+029.905408e+029.896419e+02
74402022-07-31eth8.271622e+031.637554e+041.633647e+04
..................
312022-04-19dai1.718687e+051.718687e+051.718687e+05
302022-04-19eth5.711200e+015.711200e+015.711200e+01
292022-04-18dai1.718457e+051.718457e+051.718457e+05
252022-04-18link1.237110e+041.237110e+041.237110e+04
172022-04-18eth5.710200e+015.710200e+015.710200e+01
\n

1360 rows × 5 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymbolliquidity_realstakedBalance_realpoolTokenSupply_real
74482022-07-31ocean6.912618e+056.843423e+056.843039e+05
74472022-07-31link1.953899e+063.559284e+063.545272e+06
74422022-07-31usdc1.545114e+062.700176e+062.693568e+06
74412022-07-31aave8.895992e+029.905408e+029.896419e+02
74402022-07-31eth8.271622e+031.637554e+041.633647e+04
..................
312022-04-19dai1.718687e+051.718687e+051.718687e+05
302022-04-19eth5.711200e+015.711200e+015.711200e+01
292022-04-18dai1.718457e+051.718457e+051.718457e+05
252022-04-18link1.237110e+041.237110e+041.237110e+04
172022-04-18eth5.710200e+015.710200e+015.710200e+01
\n

1360 rows × 5 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["spot_rates = spark.sql('select * from default.events_v3_historical_spotrates_emarates_parquet')\nspot_rates = spot_rates.toPandas()\nspot_rates = spot_rates.rename({'poolSymbol':'targetSymbol'}, axis=1)\nspot_rates"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"Events - v3_historical_spotrates_emarates","showTitle":true,"inputWidgets":{},"nuid":"db5a4322-b7d1-48b4-b997-a2c974715ae8"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[7]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[7]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
blocknumbertimetargetSymbolspotRateemaRatebntpricespotRate_usdemaRate_usd
0146250662022-04-20dai0.43671402886434593890368199380.43671402886434593890367760802.29666306950168231.0029849820260350271631482421.002984982026035027163138169
1146250662022-04-20eth1345.7501984151451972164296761345.7501984151451972066238392.29666306950168233090.7347814746253594860620343090.734781474625359463541331
2146250662022-04-20link6.0786026200873362445420686876.0786026200873362445414847162.296663069501682313.9605021517307500506563630213.96050215173075005065502183
3146250662022-04-20bnt112.29666306950168232.29666306950168232.2966630695016823
4146313562022-04-21dai0.43671402886434593890367961030.43671402886434593890367760802.28483822096018850.99782090477876858481312510280.9978209047787685848131205279
...........................
4897152533052022-07-31wsteth3150.6054388621830023493250713222.2009550379241684304226910.56871962615807981791.8111473613136602939113921832.528922555375931418315045
4898152533052022-07-31wxt00E+180.56871962615807980E-160E+2
4899152533052022-07-31yfi19095.5864821306620606784298219499.332231128776646389179640.568719626158079810860.0348053866323022593445511089.65293681975395140237928
4900152533052022-07-31zcn0.33738452624082442944750705510.34313245747988842871486082340.56871962615807980.19187720163520253387829387670.1951461629406653599523725750
4901152533052022-07-31bnt110.56871962615807980.56871962615807980.5687196261580798
\n

4902 rows × 8 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
blocknumbertimetargetSymbolspotRateemaRatebntpricespotRate_usdemaRate_usd
0146250662022-04-20dai0.43671402886434593890368199380.43671402886434593890367760802.29666306950168231.0029849820260350271631482421.002984982026035027163138169
1146250662022-04-20eth1345.7501984151451972164296761345.7501984151451972066238392.29666306950168233090.7347814746253594860620343090.734781474625359463541331
2146250662022-04-20link6.0786026200873362445420686876.0786026200873362445414847162.296663069501682313.9605021517307500506563630213.96050215173075005065502183
3146250662022-04-20bnt112.29666306950168232.29666306950168232.2966630695016823
4146313562022-04-21dai0.43671402886434593890367961030.43671402886434593890367760802.28483822096018850.99782090477876858481312510280.9978209047787685848131205279
...........................
4897152533052022-07-31wsteth3150.6054388621830023493250713222.2009550379241684304226910.56871962615807981791.8111473613136602939113921832.528922555375931418315045
4898152533052022-07-31wxt00E+180.56871962615807980E-160E+2
4899152533052022-07-31yfi19095.5864821306620606784298219499.332231128776646389179640.568719626158079810860.0348053866323022593445511089.65293681975395140237928
4900152533052022-07-31zcn0.33738452624082442944750705510.34313245747988842871486082340.56871962615807980.19187720163520253387829387670.1951461629406653599523725750
4901152533052022-07-31bnt110.56871962615807980.56871962615807980.5687196261580798
\n

4902 rows × 8 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["trading_liquidity = spark.sql('select * from default.events_poolcollection_tradingliquidityupdated_spotrates_csv')\n\n# convert to pandas\ntrading_liquidity = trading_liquidity.toPandas()\n\n# convert to date\ntrading_liquidity['date'] = trading_liquidity['time'].dt.date\n\n# sort by datetime\ntrading_liquidity = trading_liquidity.sort_values('time', ascending=False)\n\n# keep only needed columns\ntrading_liquidity = trading_liquidity[[\n 'blocknumber', \n 'date', \n 'poolSymbol', \n 'tknTradingLiquidity_real', \n 'bntTradingLiquidity_real', \n 'spotRate', \n 'price'\n]]\n\ntrading_liquidity = trading_liquidity.rename({'poolSymbol':'targetSymbol'}, axis=1)\ntrading_liquidity"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"Events - poolcollection_tradingliquidityupdated_spotrates","showTitle":true,"inputWidgets":{},"nuid":"de7d552c-ad83-4638-9979-c5d374327bfd"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[4]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[4]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
blocknumberdatetargetSymboltknTradingLiquidity_realbntTradingLiquidity_realspotRateprice
490763151368442022-07-13temp4.063618e+053.579333e+040.0880820.4518
490726151368442022-07-13reth0.000000e+000.000000e+000.0000000.4518
490737151368442022-07-13mfg1.395533e+062.531836e+040.0181420.4518
490736151368442022-07-13usdc9.223219e+052.044195e+062.2163570.4518
490735151368442022-07-13mkr4.071976e+017.632130e+041874.3064530.4518
........................
3146232082022-04-20eth1.486048e+012.000000e+041345.8515282.2800
5146232082022-04-20dai4.580000e+042.000000e+040.4366812.2800
2146232062022-04-20dai4.580000e+042.000000e+040.4366812.2800
1146232062022-04-20eth1.486048e+012.000000e+041345.8515282.2800
0146232022022-04-20eth1.486048e+012.000000e+041345.8515282.2800
\n

490764 rows × 7 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
blocknumberdatetargetSymboltknTradingLiquidity_realbntTradingLiquidity_realspotRateprice
490763151368442022-07-13temp4.063618e+053.579333e+040.0880820.4518
490726151368442022-07-13reth0.000000e+000.000000e+000.0000000.4518
490737151368442022-07-13mfg1.395533e+062.531836e+040.0181420.4518
490736151368442022-07-13usdc9.223219e+052.044195e+062.2163570.4518
490735151368442022-07-13mkr4.071976e+017.632130e+041874.3064530.4518
........................
3146232082022-04-20eth1.486048e+012.000000e+041345.8515282.2800
5146232082022-04-20dai4.580000e+042.000000e+040.4366812.2800
2146232062022-04-20dai4.580000e+042.000000e+040.4366812.2800
1146232062022-04-20eth1.486048e+012.000000e+041345.8515282.2800
0146232022022-04-20eth1.486048e+012.000000e+041345.8515282.2800
\n

490764 rows × 7 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["events_bancornetwork_tokenstraded_updated_csv = spark.sql('select * from default.events_bancornetwork_tokenstraded_updated_csv')\nevents_bancornetwork_tokenstraded_updated_csv = events_bancornetwork_tokenstraded_updated_csv.toPandas()\n\ntrade_count = events_bancornetwork_tokenstraded_updated_csv.groupby(['blocknumber', 'targetSymbol'])[[\n 'sourceAmount_real']].count()\ntrade_count = trade_count.reset_index()\ntrade_count = trade_count.rename({'sourceAmount_real':'trade_count'}, axis=1)\ntrade_count"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"Events - tokenstraded_updated","showTitle":true,"inputWidgets":{},"nuid":"a103bbfe-6824-402d-bda1-07bd5ebd7339"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[2]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[2]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
blocknumbertargetSymboltrade_count
014623625dai1
114623992dai1
214624215dai1
314628426bnt1
414628429bnt1
............
1764115253029wbtc1
1764215253034usdc1
1764315253080woo1
1764415253095wnxm1
1764515253096wnxm1
\n

17646 rows × 3 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
blocknumbertargetSymboltrade_count
014623625dai1
114623992dai1
214624215dai1
314628426bnt1
414628429bnt1
............
1764115253029wbtc1
1764215253034usdc1
1764315253080woo1
1764415253095wnxm1
1764515253096wnxm1
\n

17646 rows × 3 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["trade_count['trade_count'].unique()"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"b1b5c8c8-24b1-404d-b015-e0ac6d93a860"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[3]: array([1, 2, 3, 4, 5, 6])
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[3]: array([1, 2, 3, 4, 5, 6])
"]}}],"execution_count":0},{"cell_type":"code","source":["daily_trades = spark.sql('select * from default.events_combined_tokenstraded_daily_parquet')\ndaily_trades = daily_trades.toPandas()\ndaily_trades"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"Events - combined_tokenstraded_daily","showTitle":true,"inputWidgets":{},"nuid":"49443bb8-0ef4-4776-988a-ab7f88382b7b"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[5]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[5]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
timev2_totalVolume_realv2_totalVolume_real_bntv2_totalVolume_real_usdv2_daily_tx_countv2_daily_trade_countv2_average_trade_size_usdpoolSymbolv2_targetFeeAmount_realv2_targetFeeAmount_real_bntv2_targetFeeAmount_real_usdv2_actualTotalFees_real_usdv2_average_fee_size_usdv3_totalVolume_realv3_totalVolume_real_bntv3_totalVolume_real_usdv3_daily_tx_countv3_daily_trade_countv3_average_trade_size_usdv3_targetFeeAmount_realv3_targetFeeAmount_real_bntv3_targetFeeAmount_real_usdv3_actualTotalFees_real_usdv3_average_fee_size_usd__index_level_0__
02022-01-014608.8483781649357101487918.32250405813792043226094.0301142.0213047.015057aave0.0850728139084229316.71728549104910867522.36856022.36856011.184280000000000000
12022-01-016.564457235883314658595.9298843728002889801975.0003892.02987.5001945alcx0.0131552249216098481.1942482652761527933.9579163.9579161.978958000000000001
22022-01-0115902.2276923574489983163207.42080607809700382310501.2226847.071500.174669142857142857142857aleph30.8798453323131412685.43935057023027154117.81263917.8126392.544662714285714285714285714000000000002
32022-01-0155643.00030295774146874916164.00043703304119950952745.9091534.0413186.47728825alpha99.75843952653367168820.64220733029178738167.28164867.28164816.820412000000000003
42022-01-016289.5253667492842343576289.52536674928423435720692.5384561.0120692.538456amp00000000000000004
..............................................................................
212192022-07-23000000vbnt0000052270.30717181450890992947149.6866082506949277634584423881.134420697950891840571347.071695.485845923437346648596443435.866736553418881934356.8381934185755298295650850180.7370698700110877124994117181.444884564979940024534911725.920697794997134289219273121219
212202022-08-01000000vbnt000008984.0073893475643295338189.0235263673646295626693874625.1604876922875427769956701.012298.73579339341823369147407074.08604310419307560261.9796898608397806785972680235.0061288334023081272717369835.0061288334023081272717369835.0061288334023081272717369821220
212212022-07-27000000wnxm000001806.44132337819122610325393.6970181945200832789582112829.197136911813358579059332.023202.7516277478028307746444224.251678063239722136128.061477355344542374189956264.7020530858141985888783334088.6495216474542981605935333844.3247608237271490802967666921221
212222022-07-21000000wsteth000004660.962833978745278730559.5333854480719568705104399290.39782704754934561579491831.01147.02347274159136927916952210.0001774162103439040.56769984184782154591465892310.29463621791901938232970798110.58619062198489377476470798100.586190621984893774764707981021222
212232022-07-27000000wsteth00000496.8474044759204288682073.6173657685587511477408281041.1699503542200625815345642.02265.29632952274630872319654640.0006498740578305262.1172026415610959171360171511.0633119419749334491838495501.7157216336977402719054495500.85786081684887013595272477521223
\n

21224 rows × 25 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
timev2_totalVolume_realv2_totalVolume_real_bntv2_totalVolume_real_usdv2_daily_tx_countv2_daily_trade_countv2_average_trade_size_usdpoolSymbolv2_targetFeeAmount_realv2_targetFeeAmount_real_bntv2_targetFeeAmount_real_usdv2_actualTotalFees_real_usdv2_average_fee_size_usdv3_totalVolume_realv3_totalVolume_real_bntv3_totalVolume_real_usdv3_daily_tx_countv3_daily_trade_countv3_average_trade_size_usdv3_targetFeeAmount_realv3_targetFeeAmount_real_bntv3_targetFeeAmount_real_usdv3_actualTotalFees_real_usdv3_average_fee_size_usd__index_level_0__
02022-01-014608.8483781649357101487918.32250405813792043226094.0301142.0213047.015057aave0.0850728139084229316.71728549104910867522.36856022.36856011.184280000000000000
12022-01-016.564457235883314658595.9298843728002889801975.0003892.02987.5001945alcx0.0131552249216098481.1942482652761527933.9579163.9579161.978958000000000001
22022-01-0115902.2276923574489983163207.42080607809700382310501.2226847.071500.174669142857142857142857aleph30.8798453323131412685.43935057023027154117.81263917.8126392.544662714285714285714285714000000000002
32022-01-0155643.00030295774146874916164.00043703304119950952745.9091534.0413186.47728825alpha99.75843952653367168820.64220733029178738167.28164867.28164816.820412000000000003
42022-01-016289.5253667492842343576289.52536674928423435720692.5384561.0120692.538456amp00000000000000004
..............................................................................
212192022-07-23000000vbnt0000052270.30717181450890992947149.6866082506949277634584423881.134420697950891840571347.071695.485845923437346648596443435.866736553418881934356.8381934185755298295650850180.7370698700110877124994117181.444884564979940024534911725.920697794997134289219273121219
212202022-08-01000000vbnt000008984.0073893475643295338189.0235263673646295626693874625.1604876922875427769956701.012298.73579339341823369147407074.08604310419307560261.9796898608397806785972680235.0061288334023081272717369835.0061288334023081272717369835.0061288334023081272717369821220
212212022-07-27000000wnxm000001806.44132337819122610325393.6970181945200832789582112829.197136911813358579059332.023202.7516277478028307746444224.251678063239722136128.061477355344542374189956264.7020530858141985888783334088.6495216474542981605935333844.3247608237271490802967666921221
212222022-07-21000000wsteth000004660.962833978745278730559.5333854480719568705104399290.39782704754934561579491831.01147.02347274159136927916952210.0001774162103439040.56769984184782154591465892310.29463621791901938232970798110.58619062198489377476470798100.586190621984893774764707981021222
212232022-07-27000000wsteth00000496.8474044759204288682073.6173657685587511477408281041.1699503542200625815345642.02265.29632952274630872319654640.0006498740578305262.1172026415610959171360171511.0633119419749334491838495501.7157216336977402719054495500.85786081684887013595272477521223
\n

21224 rows × 25 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["events_bancornetwork_tokenstraded_updated_csv = spark.sql('select * from default.events_bancornetwork_tokenstraded_updated_csv')\nevents_bancornetwork_tokenstraded_updated_csv = events_bancornetwork_tokenstraded_updated_csv.toPandas()\nevents_bancornetwork_tokenstraded_updated_csv['date'] = events_bancornetwork_tokenstraded_updated_csv['time'].dt.date\n\ntrade_revenue = events_bancornetwork_tokenstraded_updated_csv.groupby(['date', 'targetSymbol'])[[\n 'sourceAmount_real', \n 'sourceAmount_real_usd', \n 'targetAmount_real', \n 'targetAmount_real_usd', \n 'targetFeeAmount_real',\n 'targetFeeAmount_real_usd']].sum()\n\ntrade_revenue = trade_revenue.reset_index()\ntrade_revenue = trade_revenue.rename({'targetFeeAmount_real':'trade_revenue_real',\n 'targetFeeAmount_real_usd':'trade_revenue_usd'}, axis=1)\ntrade_revenue"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"29788b8c-fa3f-4010-aec9-9e7a7c270702"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
/databricks/spark/python/pyspark/sql/pandas/utils.py:79: UserWarning: The conversion of DecimalType columns is inefficient and may take a long time. Column names: [sourceAmount, targetAmount, bntAmount, targetFeeAmount, bntFeeAmount] If those columns are not necessary, you may consider dropping them or converting to primitive types before the conversion.\n warnings.warn(\nOut[68]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
/databricks/spark/python/pyspark/sql/pandas/utils.py:79: UserWarning: The conversion of DecimalType columns is inefficient and may take a long time. Column names: [sourceAmount, targetAmount, bntAmount, targetFeeAmount, bntFeeAmount] If those columns are not necessary, you may consider dropping them or converting to primitive types before the conversion.\n warnings.warn(\nOut[68]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymbolsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usd
02022-04-20dai0.0030009.1762369.2053429.1407940.0184480.018318
12022-04-21bnt0.0022257.0058212.9879966.9919110.0059880.014012
22022-04-22bnt0.0010003.0275531.3429143.0215570.0026910.006055
32022-04-22dai0.202159601.632956618.054738601.5260211.2385871.205463
42022-04-23bnt0.8564702496.1871591136.4753382511.6104972.2775065.033288
...........................
17962022-07-31wbtc116717.87329262546.1791652.63739362402.5310870.005285125.052651
17972022-07-31wnxm119062.457517119188.1639985622.047552118663.69303656.7883591198.623162
17982022-07-31woo64690.34393654149.251861235042.60667954043.104665471.027268108.302815
17992022-07-31yfi24847.7365562877.6139710.2375862885.9774920.0004765.783522
18002022-07-31zcn1918.9036511026.6206725223.5852621028.94552326.2491725.170581
\n

1801 rows × 8 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymbolsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usd
02022-04-20dai0.0030009.1762369.2053429.1407940.0184480.018318
12022-04-21bnt0.0022257.0058212.9879966.9919110.0059880.014012
22022-04-22bnt0.0010003.0275531.3429143.0215570.0026910.006055
32022-04-22dai0.202159601.632956618.054738601.5260211.2385871.205463
42022-04-23bnt0.8564702496.1871591136.4753382511.6104972.2775065.033288
...........................
17962022-07-31wbtc116717.87329262546.1791652.63739362402.5310870.005285125.052651
17972022-07-31wnxm119062.457517119188.1639985622.047552118663.69303656.7883591198.623162
17982022-07-31woo64690.34393654149.251861235042.60667954043.104665471.027268108.302815
17992022-07-31yfi24847.7365562877.6139710.2375862885.9774920.0004765.783522
18002022-07-31zcn1918.9036511026.6206725223.5852621028.94552326.2491725.170581
\n

1801 rows × 8 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["trades_by_tkn = trade_count.merge(trade_revenue, on=['date', 'targetSymbol'])\ntrades_by_tkn"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"ea4534d8-54ea-48a0-ab89-2d98701a0083"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[69]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[69]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usd
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.018318
12022-04-21bnt30.0022257.0058212.9879966.9919110.0059880.014012
22022-04-22bnt10.0010003.0275531.3429143.0215570.0026910.006055
32022-04-22dai20.202159601.632956618.054738601.5260211.2385871.205463
42022-04-23bnt10.8564702496.1871591136.4753382511.6104972.2775065.033288
..............................
17962022-07-31wbtc22116717.87329262546.1791652.63739362402.5310870.005285125.052651
17972022-07-31wnxm51119062.457517119188.1639985622.047552118663.69303656.7883591198.623162
17982022-07-31woo2964690.34393654149.251861235042.60667954043.104665471.027268108.302815
17992022-07-31yfi624847.7365562877.6139710.2375862885.9774920.0004765.783522
18002022-07-31zcn21918.9036511026.6206725223.5852621028.94552326.2491725.170581
\n

1801 rows × 9 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usd
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.018318
12022-04-21bnt30.0022257.0058212.9879966.9919110.0059880.014012
22022-04-22bnt10.0010003.0275531.3429143.0215570.0026910.006055
32022-04-22dai20.202159601.632956618.054738601.5260211.2385871.205463
42022-04-23bnt10.8564702496.1871591136.4753382511.6104972.2775065.033288
..............................
17962022-07-31wbtc22116717.87329262546.1791652.63739362402.5310870.005285125.052651
17972022-07-31wnxm51119062.457517119188.1639985622.047552118663.69303656.7883591198.623162
17982022-07-31woo2964690.34393654149.251861235042.60667954043.104665471.027268108.302815
17992022-07-31yfi624847.7365562877.6139710.2375862885.9774920.0004765.783522
18002022-07-31zcn21918.9036511026.6206725223.5852621028.94552326.2491725.170581
\n

1801 rows × 9 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["deficit_by_tkn = spark.sql('select * from default.events_v3_historical_deficit_by_tkn_csv')\ndeficit_by_tkn = deficit_by_tkn.toPandas()\ndeficit_by_tkn = deficit_by_tkn.rename({'time': 'date', 'poolSymbol':'targetSymbol'}, axis=1)\ndeficit_by_tkn = deficit_by_tkn.drop(['_c0', 'bntprice'], axis=1)\ndeficit_by_tkn"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":true,"inputWidgets":{},"nuid":"70d33053-89d7-44ea-9b9d-365ad3229cc8"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[10]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[10]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
targetSymbolblocknumberdatesurplus_tknsurplus_bntsurplus_usdsurplus_perc
0dai146250662022-04-20-9.221023e+00-4.026950e+00-9.248547e+00-0.000054
1eth146250662022-04-203.000000e-034.037251e+009.272204e+000.000053
2link146250662022-04-200.000000e+000.000000e+000.000000e+000.000000
3bnt146250662022-04-20-6.862458e-03-6.862458e-03-1.576075e-02-0.000000
4dai146313562022-04-21-9.221023e+00-4.026950e+00-9.200929e+00-0.000036
........................
4803wsteth152469022022-07-30-8.002986e-01-2.578723e+03-1.455777e+03-0.044810
4804wxt152469022022-07-30-7.305932e+04-0.000000e+00-0.000000e+00-0.755542
4805yfi152469022022-07-30-1.200985e+00-2.402642e+04-1.356373e+04-0.202276
4806zcn152469022022-07-30-5.653728e+05-2.004780e+05-1.131767e+05-0.623519
4807bnt152469022022-07-304.081710e+074.081710e+072.304265e+070.934543
\n

4808 rows × 7 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
targetSymbolblocknumberdatesurplus_tknsurplus_bntsurplus_usdsurplus_perc
0dai146250662022-04-20-9.221023e+00-4.026950e+00-9.248547e+00-0.000054
1eth146250662022-04-203.000000e-034.037251e+009.272204e+000.000053
2link146250662022-04-200.000000e+000.000000e+000.000000e+000.000000
3bnt146250662022-04-20-6.862458e-03-6.862458e-03-1.576075e-02-0.000000
4dai146313562022-04-21-9.221023e+00-4.026950e+00-9.200929e+00-0.000036
........................
4803wsteth152469022022-07-30-8.002986e-01-2.578723e+03-1.455777e+03-0.044810
4804wxt152469022022-07-30-7.305932e+04-0.000000e+00-0.000000e+00-0.755542
4805yfi152469022022-07-30-1.200985e+00-2.402642e+04-1.356373e+04-0.202276
4806zcn152469022022-07-30-5.653728e+05-2.004780e+05-1.131767e+05-0.623519
4807bnt152469022022-07-304.081710e+074.081710e+072.304265e+070.934543
\n

4808 rows × 7 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["spot_rates['blocknumber']=spot_rates['blocknumber'].astype(int)\ndeficit_by_tkn['blocknumber']=deficit_by_tkn['blocknumber'].astype(int)\n\ndf = spot_rates.merge(deficit_by_tkn, on=['blocknumber', 'targetSymbol'])\ndf"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"98b71b8f-38ca-4327-bf09-7ba0b9506efa"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[14]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[14]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
blocknumbertimetargetSymbolspotRateemaRatebntpricespotRate_usdemaRate_usddatesurplus_tknsurplus_bntsurplus_usdsurplus_perc
0146250662022-04-20dai0.43671402886434593890368199380.43671402886434593890367760802.29666306950168231.0029849820260350271631482421.0029849820260350271631381692022-04-20-9.221023e+00-4.026950e+00-9.248547e+00-0.000054
1146250662022-04-20eth1345.7501984151451972164296761345.7501984151451972066238392.29666306950168233090.7347814746253594860620343090.7347814746253594635413312022-04-203.000000e-034.037251e+009.272204e+000.000053
2146250662022-04-20link6.0786026200873362445420686876.0786026200873362445414847162.296663069501682313.9605021517307500506563630213.960502151730750050655021832022-04-200.000000e+000.000000e+000.000000e+000.000000
3146250662022-04-20bnt112.29666306950168232.29666306950168232.29666306950168232022-04-20-6.862458e-03-6.862458e-03-1.576075e-02-0.000000
4146313562022-04-21dai0.43671402886434593890367961030.43671402886434593890367760802.28483822096018850.99782090477876858481312510280.99782090477876858481312052792022-04-21-9.221023e+00-4.026950e+00-9.200929e+00-0.000036
..........................................
4803152469022022-07-30wsteth3150.6054388621830023493250713222.2009550379241684304226910.56453418212373471778.6244646226527107615608621819.0425807906513679142299332022-07-30-8.002986e-01-2.578723e+03-1.455777e+03-0.044810
4804152469022022-07-30wxt00E+180.56453418212373470E-160E+22022-07-30-7.305932e+04-0.000000e+00-0.000000e+00-0.755542
4805152469022022-07-30yfi20385.0687760730805663774628720005.589971480669218456372830.564534182123734711508.0681290364980792467675111293.839372452628599498016902022-07-30-1.200985e+00-2.402642e+04-1.356373e+04-0.202276
4806152469022022-07-30zcn0.35112487140151296367058232290.35459434659468854330099218280.56453418212373470.19822199209995464513357269520.20018062944053260743478701022022-07-30-5.653728e+05-2.004780e+05-1.131767e+05-0.623519
4807152469022022-07-30bnt110.56453418212373470.56453418212373470.56453418212373472022-07-304.081710e+074.081710e+072.304265e+070.934543
\n

4808 rows × 13 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
blocknumbertimetargetSymbolspotRateemaRatebntpricespotRate_usdemaRate_usddatesurplus_tknsurplus_bntsurplus_usdsurplus_perc
0146250662022-04-20dai0.43671402886434593890368199380.43671402886434593890367760802.29666306950168231.0029849820260350271631482421.0029849820260350271631381692022-04-20-9.221023e+00-4.026950e+00-9.248547e+00-0.000054
1146250662022-04-20eth1345.7501984151451972164296761345.7501984151451972066238392.29666306950168233090.7347814746253594860620343090.7347814746253594635413312022-04-203.000000e-034.037251e+009.272204e+000.000053
2146250662022-04-20link6.0786026200873362445420686876.0786026200873362445414847162.296663069501682313.9605021517307500506563630213.960502151730750050655021832022-04-200.000000e+000.000000e+000.000000e+000.000000
3146250662022-04-20bnt112.29666306950168232.29666306950168232.29666306950168232022-04-20-6.862458e-03-6.862458e-03-1.576075e-02-0.000000
4146313562022-04-21dai0.43671402886434593890367961030.43671402886434593890367760802.28483822096018850.99782090477876858481312510280.99782090477876858481312052792022-04-21-9.221023e+00-4.026950e+00-9.200929e+00-0.000036
..........................................
4803152469022022-07-30wsteth3150.6054388621830023493250713222.2009550379241684304226910.56453418212373471778.6244646226527107615608621819.0425807906513679142299332022-07-30-8.002986e-01-2.578723e+03-1.455777e+03-0.044810
4804152469022022-07-30wxt00E+180.56453418212373470E-160E+22022-07-30-7.305932e+04-0.000000e+00-0.000000e+00-0.755542
4805152469022022-07-30yfi20385.0687760730805663774628720005.589971480669218456372830.564534182123734711508.0681290364980792467675111293.839372452628599498016902022-07-30-1.200985e+00-2.402642e+04-1.356373e+04-0.202276
4806152469022022-07-30zcn0.35112487140151296367058232290.35459434659468854330099218280.56453418212373470.19822199209995464513357269520.20018062944053260743478701022022-07-30-5.653728e+05-2.004780e+05-1.131767e+05-0.623519
4807152469022022-07-30bnt110.56453418212373470.56453418212373470.56453418212373472022-07-304.081710e+074.081710e+072.304265e+070.934543
\n

4808 rows × 13 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["import pandas as pd\n\ndeficit_by_tkn['date'] = pd.to_datetime(deficit_by_tkn['date']).dt.date\ntrades_by_tkn['date'] = pd.to_datetime(trades_by_tkn['date']).dt.date\ntotal_liquidity['date'] = pd.to_datetime(total_liquidity['date']).dt.date\ntrading_liquidity['date'] = pd.to_datetime(trading_liquidity['date']).dt.date\n\ndf = trades_by_tkn.merge(deficit_by_tkn, on=['date', 'targetSymbol'])\ndf = df.merge(trading_liquidity, on=['date', 'targetSymbol'])\ndf = df.merge(total_liquidity, on=['date', 'targetSymbol'])\n\ndf"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"Primary Joins","showTitle":true,"inputWidgets":{},"nuid":"4ba2918c-a259-49aa-a384-8443740d7ac7"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[71]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[71]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usdbntpricesurplus_tknsurplus_bntsurplus_usdsurplus_perctknTradingLiquidity_realbntTradingLiquidity_realspotRatepriceliquidity_realstakedBalance_realpoolTokenSupply_real
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.0183182.296663-9.221023e+00-4.026950e+00-9.248547e+00-0.0000549.161156e+044.000805e+040.4367142.29001.718604e+051.718697e+051.718697e+05
12022-04-22dai20.202159601.632956618.054738601.5260211.2385871.2054632.231059-6.283286e+02-2.744009e+02-6.122045e+02-0.0018283.202751e+051.404095e+050.4384032.22003.437408e+053.437500e+053.437500e+05
22022-04-25eth11628.1036213614.3900391.2177903649.3991440.0024407.3134252.190786-1.550104e-01-2.076344e+02-4.548826e+02-0.0013371.039690e+021.403459e+051349.8825102.22001.169769e+021.159120e+021.159120e+02
32022-04-26dai37525.70364815846.22945316368.80860315957.23798432.80322431.9784332.214641-2.101020e+04-9.493450e+03-2.102459e+04-0.0305596.197640e+052.918862e+050.4709632.07006.828865e+056.875000e+056.874721e+05
42022-04-26eth12403.6148955071.6274291.8012575103.5023300.00361010.2274602.2146411.366771e+001.827579e+034.047433e+030.0057182.187025e+022.888900e+051320.9269332.07002.388591e+022.390141e+022.390098e+02
..................................................................
5722022-07-13ren31768.6301431315.90653711368.2421051331.75549322.7820482.6688490.439336-2.925943e+04-7.788998e+03-3.421986e+03-0.0741993.650763e+059.888587e+040.2708640.45183.654831e+053.943198e+053.938701e+05
5732022-07-13usdc1112820.58231539171.48915740310.19446440287.308795407.173676406.9425080.439336-1.319153e+06-2.915052e+06-1.280687e+06-0.5382419.223219e+052.044195e+062.2163570.45181.112240e+062.450837e+062.447838e+06
5742022-07-13vbnt1317417.39600417347.15745949549.09584017188.881593754.554759261.7596180.439336-5.969363e+04-4.785695e+04-2.102528e+04-0.0152821.550398e+061.250088e+060.8063020.45183.851069e+063.906057e+063.889583e+06
5752022-07-13wbtc877132.73606540043.3588912.07596339984.6993610.00416080.1289500.439336-1.634478e+02-7.133886e+06-3.134172e+06-0.4837491.746781e+027.624048e+0643646.2708670.45181.746781e+023.378767e+023.378000e+02
5762022-07-13zcn32857.3593031643.0433658442.3908581667.28043942.4240758.3782940.439336-5.465076e+05-2.432456e+05-1.068665e+05-0.6552152.875819e+051.280001e+050.4450910.45182.875819e+058.340895e+058.329419e+05
\n

577 rows × 21 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usdbntpricesurplus_tknsurplus_bntsurplus_usdsurplus_perctknTradingLiquidity_realbntTradingLiquidity_realspotRatepriceliquidity_realstakedBalance_realpoolTokenSupply_real
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.0183182.296663-9.221023e+00-4.026950e+00-9.248547e+00-0.0000549.161156e+044.000805e+040.4367142.29001.718604e+051.718697e+051.718697e+05
12022-04-22dai20.202159601.632956618.054738601.5260211.2385871.2054632.231059-6.283286e+02-2.744009e+02-6.122045e+02-0.0018283.202751e+051.404095e+050.4384032.22003.437408e+053.437500e+053.437500e+05
22022-04-25eth11628.1036213614.3900391.2177903649.3991440.0024407.3134252.190786-1.550104e-01-2.076344e+02-4.548826e+02-0.0013371.039690e+021.403459e+051349.8825102.22001.169769e+021.159120e+021.159120e+02
32022-04-26dai37525.70364815846.22945316368.80860315957.23798432.80322431.9784332.214641-2.101020e+04-9.493450e+03-2.102459e+04-0.0305596.197640e+052.918862e+050.4709632.07006.828865e+056.875000e+056.874721e+05
42022-04-26eth12403.6148955071.6274291.8012575103.5023300.00361010.2274602.2146411.366771e+001.827579e+034.047433e+030.0057182.187025e+022.888900e+051320.9269332.07002.388591e+022.390141e+022.390098e+02
..................................................................
5722022-07-13ren31768.6301431315.90653711368.2421051331.75549322.7820482.6688490.439336-2.925943e+04-7.788998e+03-3.421986e+03-0.0741993.650763e+059.888587e+040.2708640.45183.654831e+053.943198e+053.938701e+05
5732022-07-13usdc1112820.58231539171.48915740310.19446440287.308795407.173676406.9425080.439336-1.319153e+06-2.915052e+06-1.280687e+06-0.5382419.223219e+052.044195e+062.2163570.45181.112240e+062.450837e+062.447838e+06
5742022-07-13vbnt1317417.39600417347.15745949549.09584017188.881593754.554759261.7596180.439336-5.969363e+04-4.785695e+04-2.102528e+04-0.0152821.550398e+061.250088e+060.8063020.45183.851069e+063.906057e+063.889583e+06
5752022-07-13wbtc877132.73606540043.3588912.07596339984.6993610.00416080.1289500.439336-1.634478e+02-7.133886e+06-3.134172e+06-0.4837491.746781e+027.624048e+0643646.2708670.45181.746781e+023.378767e+023.378000e+02
5762022-07-13zcn32857.3593031643.0433658442.3908581667.28043942.4240758.3782940.439336-5.465076e+05-2.432456e+05-1.068665e+05-0.6552152.875819e+051.280001e+050.4450910.45182.875819e+058.340895e+058.329419e+05
\n

577 rows × 21 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["df = df.sort_values(['date', 'targetSymbol', 'trade_count'])\ndf\n"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"776385dc-a9c9-42ce-b5c5-6f4329dec998"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[72]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[72]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usdbntpricesurplus_tknsurplus_bntsurplus_usdsurplus_perctknTradingLiquidity_realbntTradingLiquidity_realspotRatepriceliquidity_realstakedBalance_realpoolTokenSupply_real
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.0183182.296663-9.221023e+00-4.026950e+00-9.248547e+00-0.0000549.161156e+044.000805e+040.4367142.29001.718604e+051.718697e+051.718697e+05
12022-04-22dai20.202159601.632956618.054738601.5260211.2385871.2054632.231059-6.283286e+02-2.744009e+02-6.122045e+02-0.0018283.202751e+051.404095e+050.4384032.22003.437408e+053.437500e+053.437500e+05
22022-04-25eth11628.1036213614.3900391.2177903649.3991440.0024407.3134252.190786-1.550104e-01-2.076344e+02-4.548826e+02-0.0013371.039690e+021.403459e+051349.8825102.22001.169769e+021.159120e+021.159120e+02
32022-04-26dai37525.70364815846.22945316368.80860315957.23798432.80322431.9784332.214641-2.101020e+04-9.493450e+03-2.102459e+04-0.0305596.197640e+052.918862e+050.4709632.07006.828865e+056.875000e+056.874721e+05
42022-04-26eth12403.6148955071.6274291.8012575103.5023300.00361010.2274602.2146411.366771e+001.827579e+034.047433e+030.0057182.187025e+022.888900e+051320.9269332.07002.388591e+022.390141e+022.390098e+02
..................................................................
5722022-07-13ren31768.6301431315.90653711368.2421051331.75549322.7820482.6688490.439336-2.925943e+04-7.788998e+03-3.421986e+03-0.0741993.650763e+059.888587e+040.2708640.45183.654831e+053.943198e+053.938701e+05
5732022-07-13usdc1112820.58231539171.48915740310.19446440287.308795407.173676406.9425080.439336-1.319153e+06-2.915052e+06-1.280687e+06-0.5382419.223219e+052.044195e+062.2163570.45181.112240e+062.450837e+062.447838e+06
5742022-07-13vbnt1317417.39600417347.15745949549.09584017188.881593754.554759261.7596180.439336-5.969363e+04-4.785695e+04-2.102528e+04-0.0152821.550398e+061.250088e+060.8063020.45183.851069e+063.906057e+063.889583e+06
5752022-07-13wbtc877132.73606540043.3588912.07596339984.6993610.00416080.1289500.439336-1.634478e+02-7.133886e+06-3.134172e+06-0.4837491.746781e+027.624048e+0643646.2708670.45181.746781e+023.378767e+023.378000e+02
5762022-07-13zcn32857.3593031643.0433658442.3908581667.28043942.4240758.3782940.439336-5.465076e+05-2.432456e+05-1.068665e+05-0.6552152.875819e+051.280001e+050.4450910.45182.875819e+058.340895e+058.329419e+05
\n

577 rows × 21 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usdbntpricesurplus_tknsurplus_bntsurplus_usdsurplus_perctknTradingLiquidity_realbntTradingLiquidity_realspotRatepriceliquidity_realstakedBalance_realpoolTokenSupply_real
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.0183182.296663-9.221023e+00-4.026950e+00-9.248547e+00-0.0000549.161156e+044.000805e+040.4367142.29001.718604e+051.718697e+051.718697e+05
12022-04-22dai20.202159601.632956618.054738601.5260211.2385871.2054632.231059-6.283286e+02-2.744009e+02-6.122045e+02-0.0018283.202751e+051.404095e+050.4384032.22003.437408e+053.437500e+053.437500e+05
22022-04-25eth11628.1036213614.3900391.2177903649.3991440.0024407.3134252.190786-1.550104e-01-2.076344e+02-4.548826e+02-0.0013371.039690e+021.403459e+051349.8825102.22001.169769e+021.159120e+021.159120e+02
32022-04-26dai37525.70364815846.22945316368.80860315957.23798432.80322431.9784332.214641-2.101020e+04-9.493450e+03-2.102459e+04-0.0305596.197640e+052.918862e+050.4709632.07006.828865e+056.875000e+056.874721e+05
42022-04-26eth12403.6148955071.6274291.8012575103.5023300.00361010.2274602.2146411.366771e+001.827579e+034.047433e+030.0057182.187025e+022.888900e+051320.9269332.07002.388591e+022.390141e+022.390098e+02
..................................................................
5722022-07-13ren31768.6301431315.90653711368.2421051331.75549322.7820482.6688490.439336-2.925943e+04-7.788998e+03-3.421986e+03-0.0741993.650763e+059.888587e+040.2708640.45183.654831e+053.943198e+053.938701e+05
5732022-07-13usdc1112820.58231539171.48915740310.19446440287.308795407.173676406.9425080.439336-1.319153e+06-2.915052e+06-1.280687e+06-0.5382419.223219e+052.044195e+062.2163570.45181.112240e+062.450837e+062.447838e+06
5742022-07-13vbnt1317417.39600417347.15745949549.09584017188.881593754.554759261.7596180.439336-5.969363e+04-4.785695e+04-2.102528e+04-0.0152821.550398e+061.250088e+060.8063020.45183.851069e+063.906057e+063.889583e+06
5752022-07-13wbtc877132.73606540043.3588912.07596339984.6993610.00416080.1289500.439336-1.634478e+02-7.133886e+06-3.134172e+06-0.4837491.746781e+027.624048e+0643646.2708670.45181.746781e+023.378767e+023.378000e+02
5762022-07-13zcn32857.3593031643.0433658442.3908581667.28043942.4240758.3782940.439336-5.465076e+05-2.432456e+05-1.068665e+05-0.6552152.875819e+051.280001e+050.4450910.45182.875819e+058.340895e+058.329419e+05
\n

577 rows × 21 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["df = df.drop_duplicates(subset=['date','targetSymbol'])\ndf"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"c55edb7b-4ce9-491e-a4ff-a47903fad180"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[76]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[76]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usdbntpricesurplus_tknsurplus_bntsurplus_usdsurplus_perctknTradingLiquidity_realbntTradingLiquidity_realspotRatepriceliquidity_realstakedBalance_realpoolTokenSupply_real
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.0183182.296663-9.221023e+00-4.026950e+00-9.248547e+00-0.0000549.161156e+044.000805e+040.4367142.29001.718604e+051.718697e+051.718697e+05
12022-04-22dai20.202159601.632956618.054738601.5260211.2385871.2054632.231059-6.283286e+02-2.744009e+02-6.122045e+02-0.0018283.202751e+051.404095e+050.4384032.22003.437408e+053.437500e+053.437500e+05
22022-04-25eth11628.1036213614.3900391.2177903649.3991440.0024407.3134252.190786-1.550104e-01-2.076344e+02-4.548826e+02-0.0013371.039690e+021.403459e+051349.8825102.22001.169769e+021.159120e+021.159120e+02
32022-04-26dai37525.70364815846.22945316368.80860315957.23798432.80322431.9784332.214641-2.101020e+04-9.493450e+03-2.102459e+04-0.0305596.197640e+052.918862e+050.4709632.07006.828865e+056.875000e+056.874721e+05
42022-04-26eth12403.6148955071.6274291.8012575103.5023300.00361010.2274602.2146411.366771e+001.827579e+034.047433e+030.0057182.187025e+022.888900e+051320.9269332.07002.388591e+022.390141e+022.390098e+02
..................................................................
5722022-07-13ren31768.6301431315.90653711368.2421051331.75549322.7820482.6688490.439336-2.925943e+04-7.788998e+03-3.421986e+03-0.0741993.650763e+059.888587e+040.2708640.45183.654831e+053.943198e+053.938701e+05
5732022-07-13usdc1112820.58231539171.48915740310.19446440287.308795407.173676406.9425080.439336-1.319153e+06-2.915052e+06-1.280687e+06-0.5382419.223219e+052.044195e+062.2163570.45181.112240e+062.450837e+062.447838e+06
5742022-07-13vbnt1317417.39600417347.15745949549.09584017188.881593754.554759261.7596180.439336-5.969363e+04-4.785695e+04-2.102528e+04-0.0152821.550398e+061.250088e+060.8063020.45183.851069e+063.906057e+063.889583e+06
5752022-07-13wbtc877132.73606540043.3588912.07596339984.6993610.00416080.1289500.439336-1.634478e+02-7.133886e+06-3.134172e+06-0.4837491.746781e+027.624048e+0643646.2708670.45181.746781e+023.378767e+023.378000e+02
5762022-07-13zcn32857.3593031643.0433658442.3908581667.28043942.4240758.3782940.439336-5.465076e+05-2.432456e+05-1.068665e+05-0.6552152.875819e+051.280001e+050.4450910.45182.875819e+058.340895e+058.329419e+05
\n

577 rows × 21 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usdbntpricesurplus_tknsurplus_bntsurplus_usdsurplus_perctknTradingLiquidity_realbntTradingLiquidity_realspotRatepriceliquidity_realstakedBalance_realpoolTokenSupply_real
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.0183182.296663-9.221023e+00-4.026950e+00-9.248547e+00-0.0000549.161156e+044.000805e+040.4367142.29001.718604e+051.718697e+051.718697e+05
12022-04-22dai20.202159601.632956618.054738601.5260211.2385871.2054632.231059-6.283286e+02-2.744009e+02-6.122045e+02-0.0018283.202751e+051.404095e+050.4384032.22003.437408e+053.437500e+053.437500e+05
22022-04-25eth11628.1036213614.3900391.2177903649.3991440.0024407.3134252.190786-1.550104e-01-2.076344e+02-4.548826e+02-0.0013371.039690e+021.403459e+051349.8825102.22001.169769e+021.159120e+021.159120e+02
32022-04-26dai37525.70364815846.22945316368.80860315957.23798432.80322431.9784332.214641-2.101020e+04-9.493450e+03-2.102459e+04-0.0305596.197640e+052.918862e+050.4709632.07006.828865e+056.875000e+056.874721e+05
42022-04-26eth12403.6148955071.6274291.8012575103.5023300.00361010.2274602.2146411.366771e+001.827579e+034.047433e+030.0057182.187025e+022.888900e+051320.9269332.07002.388591e+022.390141e+022.390098e+02
..................................................................
5722022-07-13ren31768.6301431315.90653711368.2421051331.75549322.7820482.6688490.439336-2.925943e+04-7.788998e+03-3.421986e+03-0.0741993.650763e+059.888587e+040.2708640.45183.654831e+053.943198e+053.938701e+05
5732022-07-13usdc1112820.58231539171.48915740310.19446440287.308795407.173676406.9425080.439336-1.319153e+06-2.915052e+06-1.280687e+06-0.5382419.223219e+052.044195e+062.2163570.45181.112240e+062.450837e+062.447838e+06
5742022-07-13vbnt1317417.39600417347.15745949549.09584017188.881593754.554759261.7596180.439336-5.969363e+04-4.785695e+04-2.102528e+04-0.0152821.550398e+061.250088e+060.8063020.45183.851069e+063.906057e+063.889583e+06
5752022-07-13wbtc877132.73606540043.3588912.07596339984.6993610.00416080.1289500.439336-1.634478e+02-7.133886e+06-3.134172e+06-0.4837491.746781e+027.624048e+0643646.2708670.45181.746781e+023.378767e+023.378000e+02
5762022-07-13zcn32857.3593031643.0433658442.3908581667.28043942.4240758.3782940.439336-5.465076e+05-2.432456e+05-1.068665e+05-0.6552152.875819e+051.280001e+050.4450910.45182.875819e+058.340895e+058.329419e+05
\n

577 rows × 21 columns

\n
"]}}],"execution_count":0},{"cell_type":"code","source":["df['trade_revenue_real_rolling_7day_avg'] = df[\n 'trade_revenue_real'\n].rolling(7, min_periods=1).mean()\n\ndf['trade_revenue_usd_rolling_7day_avg'] = df[\n 'trade_revenue_usd'\n].rolling(7, min_periods=1).mean()\n\ndf['trade_revenue_real_rolling_30day_avg'] = df[\n 'trade_revenue_real'\n].rolling(30, min_periods=1).mean()\n\ndf['trade_revenue_usd_rolling_30day_avg'] = df[\n 'trade_revenue_usd'\n].rolling(30, min_periods=1).mean()\n\ndf"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"c8604fe0-55a1-47e9-b78d-7de5739a9b1e"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0},{"cell_type":"code","source":["import mlflow\n\nfilepath = '/dbfs/FileStore/tables/research/preprocessed_tradingliquidity_vs_deficit.csv'\ndf.to_csv(filepath, index=False)\nmlflow.log_artifact(filepath)\n"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"d25989ae-f719-41b6-8106-5fc5f880a729"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0}],"metadata":{"application/vnd.databricks.v1+notebook":{"notebookName":"join_tables","dashboards":[],"notebookMetadata":{"pythonIndentUnit":4},"language":"python","widgets":{},"notebookOrigID":1744197420073310}},"nbformat":4,"nbformat_minor":0} diff --git a/examples/studies/limit_max_on_curve_liquidity/proposal_with_data.ipynb b/examples/studies/limit_max_on_curve_liquidity/proposal_with_data.ipynb new file mode 100644 index 00000000..a5cfb649 --- /dev/null +++ b/examples/studies/limit_max_on_curve_liquidity/proposal_with_data.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"markdown","source":["Welcome to the Bancor Governance Forum. In this forum, the BancorDAO (Decentralized Autonomous Organization) proposes and discusses token Whitelistings, Trading liquidity limits, Fee changes, Bancor Improvement Proposals, and others.\n\nPlease head on to the [Information and Templates](https://gov.bancor.network/c/information-and-templates/16) category for more information on the DAO process.\n\nVoting happens on the [BancorDAO Snapshot Page](https://vote.bancor.network/)."],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"681b934a-2625-4070-9b66-ba81e5913b98"}}},{"cell_type":"markdown","source":["[Proposal: Limit on-curve liquidity to max(520 x 7 day fees, 100k BNT)](https://gov.bancor.network/t/proposal-limit-on-curve-liquidity-to-max-520-x-7-day-fees-100k-bnt/3876)\n=============================================================================================================================================================================\n\n[LEVEL 1 Under Review](https://gov.bancor.network/c/level-1-under-review/14)\n\n\n![](https://dub2.discourse-cdn.com/standard20/user_avatar/gov.bancor.network/thedavidmeister/90/129_2.png)\n\n[thedavidmeister](https://gov.bancor.network/u/thedavidmeister)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"4efeefaa-431b-4ede-b2d6-9f53729739b3"}}},{"cell_type":"markdown","source":["TLDR:\n\n- We pay IL on 100% of TKN available for trading\n- We get diminishing returns on new fees per unit of trading liquidity\n- If IL > fees then the protocol dies (and is already in crisis due to existing deficits)\n- B3 has the unique ability to set a cap on trading liquidity\n- Taking capital off-curve has a dual benefit of limiting IL exposure AND making it available to other revenue opportunities (native staking etc.)\n- Currently the protocol deficit increases when ETH price increases by ~1.5x annually relative to BNT, making some assumptions, we could lift this to the protocol being profitable up to a ~4x ETH annual moon relative to BNT by limiting the on-curve trading liquidity to 520x 7 day trading fees + implementing some modest staking model (or similar)\n- We should set a simple cap based on the data we have and commission a more sophisticated model in the near future\n\nProposal:\n\nWhen we look at the IL curve:\n\n![image](https://aws1.discourse-cdn.com/standard20/uploads/bancordao/optimized/2X/e/e0d10c4f716b77cc23de68cb160db8c6e9dc28e1_2_690x387.png)\n\n\nWe see that the losses due to IL are a % of all the capital deployed on the trading curve.\n\nIf TKN moons 2x relative to BNT then the IL is ~10%, a 4x moon has ~20% IL, etc.\n\nMeanwhile there are only so many fees due to trade volume across all of defi and almost all trades through bancor currently are based on arbitrage and aggregators only. That is to say, there is negligible trading being done directly on bancor due to retail etc. as that market is largely monopolized by aggregators and a few platforms that take the lion's share of human traders such as uniswap.\n\nIn considering this proposal, please consider mainly how arb bots and aggregators will respond, not human traders, as the former is 10x+ the latter in terms of protocol fee generation."],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"c7149321-2b9a-4cd0-878e-58e5b2367f38"}}},{"cell_type":"markdown","source":["Import Data"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"c318fe9f-fd11-412f-a9b5-67d55e934f7d"}}},{"cell_type":"code","source":["import pandas as pd\n\nfilepath = 'https://bancorml.s3.us-east-2.amazonaws.com/preprocessed_tradingliquidity_vs_deficit-3.csv'\ndf = pd.read_csv(filepath)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"30b026a9-3151-42ac-be60-50b5be44630f"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0},{"cell_type":"markdown","source":["Calculate Rolling Average Fee Revenue"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"8beb4fef-7b8f-4fa8-8b4c-75147450ce02"}}},{"cell_type":"code","source":["# For 7 day rolling averages\ndf['trade_revenue_real_rolling_7day_avg'] = df.groupby(['date', 'targetSymbol'])['trade_revenue_real'].rolling(7, min_periods=1).mean().reset_index(drop=True)\ndf['trade_revenue_usd_rolling_7day_avg'] = df.groupby(['date', 'targetSymbol'])['trade_revenue_usd'].rolling(7, min_periods=1).mean().reset_index(drop=True)\n\n# For 30 day rolling averages\ndf['trade_revenue_real_rolling_30day_avg'] = df.groupby(['date', 'targetSymbol'])['trade_revenue_real'].rolling(30, min_periods=1).mean().reset_index(drop=True)\ndf['trade_revenue_usd_rolling_30day_avg'] = df.groupby(['date', 'targetSymbol'])['trade_revenue_usd'].rolling(30, min_periods=1).mean().reset_index(drop=True)\ndf"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"5fb7205f-c2f8-4a49-b724-6129a472b5e4"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[29]:
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[29]:
"]}},{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usdbntpricesurplus_tknsurplus_bntsurplus_usdsurplus_perctknTradingLiquidity_realbntTradingLiquidity_realspotRatepriceliquidity_realstakedBalance_realpoolTokenSupply_realtrade_revenue_real_rolling_7day_avgtrade_revenue_usd_rolling_7day_avgtrade_revenue_real_rolling_30day_avgtrade_revenue_usd_rolling_30day_avg
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.0183182.296663-9.221023e+00-4.026950e+00-9.248547e+00-0.0000549.161156e+044.000805e+040.4367142.29001.718604e+051.718697e+051.718697e+050.0184480.0183180.0184480.018318
12022-04-22dai20.202159601.632956618.054738601.5260211.2385871.2054632.231059-6.283286e+02-2.744009e+02-6.122045e+02-0.0018283.202751e+051.404095e+050.4384032.22003.437408e+053.437500e+053.437500e+051.2385871.2054631.2385871.205463
22022-04-25eth11628.1036213614.3900391.2177903649.3991440.0024407.3134252.190786-1.550104e-01-2.076344e+02-4.548826e+02-0.0013371.039690e+021.403459e+051349.8825102.22001.169769e+021.159120e+021.159120e+020.0024407.3134250.0024407.313425
32022-04-26dai37525.70364815846.22945316368.80860315957.23798432.80322431.9784332.214641-2.101020e+04-9.493450e+03-2.102459e+04-0.0305596.197640e+052.918862e+050.4709632.07006.828865e+056.875000e+056.874721e+0532.80322431.97843332.80322431.978433
42022-04-26eth12403.6148955071.6274291.8012575103.5023300.00361010.2274602.2146411.366771e+001.827579e+034.047433e+030.0057182.187025e+022.888900e+051320.9269332.07002.388591e+022.390141e+022.390098e+020.00361010.2274600.00361010.227460
..............................................................................
5722022-07-13ren31768.6301431315.90653711368.2421051331.75549322.7820482.6688490.439336-2.925943e+04-7.788998e+03-3.421986e+03-0.0741993.650763e+059.888587e+040.2708640.45183.654831e+053.943198e+053.938701e+0522.7820482.66884922.7820482.668849
5732022-07-13usdc1112820.58231539171.48915740310.19446440287.308795407.173676406.9425080.439336-1.319153e+06-2.915052e+06-1.280687e+06-0.5382419.223219e+052.044195e+062.2163570.45181.112240e+062.450837e+062.447838e+06407.173676406.942508407.173676406.942508
5742022-07-13vbnt1317417.39600417347.15745949549.09584017188.881593754.554759261.7596180.439336-5.969363e+04-4.785695e+04-2.102528e+04-0.0152821.550398e+061.250088e+060.8063020.45183.851069e+063.906057e+063.889583e+06754.554759261.759618754.554759261.759618
5752022-07-13wbtc877132.73606540043.3588912.07596339984.6993610.00416080.1289500.439336-1.634478e+02-7.133886e+06-3.134172e+06-0.4837491.746781e+027.624048e+0643646.2708670.45181.746781e+023.378767e+023.378000e+020.00416080.1289500.00416080.128950
5762022-07-13zcn32857.3593031643.0433658442.3908581667.28043942.4240758.3782940.439336-5.465076e+05-2.432456e+05-1.068665e+05-0.6552152.875819e+051.280001e+050.4450910.45182.875819e+058.340895e+058.329419e+0542.4240758.37829442.4240758.378294
\n

577 rows × 25 columns

\n
","textData":null,"removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"htmlSandbox","arguments":{}}},"output_type":"display_data","data":{"text/html":["
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
datetargetSymboltrade_countsourceAmount_realsourceAmount_real_usdtargetAmount_realtargetAmount_real_usdtrade_revenue_realtrade_revenue_usdbntpricesurplus_tknsurplus_bntsurplus_usdsurplus_perctknTradingLiquidity_realbntTradingLiquidity_realspotRatepriceliquidity_realstakedBalance_realpoolTokenSupply_realtrade_revenue_real_rolling_7day_avgtrade_revenue_usd_rolling_7day_avgtrade_revenue_real_rolling_30day_avgtrade_revenue_usd_rolling_30day_avg
02022-04-20dai30.0030009.1762369.2053429.1407940.0184480.0183182.296663-9.221023e+00-4.026950e+00-9.248547e+00-0.0000549.161156e+044.000805e+040.4367142.29001.718604e+051.718697e+051.718697e+050.0184480.0183180.0184480.018318
12022-04-22dai20.202159601.632956618.054738601.5260211.2385871.2054632.231059-6.283286e+02-2.744009e+02-6.122045e+02-0.0018283.202751e+051.404095e+050.4384032.22003.437408e+053.437500e+053.437500e+051.2385871.2054631.2385871.205463
22022-04-25eth11628.1036213614.3900391.2177903649.3991440.0024407.3134252.190786-1.550104e-01-2.076344e+02-4.548826e+02-0.0013371.039690e+021.403459e+051349.8825102.22001.169769e+021.159120e+021.159120e+020.0024407.3134250.0024407.313425
32022-04-26dai37525.70364815846.22945316368.80860315957.23798432.80322431.9784332.214641-2.101020e+04-9.493450e+03-2.102459e+04-0.0305596.197640e+052.918862e+050.4709632.07006.828865e+056.875000e+056.874721e+0532.80322431.97843332.80322431.978433
42022-04-26eth12403.6148955071.6274291.8012575103.5023300.00361010.2274602.2146411.366771e+001.827579e+034.047433e+030.0057182.187025e+022.888900e+051320.9269332.07002.388591e+022.390141e+022.390098e+020.00361010.2274600.00361010.227460
..............................................................................
5722022-07-13ren31768.6301431315.90653711368.2421051331.75549322.7820482.6688490.439336-2.925943e+04-7.788998e+03-3.421986e+03-0.0741993.650763e+059.888587e+040.2708640.45183.654831e+053.943198e+053.938701e+0522.7820482.66884922.7820482.668849
5732022-07-13usdc1112820.58231539171.48915740310.19446440287.308795407.173676406.9425080.439336-1.319153e+06-2.915052e+06-1.280687e+06-0.5382419.223219e+052.044195e+062.2163570.45181.112240e+062.450837e+062.447838e+06407.173676406.942508407.173676406.942508
5742022-07-13vbnt1317417.39600417347.15745949549.09584017188.881593754.554759261.7596180.439336-5.969363e+04-4.785695e+04-2.102528e+04-0.0152821.550398e+061.250088e+060.8063020.45183.851069e+063.906057e+063.889583e+06754.554759261.759618754.554759261.759618
5752022-07-13wbtc877132.73606540043.3588912.07596339984.6993610.00416080.1289500.439336-1.634478e+02-7.133886e+06-3.134172e+06-0.4837491.746781e+027.624048e+0643646.2708670.45181.746781e+023.378767e+023.378000e+020.00416080.1289500.00416080.128950
5762022-07-13zcn32857.3593031643.0433658442.3908581667.28043942.4240758.3782940.439336-5.465076e+05-2.432456e+05-1.068665e+05-0.6552152.875819e+051.280001e+050.4450910.45182.875819e+058.340895e+058.329419e+0542.4240758.37829442.4240758.378294
\n

577 rows × 25 columns

\n
"]}}],"execution_count":0},{"cell_type":"markdown","source":["[](https://gov.bancor.network/t/proposal-limit-on-curve-liquidity-to-max-520-x-7-day-fees-100k-bnt/3876/1#current-situation-1)Current situation\n-----------------------------------------------------------------------------------------------------------------------------------------------\n\nLet's look at how that translates to the current state of play for ETH.\n\nThere is 8807 ETH on the trading curve right now:\n\n![image](https://aws1.discourse-cdn.com/standard20/uploads/bancordao/original/2X/7/7fc569f4bf2f391578b84463ea82683fd815b20d.png)"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"bebfedd4-6b11-4eef-94a1-3d6b8c65730d"}}},{"cell_type":"markdown","source":["Get the latest date in the dataset:"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"ea01a7ac-32a5-4422-afc1-93ab9c723cc1"}}},{"cell_type":"code","source":["latest_date = df.sort_values('date', ascending=False)['date'].values[0]\nlatest_date"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"e8aba016-3643-403c-a470-81b2324264e3"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[30]: '2022-07-13'
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[30]: '2022-07-13'
"]}}],"execution_count":0},{"cell_type":"markdown","source":["Based on the above, set `oncurve_eth` and `token_symbol` constants:"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"468ca5b7-0e4d-4765-8839-f89d49062352"}}},{"cell_type":"code","source":["token_symbol = 'eth'"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"a14c9306-d442-44b5-8ce2-79bab7878ef5"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
"]}}],"execution_count":0},{"cell_type":"code","source":["oncurve_eth = int(round(df[(df['date']==latest_date) & (df['targetSymbol']==token_symbol)]['tknTradingLiquidity_real'].values[0]))\noncurve_eth"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"99a3c628-d264-4ea7-9e2d-617f2d4b6d68"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Out[32]: 9724
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Out[32]: 9724
"]}}],"execution_count":0},{"cell_type":"markdown","source":["30 day rolling average ETH fees are:"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"aa51a4c9-ad48-49a0-aaba-2c626a33d6bf"}}},{"cell_type":"code","source":["eth_rolling_30day_real_avg = df[(df['date']==latest_date) & (df['targetSymbol']==token_symbol)]['trade_revenue_real_rolling_30day_avg'].values[0]\n\neth_rolling_30day_usd_avg = df[(df['date']==latest_date) & (df['targetSymbol']==token_symbol)]['trade_revenue_usd_rolling_30day_avg'].values[0]\n\nprint(f'\\033[1m 30 day rolling avg: {eth_rolling_30day_real_avg} (real/day) \\033[1m \\n')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"52eb8924-e303-4cc7-a5c2-d8655b246d92"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
30 day rolling avg: 0.5032507641136772 (real/day) \n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
30 day rolling avg: 0.5032507641136772 (real/day) \n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["print(f'\\033[1m 30 day rolling avg: {eth_rolling_30day_usd_avg} (usd/day) \\033[1m')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"b9b9b980-07fe-4e3a-b533-26be6ea5e10d"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
30 day rolling avg: 532.0927496151701 (usd/day) \n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
30 day rolling avg: 532.0927496151701 (usd/day) \n
"]}}],"execution_count":0},{"cell_type":"markdown","source":["Estimated 7 day ETH fees are:"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"7f621e21-6cea-42b0-b991-fa8ecc906c3a"}}},{"cell_type":"code","source":["estimated_7day_eth_fees_real = eth_rolling_30day_real_avg * 7\nestimated_7day_eth_fees_usd = eth_rolling_30day_usd_avg * 7\n\nprint(f'\\033[1m Estimated 7 day ETH fees: {estimated_7day_eth_fees_real} (real) \\033[1m \\n')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"2a835fe0-7fea-402a-b811-f55b1a87c911"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Estimated 7 day ETH fees: 3.5227553487957404 (real) \n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Estimated 7 day ETH fees: 3.5227553487957404 (real) \n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["print(f'\\033[1m Estimated 7 day ETH fees: {estimated_7day_eth_fees_usd} (usd) \\033[1m')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"7ca63500-0877-4fde-8055-70dbf1fb9dfb"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
Estimated 7 day ETH fees: 3724.649247306191 (usd) \n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
Estimated 7 day ETH fees: 3724.649247306191 (usd) \n
"]}}],"execution_count":0},{"cell_type":"markdown","source":["Comparing the above to prior naive estimate (limited data):\n\n![image](https://aws1.discourse-cdn.com/standard20/uploads/bancordao/original/2X/3/3b2d3eb390e5564193283285bad0d7a4a333cf53.png)\n\nIf we annualize the estimated fees we get:"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":true,"inputWidgets":{},"nuid":"386e63bd-882d-4834-9477-406569bf005c"}}},{"cell_type":"code","source":["eth_annualized = round(52 * estimated_7day_eth_fees_real, 2)\neth_annualized_percent_of_oncurve = round((eth_annualized / oncurve_eth) * 100, 2)\n\nprint(f'\\033[1m ETH Fees annualized: {eth_annualized} (real) \\033[1m \\n')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"d87952a5-06e6-4320-bf8e-c32471167ee2"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
ETH Fees annualized: 183.18 (real) \n\n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
ETH Fees annualized: 183.18 (real) \n\n
"]}}],"execution_count":0},{"cell_type":"code","source":["print(f'\\033[1m ETH Fees annualized as a percent of ETH on curve: {eth_annualized_percent_of_oncurve} (%) \\033[1m')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"1bdc4c18-33ef-4e3a-838c-1a9bf75fcc1d"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
ETH Fees annualized as a percent of ETH on curve: 1.88 (%) \n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
ETH Fees annualized as a percent of ETH on curve: 1.88 (%) \n
"]}}],"execution_count":0},{"cell_type":"markdown","source":["Setting aside mechanics like leveraged vortexing for the moment, the baseline is that the protocol will break even on ETH if IL on 8800 ETH is 1.29% or less, relative to BNT."],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"ea3f9edb-7889-4071-843e-9964859675f4"}}},{"cell_type":"markdown","source":["That means that if ETH increases by just 50% relative to BNT over a year, all else equal, the protocol loses ETH and the deficit increases."],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"468ba4f4-545d-4e15-b70d-9f2e160e4de6"}}},{"cell_type":"markdown","source":["[](https://gov.bancor.network/t/proposal-limit-on-curve-liquidity-to-max-520-x-7-day-fees-100k-bnt/3876/1#proposed-2)Proposed\n-----------------------------------------------------------------------------------------------------------------------------\n\nLet's limit the ETH pool size to 520x the 7 day fees, i.e. an APR of 10% all else equal.\n\nThis gives us a limited trading liquidity of:"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"937e79eb-d82c-4f93-b14f-ee7d3999d0c7"}}},{"cell_type":"code","source":["limited_pool_size_520 = int(round(520 * estimated_7day_eth_fees_real, 0))\nprint(f'\\033[1m {limited_pool_size_520} (ETH) \\033[1m')"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"1f206032-7c22-4575-b5a2-503774458605"}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"
1832 (ETH) \n
","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["\n
1832 (ETH) \n
"]}}],"execution_count":0},{"cell_type":"markdown","source":["If we assume that the fees generated on the limited trading liquidity are not significantly less than the fees on the current on-curve liquidity then this gives us an APR of 10% on ETH."],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"cbc3f824-2a8e-40b6-bf78-1bf6b32ad50b"}}},{"cell_type":"markdown","source":["### TODO: Below not yet completed."],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"3cd706e1-f95a-4c54-93a6-bd930a3d61fa"}}},{"cell_type":"markdown","source":["We spent all of bancor v2.1 with caps on trading pools showing that 10% APR is sustainable for many TKN, but the reality of how many fees we would miss on a 2400 ETH pool vs. an 8800 ETH pool is something that we would have to measure and monitor.\n\nContinuing with the assumption of comparable fees with the limited pool...\n\nThis now means that a 2x in ETH vs. BNT costs the protocol 240 ETH instead of 880 ETH. That is to say, over 1 year we can expect the protocol to break even on the 10% APR even if ETH moons 2x relative to BNT.\n\nWe also have 6400 ETH freed up to generate fees. Native staking on ETH yields about 3%.\n\n6400 ETH x 0.03 = 192 ETH ~= 200 ETH\n\nAssuming we do the most conservative thing other than doing nothing at all, use the native ETH staking mechanism, we now have a budget of 200 ETH from staking 6400 ETH and 240 ETH from a 10% APR on 2400 ETH to cover the IL on 2400 ETH.\n\nWith 440 ETH we can cover up to ~18% IL on 2400 ETH which allows ETH to annually moon ~4x relative to BNT\n\nClearly a 4x annual moon is a significantly larger safety margin than a 1.5x annual moon.\n\nAll we need to do is:\n\n- Limit pool to 520x the 7 day fees to give a minimum 10% APR\n- Move the off-curve liquidity into a conservative yield generating mechanism offering 3% e.g. native staking\n\nGenerally we could and should apply this 520x cap to all TKN on the platform as a rule of thumb and then backfill more sophisticated analytics over time.\n\nFor many TKN we might run into a situation where the 7 day fees are too small to support trading of any size, so we can set a minimum, which right now can be somewhat arbitrary like 100k BNT.\n\n[](https://gov.bancor.network/t/proposal-limit-on-curve-liquidity-to-max-520-x-7-day-fees-100k-bnt/3876/1#voting-3)Voting\n-------------------------------------------------------------------------------------------------------------------------\n\nYES: Cap all on-curve TKN trading liquidity to 520x their rolling 7 day fees\n\n- Frequency and level of automation of the cap management TBD and improved over time\n- Commit to alternative revenue generation for the off-curve capital\n- Commit to monitoring and ongoing analysis that is more sophisticated than what is presented above\n\nNO: Continue to attempt to cover double digit annual % IL with single digit % annual TKN fees"],"metadata":{"application/vnd.databricks.v1+cell":{"title":"","showTitle":false,"inputWidgets":{},"nuid":"2f9033a8-e93b-4f49-8dad-ff4e62c0e100"}}}],"metadata":{"application/vnd.databricks.v1+notebook":{"notebookName":"limit_tradingliquidity_proposal_study","dashboards":[],"notebookMetadata":{"pythonIndentUnit":4},"language":"python","widgets":{},"notebookOrigID":1744197420073319}},"nbformat":4,"nbformat_minor":0} diff --git a/examples/studies/limit_max_on_curve_liquidity/simulation.ipynb b/examples/studies/limit_max_on_curve_liquidity/simulation.ipynb new file mode 100644 index 00000000..28585074 --- /dev/null +++ b/examples/studies/limit_max_on_curve_liquidity/simulation.ipynb @@ -0,0 +1,56 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "zsh:1: permission denied: /Users/mikewcasale/Local/projects/bancor/research/bancor_research/scenario_generator/batch_run.py\r\n" + ] + } + ], + "source": [ + "! /Users/mikewcasale/Local/projects/bancor/research/bancor_research/scenario_generator/batch_run.py" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + } + ], + "metadata": { + "kernelspec": { + "name": "bancor_research_env", + "language": "python", + "display_name": "bancor_research_env" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file