Solving constant product for price
The constant product is used in decentralized finance. It is used to calculate how much someone gets for currency $Y$ when giving funds of currency $X$. $X$ and $Y$ indicate the size of funds in the corresponding currencies, $b$ stands for the amount of funds of currency $X$ taken from the pool, $a$ stands for the amount of funds one has to give in currency $Y$ in return. $p$ is the price paid for the transaction.
$k = X Y$
$a = (XY / (X-b)) - X$
$p = a/b$
For a two-step trade covering intermediate currency $T$ (The pool sizes can differ when $T$ is paired with different currencies, which is why there are $T_1$ and $T_2$), when buying amount $b$:
$k_2 = T_2Y$
$k_1 = XT_1$
$t = (T_2Y / (T_2 - b)) - T_2 $
$a = (X T_1 / (X - t)) - X $
$p = a/b$
My question is: How do I solve that second set of formulas, those using $T_1$ and $T_2$, for $b$? Meaning, how much do I need to take to get a specific price $p$?
Known variables are $X$, $T_1$, $T_2$, $Y$ and $p$.
$k = X Y$
$a = (XY / (X-b)) - X$
$p = a/b$
For a two-step trade covering intermediate currency $T$ (The pool sizes can differ when $T$ is paired with different currencies, which is why there are $T_1$ and $T_2$), when buying amount $b$:
$k_2 = T_2Y$
$k_1 = XT_1$
$t = (T_2Y / (T_2 - b)) - T_2 $
$a = (X T_1 / (X - t)) - X $
$p = a/b$
My question is: How do I solve that second set of formulas, those using $T_1$ and $T_2$, for $b$? Meaning, how much do I need to take to get a specific price $p$?
Known variables are $X$, $T_1$, $T_2$, $Y$ and $p$.
46
Answer
Answers can only be viewed under the following conditions:
- The questioner was satisfied with and accepted the answer, or
- The answer was evaluated as being 100% correct by the judge.
1 Attachment
3.7K
The answer is accepted.
Join Matchmaticians Affiliate Marketing
Program to earn up to a 50% commission on every question that your affiliated users ask or answer.
- answered
- 1948 views
- $30.00
Related Questions
- Finance question with bonds
- Finding Probability Density Function of a Standard Brownian motion: Conditioning for two different cases
- Year 12 Finance - Combining Superannuation and withdrawals
- Solving Constant Product for ratio
- Disecting Constant Product formula
- Solving constant product for price
- Kelly Criterion for an example
- Amortization Table
If p is known, why do you want to get a specific price p?
I want to solve for b
Notice that these are different equations compared to the last problem. Do you want me to try to answer it?
It's like: The more I buy, the higher the price gets. And what I want to know is how much I can buy until the price reaches a specific value.
Yes the equations are slightly different. The previous question was about how to much one can sell, this one is about how much one can buy. The previous one was from a to b, this is one from b to a, so it's backwards.
These equations are slightly more difficult. Would you consider increasing the bounty?
Yes, done.