Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Slight edits to original challenge, split further challenges into own document #88

Open
wants to merge 3 commits into
base: MathChallenge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
343 changes: 25 additions & 318 deletions BalancerSimulations - Math Challenge.ipynb

Large diffs are not rendered by default.

240 changes: 240 additions & 0 deletions further-challenges.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge No. 1\n",
"\n",
"For the following questions, there are two tokens $X$ and $Y$, with $x$ representing the number of Token $X$ in the pool, and $y$ representing the number of Token $Y$ in the pool. \n",
"\n",
"The plots below represent the invariant curves for two Balancer Pools. Both curves are of the form $2 = x^ay^{1-a}$ for some value of $a$. Try as many of the exercises below as you want -- discuss them with others and have fun!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Explain how the equation $V = B_1^{W_1}B_2^{W_2}$ becomes $2 = x^ay^{1-a}$ in this context. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Give one possible value of $a$ and a pair of possible legal values for $x$ and $y$ in this context. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Rewrite the curve $2 = x^ay^{1-a}$ in the form \"$y =$ (some expression involving x)\" and plot it using the Python tool of your choice. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"4. Generate 100 $(x,y)$ points on the curve $2 = x^{0.6}y^{0.4}$. Now take the **logarithm** of both $x$ and $y$ in your 100 points. Plot $\\log(x)$ against $\\log(y)$. What do you notice? "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"5. Both pictures above represent AMM curves of the form $2 = x^{a}y^{1-a}$. One of the curves has $a =0.6$ and the other has $a = 0.8$. Which is which? How can you tell? "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"6. Both of the curves pictured above contain the point $(2,2)$. Explain why any curve of the form $2= x^{a}y^{1-a}$ will pass through $(2,2)$. Is this a special property of the number 2, or will any curve of the form $k = x^{a}y^{1-a}$ pass through $(k,k)$? (You can determine this with an algebraic proof, or by playing with Python graphs.)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"7. Suppose a curve $2 = x^ay^{1-a}$ passes through the point $(2,2)$ and $(p,q)$. Explain how you can use the values of $p$ and $q$ to determine the weights of Token $X$ and Token $Y$. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"8. In **Alice's Pool**, which point has the highest spot price $SP_X^{Y}$: **A**, **B** or **C**? (You may be able to answer this without calculation.)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"9. Suppose Alice is actively managing her pool against Bob's pool and wishes to trade it against Bob's pool. Identify a pair of points -- one in her pool and one in Bob's pool -- that would represent an arbitrage opportunity for Alice. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"10. Create the invariant curves for Alice's pool and Bob's pool in Python using the graphing tool of your choice. Choose one point on Bob's curve and highlight it in Blue. Call this point **Z**. On your graph of Alice's curve, color in red **all of the points that represent arbitrage opportunities for Alice against Z**, i.e. color red all of the points on Alice's curve that represent where she could make a profit if she traded with Bob while he held the position represented by **Z**. (**Note**: This is the hardest one in terms of symbolic math, since it involves solving an inequality involving power functions.)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge No. 2\n",
"\n",
"Alice wants to set up another pool. \n",
"\n",
"She knows that the current price of 1 token C is 37 token D. \n",
"She owns 57000 token C, and 510000 token D. She plans to set a fee to 1%, and maximize her capital returns via this pool. \n",
"\n",
"#### 1.\n",
"What is the optimal set up for Alice’s new pool? Think about how you’d approach it and explain why.\n",
"\n",
"#### 2.\n",
"Due to a huge price dump, the price of token C on external markets drops to 28 token D. Now, Arbitrage traders get to work. Image Alice wanted to re-balance the pool herself, how much token C would she need in order to re-balance the pool in one trade? Keep in mind swap fees and slippage!\n",
"\n",
"#### 3.\n",
"Imagine Alice’s pool would be twice as big. How much liquidity would she need for the same price change?\n",
"\n",
"#### 4.\n",
"Explore the general relation between the size of the pool (liquidity m in token C and n in token D) and price changes with a series of experiments. \n",
"\t• derive an expression \n",
"\t• plot a graph "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge No. 3\n",
"\n",
"Bob runs a 50-50 Token X-Token Y pool with a 5% swap fee. \n",
"\n",
"The following traders want to interact with this pool:\n",
"- Carlos wants to increase the amount of Token X by 10% by trading X for Y\n",
"- Diana wants to increase the amount of Token Y by 10% by trading Y for X\n",
"- Ellen wants to increase the spot price X:Y by 10%\n",
"- Fabricio wants to increase the spot price Y:X by 10%\n",
"\n",
"#### 1.\n",
"For each action, specify the amount that the person will need to trade in to achieve the result. \n",
"\n",
"#### 2.\n",
"These actions can not occur simultaneously and will be processed in some order. There are 24 different total orders -- choose a few different ones and simulate the effect on spot price and liquidity. Can you make a conclusion about how increasing liquidity or changing balances affects spot price? If not, try running additional simulations with varying numbers besides 10%.\n",
"\n",
"#### 3.\n",
"Now add in two agents who want to increase the pool liquidity by making a deposit. With 6 actors, there are 720 different orderings of the actions. Analyze some. Which actions work \"together\" (reducing the amount needed of the second action to achieve a particular effect) and which work \"against each other\"? "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge No. 4\n",
"\n",
"A user has $a$ **TKNA** and $b$ **TKNB**: \n",
"The TKNA-TKNB pool has 50:50 weights, and reserves of TKNA and TKNB of m and n, respectively. \n",
"The user wishes to perform a swap such that the ratio of TKNA:TKNB in their wallet is p:q \n",
"\n",
"$$\\frac{a + x}{b + y} = \\frac{p}{q}$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1. \n",
"Assuming the user performs a swap between TKNA and TKNB on the TKNA-TKNB pool, derive an expression for x and y."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2.\n",
"Using data or algebra, which is the best option to reduce slippage when trading X for Y: \n",
" a) finding a pool with the same invariant but a different X balance value, \n",
" b) finding a pool with a different weight on X, \n",
" c) or finding a pool with a different invariant value? \n",
" Justify your answer in any way you like, \n",
" and explain whether \"different\" should be \"smaller\" or \"larger\" here."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge No. 5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1.\n",
"**Design a new value function.** \n",
"Use the balances of token A from Q1.2, and apply your new value function. \n",
"Add the resulting balances for token B"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2.\n",
"**Plot your curve.** \n",
"Send a screenshot of your curve to the Discord channel. \n",
"Let your fellow TE's reverse engineer the value function!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3.\n",
"**Pick a screenshot at the Discord.** \n",
"Reverse engineer the value function!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}