<jupyter_start><jupyter_text>Testing the Bonding Curve Mechanisms We test the functionality of the bonding curve and its constituent mechanisms, **bond-to-mint** and **burn-to-withdraw**.  Bond-to-Mint An agent employs a bond-to-mint mechanism to bond $\Delta R$ quantity of reserve tokens to mint $\Delta S$ quantity of supply tokens. ![bond to mint](img/bond.png)  Burn-to-Withdraw An agent employs a burn-to-withdraw mechanism to burn $\Delta S$ quantity of supply tokens to withdraw $\Delta R$ quantity of reserve tokens. ![burn to withdraw](img/burn.png) These two mechansims work in conjunction to allow agents to trade their reserve and supply tokens in the bonding curve.  In order to test the bonding curve in isolation, we remove all partial state update blocks (PSUBs) that resolve for the prediction market mechanisms, and only maintain the PSUBs that facilitate trading in the bonding curve.<jupyter_code>import sys
sys.path.append('../')

from src.sim import run
import matplotlib.pyplot as plt
experiments = run.run()<jupyter_output>__________   ____ 
          ________ __ _____/ ____/   |  / __ \
         / ___/ __` / __  / /   / /| | / / / /
        / /__/ /_/ / /_/ / /___/ ___ |/ /_/ / 
        \___/\__,_/\__,_/\____/_/  |_/_____/  
        by BlockScience
        
Execution Mode: multi_proc: [<cadCAD.configuration.Configuration object at 0x11b9a4e50>]
Configurations: [<cadCAD.configuration.Configuration object at 0x11b9a4e50>]
----Agent supply too low---- | s =  0
--------------------------------------2
Agent bonds. P =  1 | private_price =  1.00078539687147
RESERVE =  300.01963492178675  | deltaR =  0.0  | deltaS =  0
SUPPLY =  600.0196346005221  | deltaR =  0.019634921786748638  | deltaS =  -0.019634600522067558
AGENT RESERVE = 49.980365078213254 deltar =  0.0 policy_input['amt_to_bond'] =  0.019634921786748638
AGENT SUPPLY = 0.019634600522067558 deltas =  0.019634600522067558 policy_input['amt_to_burn'] =  0
SPOT PRICE P (from bondburn update) =  1.0
PRICE pbar (from bondburn up[...]<jupyter_text>Kappa Expectation: $\kappa$ does not change under the bond-to-mint and burn-to-withdraw mechanism.Result<jupyter_code>plt.plot(experiments.dataset[0].kappa)
plt.title('Kappa')
plt.ylabel('$\kappa$')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Alpha Expectation: $\alpha$ does not change under the bond-to-mint and burn-to-withdraw mechanism.Result<jupyter_code>plt.plot(experiments.dataset[0].alpha)
plt.title('Alpha')
plt.ylabel('alpha')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Reserve Expectation: Reserve varies in accordance to update_R() function as the agents execute bond-to-mint and burn-to-withdraw trades. Result<jupyter_code>plt.plot(experiments.dataset[0].reserve)
plt.title('Reserve')
plt.ylabel('R')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Supply Expectation: Supply varies in accordance to update_S() function as the agents execute bond-to-mint and burn-to-withdraw trades. Result<jupyter_code>plt.plot(experiments.dataset[0].supply)
plt.title('Supply')
plt.ylabel('S')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Price Expectation: Price varies in accordance to update_P() function as the agents execute bond-to-mint and burn-to-withdraw trades.     Result<jupyter_code>plt.plot(experiments.dataset[0].price)
plt.title('Price')
plt.ylabel('P')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Spot Price Expectation: Spot Price varies in accordance to update_P_bondburn() function as the agents execute bond-to-mint and burn-to-withdraw trades.     Result<jupyter_code>plt.plot(experiments.dataset[0].spot_price)
plt.title('Spot Price')
plt.ylabel('Spot Price')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Invariant V Expectation: Invariant V is invariant on the bonding curve, so it should not change.Result<jupyter_code>plt.plot(experiments.dataset[0].invariant_V)
plt.title('Invariant V')
plt.ylabel('V')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Invariant I Expectation: The indifference invariant, I is invariant on the prediction market attestation mechansims but does vary upon the bonding curve bond-to-mint and burn-to-withdraw mechansims.Result<jupyter_code>plt.plot(experiments.dataset[0].invariant_I)
plt.title('Invariant I')
plt.ylabel('I')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Price vs Spot Price<jupyter_code>plt.plot(experiments.dataset[0].price)
plt.plot(experiments.dataset[0].spot_price)
plt.title('Price and Spot Price')
plt.ylabel('Price, Spot Price')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Difference between Spot Price and Price Expectation: Since the update functions for both spot price and price are similar, we expect no difference between Spot Price and Price. Result<jupyter_code>plt.plot(experiments.dataset[0].price-experiments.dataset[0].spot_price)
plt.title('Difference between Spot Price and Price')
plt.ylabel('Price - Spot Price')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>The difference between Spot Price and Price is in the order of magnitude $10^{-3}$. This could be caused due to lack of computational precision and rounding errors.  Difference between Supply and Reserve Expectation: We expect to see a difference between Supply and Reserve guided by the conservation function with invariant V. $$V = \frac{S^{\kappa}}{R}$$Result<jupyter_code>plt.plot(experiments.dataset[0].supply - experiments.dataset[0].reserve)
plt.title('Difference between Supply and Reserve')
plt.ylabel('S - R')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Supply:Reserve Ratio Expectation: The ratio between Supply and Reserve varies according to the conservation function with invariant V. $$V = \frac{S^{\kappa}}{R}$$ which gives $$VS^{1-\kappa} = 1$$Result<jupyter_code>plt.plot(experiments.dataset[0].supply / experiments.dataset[0].reserve)
plt.title('Supply:Reserve Ratio')
plt.ylabel('Supply:Reserve')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Plot $VS^{1-\kappa}$<jupyter_code>plt.plot((experiments.dataset[0].invariant_V*(experiments.dataset[0].supply)**(1-experiments.dataset[0].kappa)))
plt.title('$VS^{1-\kappa}$')
plt.ylabel('$VS^{1-\kappa}$')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>Computed Kappa Expectation: $\kappa$ does not change under the bonding curve bond-to-mint and burn-to-withdraw mechanisms.    Result<jupyter_code>plt.plot(experiments.dataset[0].spot_price * experiments.dataset[0].supply  / experiments.dataset[0].reserve)
plt.title('Computed Kappa')
plt.ylabel('$\kappa$')
plt.xlabel('t')<jupyter_output><empty_output><jupyter_text>The computed kappa strays from its initial value of 2 by an order of magnitude $10^{-3}$. This could be caused due to lack of computational precision and rounding errors.Plotting the difference between the initial kappa value 2 and the computed kappa on a log scale, we have<jupyter_code>plt.plot(2-(experiments.dataset[0].spot_price * experiments.dataset[0].supply  / experiments.dataset[0].reserve))
plt.yscale('log')
plt.plot(experiments.dataset[0].kappa-(experiments.dataset[0].spot_price * experiments.dataset[0].supply  / experiments.dataset[0].reserve))
plt.yscale('log')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12901005094313645, 'fraction_numerical': 0.031529670934875395, 'mean_word_length': 5.639853747714808, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '243601', 'license': 'MIT', 'n_tokens_mistral': 2575, 'n_tokens_neox': 2354, 'n_words': 582, 'path': 'tests/bondingcurve.ipynb', 'repo_name': 'witwiki/Risk-Adjusted-Bonding-Curves', 'size': '7263'}