From 565b3cad629921e5be6a000947b1db17aa4ae54c Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Wed, 21 Feb 2024 08:26:05 -0700 Subject: [PATCH] add notebooks and READMEs --- src/ConstantSum/README.md | 0 src/GeometricMean/README.md | 236 +++ src/GeometricMean/geometric_mean.nb | 2324 +++++++++++++++++++++++++++ src/LogNormal/README.md | 292 ++++ src/LogNormal/log_normal.nb | 2318 ++++++++++++++++++++++++++ 5 files changed, 5170 insertions(+) create mode 100644 src/ConstantSum/README.md create mode 100644 src/GeometricMean/README.md create mode 100644 src/GeometricMean/geometric_mean.nb create mode 100644 src/LogNormal/README.md create mode 100644 src/LogNormal/log_normal.nb diff --git a/src/ConstantSum/README.md b/src/ConstantSum/README.md new file mode 100644 index 00000000..e69de29b diff --git a/src/GeometricMean/README.md b/src/GeometricMean/README.md new file mode 100644 index 00000000..cf4fae66 --- /dev/null +++ b/src/GeometricMean/README.md @@ -0,0 +1,236 @@ +# Geometric Mean Market Maker +This will be all the background needed to understand the `GeometricMean` DFMM. + +## Conceptual Overview +The `GeometricMean` DFMM gives the LP a portfolio that consists of a value-weighted ratio of the two assets based on the internal pricing mechanism. +If we pick the weight of the $X$-token to be $0.80$ and $0.20$ for the $Y$-token, then the LP will have a portfolio that is 80% in $X$ and 20% $Y$ by value. + +## Core +Mechanically, G3M of two variable parameters: +- $w_x \equiv \mathtt{weight\_x}$ +- $w_y \equiv \mathtt{weight\_y}$ +- These parameters must satisfy +$$ +w_x, w_y \geq 0 \\ +w_x+w_y=1 +$$ + +Next, we define the trading function to be: +$$ +\varphi(x,y) = x^{w_x} y^{w_y} = L +$$ +where $L$ is the invariant of the pool. +We can put: +$$ +L \equiv \mathtt{liquidity} +$$ +Note that $L$ is in units of Token by virtue of the geometric mean. + +## Price +If we compute the derivatives and simplify the expression, we get that the pool price is: +$$ +\boxed{P = \frac{w_x}{w_y}\frac{y}{x}} +$$ +We can determine a price in terms of just $x$ or just $y$ if need be. + +## Initializing Pool +We need to initalize a pool from a given price $p$ and an amount of a token. We can also do it by specifying liquidity too. + +### Given x and price + +Noting that +$$ +y= \frac{w_y}{w_x}p x +$$ +we can get +$$ +\begin{equation} +\boxed{L_X(x,S) = x\left(\frac{w_y}{w_x}S\right)^{w_y}} +\end{equation} +$$ +This is a linear function in $x$: +$$ +L_X(x+a\delta_x) = L_X(x) + aL_X(\delta_X) +$$ +We can get now the amount of $Y$ needed from $L$ and $x$ using the trading function and note: +$$ +\boxed{y(x,L;w_x) = \left(\frac{L}{x^{w_x}}\right)^{1/w_y}} +$$ + +### Given y and price +Noting that +$$ +x = \frac{w_x}{w_y}\frac{1}{p}y +$$ +we can get +$$ +\begin{equation} +\boxed{L_Y(y,S) = y\left(\frac{w_x}{w_y}\frac{1}{S}\right)^{w_x}} +\end{equation} +$$ +We can get now the amount of $X$ needed from $L$ and $y$ using the trading function and note: +$$ +\boxed{x(y,L;w_y) = \left(\frac{L}{y^{w_y}}\right)^{1/w_x}} +$$ + + +## Swap + +We require that the trading function remain invariant when a swap is applied, that is: +$$ +L(x,y) = (x+\Delta_x)^{w_x}(y+\Delta_y)^{w_y} +$$ +while also taking fees as a liquidity deposit (which will increase the liquidity $L$). + +### Trade in $\Delta_X$ for $\Delta_Y$ +Suppose that we want to trade in $\Delta_X$ for $\Delta_Y$. +Then we have that we are really inputting $\gamma\Delta_X$ while raising $L\mapsto L+\delta_L$. +From Equation (1) we get that: +$$ +x = \frac{L}{\left(\frac{w_y}{w_x}S\right))^{w_y}} +$$ +and note that $L_X(x,p)$ is linear in $x$. +Then we have that: +$$ +L_X(x+\delta_x) = L_X(x) + \delta_L \\= L_X(x) + \delta_X(\frac{w_y}{w_x}p)^{w_y} +$$ +so +$$ +\boxed{\delta_{L_X} = \delta_X\left(\frac{w_y}{w_x}p\right)^{w_y}} +$$ +TODO: CAN REWRITE THIS WITHOUT PRICE + +Hence we have for a swap with fees that (note $\Delta$ are what users input and receive): +$$ +L+\delta_L = (x+\gamma \Delta_X)^{w_x}(y+\Delta_y)^{w_y} +$$ +Then: +$$ +\boxed{\Delta_Y(\Delta_X) = \left(\frac{L+\delta_{L_X}}{(x+\Delta_X)^{w_x}}\right)^{1/w_y}-y} +$$ + +### Trade in $\Delta_Y$ for $\Delta_X$ +We can get the +$$ +x = \frac{y}{p}\frac{w_x}{w_y} +$$ +We have the linear function: +$$ +\boxed{L_Y(y,S) = y\left(\frac{w_x}{w_y}\frac{1}{S}\right)^{w_x}} +$$ +so that: +$$ +\boxed{\delta_{L_Y} = \delta_Y\left(\frac{w_x}{w_y}\frac{1}{p}\right)^{w_x}} +$$ + +Then +$$ +\boxed{\Delta_X(\Delta_Y) = \left(\frac{L+\delta_{L_Y}}{(y+\Delta_Y)^{w_y}}\right)^{1/w_x}-x} +$$ + + +## Liquidity Provision +It must be that adding liquidity does not change the price of the pool. +This makes it quite simple to add liquidity. +If a user wants to add liquidity, they can just add the tokens such that the ratio of the reserves does not change. +If a user wants to input $\Delta_x$ and $\Delta_y$ to the pool, then they must have: +$$ +p = \frac{w_x}{w_y} \frac{y}{x} = \frac{w_x}{w_y} \frac{y+\Delta_y}{x+\Delta_x} +$$ +which implies if they choose a given $\Delta_x$, then they must have: +$$ +\Delta_y = \frac{y}{x}(x+\Delta_x)-y +$$ +and similarly if they choose a given $\Delta_y$, then they must have: +$$ +\Delta_x = \frac{x}{y}(y+\Delta_y)-x +$$ + +## Arbitrage Math +We can solve for each variable in terms of the other and the invariant $k$: +$$ +x^{w_x}y^{w_y} = k +$$ + +First, $x$: +$$ +\implies \boxed{x = \left(\frac{L}{y^{w_y}}\right)^{1/w_x} } +$$ + +The work is analogous for $y$: +$$ +\implies \boxed{y = \left(\frac{L}{x^{w_x}}\right)^{1/w_y}} +$$ + +### Lowering Price +Suppose that we need the price to move $p\mapsto p'$ with $p'p$. +This means we tender $x$ in the swap so $y\mapsto y+\delta_x$. +Then we want $p'$ and $y\mapsto y+\delta_y$ with: +$$ +p' = \frac{w_x}{w_y}\frac{y+\delta_y}{x+\delta_x} +$$ +Now we can replace the $y+\delta_y$ with our equation above to get: +$$ +p'=\frac{w_x}{w_y}\frac{y+\delta_y}{\left( \frac{k}{(y+\delta_y)^{w_y}}\right)^{1/w_x}} +$$ +Then solving for $\delta_x$ yields +$$ +\implies \delta_y = \left(\frac{w_y}{w_x}p'k^{1/w_x}\right)^{\frac{1}{1+w_y/w_x}}-y +$$ + +This can be simplified to: +$$ +\implies \boxed{ \delta_y = k\left(\frac{w_y}{w_x}p'\right)^{w_x}-y } +$$ + +## Value Function via $L$ and $S$ +Given that we treat $Y$ as the numeraire, we know that the portfolio value of a pool when $X$ is at price $S$ is: +$$ +V(x,y,S) = x S + y +$$ +We can find the relationship to portfolio value from $V(L,S)$. +This will be helpful when tokenizing pool LP positions. + +Since we have $L_X(x, S)$ and $L_Y(y, S)$, we can get the following: +$$ +x = \frac{L}{(\frac{w_y}{w_x}S)^{w_y}}\\ +y = \frac{\left(\frac{w_x}{w_y}\frac{1}{S}\right)^{w_x}}{L} +$$ +Therefore: +$$ +V(L,S) = \frac{LS}{\left(\frac{w_y}{w_x}S\right)^{w_y}} + \frac{L}{\left(\frac{w_x}{w_y}\frac{1}{S}\right)^{w_x}}\\ +\boxed{V(L,S)=LS^{w_x}\left(\left( \frac{w_x}{w_y}\right)^{w_y}+\left( \frac{w_y}{w_x}\right)^{w_x}\right)} +$$ +Note that $V$ is linear in $L$ and so we can use this to tokenize. diff --git a/src/GeometricMean/geometric_mean.nb b/src/GeometricMean/geometric_mean.nb new file mode 100644 index 00000000..73ec28e0 --- /dev/null +++ b/src/GeometricMean/geometric_mean.nb @@ -0,0 +1,2324 @@ +(* Content-type: application/vnd.wolfram.mathematica *) + +(*** Wolfram Notebook File ***) +(* http://www.wolfram.com/nb *) + +(* CreatedBy='WolframDesktop 13.2' *) + +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 161, 7] +NotebookDataLength[ 83159, 2316] +NotebookOptionsPosition[ 75246, 2169] +NotebookOutlinePosition[ 75802, 2188] +CellTagsIndexPosition[ 75759, 2185] +WindowFrame->Normal*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell["Geometric Mean Trading Function Calculations", "Title", + CellChangeTimes->{{3.911911510375986*^9, + 3.9119115202551813`*^9}},ExpressionUUID->"464b00f2-edbc-4299-9ebc-\ +bbbbadc48e36"], + +Cell[CellGroupData[{ + +Cell["First, we set up the workspace", "Section", + CellChangeTimes->{{3.9119115280235243`*^9, + 3.911911535817244*^9}},ExpressionUUID->"7647c4f8-4fe4-4b60-9236-\ +0948b016bc8d"], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"On", "[", "Assert", "]"}], ";"}], " ", + RowBox[{"(*", " ", + RowBox[{ + RowBox[{ + "Asserts", " ", "will", " ", "show", " ", "a", " ", "failure", " ", "if", + " ", "they", " ", "fail"}], ",", " ", + RowBox[{"and", " ", "nothing", " ", "if", " ", "they", " ", + RowBox[{"don", "'"}], "t"}]}], " ", "*)"}]}]], "Code", + CellChangeTimes->{{3.9119115610079527`*^9, 3.91191157715276*^9}}, + CellLabel-> + "In[813]:=",ExpressionUUID->"90a85ca4-15ef-43a6-a1c9-9ded2b5b4873"], + +Cell[CellGroupData[{ + +Cell["Let\[CloseCurlyQuote]s define the functions for the DFMM.", "Subsection", + CellChangeTimes->{{3.9119116219881563`*^9, + 3.911911629097294*^9}},ExpressionUUID->"2a9c67df-985b-48b8-9ff4-\ +a81c2ce2cf78"], + +Cell[CellGroupData[{ + +Cell["\<\ +Functions to get initial liquidity given a token amount and a price.\ +\>", "Subsubsection", + CellChangeTimes->{{3.911911635661106*^9, + 3.911911650465029*^9}},ExpressionUUID->"a33110f6-a0d7-448f-8bd8-\ +0f79efb458dd"], + +Cell[TextData[{ + "We will assume for this whole document that ", + Cell[BoxData[ + FormBox[ + RowBox[{"w", "=", + SubscriptBox["w", "X"]}], TraditionalForm]],ExpressionUUID-> + "477424ec-0032-438b-aee2-6d6a473201b1"], + " and ", + Cell[BoxData[ + FormBox[ + RowBox[{ + SubscriptBox["w", "X"], "=", + RowBox[{"1", "-", + SubscriptBox["w", "Y"]}]}], TraditionalForm]],ExpressionUUID-> + "e8d1d46e-b904-454c-99fc-b2a495220d0d"], + " for simplicity" +}], "Text", + CellChangeTimes->{{3.911911717758877*^9, 3.9119117406902027`*^9}, { + 3.911912327913166*^9, + 3.911912333780533*^9}},ExpressionUUID->"9a6a4459-0d52-4b73-811d-\ +1f5b6974a4d1"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["L", "X"], "[", + RowBox[{"x_", ",", "S_", ",", "w_"}], "]"}], ":=", + RowBox[{"x", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + FractionBox[ + RowBox[{"1", "-", "w"}], "w"], "S"}], ")"}], + RowBox[{"1", "-", "w"}]]}]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["L", "Y"], "[", + RowBox[{"y_", ",", "S_", ",", "w_"}], "]"}], ":=", + RowBox[{"y", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + FractionBox["w", + RowBox[{"1", "-", "w"}]], + FractionBox["1", "S"]}], ")"}], "w"]}]}], "\n", + RowBox[{ + RowBox[{"X", "[", + RowBox[{"y_", ",", "S_", ",", "w_"}], "]"}], ":=", + RowBox[{ + FractionBox["w", + RowBox[{"1", "-", "w"}]], + FractionBox["1", "S"], "y"}]}], "\n", + RowBox[{ + RowBox[{"Y", "[", + RowBox[{"x_", ",", "S_", ",", "w_"}], "]"}], ":=", + RowBox[{ + FractionBox[ + RowBox[{"1", "-", "w"}], "w"], "S", " ", "x"}]}]}], "Code", + CellChangeTimes->{{3.911911651706427*^9, 3.9119117138210907`*^9}, { + 3.911911789108042*^9, 3.911911844681787*^9}, {3.911911892241302*^9, + 3.911911901341136*^9}, {3.91191211289227*^9, 3.911912147909412*^9}, { + 3.911912238579266*^9, 3.911912318380584*^9}, {3.9119123799914913`*^9, + 3.911912447202764*^9}, {3.9119132862667913`*^9, 3.911913339991631*^9}, { + 3.911913462657144*^9, 3.9119134680216084`*^9}}, + CellLabel-> + "In[814]:=",ExpressionUUID->"7253b091-e52f-418b-a1c8-287d88022e6a"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell[TextData[{ + "This is the price function (we could write this out as ", + Cell[BoxData[ + FormBox[ + SubscriptBox["P", "X"], TraditionalForm]],ExpressionUUID-> + "2101af69-5077-45c8-b151-8649e17c5f95"], + " and ", + Cell[BoxData[ + FormBox[ + SubscriptBox["P", "Y"], TraditionalForm]],ExpressionUUID-> + "b5427b3a-6ad2-4ac3-884c-35e3a778bde4"], + " if needed)" +}], "Subsubsection", + CellChangeTimes->{{3.911912491041603*^9, 3.911912499928299*^9}, { + 3.911912547710608*^9, + 3.911912559677248*^9}},ExpressionUUID->"c79752c3-b802-42fd-9612-\ +2c9ed31365e8"], + +Cell[BoxData[ + RowBox[{ + RowBox[{"P", "[", + RowBox[{"x_", ",", "y_", ",", "w_"}], "]"}], ":=", + RowBox[{ + FractionBox["w", + RowBox[{"1", "-", "w"}]], + FractionBox["y", "x"]}]}]], "Code", + CellChangeTimes->{{3.911912501940172*^9, 3.911912546049423*^9}, { + 3.911912581390644*^9, 3.911912592262026*^9}}, + CellLabel-> + "In[818]:=",ExpressionUUID->"18a899a0-963a-45c4-a7a0-9fbeda760047"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Then we have the trading function", "Subsubsection", + CellChangeTimes->{{3.9119125999574957`*^9, + 3.9119126032787*^9}},ExpressionUUID->"ccc19f67-4212-4173-8f38-591d9c869a78"], + +Cell[BoxData[ + RowBox[{ + RowBox[{"\[CurlyPhi]", "[", + RowBox[{"x_", ",", "y_", ",", "L_", ",", "w_"}], "]"}], ":=", + RowBox[{ + RowBox[{ + SuperscriptBox["x", "w"], + SuperscriptBox["y", + RowBox[{"1", "-", "w"}]]}], "-", "L"}]}]], "Code", + CellChangeTimes->{{3.911912609075673*^9, 3.911912634724598*^9}}, + CellLabel-> + "In[819]:=",ExpressionUUID->"25e959b2-4561-4b40-a658-c7cf56341acc"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +Let\[CloseCurlyQuote]s initialize a pool with some constants and some \ +liquidity.\ +\>", "Section", + CellChangeTimes->{{3.9119126417440157`*^9, + 3.911912651277295*^9}},ExpressionUUID->"8ecbbf5d-d7c2-4753-8dae-\ +ccd81d3ed5db"], + +Cell[CellGroupData[{ + +Cell["\<\ +First, let\[CloseCurlyQuote]s set the parameters for our curve, including the \ +fee parameter \[Gamma]\ +\>", "Subsection", + CellChangeTimes->{{3.91191265333202*^9, + 3.911912664215665*^9}},ExpressionUUID->"3778290c-33c8-4669-bd57-\ +a54efc82c76a"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["w", "0"], ",", " ", + SubscriptBox["\[Gamma]", "0"]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{ + FractionBox["1", "2"], ",", "1"}], "}"}]}], ";"}], "\n", + RowBox[{"Assert", "[", + RowBox[{"0", "<=", + SubscriptBox["w", "0"], "<=", "1"}], "]"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["w", "0"], ",", " ", + "\"\<\!\(\*SubscriptBox[\(w\), \(0\)]\) = \>\""}], "]"}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["\[Gamma]", "0"], ",", " ", + "\"\<\!\(\*SubscriptBox[\(\[Gamma]\), \(0\)]\) = \>\""}], "]"}], + ";"}]}], "Code", + CellChangeTimes->{{3.9119126661143427`*^9, 3.911912745472548*^9}, { + 3.913751197438278*^9, 3.913751203946327*^9}, {3.916755641867735*^9, + 3.916755653408431*^9}, {3.916758352270589*^9, 3.916758352990745*^9}, { + 3.916758461710663*^9, 3.916758485200482*^9}, {3.9167630696181583`*^9, + 3.9167630711333857`*^9}, {3.9168506991445208`*^9, 3.916850699759934*^9}, { + 3.917375527833433*^9, 3.917375530306773*^9}, {3.917474535641025*^9, + 3.917474536663909*^9}}, + CellLabel-> + "In[820]:=",ExpressionUUID->"a277fd9d-36f8-4eee-9601-665001bbe972"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*SubscriptBox[\\(w\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", + FractionBox["1", "2"]}]], "Echo", + CellChangeTimes->{ + 3.917474537220233*^9},ExpressionUUID->"e292a780-3309-44c3-be1d-\ +26b2a20e24a3"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*SubscriptBox[\\(\[Gamma]\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "1"}]], "Echo", + CellChangeTimes->{ + 3.917474537230825*^9},ExpressionUUID->"b4ef115e-13e6-465e-afa5-\ +f607b00b73a0"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +Now, let\[CloseCurlyQuote]s set the initial liquidity by providing an amount \ +of X and a price S.\ +\>", "Subsection", + CellChangeTimes->{{3.911912758416833*^9, + 3.911912770460993*^9}},ExpressionUUID->"0e4b0b5f-de16-4a42-af35-\ +cb7f8c5a845c"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["S", "0"]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{"1", ",", " ", "1"}], "}"}]}], ";"}], " "}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["x", "0"], ",", " ", + "\"\\""}], "]"}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["S", "0"], ",", " ", + "\"\<\!\(\*SubscriptBox[\(S\), \(0\)]\) = \>\""}], "]"}], ";"}]}], "Code",\ + + CellChangeTimes->{{3.91375121715248*^9, 3.913751217262199*^9}, { + 3.9167584720251627`*^9, 3.916758473473184*^9}, {3.916763078664383*^9, + 3.916763079312771*^9}, {3.916850486059314*^9, 3.916850517153616*^9}, { + 3.9173801291544447`*^9, 3.917380133892503*^9}, {3.9173803308316917`*^9, + 3.9173803309348583`*^9}, {3.917474542527548*^9, 3.917474545068673*^9}}, + CellLabel-> + "In[823]:=",ExpressionUUID->"fabf4afc-21e6-47a6-b63d-ba788b915987"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The initial X-reserve balance is: \ +\\!\\(\\*SubscriptBox[\\(x\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "1"}]], "Echo", + CellChangeTimes->{ + 3.917474545509263*^9},ExpressionUUID->"01616c47-d47f-4163-ae7f-\ +1486a28100e4"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*SubscriptBox[\\(S\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "1"}]], "Echo", + CellChangeTimes->{ + 3.917474545542253*^9},ExpressionUUID->"fc434cef-4acc-4e55-bde9-\ +391e8b23b2d8"] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +From this, let\[CloseCurlyQuote]s see what we will get for the initial amount \ +of Y and L.\ +\>", "Subsubsection", + CellChangeTimes->{{3.911912799855054*^9, + 3.911912808975162*^9}},ExpressionUUID->"d14796ee-6661-403b-a067-\ +2e1c5a6c6211"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["L", "0"], ",", " ", + SubscriptBox["y", "0"]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["L", "X"], "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["S", "0"], ",", + SubscriptBox["w", "0"]}], "]"}], ",", " ", + RowBox[{"Y", "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["S", "0"], ",", + SubscriptBox["w", "0"]}], "]"}]}], "}"}]}], ";"}], " "}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["L", "0"], ",", " ", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["y", "0"], ",", " ", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}]}], "Code", + CellChangeTimes->{{3.911912822320621*^9, 3.911912827848645*^9}, { + 3.911912883452937*^9, 3.9119128835495768`*^9}}, + CellLabel-> + "In[825]:=",ExpressionUUID->"ee083f7c-4161-4e24-8675-42d8b5ffacbe"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The initial liquidity is: \\!\\(\\*SubscriptBox[\\(L\\), \ +\\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "1.`18."}]], "Echo", + CellChangeTimes->{ + 3.917474548436577*^9},ExpressionUUID->"47b0b03a-8b5e-49c0-ab03-\ +4782db75c308"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The initial Y-reserve balance is: \ +\\!\\(\\*SubscriptBox[\\(y\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "1.`18."}]], "Echo", + CellChangeTimes->{ + 3.9174745484663353`*^9},ExpressionUUID->"dc83f75a-8600-43f2-b1e3-\ +eba4431e2b04"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Let\[CloseCurlyQuote]s check that the prices are correct after the \ +fact.", "Subsubsection", + CellChangeTimes->{{3.911912905875383*^9, + 3.911912912599833*^9}},ExpressionUUID->"0a95fd1e-5759-46f5-b752-\ +6b4f74d4268c"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{"Assert", "[", + RowBox[{ + RowBox[{"P", "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["w", "0"]}], "]"}], " ", "==", " ", + SubscriptBox["S", "0"]}], "]"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"P", "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["w", "0"]}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}]}], "Code", + CellChangeTimes->{{3.911912932500325*^9, 3.911912980651959*^9}}, + CellLabel-> + "In[827]:=",ExpressionUUID->"9b2bc5ef-d095-45dd-ac2b-15f02684ac4f"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The initial price is: P = \"\>", + "EchoLabel"], " ", "1"}]], "Echo", + CellChangeTimes->{ + 3.917474552187778*^9},ExpressionUUID->"4a6673d1-2530-4a7d-9666-\ +b22656868b6c"] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +Just to verify that we could have done this the other way, and show the flow, \ +let\[CloseCurlyQuote]s do that real fast.\ +\>", "Subsubsection", + CellChangeTimes->{{3.911913367118602*^9, + 3.911913377190076*^9}},ExpressionUUID->"f59add3e-9736-413f-b760-\ +d953f4b2de71"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["L", + SubscriptBox["0", "y"]], ",", " ", + SubscriptBox["x", + SubscriptBox["0", "y"]]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["L", "Y"], "[", + RowBox[{ + SubscriptBox["y", "0"], ",", + SubscriptBox["S", "0"], ",", + SubscriptBox["w", "0"]}], "]"}], ",", " ", + RowBox[{"X", "[", + RowBox[{ + SubscriptBox["y", "0"], ",", + SubscriptBox["S", "0"], ",", + SubscriptBox["w", "0"]}], "]"}]}], "}"}]}], ";"}], "\n", + RowBox[{ + RowBox[{"Assert", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["L", + SubscriptBox["0", "y"]], ",", + SubscriptBox["x", + SubscriptBox["0", "y"]]}], "}"}], " ", "==", " ", + RowBox[{"{", + RowBox[{ + SubscriptBox["L", "0"], ",", + SubscriptBox["x", "0"]}], "}"}]}], "]"}], ";"}]}], "Code", + CellChangeTimes->{{3.911913388555017*^9, 3.911913437262168*^9}, + 3.9119134968996763`*^9}, + CellLabel-> + "In[829]:=",ExpressionUUID->"5ace6d65-c46d-491e-a7b3-d364ee7f21fb"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Swapping", "Section", + CellChangeTimes->{{3.911913506803228*^9, + 3.911913507641082*^9}},ExpressionUUID->"0aa1aa4a-a222-4348-9a33-\ +bdcf246c0ec1"], + +Cell[CellGroupData[{ + +Cell["Now we need to set up the swap logic.", "Subsection", + CellChangeTimes->{{3.911913509615294*^9, 3.911913519388177*^9}, + 3.911913612736845*^9},ExpressionUUID->"a09de9d8-3ec0-4d13-8819-\ +089fc369fa6e"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"\[CapitalDelta]_", ",", "\[Gamma]_"}], "]"}], " ", ":=", " ", + RowBox[{ + RowBox[{"(", + RowBox[{"1", "-", "\[Gamma]"}], ")"}], "\[CapitalDelta]"}]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{"\[CapitalDelta]_", ",", "R_", ",", "L_", ",", "\[Gamma]_"}], + "]"}], " ", ":=", " ", + RowBox[{ + FractionBox["1", "2"], + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"\[CapitalDelta]", ",", "\[Gamma]"}], "]"}], + FractionBox["L", "R"]}]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + "\[CapitalDelta]_", ",", "x_", ",", "y_", ",", "L_", ",", "w_", ",", + "\[Gamma]_"}], "]"}], " ", ":=", " ", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + FractionBox[ + RowBox[{"L", "+", + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{"\[CapitalDelta]", ",", "y", ",", "L", ",", "\[Gamma]"}], + "]"}]}], + SuperscriptBox[ + RowBox[{"(", + RowBox[{"y", "+", "\[CapitalDelta]"}], ")"}], + RowBox[{"1", "-", "w"}]]], ")"}], + FractionBox["1", "w"]], "-", "x"}]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + "\[CapitalDelta]_", ",", "x_", ",", "y_", ",", "L_", ",", "w_", ",", + "\[Gamma]_"}], "]"}], " ", ":=", " ", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + FractionBox[ + RowBox[{"L", "+", + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{"\[CapitalDelta]", ",", "x", ",", "L", ",", "\[Gamma]"}], + "]"}]}], + SuperscriptBox[ + RowBox[{"(", + RowBox[{"x", "+", "\[CapitalDelta]"}], ")"}], "w"]], ")"}], + FractionBox["1", + RowBox[{"1", "-", "w"}]]], "-", "y"}]}]}], "Code", + CellChangeTimes->{{3.911913527155746*^9, 3.9119135334049797`*^9}, { + 3.911913609956356*^9, 3.911913618625647*^9}, {3.9119138718346777`*^9, + 3.911914007786831*^9}, {3.911914050154006*^9, 3.911914216429152*^9}, + 3.911914432257678*^9, {3.911914740377337*^9, 3.911914765079064*^9}, { + 3.9119148556108437`*^9, 3.91191486213737*^9}, {3.91191511989001*^9, + 3.911915138754508*^9}, {3.911915179500216*^9, 3.911915240429996*^9}, { + 3.9137510946925173`*^9, 3.913751129833908*^9}, {3.913751233158678*^9, + 3.913751361923436*^9}, {3.913803336011858*^9, 3.9138033400453243`*^9}, { + 3.916750092177647*^9, 3.916750092710829*^9}, {3.917375550285816*^9, + 3.917375553361146*^9}, {3.917375646968779*^9, 3.917375651113062*^9}, { + 3.9173757221234703`*^9, 3.9173758146366262`*^9}, {3.917380235352436*^9, + 3.917380256042615*^9}, {3.917380371447682*^9, 3.917380373267902*^9}}, + CellLabel-> + "In[831]:=",ExpressionUUID->"6c9eba4a-50a0-4c93-b07c-3139817809de"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{"0.1", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], "\n", + RowBox[{ + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], "+", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{"0.1", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", + RowBox[{ + SubscriptBox["y", "0"], "+", "0.1"}], ",", + RowBox[{ + SubscriptBox["L", "0"], "+", + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{"0.1", ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", + SubscriptBox["w", "0"]}], "]"}], "\n"}], "\n", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{"0.1", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], "\n", + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], "+", "0.1"}], ",", + RowBox[{ + SubscriptBox["y", "0"], "+", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{"0.1", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", + RowBox[{ + SubscriptBox["L", "0"], "+", + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{"0.1", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", + SubscriptBox["w", "0"]}], "]"}]}], "Code", + CellChangeTimes->{{3.9173801538368683`*^9, 3.917380182502496*^9}, { + 3.917380406138091*^9, 3.917380427451881*^9}, {3.917382817211936*^9, + 3.917382944892488*^9}, {3.917474578659257*^9, 3.917474580665434*^9}}, + CellLabel-> + "In[835]:=",ExpressionUUID->"57d57c6e-b361-4057-8fe3-86b50c9464e4"], + +Cell[BoxData[ + RowBox[{"-", "0.09090909090909105`"}]], "Output", + CellChangeTimes->{ + 3.917380183658939*^9, 3.917380259953665*^9, 3.917380340546103*^9, { + 3.917380375623798*^9, 3.917380379003302*^9}, 3.9173804285014133`*^9, { + 3.9173829183952293`*^9, 3.917382946517559*^9}, 3.917474557013838*^9}, + CellLabel-> + "Out[835]=",ExpressionUUID->"705276af-d995-4ce0-b354-84831b308d2d"], + +Cell[BoxData["0.`"], "Output", + CellChangeTimes->{ + 3.917380183658939*^9, 3.917380259953665*^9, 3.917380340546103*^9, { + 3.917380375623798*^9, 3.917380379003302*^9}, 3.9173804285014133`*^9, { + 3.9173829183952293`*^9, 3.917382946517559*^9}, 3.917474557016643*^9}, + CellLabel-> + "Out[836]=",ExpressionUUID->"2110b4c3-3d24-4487-ab7a-315bad605229"], + +Cell[BoxData[ + RowBox[{"-", "0.09090909090909105`"}]], "Output", + CellChangeTimes->{ + 3.917380183658939*^9, 3.917380259953665*^9, 3.917380340546103*^9, { + 3.917380375623798*^9, 3.917380379003302*^9}, 3.9173804285014133`*^9, { + 3.9173829183952293`*^9, 3.917382946517559*^9}, 3.91747455701805*^9}, + CellLabel-> + "Out[837]=",ExpressionUUID->"da9c9147-ed0c-4928-9879-cb5907e8605b"], + +Cell[BoxData["0.`"], "Output", + CellChangeTimes->{ + 3.917380183658939*^9, 3.917380259953665*^9, 3.917380340546103*^9, { + 3.917380375623798*^9, 3.917380379003302*^9}, 3.9173804285014133`*^9, { + 3.9173829183952293`*^9, 3.917382946517559*^9}, 3.917474557019392*^9}, + CellLabel-> + "Out[838]=",ExpressionUUID->"318c935c-af9d-45ae-996b-68e575a47d69"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Arbitrage", "Section", + CellChangeTimes->{{3.9119142472576113`*^9, + 3.911914255664398*^9}},ExpressionUUID->"2af33c95-75fa-4c2a-987e-\ +0c0efa8a1771"], + +Cell[TextData[{ + "We will assume there is some external price ", + Cell[BoxData[ + FormBox[ + SubscriptBox["S", "ext"], TraditionalForm]],ExpressionUUID-> + "8e70a992-445b-45fa-8ff6-75d441c5609b"], + " that we are given and decide whether or not to perform an arbitrage and, \ +if so, to get the optimal trade size. That is, the trade that gives the \ +arbitrageur maximal profit." +}], "Text", + CellChangeTimes->{{3.911914264985302*^9, + 3.91191432874524*^9}},ExpressionUUID->"72430652-d39e-479e-8fb5-\ +8c2568d7c943"], + +Cell[CellGroupData[{ + +Cell[TextData[{ + "We will need the marginal price ", + Cell[BoxData[ + FormBox[ + SubscriptBox["P", "M"], TraditionalForm]],ExpressionUUID-> + "99042f72-0eb5-4f69-870e-9076c4359cec"], + " of a swap to compute the optimal arbitrages and a profit calculation ", + Cell[BoxData[ + FormBox[ + SubscriptBox["V", "A"], TraditionalForm]],ExpressionUUID-> + "8e6910c5-e4d2-40af-b100-2c1e2d5d76b5"] +}], "Subsubsection", + CellChangeTimes->{{3.911914330823928*^9, + 3.9119143508811502`*^9}},ExpressionUUID->"a8656622-88c3-4ada-82e5-\ +d33556722b56"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{"dX_", ",", "dY_"}], "]"}], " ", ":=", " ", + FractionBox[ + RowBox[{"-", "dY"}], "dX"]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{"Pm_", ",", "Pext_", ",", "\[CapitalDelta]_"}], "]"}], " ", ":=", + " ", + RowBox[{ + RowBox[{"(", + RowBox[{"Pm", " ", "-", " ", "Pext"}], ")"}], + "\[CapitalDelta]"}]}]}], "Code", + CellLabel-> + "In[267]:=",ExpressionUUID->"8864b3f3-1b36-4dcd-99b8-7a357f5a3a30"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Lower External Price:", "Subsection", + CellChangeTimes->{{3.911914361205379*^9, + 3.9119143742418222`*^9}},ExpressionUUID->"f9739415-ba82-4653-b842-\ +33b37c1cd286"], + +Cell[CellGroupData[{ + +Cell[TextData[{ + "We will let ", + Cell[BoxData[ + FormBox[ + SubscriptBox["O", "X"], TraditionalForm]],ExpressionUUID-> + "02f62581-159d-4887-b98d-1428c55170a9"], + " be the optimal amount of X token to tender to achieve the maximal \ +arbitrage profit." +}], "Subsubsection", + CellChangeTimes->{{3.911914379462582*^9, + 3.911914392960053*^9}},ExpressionUUID->"905228e2-efe5-43aa-9780-\ +0b193149ea3d"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["S", "ext"], " ", "=", " ", "0.8"}], ";", " ", + RowBox[{"Assert", "[", + RowBox[{ + SubscriptBox["S", "ext"], " ", "<", " ", + SubscriptBox["S", "0"]}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Lower"], "[", "in_", "]"}], " ", ":=", " ", + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{"in", ",", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{"in", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], "]"}], ",", " ", + SubscriptBox["S", "ext"], ",", " ", "in"}], "]"}]}], "\n", + RowBox[{"Plot", "[", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Lower"], "[", "v", "]"}], ",", " ", + RowBox[{"{", + RowBox[{"v", ",", "0", ",", "0.2"}], "}"}]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{ + SubscriptBox["O", "X"], " ", "=", " ", + RowBox[{"N", "[", + RowBox[{ + RowBox[{"ArgMax", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Lower"], "[", "x", "]"}], ",", " ", + RowBox[{"0", "<=", "x", "<=", "5"}]}], "}"}], ",", " ", "x"}], + "]"}], ",", "18"}], "]"}]}], ";"}], " "}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["O", "X"], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + SubscriptBox["O", "X"]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}]}], "}"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], "]"}], ",", " ", + "\"\\ +\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["P", "F"], " ", "=", " ", + RowBox[{"P", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + SubscriptBox["O", "X"]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], "+", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + SubscriptBox["w", "0"]}], "]"}]}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["P", "F"], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"D", "[", + RowBox[{ + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{"v", ",", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + "v", ",", "x", ",", "y", ",", "L", ",", "w", ",", "\[Gamma]"}], + "]"}]}], "]"}], ",", " ", "S", ",", " ", "v"}], "]"}], ",", " ", + "v"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], + "\n", + RowBox[{"(*", " ", + RowBox[{ + "Check", " ", "that", " ", "the", " ", "trading", " ", "function", " ", + "is", " ", "invariant", " ", "under", " ", "the", " ", "swap"}], " ", + "*)"}]}], "\n", + RowBox[{ + RowBox[{"Assert", "[", + RowBox[{ + RowBox[{"Abs", "[", + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + SubscriptBox["O", "X"]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + RowBox[{ + SubscriptBox["L", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + SubscriptBox["w", "0"]}], "]"}], "]"}], " ", "<", " ", + SuperscriptBox["10", + RowBox[{"-", "15"}]]}], "]"}], "\n"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"check", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "w_", ",", + "\[Gamma]_"}], "]"}], ":=", + RowBox[{ + RowBox[{"-", "S"}], "+", + FractionBox[ + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"L", " ", "w", " ", "x", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["y", "x"], ")"}], "w"]}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{"v", "-", + RowBox[{"v", " ", "w"}], "+", "x"}], ")"}], " ", "y", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}], " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], + RowBox[{"-", "w"}]], " ", + RowBox[{"(", + RowBox[{"L", "-", + RowBox[{"v", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["y", "x"], ")"}], + RowBox[{"1", "-", "w"}]], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}], + ")"}], + FractionBox["1", + RowBox[{"1", "-", "w"}]]]}], + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "w"}], ")"}], " ", + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"-", "L"}], " ", "x", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["y", "x"], ")"}], "w"]}], "+", + RowBox[{"v", " ", "y", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}]]}]}], + ";"}], "\n", + RowBox[{"check", "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["S", "ext"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"num", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "w_", ",", + "\[Gamma]_"}], "]"}], ":=", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"L", " ", "w", " ", "x", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["y", "x"], ")"}], "w"]}], "+", + RowBox[{ + RowBox[{"(", + RowBox[{"v", "-", + RowBox[{"v", " ", "w"}], "+", "x"}], ")"}], " ", "y", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}], " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], + RowBox[{"-", "w"}]], " ", + RowBox[{"(", + RowBox[{"L", "-", + RowBox[{"v", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["y", "x"], ")"}], + RowBox[{"1", "-", "w"}]], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}], ")"}], + + FractionBox["1", + RowBox[{"1", "-", "w"}]]]}]}], ";"}], "\n", + RowBox[{"num", "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["S", "ext"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"denom", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "w_", ",", + "\[Gamma]_"}], "]"}], ":=", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "w"}], ")"}], " ", + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"-", "L"}], " ", "x", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["y", "x"], ")"}], "w"]}], "+", + RowBox[{"v", " ", "y", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}]}], + ";"}], "\n", + RowBox[{"denom", "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["S", "ext"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], "Code", + CellChangeTimes->{{3.911914422645937*^9, 3.911914555345026*^9}, { + 3.911914588999901*^9, 3.91191460090387*^9}, {3.911914673363236*^9, + 3.911914711242825*^9}, {3.911914790397727*^9, 3.911914808449383*^9}, { + 3.911914911266861*^9, 3.9119149253646173`*^9}, {3.9119153099803047`*^9, + 3.911915356848312*^9}, {3.911915395365718*^9, 3.911915397737707*^9}, { + 3.911915436220303*^9, 3.911915514601404*^9}, {3.9119162095262337`*^9, + 3.9119162714050093`*^9}, {3.911930073685734*^9, 3.9119300942727833`*^9}, + 3.9119301712068167`*^9, {3.916750125402011*^9, 3.916750152368066*^9}, { + 3.9167502280613003`*^9, 3.916750274923284*^9}, {3.916750440937388*^9, + 3.916750629671793*^9}, {3.916750811189536*^9, 3.9167508209424*^9}, { + 3.916765121182337*^9, 3.916765152172139*^9}, {3.9168278451701593`*^9, + 3.9168278845934877`*^9}, {3.9168279434370823`*^9, + 3.9168280951568737`*^9}, {3.9168283033725853`*^9, 3.916828311498711*^9}, { + 3.916828426976664*^9, 3.9168284392552032`*^9}, 3.916828472810547*^9, { + 3.916828513238497*^9, 3.9168287199450808`*^9}, {3.916834831289481*^9, + 3.916834911904212*^9}, {3.9168506147106237`*^9, 3.9168506234890203`*^9}, + 3.916850658582822*^9, 3.9173761160328093`*^9, {3.917376475745462*^9, + 3.9173764910618362`*^9}}, + CellLabel-> + "In[303]:=",ExpressionUUID->"1a8d1d1f-d7f4-4461-a836-4d4571ea6392"], + +Cell[BoxData[ + GraphicsBox[{{{}, {}, + TagBox[ + {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[ + 1.], LineBox[CompressedData[" +1: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 +pfIv8tcy8X815bsR + "]]}, + Annotation[#, "Charting`Private`Tag$52295#1"]& ]}, {}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + Axes->{True, True}, + AxesLabel->{None, None}, + AxesOrigin->{0, 0}, + DisplayFunction->Identity, + Frame->{{False, False}, {False, False}}, + FrameLabel->{{None, None}, {None, None}}, + FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}}, + GridLines->{None, None}, + GridLinesStyle->Directive[ + GrayLevel[0.5, 0.4]], + ImagePadding->All, + Method->{ + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, "DefaultMeshStyle" -> + AbsolutePointSize[6], "ScalingFunctions" -> None, + "CoordinatesToolOptions" -> {"DisplayFunction" -> ({ + (Identity[#]& )[ + Part[#, 1]], + (Identity[#]& )[ + Part[#, 2]]}& ), "CopiedValueFunction" -> ({ + (Identity[#]& )[ + Part[#, 1]], + (Identity[#]& )[ + Part[#, 2]]}& )}}, + PlotRange->{{0, 0.2}, {0., 0.010520148912324685`}}, + PlotRangeClipping->True, + PlotRangePadding->{{ + Scaled[0.02], + Scaled[0.02]}, { + Scaled[0.05], + Scaled[0.05]}}, + Ticks->{Automatic, Automatic}]], "Output", + CellChangeTimes->{{3.916850668010118*^9, 3.916850703273357*^9}, + 3.917375605555485*^9, 3.917375834699234*^9, 3.917376117017376*^9, + 3.91737615836895*^9, {3.917376442233181*^9, 3.9173764500649357`*^9}, + 3.917376514200519*^9}, + CellLabel-> + "Out[305]=",ExpressionUUID->"986f7163-cf03-4de4-b998-9538f3a4c8bc"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The optimal amount of X to tender is: \\!\\(\\*SubscriptBox[\\(\ +\[CapitalDelta]\\), \\(X\\)]\\) = \"\>", + "EchoLabel"], " ", "0.11467362047981638`"}]], "Echo", + CellChangeTimes->{ + 3.91737651422582*^9},ExpressionUUID->"6394a97c-351e-437d-8c02-9b0642aacf09"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The amount out is: \\!\\(\\*SubscriptBox[\\(\[CapitalDelta]\\), \ +\\(Y\\)]\\) = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "0.10225904543925524`"}]}]], "Echo", + CellChangeTimes->{ + 3.917376514233597*^9},ExpressionUUID->"5e6b589a-5de5-4f17-9268-\ +a35f46b410b1"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The resulting reserves are: (\\!\\(\\*SubscriptBox[\\(x\\), \ +\\(1\\)]\\),\\!\\(\\*SubscriptBox[\\(y\\), \\(1\\)]\\)) = \"\>", + "EchoLabel"], " ", + RowBox[{"{", + RowBox[{"1.1146736204798164`", ",", "0.8977409545607448`"}], + "}"}]}]], "Echo", + CellChangeTimes->{ + 3.917376514253421*^9},ExpressionUUID->"957d146b-e63f-416f-a7cb-\ +8c6b69727396"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The marginal price paid was: \\!\\(\\*SubscriptBox[\\(P\\), \ +\\(M\\)]\\) = \"\>", + "EchoLabel"], " ", "0.8917399224981631`"}]], "Echo", + CellChangeTimes->{ + 3.917376514261448*^9},ExpressionUUID->"a6375d85-fb17-4296-9761-\ +db2b17a953c6"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The final price of the pool is: P = \"\>", + "EchoLabel"], " ", "0.8053845879785941`"}]], "Echo", + CellChangeTimes->{ + 3.91737651427712*^9},ExpressionUUID->"ea158521-8811-4328-bda0-60677eb48800"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The equation to do root finding with is: \"\>", + "EchoLabel"], " ", + RowBox[{ + RowBox[{"-", "S"}], "-", + FractionBox[ + RowBox[{ + RowBox[{"-", "y"}], "+", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], + RowBox[{"-", "w"}]], " ", + RowBox[{"(", + RowBox[{"L", "+", + FractionBox[ + RowBox[{"L", " ", "v", " ", + RowBox[{"(", + RowBox[{"1", "-", "\[Gamma]"}], ")"}]}], "x"]}], ")"}]}], ")"}], + + FractionBox["1", + RowBox[{"1", "-", "w"}]]]}], "v"], "+", + RowBox[{"v", " ", + RowBox[{"(", + RowBox[{ + FractionBox[ + RowBox[{ + RowBox[{"-", "y"}], "+", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], + RowBox[{"-", "w"}]], " ", + RowBox[{"(", + RowBox[{"L", "+", + FractionBox[ + RowBox[{"L", " ", "v", " ", + RowBox[{"(", + RowBox[{"1", "-", "\[Gamma]"}], ")"}]}], "x"]}], ")"}]}], + ")"}], + FractionBox["1", + RowBox[{"1", "-", "w"}]]]}], + SuperscriptBox["v", "2"]], "-", + RowBox[{ + FractionBox["1", + RowBox[{"v", " ", + RowBox[{"(", + RowBox[{"1", "-", "w"}], ")"}]}]], + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], + RowBox[{"-", "w"}]], " ", + RowBox[{"(", + RowBox[{"L", "+", + FractionBox[ + RowBox[{"L", " ", "v", " ", + RowBox[{"(", + RowBox[{"1", "-", "\[Gamma]"}], ")"}]}], "x"]}], ")"}]}], + ")"}], + RowBox[{ + RowBox[{"-", "1"}], "+", + FractionBox["1", + RowBox[{"1", "-", "w"}]]}]], " ", + RowBox[{"(", + RowBox[{ + RowBox[{ + RowBox[{"-", "w"}], " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], + RowBox[{ + RowBox[{"-", "1"}], "-", "w"}]], " ", + RowBox[{"(", + RowBox[{"L", "+", + FractionBox[ + RowBox[{"L", " ", "v", " ", + RowBox[{"(", + RowBox[{"1", "-", "\[Gamma]"}], ")"}]}], "x"]}], ")"}]}], "+", + FractionBox[ + RowBox[{"L", " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}], + RowBox[{"-", "w"}]], " ", + RowBox[{"(", + RowBox[{"1", "-", "\[Gamma]"}], ")"}]}], "x"]}], ")"}]}]}]}], + ")"}]}]}]}]], "Echo", + CellChangeTimes->{ + 3.917376514286028*^9},ExpressionUUID->"4c5f61bd-03b7-4432-a272-\ +0f26503b2dfb"] +}, Open ]], + +Cell[BoxData[ + RowBox[{"-", "5.336339703454485`*^-9"}]], "Output", + CellChangeTimes->{{3.916850668010118*^9, 3.916850703273357*^9}, + 3.917375605555485*^9, 3.917375834699234*^9, 3.917376117017376*^9, + 3.91737615836895*^9, {3.917376442233181*^9, 3.9173764500649357`*^9}, + 3.917376514301814*^9}, + CellLabel-> + "Out[315]=",ExpressionUUID->"a1f818a7-7515-42f6-8412-5023424e7584"], + +Cell[BoxData["0.4460228336084214`"], "Output", + CellChangeTimes->{{3.916850668010118*^9, 3.916850703273357*^9}, + 3.917375605555485*^9, 3.917375834699234*^9, 3.917376117017376*^9, + 3.91737615836895*^9, {3.917376442233181*^9, 3.9173764500649357`*^9}, + 3.917376514303438*^9}, + CellLabel-> + "Out[317]=",ExpressionUUID->"53eae298-6178-4ff5-afd7-6d8d8a6d15d1"], + +Cell[BoxData["0.5575285457294789`"], "Output", + CellChangeTimes->{{3.916850668010118*^9, 3.916850703273357*^9}, + 3.917375605555485*^9, 3.917375834699234*^9, 3.917376117017376*^9, + 3.91737615836895*^9, {3.917376442233181*^9, 3.9173764500649357`*^9}, + 3.91737651430447*^9}, + CellLabel-> + "Out[319]=",ExpressionUUID->"8a5a30f2-553b-4cde-86b0-6f924840169e"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Raise External Price:", "Subsection", + CellChangeTimes->{{3.9119155525165854`*^9, + 3.911915558137148*^9}},ExpressionUUID->"f642d822-e56a-4daf-87b3-\ +4a7c12588060"], + +Cell[CellGroupData[{ + +Cell[TextData[{ + "Let ", + Cell[BoxData[ + FormBox[ + SubscriptBox["O", "Y"], TraditionalForm]],ExpressionUUID-> + "eaba641e-4e33-4917-a83f-d6c2123511de"], + " be the optimal amount of Y token to tender to get max arbitrage profit." +}], "Subsubsection", + CellChangeTimes->{{3.91191556049035*^9, + 3.911915572188102*^9}},ExpressionUUID->"53a95604-bde4-406e-8c5f-\ +f440053636d6"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["S", "ext"], " ", "=", " ", "1.2"}], ";", " ", + RowBox[{"Assert", "[", + RowBox[{ + SubscriptBox["S", "ext"], " ", ">", " ", + SubscriptBox["S", "0"]}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Raise"], "[", "in_", "]"}], " ", ":=", " ", + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{"in", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], ",", "in"}], "]"}], ",", " ", + + SubscriptBox["S", "ext"], ",", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{"in", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], "]"}]}], "\n", + RowBox[{"Plot", "[", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Raise"], "[", "v", "]"}], ",", " ", + RowBox[{"{", + RowBox[{"v", ",", "0", ",", "0.2"}], "}"}]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{ + SubscriptBox["O", "Y"], " ", "=", " ", + RowBox[{"ArgMax", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Raise"], "[", "y", "]"}], ",", " ", + RowBox[{"0", "<=", "y", "<=", "5"}]}], "}"}], ",", " ", "y"}], + "]"}]}], ";"}], " "}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + SubscriptBox["O", "Y"]}]}], "}"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], ",", + SubscriptBox["O", "Y"]}], "]"}], ",", " ", + "\"\\ +\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["P", "F"], " ", "=", " ", + RowBox[{"P", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], "+", + SubscriptBox["O", "Y"]}], ",", " ", + SubscriptBox["w", "0"]}], "]"}]}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["P", "F"], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"diffRaise", "[", "v_", "]"}], ":=", + RowBox[{"D", "[", + RowBox[{ + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + "v", ",", "x", ",", "y", ",", "L", ",", "w", ",", "\[Gamma]"}], + "]"}], ",", "v"}], "]"}], ",", " ", "S", ",", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + "v", ",", "x", ",", "y", ",", "L", ",", "w", ",", "\[Gamma]"}], + "]"}]}], "]"}], ",", "v"}], "]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"FullSimplify", "[", + RowBox[{"diffRaise", "[", "v", "]"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], + "\n", + RowBox[{"(*", " ", + RowBox[{ + "Check", " ", "that", " ", "the", " ", "trading", " ", "function", " ", + "is", " ", "invariant", " ", "under", " ", "the", " ", "swap"}], " ", + "*)"}]}], "\n", + RowBox[{"Assert", "[", + RowBox[{ + RowBox[{"Abs", "[", + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + SubscriptBox["O", "Y"]}], ",", " ", + RowBox[{ + SubscriptBox["L", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[Delta]", "LiqX"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + SubscriptBox["w", "0"]}], "]"}], "]"}], " ", "<", " ", + SuperscriptBox["10", + RowBox[{"-", "15"}]]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"checkRaise", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "w_", ",", + "\[Gamma]_"}], "]"}], ":=", " ", + FractionBox[ + RowBox[{ + RowBox[{"w", " ", + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}], " ", + RowBox[{"(", + RowBox[{"L", "-", + RowBox[{"v", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["x", "y"], ")"}], "w"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}], "+", + RowBox[{"S", " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}], + RowBox[{ + RowBox[{"-", "1"}], "+", "w"}]], " ", + RowBox[{"(", + RowBox[{"L", "-", + RowBox[{"v", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["x", "y"], ")"}], "w"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}], + ")"}], + FractionBox["1", "w"]], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"L", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "w"}], ")"}]}], "-", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + FractionBox["x", "y"], ")"}], "w"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"v", " ", "w"}], "+", "y"}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}]}], + RowBox[{"w", " ", + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "L"}], "+", + RowBox[{"v", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["x", "y"], ")"}], "w"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}]]}], + ";"}], "\n", + RowBox[{"checkRaise", "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["S", "ext"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"numRaise", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "w_", ",", + "\[Gamma]_"}], "]"}], ":=", " ", + RowBox[{ + RowBox[{"w", " ", + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}], " ", + RowBox[{"(", + RowBox[{"L", "-", + RowBox[{"v", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["x", "y"], ")"}], "w"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}], "+", + RowBox[{"S", " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}], + RowBox[{ + RowBox[{"-", "1"}], "+", "w"}]], " ", + RowBox[{"(", + RowBox[{"L", "-", + RowBox[{"v", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["x", "y"], ")"}], "w"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}], ")"}], + FractionBox["1", "w"]], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"L", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "w"}], ")"}]}], "-", + RowBox[{ + SuperscriptBox[ + RowBox[{"(", + FractionBox["x", "y"], ")"}], "w"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"v", " ", "w"}], "+", "y"}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}]}]}], + ";"}], "\n", + RowBox[{"numRaise", "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["S", "ext"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"denomRaise", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "w_", ",", + "\[Gamma]_"}], "]"}], ":=", " ", + RowBox[{"w", " ", + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "L"}], "+", + RowBox[{"v", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox["x", "y"], ")"}], "w"], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}]}], + ";"}], "\n", + RowBox[{ + RowBox[{"denomRaise", "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["S", "ext"], ",", + SubscriptBox["w", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], "\n", "\n"}], "\n", + RowBox[{ + RowBox[{"(*", + RowBox[{ + RowBox[{ + RowBox[{"diffLower", "[", "v_", "]"}], ":=", + RowBox[{"D", "[", + RowBox[{ + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{"v", ",", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + "v", ",", "x", ",", "y", ",", "L", ",", "w", ",", "\[Gamma]"}], + "]"}]}], "]"}], ",", " ", "S", ",", " ", "v"}], "]"}], ",", " ", + "v"}], "]"}]}], ";", "\n", + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"FullSimplify", "[", + RowBox[{"diffLower", "[", "v", "]"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], + "*)"}]}]}], "Code", + CellChangeTimes->{{3.9119155810024433`*^9, 3.911915714750348*^9}, { + 3.911915807605125*^9, 3.911915819329722*^9}, {3.911915898415785*^9, + 3.911915941457925*^9}, {3.911916261572165*^9, 3.911916269164069*^9}, { + 3.91675082748877*^9, 3.916750830647251*^9}, {3.916755607350933*^9, + 3.9167556247681293`*^9}, {3.916837467954167*^9, 3.9168375040876637`*^9}, { + 3.916840006139349*^9, 3.9168400489569063`*^9}, {3.916840492337409*^9, + 3.916840493344598*^9}, {3.916840601017839*^9, 3.916840601114201*^9}, { + 3.916840694014946*^9, 3.9168407027692823`*^9}, {3.9168408412216988`*^9, + 3.9168408415590687`*^9}, {3.9168408892290707`*^9, 3.916840890247583*^9}, { + 3.91684092129491*^9, 3.9168409213471937`*^9}, {3.916841127738755*^9, + 3.916841200194109*^9}, {3.916841307935339*^9, 3.916841324012429*^9}, { + 3.916841359362419*^9, 3.916841415683488*^9}, {3.91737652142321*^9, + 3.917376524511488*^9}}, + CellLabel-> + "In[320]:=",ExpressionUUID->"7a15b2a1-0c7b-4080-9632-dc9021620919"], + +Cell[BoxData[ + GraphicsBox[{{{}, {}, + TagBox[ + {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[ + 1.], LineBox[CompressedData[" +1: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 + "]]}, + Annotation[#, "Charting`Private`Tag$52369#1"]& ]}, {}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + Axes->{True, True}, + AxesLabel->{None, None}, + AxesOrigin->{0, 0}, + DisplayFunction->Identity, + Frame->{{False, False}, {False, False}}, + FrameLabel->{{None, None}, {None, None}}, + FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}}, + GridLines->{None, None}, + GridLinesStyle->Directive[ + GrayLevel[0.5, 0.4]], + ImagePadding->All, + Method->{ + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, "DefaultMeshStyle" -> + AbsolutePointSize[6], "ScalingFunctions" -> None, + "CoordinatesToolOptions" -> {"DisplayFunction" -> ({ + (Identity[#]& )[ + Part[#, 1]], + (Identity[#]& )[ + Part[#, 2]]}& ), "CopiedValueFunction" -> ({ + (Identity[#]& )[ + Part[#, 1]], + (Identity[#]& )[ + Part[#, 2]]}& )}}, + PlotRange->{{0, 0.2}, {-0.0012003592993060877`, 0.008492244754738969}}, + PlotRangeClipping->True, + PlotRangePadding->{{ + Scaled[0.02], + Scaled[0.02]}, { + Scaled[0.05], + Scaled[0.05]}}, + Ticks->{Automatic, Automatic}]], "Output", + CellChangeTimes->{ + 3.9168413278484707`*^9, {3.916841360364497*^9, 3.916841380221867*^9}, + 3.9173756151018047`*^9, 3.917376525425939*^9}, + CellLabel-> + "Out[322]=",ExpressionUUID->"f6e93834-5111-4db5-8c3e-43dda9b8a147"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The optimal amount of Y to tender is: \\!\\(\\*SubscriptBox[\\(\ +\[CapitalDelta]\\), \\(Y\\)]\\) = \"\>", + "EchoLabel"], " ", "0.0921528843667211`"}]], "Echo", + CellChangeTimes->{ + 3.9173765254619226`*^9},ExpressionUUID->"8ac1734a-e0db-4cdb-81dc-\ +2aa139ec630e"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The amount out is: \\!\\(\\*SubscriptBox[\\(\[CapitalDelta]\\), \ +\\(X\\)]\\) = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "0.08387094146095486`"}]}]], "Echo", + CellChangeTimes->{ + 3.9173765254698887`*^9},ExpressionUUID->"cef205b4-24c5-4b42-84f6-\ +3911caee3c22"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The resulting reserves are: (\\!\\(\\*SubscriptBox[\\(x\\), \ +\\(1\\)]\\),\\!\\(\\*SubscriptBox[\\(y\\), \\(1\\)]\\)) = \"\>", + "EchoLabel"], " ", + RowBox[{"{", + RowBox[{"0.9161290585390451`", ",", "1.0921528843667212`"}], + "}"}]}]], "Echo", + CellChangeTimes->{ + 3.9173765254926977`*^9},ExpressionUUID->"7b57ec96-1204-4b48-b343-\ +3a8cb80fbd77"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The marginal price paid was: \\!\\(\\*SubscriptBox[\\(P\\), \ +\\(M\\)]\\) = \"\>", + "EchoLabel"], " ", "1.0987462732801418`"}]], "Echo", + CellChangeTimes->{ + 3.917376525500349*^9},ExpressionUUID->"9c3d0530-4afa-4a50-a712-\ +9da4101925ad"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The final price of the pool is: P = \"\>", + "EchoLabel"], " ", "1.1921386776098795`"}]], "Echo", + CellChangeTimes->{ + 3.9173765255174093`*^9},ExpressionUUID->"40d8d1a6-b0d6-46a6-b818-\ +6eaf5ee08fcd"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The equation to do root finding with is: \"\>", + "EchoLabel"], " ", + RowBox[{ + RowBox[{"-", "1"}], "+", + FractionBox[ + RowBox[{"S", " ", + SuperscriptBox[ + RowBox[{"(", + FractionBox[ + RowBox[{"L", " ", + SuperscriptBox[ + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}], + RowBox[{ + RowBox[{"-", "1"}], "+", "w"}]], " ", + RowBox[{"(", + RowBox[{"v", "+", "y", "-", + RowBox[{"v", " ", "\[Gamma]"}]}], ")"}]}], "y"], ")"}], + FractionBox["1", "w"]], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"w", " ", + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}]}], "-", + RowBox[{ + RowBox[{"(", + RowBox[{ + RowBox[{"v", " ", "w"}], "+", "y"}], ")"}], " ", "\[Gamma]"}]}], + ")"}]}], + RowBox[{"w", " ", + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}], " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "y"}], "+", + RowBox[{"v", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], + ")"}]}]]}]}]], "Echo", + CellChangeTimes->{ + 3.91737652579002*^9},ExpressionUUID->"ed0c361d-6c42-46c2-a90d-f49fa0612c9c"] +}, Open ]], + +Cell[BoxData[ + RowBox[{"-", "4.232163287864434`*^-9"}]], "Output", + CellChangeTimes->{ + 3.9168413278484707`*^9, {3.916841360364497*^9, 3.916841380221867*^9}, + 3.9173756151018047`*^9, 3.917376525796341*^9}, + CellLabel-> + "Out[333]=",ExpressionUUID->"7cf2cd9d-1ff3-448c-8907-80dcc7585b4c"], + +Cell[BoxData["2.3117235903313826`*^-9"], "Output", + CellChangeTimes->{ + 3.9168413278484707`*^9, {3.916841360364497*^9, 3.916841380221867*^9}, + 3.9173756151018047`*^9, 3.917376525798567*^9}, + CellLabel-> + "Out[335]=",ExpressionUUID->"a16d71b5-1eb7-4c52-831c-1c470734a16a"], + +Cell[BoxData[ + RowBox[{"-", "0.5462274097410563`"}]], "Output", + CellChangeTimes->{ + 3.9168413278484707`*^9, {3.916841360364497*^9, 3.916841380221867*^9}, + 3.9173756151018047`*^9, 3.917376525799547*^9}, + CellLabel-> + "Out[337]=",ExpressionUUID->"ae67615f-9200-4a1b-b127-1e6135b099df"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +}, +WindowSize->{992, 1233}, +WindowMargins->{{Automatic, 12}, {-819, Automatic}}, +PrintingCopies->1, +PrintingPageRange->{1, Automatic}, +FrontEndVersion->"13.2 for Mac OS X ARM (64-bit) (January 31, 2023)", +StyleDefinitions->FrontEnd`FileName[{$RootDirectory, "Users", "colin", + "Documents"}, "DarkMode.nb", CharacterEncoding -> "UTF-8"], +ExpressionUUID->"3103eac2-d17e-4a34-a2c9-7112f09edadf" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[583, 22, 189, 3, 238, "Title",ExpressionUUID->"464b00f2-edbc-4299-9ebc-bbbbadc48e36"], +Cell[CellGroupData[{ +Cell[797, 29, 177, 3, 101, "Section",ExpressionUUID->"7647c4f8-4fe4-4b60-9236-0948b016bc8d"], +Cell[977, 34, 531, 13, 54, "Code",ExpressionUUID->"90a85ca4-15ef-43a6-a1c9-9ded2b5b4873"], +Cell[CellGroupData[{ +Cell[1533, 51, 207, 3, 81, "Subsection",ExpressionUUID->"2a9c67df-985b-48b8-9ff4-a81c2ce2cf78"], +Cell[CellGroupData[{ +Cell[1765, 58, 227, 5, 67, "Subsubsection",ExpressionUUID->"a33110f6-a0d7-448f-8bd8-0f79efb458dd"], +Cell[1995, 65, 644, 20, 50, "Text",ExpressionUUID->"9a6a4459-0d52-4b73-811d-1f5b6974a4d1"], +Cell[2642, 87, 1453, 43, 230, "Code",ExpressionUUID->"7253b091-e52f-418b-a1c8-287d88022e6a"] +}, Open ]], +Cell[CellGroupData[{ +Cell[4132, 135, 558, 16, 107, "Subsubsection",ExpressionUUID->"c79752c3-b802-42fd-9612-2c9ed31365e8"], +Cell[4693, 153, 399, 11, 68, "Code",ExpressionUUID->"18a899a0-963a-45c4-a7a0-9fbeda760047"] +}, Open ]], +Cell[CellGroupData[{ +Cell[5129, 169, 182, 2, 67, "Subsubsection",ExpressionUUID->"ccc19f67-4212-4173-8f38-591d9c869a78"], +Cell[5314, 173, 404, 11, 54, "Code",ExpressionUUID->"25e959b2-4561-4b40-a658-c7cf56341acc"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[5779, 191, 237, 6, 158, "Section",ExpressionUUID->"8ecbbf5d-d7c2-4753-8dae-ccd81d3ed5db"], +Cell[CellGroupData[{ +Cell[6041, 201, 257, 6, 122, "Subsection",ExpressionUUID->"3778290c-33c8-4669-bd57-a54efc82c76a"], +Cell[CellGroupData[{ +Cell[6323, 211, 1232, 31, 136, "Code",ExpressionUUID->"a277fd9d-36f8-4eee-9601-665001bbe972"], +Cell[CellGroupData[{ +Cell[7580, 246, 251, 7, 53, "Echo",ExpressionUUID->"e292a780-3309-44c3-be1d-26b2a20e24a3"], +Cell[7834, 255, 237, 6, 38, "Echo",ExpressionUUID->"b4ef115e-13e6-465e-afa5-f607b00b73a0"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[8132, 268, 254, 6, 122, "Subsection",ExpressionUUID->"0e4b0b5f-de16-4a42-af35-cb7f8c5a845c"], +Cell[CellGroupData[{ +Cell[8411, 278, 1047, 27, 86, "Code",ExpressionUUID->"fabf4afc-21e6-47a6-b63d-ba788b915987"], +Cell[CellGroupData[{ +Cell[9483, 309, 266, 7, 38, "Echo",ExpressionUUID->"01616c47-d47f-4163-ae7f-1486a28100e4"], +Cell[9752, 318, 230, 6, 38, "Echo",ExpressionUUID->"fc434cef-4acc-4e55-bde9-391e8b23b2d8"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[10031, 330, 250, 6, 67, "Subsubsection",ExpressionUUID->"d14796ee-6661-403b-a067-2e1c5a6c6211"], +Cell[CellGroupData[{ +Cell[10306, 340, 1297, 39, 86, "Code",ExpressionUUID->"ee083f7c-4161-4e24-8675-42d8b5ffacbe"], +Cell[CellGroupData[{ +Cell[11628, 383, 263, 7, 38, "Echo",ExpressionUUID->"47b0b03a-8b5e-49c0-ab03-4782db75c308"], +Cell[11894, 392, 273, 7, 38, "Echo",ExpressionUUID->"dc83f75a-8600-43f2-b1e3-eba4431e2b04"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[12228, 406, 225, 4, 67, "Subsubsection",ExpressionUUID->"0a95fd1e-5759-46f5-b752-6b4f74d4268c"], +Cell[CellGroupData[{ +Cell[12478, 414, 675, 20, 86, "Code",ExpressionUUID->"9b2bc5ef-d095-45dd-ac2b-15f02684ac4f"], +Cell[13156, 436, 211, 6, 38, "Echo",ExpressionUUID->"4a6673d1-2530-4a7d-9666-b22656868b6c"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[13416, 448, 280, 6, 106, "Subsubsection",ExpressionUUID->"f59add3e-9736-413f-b760-d953f4b2de71"], +Cell[13699, 456, 1145, 38, 98, "Code",ExpressionUUID->"5ace6d65-c46d-491e-a7b3-d364ee7f21fb"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[14905, 501, 153, 3, 101, "Section",ExpressionUUID->"0aa1aa4a-a222-4348-9a33-bdcf246c0ec1"], +Cell[CellGroupData[{ +Cell[15083, 508, 208, 3, 81, "Subsection",ExpressionUUID->"a09de9d8-3ec0-4d13-8819-089fc369fa6e"], +Cell[15294, 513, 2831, 72, 242, "Code",ExpressionUUID->"6c9eba4a-50a0-4c93-b07c-3139817809de"], +Cell[CellGroupData[{ +Cell[18150, 589, 2337, 68, 183, "Code",ExpressionUUID->"57d57c6e-b361-4057-8fe3-86b50c9464e4"], +Cell[20490, 659, 384, 7, 40, "Output",ExpressionUUID->"705276af-d995-4ce0-b354-84831b308d2d"], +Cell[20877, 668, 350, 6, 40, "Output",ExpressionUUID->"2110b4c3-3d24-4487-ab7a-315bad605229"], +Cell[21230, 676, 383, 7, 40, "Output",ExpressionUUID->"da9c9147-ed0c-4928-9879-cb5907e8605b"], +Cell[21616, 685, 350, 6, 40, "Output",ExpressionUUID->"318c935c-af9d-45ae-996b-68e575a47d69"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[22027, 698, 156, 3, 101, "Section",ExpressionUUID->"2af33c95-75fa-4c2a-987e-0c0efa8a1771"], +Cell[22186, 703, 515, 12, 111, "Text",ExpressionUUID->"72430652-d39e-479e-8fb5-8c2568d7c943"], +Cell[CellGroupData[{ +Cell[22726, 719, 537, 14, 108, "Subsubsection",ExpressionUUID->"a8656622-88c3-4ada-82e5-d33556722b56"], +Cell[23266, 735, 517, 17, 107, "Code",ExpressionUUID->"8864b3f3-1b36-4dcd-99b8-7a357f5a3a30"] +}, Open ]], +Cell[CellGroupData[{ +Cell[23820, 757, 171, 3, 81, "Subsection",ExpressionUUID->"f9739415-ba82-4653-b842-33b37c1cd286"], +Cell[CellGroupData[{ +Cell[24016, 764, 400, 11, 107, "Subsubsection",ExpressionUUID->"905228e2-efe5-43aa-9780-0b193149ea3d"], +Cell[CellGroupData[{ +Cell[24441, 779, 12280, 363, 721, "Code",ExpressionUUID->"1a8d1d1f-d7f4-4461-a836-4d4571ea6392"], +Cell[36724, 1144, 7205, 138, 337, "Output",ExpressionUUID->"986f7163-cf03-4de4-b998-9538f3a4c8bc"], +Cell[CellGroupData[{ +Cell[43954, 1286, 300, 6, 38, "Echo",ExpressionUUID->"6394a97c-351e-437d-8c02-9b0642aacf09"], +Cell[44257, 1294, 302, 8, 38, "Echo",ExpressionUUID->"5e6b589a-5de5-4f17-9268-a35f46b410b1"], +Cell[44562, 1304, 392, 10, 38, "Echo",ExpressionUUID->"957d146b-e63f-416f-a7cb-8c6b69727396"], +Cell[44957, 1316, 279, 7, 38, "Echo",ExpressionUUID->"a6375d85-fb17-4296-9761-db2b17a953c6"], +Cell[45239, 1325, 236, 5, 38, "Echo",ExpressionUUID->"ea158521-8811-4328-bda0-60677eb48800"], +Cell[45478, 1332, 3029, 98, 201, "Echo",ExpressionUUID->"4c5f61bd-03b7-4432-a272-0f26503b2dfb"] +}, Open ]], +Cell[48522, 1433, 384, 7, 40, "Output",ExpressionUUID->"a1f818a7-7515-42f6-8412-5023424e7584"], +Cell[48909, 1442, 364, 6, 40, "Output",ExpressionUUID->"53eae298-6178-4ff5-afd7-6d8d8a6d15d1"], +Cell[49276, 1450, 363, 6, 40, "Output",ExpressionUUID->"8a5a30f2-553b-4cde-86b0-6f924840169e"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[49700, 1463, 171, 3, 81, "Subsection",ExpressionUUID->"f642d822-e56a-4daf-87b3-4a7c12588060"], +Cell[CellGroupData[{ +Cell[49896, 1470, 377, 10, 68, "Subsubsection",ExpressionUUID->"53a95604-bde4-406e-8c5f-f440053636d6"], +Cell[CellGroupData[{ +Cell[50298, 1484, 13806, 417, 879, "Code",ExpressionUUID->"7a15b2a1-0c7b-4080-9632-dc9021620919"], +Cell[64107, 1903, 7344, 140, 330, "Output",ExpressionUUID->"f6e93834-5111-4db5-8c3e-43dda9b8a147"], +Cell[CellGroupData[{ +Cell[71476, 2047, 304, 7, 38, "Echo",ExpressionUUID->"8ac1734a-e0db-4cdb-81dc-2aa139ec630e"], +Cell[71783, 2056, 304, 8, 38, "Echo",ExpressionUUID->"cef205b4-24c5-4b42-84f6-3911caee3c22"], +Cell[72090, 2066, 394, 10, 38, "Echo",ExpressionUUID->"7b57ec96-1204-4b48-b343-3a8cb80fbd77"], +Cell[72487, 2078, 279, 7, 38, "Echo",ExpressionUUID->"9c3d0530-4afa-4a50-a712-9da4101925ad"], +Cell[72769, 2087, 241, 6, 38, "Echo",ExpressionUUID->"40d8d1a6-b0d6-46a6-b818-6eaf5ee08fcd"], +Cell[73013, 2095, 1291, 43, 86, "Echo",ExpressionUUID->"ed0c361d-6c42-46c2-a90d-f49fa0612c9c"] +}, Open ]], +Cell[74319, 2141, 292, 6, 40, "Output",ExpressionUUID->"7cf2cd9d-1ff3-448c-8907-80dcc7585b4c"], +Cell[74614, 2149, 276, 5, 40, "Output",ExpressionUUID->"a16d71b5-1eb7-4c52-831c-1c470734a16a"], +Cell[74893, 2156, 289, 6, 40, "Output",ExpressionUUID->"ae67615f-9200-4a1b-b127-1e6135b099df"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +} +] +*) + diff --git a/src/LogNormal/README.md b/src/LogNormal/README.md new file mode 100644 index 00000000..e68434c6 --- /dev/null +++ b/src/LogNormal/README.md @@ -0,0 +1,292 @@ + + +# Log Normal +This will be all the math involved with the Log Normal (LN?) trading function. + +## Conceptual Overview +The normal strategy provides the LP with a a log-normal shaped liquidity distribution centered around a price $K$ with a width given by $\sigma$. +This strategy can be made time-dependent by an additional $\tau$ parameter that is the time til the pool will "expire". +In this case, the LN trading function provides the LP with a payoff that is equivalent to a Black-Scholes covered call option with strike $K$, implied volatility $\sigma$, and time to expiration $\tau$. The parameters $K$ and $\sigma$ can also be made time dependent. + +## Core +LN has three variable parameters: +- $K \equiv \mathtt{strike}$ +- $\sigma \equiv \mathtt{volatility}$ +- $\tau \equiv \mathtt{time\_to\_expiration}$ +- These parameters must satisfy: +$$ +K>0\\ +\sigma>0\\ +\tau>0 +$$ +Let's separate variables from parameters in function inputs with $;$ just to stay clear (though it may be verbose). +The trading function for this strategy is given by +$$ +\begin{equation} +\varphi(x,y,L;K,\sigma, \tau) = \Phi^{-1}\left(\frac{x}{L}\right)+\Phi^{-1}\left(\frac{y}{KL}\right)+\sigma \sqrt{\tau}. +\end{equation} +$$ +In the equation above, $x$ and $y$ are reserves, and $L$ is the *liquidity*. +We can put: +$$ +L \equiv \mathtt{liquidity} +$$ +Note that $L$ has units of Token (this is what we want). +Given the domain of $\Phi^{-1}$ we can see that $x\in\[0,L\]$ and $y\in\[0,KL\]$. +As the pool's liquidity increases, the maximal amount of each reserve increases and both are scaled by the same factor (this is what we want). + +## Useful Notation +We will use the following notation: +$$ +\begin{equation} +d_1(S;K,\sigma,\tau) = \frac{\ln\frac{S}{K}+\frac{1}{2}\sigma^2 \tau }{\sigma \sqrt{\tau}} +\end{equation} +$$ +$$ +\begin{equation} +d_2(S;K,\sigma,\tau) = \frac{\ln\frac{S}{K}-\frac{1}{2}\sigma^2 \tau }{\sigma \sqrt{\tau}} +\end{equation} +$$ + +## Price +If we compute the derivatives and simplify the expression, we get that the pool price is given by either: +$$ +\begin{equation} +\boxed{P_X(x, L; K, \sigma, \tau) = K \exp\left(\Phi^{-1} \left(1 - \frac{x}{L}\right) \sigma \sqrt{\tau} - \frac{1}{2} \sigma^2 \tau \right)} +\end{equation} +$$ +$$ +\begin{equation} +\boxed{P_Y(y, L; K, \sigma, \tau) = K \exp\left(\Phi^{-1} \left(\frac{y}{KL}\right) \sigma \sqrt{\tau} + \frac{1}{2} \sigma^2 \tau \right)} +\end{equation} +$$ +Do not that other DFMMs such as the [geometric mean market maker](./geometric_mean.md) have a price that can be determined from both reserves at once so we typically do not write `P_X` and `P_Y`. + +## Determining $L$ from Price and Reserves +There are a few distinct times where we need to determine the value of $L$, but they all come down to liquidity being deposited into the pool and not from swaps. +We want to disentangle swaps and liquidity provision/donation. +Note that for [G3M](./geometric_mean.md), we don't have this same need as the $L$ is determined by the trading function explicitly. + +### $L$ from $x$ +Without showing all the work, we can recall that $\frac{x}{L}$ is one of the option binaries: +$$ +\begin{equation} +\frac{x}{L} = 1-\Phi((d_1(S;K,\sigma, \tau)) +\end{equation} +$$ +Since we know $x$ and we know $S$, we can solve for $L$ to find: +$$ +\begin{equation} +\boxed{L_X(x, S; K, \sigma, \tau) = \frac{x}{1-\Phi(d_1(S;K,\sigma, \tau))}} +\end{equation} +$$ + +### $L$ from $y$ +The work here is basically a mirrored image of the above. +$$ +\begin{equation} +\frac{y}{KL} = \Phi(d_2(S;K,\sigma, \tau)) +\end{equation} +$$ +From here we get $L$: +$$ +\begin{equation} +\boxed{L_Y(y, S; K, \sigma, \tau) = \frac{y}{K\Phi(d_2(S;K,\sigma, \tau))}} +\end{equation} +$$ + + +## Pool Initialization +When the pool is initialized, we need to determine the value of $L$. +The user will provide a price $S$ and an amount of $x$ or an amount of $y$ that they wish to tender. +From there, we should be able to determine how much of both tokens must be allocated as well as the value of $L$. + +### Specifying $x$ +Suppose that the user specifies the amount $x_0$ they wish to allocate and they also choose a price $S_0$. +Further, we need to know how much $y_0$ to allocate, which we can also use the other binary in Equation $(8)$. +At this point, we know $S$ and $L$ and so we can get: +$$ +\boxed{y_0 = y(x_0,S_0;K,\sigma, \tau) = K L_X(x_0, S_0; K, \sigma, \tau) \Phi(d_2(S;K,\sigma, \tau))} +$$ +Note that the above is not simplified and likely could be drastically simplified. + + +### Specifying $y$ +Suppose that the user specifies the amount $y$ they wish to allocate and they also choose a price $S$. +Now we need to get $x$: +$$ +\boxed{x_0 = x(y_0, S_0) = L_Y(y_0, S_0; K, \sigma, \tau) \left(1-\Phi\left(d_1(S;K,\sigma, \tau)\right)\right)} +$$ + +## Adding/Removing Liquidity +When a user adds liquidity, they will specify an amount of $x$ or an amount of $y$, and the pool's price $S$ and liquidity $L$ will already be known. +When adding liquidity, we assume that price will not change whatsoever and only the value of $L$ will change. + +### Specifying $x$ +Given some amount of $\delta_x$ the user wants to add, we can just use the equation for $L(x,S)$ above to get: +$$ +L_X(x+\delta_x,S; K, \sigma, \tau) = \frac{x+\delta_x}{1-\Phi\left(d_1(S;K,\sigma, \tau)\right)} +$$ +In fact, $L$ is linear in the first variable, so: +$$ +L_X(x+\delta_x,S; K, \sigma, \tau) = L_X(x,S; K, \sigma, \tau)+\underbrace{L_X(\delta_x,S; K, \sigma, \tau)}_{\delta_L} +$$ +can be used to make the calculation easier. In fact, if we just want to determine $\delta_L$, we can just use the above equation and subtract $L_X(x,S)$ from both sides and use our $S= P_X(x)$ equation to get: +$$ +\boxed{\delta_{L,X} = \delta_X \frac{L}{x}} +$$ +where $x$ is the amount of $X$ reserves in the pool before the liquidity is added. + +### Specifying $y$ +Given some amount of $\delta_y$ the user wants to add, we can just use the equation for $L(y,S)$ above to get: +$$ +L_Y(y+\delta_y,S; K, \sigma, \tau) = \frac{y+\delta_y}{K\Phi\left(d_1(S;K,\sigma, \tau)\right)} +$$ +Again, $L$ is linear in the first variable. We can use the same technique above to show that: +$$ +\begin{equation} +\boxed{\delta_{L,Y} = \delta_Y \frac{L}{y}} +\end{equation} +$$ + +### Getting the Inputs +Given that we have either $\delta_{L,X}$ or $\delta_{L,Y}$, we can use the above equations to get the amount of $X$ or $Y$ that must be added to the pool. +Specifically, if the user wants to add $\delta_X$, we find $\delta_{L,X}$ then use Equation (10) like so: +$$ +\delta_{L,X} = \delta_Y \frac{L}{y}. +$$ +The other way follows mutatis mutandis. + +### Removing Liquidity +When a user removes liquidity, they will specify an amount of $x$ or an amount of $y$, and the pool's price $S$ and liquidity $L$ will already be known. +When removing liquidity, we assume that price will not change whatsoever and only the value of $L$ will change. +We can just use the same formulation as above and note that $\delta_x$ and $\delta_y$ may be positive or negative. + +## Swaps +When a user swaps, it must be that the trading function $\varphi$ remains invariant. +Specifically, +$$ +\varphi(x+\Delta_X, y+\Delta_Y, L+\delta_L) = 0. +$$ +**Note again I'm allowing for $\Delta_X$ and $\Delta_Y$ to be positive or negative.** +In absence of fees, the liquidity $L$ is invariant, that is $\delta_L = 0$. +We will continue to use the lowercase $\delta$ for fee-based changes and $\Delta$ for swap inputs and outputs to distinguish these components. +To compute a swap, it is a matter of finding the $\Delta_X(\Delta_Y)$ or $\Delta_Y(\Delta_X)$ that satisfies the above equation. + +### With Fees +Assume now that there is a fee parameter $\gamma$ such that the fee invested into the pool is $1-\gamma$. +Assume further that the fee is always taken out of the input token for the swap. +Think of the swap as a two step process: + +1. Adding liquidity. E.g., $\delta_Y \coloneqq (1-\gamma)\Delta_Y$. +This is the amount of the input token that is added to the pool and it is what is used to calculate the change in liquidity $\delta_L$. +From here, we can imagine that the swapper then takes temporary debt in adding $\delta_Y$ to the pool where the $\delta_Y$ can by found by using Equation $(10)$ and we specifically get: +$$ +\delta_Y = y \frac{\delta_L}{L} +$$ +2. Computing a no-fee swap with the remaining amount of the input token. E.g., $\widetilde{\Delta_x} \coloneqq \gamma\Delta_x$. +Note at this point, the reserves are then $x+\delta_x$ and $y+\delta_y$ and the liquidity $L+\delta_L$. +So we must use these in the swap calculation. +Then we can use all of the rules we defined here. + +#### $\Delta_y$ given $\Delta_x$ +Suppose that the user wants to swap $x$ for $y$ and the price is $S$. +They specifically tender $\Delta_x$ and the fee parameter is $\gamma$. +Now $\delta_x=(1-\gamma)\Delta_x$ and $\widetilde{\Delta_x}=\gamma\Delta_x$. +From this we get +$$ +\delta_L=L_X(\delta_x, S)=\frac{\delta_x}{1-\Phi\left(\frac{\ln\frac{S}{K}+\frac{1}{2}\sigma^2}{\sigma}\right)} +$$ +Using the trading function, we solve for $\Delta_y$: +$$ +\Phi^{-1}\left(\frac{x+\Delta_x}{L+\delta_L}\right)+\Phi^{-1}\left(\frac{y+\Delta_y}{K(L+\delta_L)}\right)=-\sigma\\ + +\boxed{\Delta_y(\Delta_x) = K(L+\delta_L)\cdot\Phi\left(-\sigma-\Phi^{-1}\left(\frac{x+\Delta_x}{L+\delta_L}\right)\right)-y} +$$ + +#### $\Delta_x$ given $\Delta_y$ + +Suppose that the user wants to swap $y$ for $x$ and the price is $S$. +They specifically tender $\Delta_y$ and the fee parameter is $\gamma$. +Now $\delta_y=(1-\gamma)\Delta_y$ and $\widetilde{\Delta_y}=\gamma\Delta_y$. +From this we get +$$ +\delta_L=L_Y(\delta_y, S)=\frac{\delta_y}{K\cdot\Phi\left(\frac{\ln\frac{S}{K}-\frac{1}{2}\sigma^2}{\sigma}\right)} +$$ +Using the trading function, we solve for $\Delta_x$: +$$ +\Phi^{-1}\left(\frac{x+\Delta_x}{L+\delta_L}\right)+\Phi^{-1}\left(\frac{y+\Delta_y}{K(L+\delta_L)}\right)=-\sigma\\ +\boxed{\Delta_x(\Delta_y) = (L+\delta_L)\cdot\Phi\left(-\sigma-\Phi^{-1}\left(\frac{y+\Delta_y}{K(L+\delta_L)}\right)\right)-x} +$$ + +## Arbitrage Math + +### Raising the price +When we need to raise the price, we need to tender in $Y$. +If the current price is $S$ and we want to raise it to $S'$, then we need to tender in $Y$ such that we go from $y$ to $y'$ and: +$$ +y' = K\cdot (L+\delta_L) \cdot \Phi\left(\frac{\ln\frac{S'}{K}-\frac{1}{2}\sigma^2}{\sigma}\right) +$$ +and we know $\delta_L$ in terms of $\Delta_y$: +$$ +\frac{(1-\gamma) \Delta_y}{K\cdot\Phi\left(\frac{\ln\frac{S}{K}-\frac{1}{2}\sigma^2}{\sigma}\right)} +$$ +therefore the amount of $Y$ to tender is: +$$ +\Delta_y = y'-y = K\cdot (L+\delta_L) \cdot \Phi\left(\frac{\ln\frac{S'}{K}-\frac{1}{2}\sigma^2}{\sigma}\right)-y\\ += K\cdot L \cdot \Phi\left(\frac{\ln\frac{S'}{K}-\frac{1}{2}\sigma^2}{\sigma} \right) + (1-\gamma)\Delta_y \cdot \frac{\Phi\left(\frac{\ln\frac{S'}{K}-\frac{1}{2}\sigma^2}{\sigma}\right)}{\Phi\left(\frac{\ln\frac{S}{K}-\frac{1}{2}\sigma^2}{\sigma}\right) } -y\\ +\implies \boxed{\Delta_y = \frac{KL\Phi\left(\frac{\ln\frac{S'}{K}-\frac{1}{2}\sigma^2}{\sigma}\right) - y}{1+(\gamma-1)\frac{\Phi\left(\frac{\ln\frac{S'}{K}-\frac{1}{2}\sigma^2}{\sigma}\right)}{\Phi\left(\frac{\ln\frac{S}{K}-\frac{1}{2}\sigma^2}{\sigma}\right) }}} +$$ + + +### Lowering the price +When we need to lower the price, we need to tender in $X$. +If the current price is $S$ and we want to lower it to $S'$, then we need to tender in $X$ such that we go from $x$ to $x'$ and: +$$ +\Delta x = (L + \delta_L)\cdot\left(1-\Phi\left(\frac{\ln\frac{S'}{K}+\frac{1}{2}\sigma^2}{\sigma}\right)\right) - x \\ +\implies \boxed{ \Delta_x = \frac{L\left(1-\Phi\left(\frac{\ln\frac{S'}{K}+\frac{1}{2}\sigma^2}{\sigma}\right)\right)-x}{1+(\gamma-1)\frac{1-\Phi\left(\frac{\ln\frac{S'}{K}+\frac{1}{2}\sigma^2}{\sigma}\right)}{1-\Phi\left(\frac{\ln\frac{S}{K}+\frac{1}{2}\sigma^2}{\sigma}\right)}}} +$$ + +## Value Function on $L(S)$ +Relate to value on $V(L,S)$ and $V(x,y)$. +Then we can use this to tokenize. We have $L_X(x, S)$ and $L_Y(y, S)$. +We know that: +$$ +V(x(S),y(S)) = x S + y +$$ +Now we also have the following +$$ +x = LS\cdot\left(1-\Phi\left(\frac{\ln\frac{S}{K}+\frac{1}{2}\sigma^2}{\sigma}\right)\right)\\ +y = K\cdot L\cdot \Phi\left(\frac{\ln\frac{S}{K}-\frac{1}{2}\sigma^2}{\sigma}\right) +$$ +Therefore: +$$ +\boxed{V(L,S) = L\left( S\cdot\left(1-\Phi\left(\frac{\ln\frac{S}{K}+\frac{1}{2}\sigma^2}{\sigma}\right)\right) + K\cdot \Phi\left(\frac{\ln\frac{S}{K}-\frac{1}{2}\sigma^2}{\sigma}\right)\right)} +$$ +Note that $V$ is linear in $L$ and so we can use this to tokenize. + +### Time Dependence +Note that $L$ effectively changes as parameters of the trading function change. +To see this, note that the trading function must always satisfy: +$$ +\Phi^{-1}\left(\frac{x}{L}\right)+\Phi^{-1}\left(\frac{y}{KL}\right) + \sigma \sqrt{\tau} = 0. +$$ +For new parameters, $K'$, $\sigma'$ and $\tau'$, we must find an $L'$ so that the trading function is satisfied: +$$ +\Phi^{-1}\left(\frac{x}{L'}\right)+\Phi^{-1}\left(\frac{y}{K'L'}\right) + \sigma' \sqrt{\tau'} = 0. +$$ +We can find this new $L'$ using a root finding algorithm. + +#### Root Finding +We will use a bisection algorithm to determine the new $L'$. +Suppose that $(K, \sigma, \tau, L)$ are the current parameters and we have $(K', \sigma', \tau')$ as the new parameters. +Then we can compute: +$$ +f(L) = \Phi^{-1}\left(\frac{x}{L}\right)+\Phi^{-1}\left(\frac{y}{K'L}\right) + \sigma' \sqrt{\tau'}. +$$ +- If $f(L)<0$, then: + - Upper bound: $L$ + - Lower bound: $\max \{x, y/K\}$. +- If $f(L)>0$, then: + - Upper bound: $L \cdot 1.5$. + - Lower bound: $L$ diff --git a/src/LogNormal/log_normal.nb b/src/LogNormal/log_normal.nb new file mode 100644 index 00000000..3ce64e8d --- /dev/null +++ b/src/LogNormal/log_normal.nb @@ -0,0 +1,2318 @@ +(*CacheID: 234*) +(* Internal cache information: +NotebookFileLineBreakTest +NotebookFileLineBreakTest +NotebookDataPosition[ 0, 0] +NotebookDataLength[ 81895, 2317] +NotebookOptionsPosition[ 73068, 2142] +NotebookOutlinePosition[ 73624, 2161] +CellTagsIndexPosition[ 73581, 2158] +WindowFrame->Normal*) + +(* Beginning of Notebook Content *) +Notebook[{ + +Cell[CellGroupData[{ +Cell["Log Normal Trading Function Calculations", "Title", + CellChangeTimes->{{3.911382811596325*^9, + 3.9113828340058823`*^9}},ExpressionUUID->"2003d08a-fff7-4f74-8623-\ +7a0823c9cafa"], + +Cell[CellGroupData[{ + +Cell["\<\ +First, we set up the basic functions we need throughout the notebook.\ +\>", "Section", + CellChangeTimes->{{3.911382862311339*^9, + 3.91138289581577*^9}},ExpressionUUID->"514be430-48c5-4dc6-92af-\ +6b1c3a5b8586"], + +Cell[CellGroupData[{ + +Cell["\<\ +Before anything, we should set some environment level variables.\ +\>", "Subsection", + CellChangeTimes->{{3.911387263997834*^9, + 3.9113872765136137`*^9}},ExpressionUUID->"f16f1652-ed41-4414-8c9b-\ +6b6d5d8061ac"], + +Cell[BoxData[ + RowBox[{ + RowBox[{ + RowBox[{"On", "[", "Assert", "]"}], ";"}], " ", + RowBox[{"(*", " ", + RowBox[{ + RowBox[{ + "Asserts", " ", "will", " ", "show", " ", "a", " ", "failure", " ", "if", + " ", "they", " ", "fail"}], ",", " ", + RowBox[{"and", " ", "nothing", " ", "if", " ", "they", " ", + RowBox[{"don", "'"}], "t"}]}], " ", "*)"}]}]], "Code", + CellChangeTimes->{{3.91138727840687*^9, 3.911387281430051*^9}, { + 3.911387543969853*^9, 3.911387555514419*^9}}, + CellLabel-> + "In[897]:=",ExpressionUUID->"8255c47c-fa0b-4fdd-8638-752453aca613"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["First are the CDF and inverse CDF (PPF) functions.", "Subsection", + CellChangeTimes->{{3.9113829761574574`*^9, + 3.9113829863941193`*^9}},ExpressionUUID->"b3dd161e-0b53-4183-b30c-\ +be7844f26477"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{"\[CapitalPhi]", "[", "x_", "]"}], " ", ":=", " ", + RowBox[{"CDF", "[", + RowBox[{ + RowBox[{"NormalDistribution", "[", + RowBox[{"0", ",", "1"}], "]"}], ",", " ", "x"}], "]"}]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalPhi]", "inv"], "[", "y_", "]"}], " ", ":=", " ", + RowBox[{"Quantile", "[", + RowBox[{ + RowBox[{"NormalDistribution", "[", + RowBox[{"0", ",", " ", "1"}], "]"}], ",", " ", "y"}], "]"}]}]}], "Code", + CellChangeTimes->{{3.911382903714142*^9, 3.911383006799996*^9}, { + 3.911385117889493*^9, 3.911385119663499*^9}, {3.91738309829743*^9, + 3.917383102823773*^9}, {3.9173831552741337`*^9, 3.917383158507695*^9}, + 3.917383532443891*^9}, + CellLabel-> + "In[898]:=",ExpressionUUID->"25d6c1c4-f902-41e0-8746-c63f6b03d94e"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +Next let\[CloseCurlyQuote]s define some helper functions. These will appear \ +often in calculations.\ +\>", "Subsection", + CellChangeTimes->{{3.911383043072701*^9, 3.911383082172174*^9}, { + 3.911383316418652*^9, + 3.9113833317783127`*^9}},ExpressionUUID->"f601d02f-f91e-4780-a166-\ +a78097a54f48"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["d", "1"], "[", + RowBox[{"S_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], "]"}], " ", ":=", + " ", + FractionBox[ + RowBox[{ + RowBox[{"Log", "[", + FractionBox["S", "K"], "]"}], " ", "+", " ", + RowBox[{ + FractionBox["1", "2"], + SuperscriptBox["\[Sigma]", "2"], "\[Tau]"}]}], + RowBox[{"\[Sigma]", + RowBox[{"\[Sqrt]", "\[Tau]"}]}]]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["d", "2"], "[", + RowBox[{"S_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], "]"}], " ", ":=", + " ", + FractionBox[ + RowBox[{ + RowBox[{"Log", "[", + FractionBox["S", "K"], "]"}], " ", "-", " ", + RowBox[{ + FractionBox["1", "2"], + SuperscriptBox["\[Sigma]", "2"], "\[Tau]"}]}], + RowBox[{"\[Sigma]", + RowBox[{"\[Sqrt]", "\[Tau]"}]}]]}]}], "Code", + CellChangeTimes->{{3.911383086202894*^9, 3.911383096527341*^9}, { + 3.911383144055451*^9, 3.911383310823001*^9}, {3.9113851030677443`*^9, + 3.91138511600043*^9}}, + CellLabel-> + "In[900]:=",ExpressionUUID->"d5d16a82-3e60-44ff-affc-b50eb9144304"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +Now let\[CloseCurlyQuote]s define functions that are more explicitly used for \ +the DFMM.\ +\>", "Subsection", + CellChangeTimes->{{3.911383368894425*^9, 3.9113833696600657`*^9}, { + 3.911383542720358*^9, + 3.911383554344432*^9}},ExpressionUUID->"009a24ad-ebe5-4d73-bdda-\ +a7839592332a"], + +Cell[CellGroupData[{ + +Cell["\<\ +These are functions used to get initial liquidity given a token amount and a \ +price.\ +\>", "Subsubsection", + CellChangeTimes->{{3.911383821691424*^9, + 3.911383842953394*^9}},ExpressionUUID->"3b15f5e3-f420-4095-899a-\ +506c7286cc40"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["L", "X"], "[", + RowBox[{"x_", ",", "S_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], + "]"}], " ", ":=", " ", + FractionBox["x", + RowBox[{"1", " ", "-", " ", + RowBox[{"\[CapitalPhi]", "[", + RowBox[{ + SubscriptBox["d", "1"], "[", + RowBox[{"S", ",", "K", ",", "\[Sigma]", ",", "\[Tau]"}], "]"}], + "]"}]}]]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["L", "Y"], "[", + RowBox[{"y_", ",", "S_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], + "]"}], " ", ":=", " ", + FractionBox["y", + RowBox[{"K", " ", + RowBox[{"\[CapitalPhi]", "[", + RowBox[{ + SubscriptBox["d", "2"], "[", + RowBox[{"S", ",", "K", ",", "\[Sigma]", ",", "\[Tau]"}], "]"}], + "]"}]}]]}], "\n", + RowBox[{ + RowBox[{"X", "[", + RowBox[{"y_", ",", "S_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], + "]"}], " ", ":=", " ", + RowBox[{ + RowBox[{ + SubscriptBox["L", "Y"], "[", + RowBox[{"y", ",", "S", ",", "K", ",", "\[Sigma]", ",", "\[Tau]"}], "]"}], + " ", + RowBox[{"(", + RowBox[{"1", " ", "-", " ", + RowBox[{"\[CapitalPhi]", "[", + RowBox[{ + SubscriptBox["d", "1"], "[", + RowBox[{"S", ",", "K", ",", "\[Sigma]", ",", "\[Tau]"}], "]"}], + "]"}]}], ")"}]}]}], "\n", + RowBox[{ + RowBox[{"Y", "[", + RowBox[{"x_", ",", "S_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], + "]"}], " ", ":=", " ", + RowBox[{"K", " ", + RowBox[{ + SubscriptBox["L", "X"], "[", + RowBox[{"x", ",", "S", ",", "K", ",", "\[Sigma]", ",", "\[Tau]"}], "]"}], + " ", + RowBox[{"\[CapitalPhi]", "[", + RowBox[{ + SubscriptBox["d", "2"], "[", + RowBox[{"S", ",", "K", ",", "\[Sigma]", ",", "\[Tau]"}], "]"}], + "]"}]}]}]}], "Code", + CellChangeTimes->{{3.911383688783895*^9, 3.911383741794456*^9}, { + 3.911383797950727*^9, 3.911383809912835*^9}, {3.9113838491740713`*^9, + 3.911383864952888*^9}, {3.9113841779644413`*^9, 3.911384322151863*^9}, { + 3.911384433609087*^9, 3.911384448745434*^9}, {3.9113850554248533`*^9, + 3.911385099649076*^9}, {3.91138525707533*^9, 3.911385263363533*^9}, { + 3.911385324670476*^9, 3.911385325035862*^9}, {3.911409187909778*^9, + 3.9114091880800257`*^9}}, + CellLabel-> + "In[902]:=",ExpressionUUID->"3950a1e9-9c32-45c4-b5ef-404c37d6ef65"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +These are functions that are used to get prices from either a balance in X or \ +a balance in Y.\ +\>", "Subsubsection", + CellChangeTimes->{{3.91138394332069*^9, + 3.911383960427863*^9}},ExpressionUUID->"6228385e-cfd2-4bd0-97f4-\ +58c98a5a994e"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["P", "X"], "[", + RowBox[{"x_", ",", "L_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], + "]"}], " ", ":=", " ", + RowBox[{"K", " ", + RowBox[{"Exp", "[", + RowBox[{ + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalPhi]", "inv"], "[", + RowBox[{"1", " ", "-", " ", + FractionBox["x", "L"]}], "]"}], "\[Sigma]"}], " ", "-", " ", + RowBox[{ + FractionBox["1", "2"], + SuperscriptBox["\[Sigma]", "2"]}]}], "]"}]}]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["P", "Y"], "[", + RowBox[{"y_", ",", "L_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], + "]"}], " ", ":=", " ", + RowBox[{"K", " ", + RowBox[{"Exp", "[", + RowBox[{ + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalPhi]", "inv"], "[", + FractionBox["y", + RowBox[{"K", " ", "L"}]], "]"}], "\[Sigma]"}], " ", "+", " ", + RowBox[{ + FractionBox["1", "2"], + SuperscriptBox["\[Sigma]", "2"]}]}], "]"}]}]}]}], "Code", + CellChangeTimes->{{3.9113839769604807`*^9, 3.911384029460125*^9}, { + 3.911385062781126*^9, 3.911385091502931*^9}}, + CellLabel-> + "In[906]:=",ExpressionUUID->"cdbca2c9-2426-4adf-8516-6c22e3b352b1"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Then we have the trading function", "Subsubsection", + CellChangeTimes->{{3.9114107980754547`*^9, + 3.911410804009096*^9}},ExpressionUUID->"18015876-38da-4fa9-82b7-\ +a417d745ef90"], + +Cell[BoxData[ + RowBox[{ + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + "x_", ",", "y_", ",", "L_", ",", "K_", ",", "\[Sigma]_", ",", "\[Tau]_"}], + "]"}], " ", ":=", " ", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalPhi]", "inv"], "[", + FractionBox["x", "L"], "]"}], "+", + RowBox[{ + SubscriptBox["\[CapitalPhi]", "inv"], "[", + FractionBox["y", + RowBox[{"K", " ", "L"}]], "]"}], "+", + RowBox[{"\[Sigma]", + RowBox[{"\[Sqrt]", "\[Tau]"}]}]}]}]], "Code", + CellChangeTimes->{{3.911410806554799*^9, 3.911410882453505*^9}, { + 3.9114109468550673`*^9, 3.9114109866059113`*^9}}, + CellLabel-> + "In[908]:=",ExpressionUUID->"a65cb5ec-cdac-40e0-bb49-f3d8157592d9"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +Let\[CloseCurlyQuote]s initialize a pool with some constants and some \ +liquidity. \ +\>", "Section", + CellChangeTimes->{{3.911384055956565*^9, 3.911384066810919*^9}, { + 3.911384711690135*^9, + 3.911384714277852*^9}},ExpressionUUID->"da815218-0c74-4720-a5c9-\ +76f45781c5e2"], + +Cell[CellGroupData[{ + +Cell["\<\ +First, let\[CloseCurlyQuote]s set the parameters for our curve, including the \ +fee parameter \[Gamma]\ +\>", "Subsection", + CellChangeTimes->{{3.911384725040826*^9, 3.911384731518064*^9}, { + 3.9113851982356*^9, + 3.911385205023809*^9}},ExpressionUUID->"d461a415-44ca-4804-8248-\ +6137a0f9449f"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + RowBox[{"(*", + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["K", "0"], ",", " ", + SubscriptBox["\[Sigma]", "0"], ",", " ", + SubscriptBox["\[Tau]", "0"], ",", " ", + SubscriptBox["\[Gamma]", "0"]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{"3", ",", " ", + FractionBox["1", "4"], ",", " ", "1", ",", " ", "0.997"}], "}"}]}], + ";"}], " ", "*)"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["K", "0"], ",", " ", + SubscriptBox["\[Sigma]", "0"], ",", " ", + SubscriptBox["\[Tau]", "0"], ",", " ", + SubscriptBox["\[Gamma]", "0"]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{"1", ",", " ", + FractionBox["1", "8"], ",", " ", "1", ",", " ", "0.997"}], "}"}]}], + ";"}], " ", "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["K", "0"], ",", " ", + "\"\<\!\(\*SubscriptBox[\(K\), \(0\)]\) = \>\""}], "]"}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["\[Sigma]", "0"], ",", " ", + "\"\<\!\(\*SubscriptBox[\(\[Sigma]\), \(0\)]\) = \>\""}], "]"}], ";", + " ", + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["\[Tau]", "0"], ",", " ", + "\"\<\!\(\*SubscriptBox[\(\[Tau]\), \(0\)]\) = \>\""}], "]"}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["\[Gamma]", "0"], ",", " ", + "\"\<\!\(\*SubscriptBox[\(\[Gamma]\), \(0\)]\) = \>\""}], "]"}], + ";"}]}]}]], "Code", + CellChangeTimes->{ + 3.91138448247676*^9, {3.9113845136096563`*^9, 3.911384540517331*^9}, { + 3.911384579083336*^9, 3.911384646274679*^9}, {3.911384706054633*^9, + 3.911384732869401*^9}, {3.911385194438079*^9, 3.9113852384442177`*^9}, + 3.911387336640081*^9, {3.911408996136958*^9, 3.9114090092659817`*^9}, { + 3.9169341546962433`*^9, 3.916934155785771*^9}, {3.916934920973572*^9, + 3.916934921366069*^9}, {3.916935004865656*^9, 3.916935006671085*^9}, { + 3.916935097711054*^9, 3.916935099175394*^9}, {3.91693537100875*^9, + 3.916935393268579*^9}, {3.916935561687649*^9, 3.916935563633135*^9}, { + 3.91738367920582*^9, 3.917383680576692*^9}, {3.917384081819539*^9, + 3.917384085426984*^9}, {3.9173856229323063`*^9, 3.917385639341588*^9}, { + 3.91751517656183*^9, + 3.917515189435231*^9}},ExpressionUUID->"8d262a91-37a1-41fb-b1b3-\ +ae8191b1ccda"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*SubscriptBox[\\(K\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "3"}]], "Echo", + CellChangeTimes->{ + 3.917385639673291*^9},ExpressionUUID->"af988e57-d45b-493e-8c77-\ +aeb0d6754a04"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*SubscriptBox[\\(\[Sigma]\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", + FractionBox["1", "4"]}]], "Echo", + CellChangeTimes->{ + 3.917385639702611*^9},ExpressionUUID->"7cbb943d-e136-42be-b7bf-\ +17128b81f7f7"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*SubscriptBox[\\(\[Tau]\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "1"}]], "Echo", + CellChangeTimes->{ + 3.917385639712528*^9},ExpressionUUID->"35bc58ee-e40e-4bf3-9e9f-\ +061ba0d278fb"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*SubscriptBox[\\(\[Gamma]\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "0.997`"}]], "Echo", + CellChangeTimes->{ + 3.917385639734725*^9},ExpressionUUID->"e144304b-6b21-4799-ac3b-\ +3fa33013028a"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +Now, let\[CloseCurlyQuote]s set the initial liquidity by providing an amount \ +of X and a price S.\ +\>", "Subsection", + CellChangeTimes->{{3.9113847363117323`*^9, 3.911384755116337*^9}, { + 3.911384849366685*^9, + 3.9113848505774117`*^9}},ExpressionUUID->"a6874bc0-590c-4cb3-9d20-\ +f010a014a154"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["S", "0"]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{"1000000", ",", " ", "2"}], "}"}]}], ";"}], " "}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["x", "0"], ",", " ", + "\"\\""}], "]"}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["S", "0"], ",", " ", + "\"\<\!\(\*SubscriptBox[\(S\), \(0\)]\) = \>\""}], "]"}], ";"}]}], "Code",\ + + CellChangeTimes->{{3.911384757671178*^9, 3.911384806225191*^9}, { + 3.911386982132729*^9, 3.911386989059497*^9}, 3.91138734111685*^9, { + 3.9114090196649647`*^9, 3.9114090339697657`*^9}, {3.917383705204445*^9, + 3.917383705323718*^9}, {3.917383899939695*^9, 3.9173839018597183`*^9}, { + 3.917383976339484*^9, 3.917383976688408*^9}, 3.917384041262576*^9, { + 3.9173840921075373`*^9, 3.9173840922911777`*^9}, 3.917384525229738*^9, { + 3.917515198755231*^9, + 3.917515199530878*^9}},ExpressionUUID->"085ca656-cc94-43cf-a8c6-\ +c116e23e4910"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The initial X-reserve balance is: \ +\\!\\(\\*SubscriptBox[\\(x\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "1000"}]], "Echo", + CellChangeTimes->{ + 3.9173856411472588`*^9},ExpressionUUID->"b0609413-5fee-4b86-aed9-\ +380cc72ca5ad"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*SubscriptBox[\\(S\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", "2"}]], "Echo", + CellChangeTimes->{ + 3.917385641179336*^9},ExpressionUUID->"0d8deb13-fecc-40d5-b792-\ +e5be624a621e"] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +From this, let\[CloseCurlyQuote]s see what we will get for the initial amount \ +of Y and L.\ +\>", "Subsubsection", + CellChangeTimes->{{3.9113848345992517`*^9, + 3.91138485967836*^9}},ExpressionUUID->"d0f44536-b00f-4974-8c75-\ +dd65dd319645"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["L", "0"], ",", " ", + SubscriptBox["y", "0"]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["L", "X"], "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["S", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}], ",", " ", + RowBox[{"Y", "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["S", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}]}], "}"}]}], ";"}], " "}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["L", "0"], ",", " ", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["y", "0"], ",", " ", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}]}], "Code", + CellChangeTimes->{{3.911384864489366*^9, 3.911384942301722*^9}, { + 3.911384992602735*^9, 3.9113850128379593`*^9}, {3.911385047347066*^9, + 3.9113850518014383`*^9}, {3.9113851385254107`*^9, 3.9113851753238697`*^9}, { + 3.91138696634296*^9, 3.911386992951726*^9}, {3.911387349621842*^9, + 3.911387398394403*^9}, {3.911912845565853*^9, 3.9119128460491123`*^9}}, + CellLabel-> + "In[811]:=",ExpressionUUID->"57112165-db6f-447c-9713-f9c85c6d4828"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The initial liquidity is: \\!\\(\\*SubscriptBox[\\(L\\), \ +\\(0\\)]\\) = \"\>", + "EchoLabel"], " ", + "1072.05816303780375296378681139341832357048`18."}]], "Echo", + CellChangeTimes->{ + 3.91738564223216*^9},ExpressionUUID->"4fd65137-02a9-41b3-ba18-0ebf41cc4e36"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The initial Y-reserve balance is: \ +\\!\\(\\*SubscriptBox[\\(y\\), \\(0\\)]\\) = \"\>", + "EchoLabel"], " ", + "129.71081089049378429032401949955047960211`18."}]], "Echo", + CellChangeTimes->{ + 3.917385642263144*^9},ExpressionUUID->"21eb62ab-27a6-41dd-a389-\ +5142ff75a033"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Let\[CloseCurlyQuote]s check that the prices are correct after the \ +fact.", "Subsubsection", + CellChangeTimes->{{3.911385351666885*^9, + 3.91138536037985*^9}},ExpressionUUID->"0dabba71-0908-48dd-b11c-\ +9fc06ac2d79b"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{"Assert", "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "X"], "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}], " ", "==", " ", + RowBox[{ + SubscriptBox["P", "Y"], "[", + RowBox[{ + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "X"], "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], " "}]}], "Code", + CellChangeTimes->{{3.9113853639105387`*^9, 3.9113854185634947`*^9}, { + 3.9113869483534203`*^9, 3.911386962492029*^9}, {3.911386994813387*^9, + 3.911387177122032*^9}, {3.911387291516371*^9, 3.911387309281919*^9}, + 3.911912928324705*^9}, + CellLabel-> + "In[356]:=",ExpressionUUID->"05df5500-1e66-49a9-afd7-256365f8b6dc"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The initial price is: P = \"\>", + "EchoLabel"], " ", "2"}]], "Echo", + CellChangeTimes->{ + 3.917384531034382*^9},ExpressionUUID->"15c46bab-62f8-4c23-be66-\ +af5cfc278ceb"] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["\<\ +Just to verify that we could have done this the other way, and show the flow, \ +let\[CloseCurlyQuote]s do that real fast.\ +\>", "Subsubsection", + CellChangeTimes->{{3.9113853013290577`*^9, + 3.9113853161239634`*^9}},ExpressionUUID->"6c78f375-83c5-40c5-a26f-\ +9dfafb83427b"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["L", + SubscriptBox["0", "y"]], ",", " ", + SubscriptBox["x", + SubscriptBox["0", "y"]]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["L", "Y"], "[", + RowBox[{ + SubscriptBox["y", "0"], ",", + SubscriptBox["S", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}], ",", " ", + RowBox[{"X", "[", + RowBox[{ + SubscriptBox["y", "0"], ",", + SubscriptBox["S", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}]}], "}"}]}], ";"}], "\n", + RowBox[{ + RowBox[{"Assert", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["L", + SubscriptBox["0", "y"]], ",", + SubscriptBox["x", + SubscriptBox["0", "y"]]}], "}"}], " ", "==", " ", + RowBox[{"{", + RowBox[{ + SubscriptBox["L", "0"], ",", + SubscriptBox["x", "0"]}], "}"}]}], "]"}], ";"}]}], "Code", + CellChangeTimes->{{3.911387447754344*^9, 3.911387533259612*^9}, { + 3.911409113951961*^9, 3.911409136342054*^9}, {3.911409206127439*^9, + 3.911409206365666*^9}}, + CellLabel-> + "In[358]:=",ExpressionUUID->"05cdeb1a-e1b0-40a7-af51-51ab9b75cc2e"] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Swapping", "Section", + CellChangeTimes->{{3.911387861088531*^9, + 3.9113878701923523`*^9}},ExpressionUUID->"e0558e89-2c12-471a-af64-\ +7b6a1457eb4d"], + +Cell[CellGroupData[{ + +Cell["\<\ +Now we need to set up the swap logic. We will use R to denote an arbitrary \ +reserve.\ +\>", "Subsection", + CellChangeTimes->{{3.911387873703059*^9, 3.911387883191267*^9}, { + 3.911388058682213*^9, + 3.911388067027336*^9}},ExpressionUUID->"2f7348b3-443c-4a22-943e-\ +943b7962999e"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"\[CapitalDelta]_", ",", "\[Gamma]_"}], "]"}], " ", ":=", " ", + RowBox[{ + RowBox[{"(", + RowBox[{"1", "-", "\[Gamma]"}], ")"}], "\[CapitalDelta]"}]}], "\n", + RowBox[{"(*", + RowBox[{ + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{"\[CapitalDelta]_", ",", "R_", ",", "L_", ",", "\[Gamma]_"}], + "]"}], " ", ":=", " ", + RowBox[{ + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"\[CapitalDelta]", ",", "\[Gamma]"}], "]"}], + FractionBox["L", "R"]}]}], "*)"}]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + "\[CapitalDelta]_", ",", "x_", ",", "y_", ",", "L_", ",", "K_", ",", + "\[Sigma]_", ",", "\[Tau]_", ",", "\[Gamma]_"}], "]"}], " ", ":=", " ", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"L", "+", + RowBox[{ + FractionBox["1", "K"], + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"\[CapitalDelta]", ",", "\[Gamma]"}], "]"}]}]}], ")"}], + RowBox[{"\[CapitalPhi]", "[", + RowBox[{ + RowBox[{ + RowBox[{"-", "\[Sigma]"}], + RowBox[{"\[Sqrt]", "\[Tau]"}]}], " ", "-", " ", + RowBox[{ + SubscriptBox["\[CapitalPhi]", "inv"], "[", + FractionBox[ + RowBox[{"y", "+", "\[CapitalDelta]"}], + RowBox[{"K", + RowBox[{"(", + RowBox[{"L", "+", + RowBox[{ + FractionBox["1", "K"], + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"\[CapitalDelta]", ",", "\[Gamma]"}], "]"}]}]}], + ")"}]}]], "]"}]}], "]"}]}], "-", "x"}]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + "\[CapitalDelta]_", ",", "x_", ",", "y_", ",", "L_", ",", "K_", ",", + "\[Sigma]_", ",", "\[Tau]_", ",", "\[Gamma]_"}], "]"}], " ", ":=", " ", + RowBox[{ + RowBox[{"K", + RowBox[{"(", + RowBox[{"L", "+", + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"\[CapitalDelta]", ",", "\[Gamma]"}], "]"}]}], ")"}], + RowBox[{"\[CapitalPhi]", "[", + RowBox[{ + RowBox[{ + RowBox[{"-", "\[Sigma]"}], + RowBox[{"\[Sqrt]", "\[Tau]"}]}], " ", "-", " ", + RowBox[{ + SubscriptBox["\[CapitalPhi]", "inv"], "[", + FractionBox[ + RowBox[{"x", "+", "\[CapitalDelta]"}], + RowBox[{"L", "+", + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"\[CapitalDelta]", ",", "\[Gamma]"}], "]"}]}]], "]"}]}], + "]"}]}], "-", "y"}]}]}], "Code", + CellChangeTimes->{{3.9113879019426517`*^9, 3.91138810608572*^9}, { + 3.911388182414874*^9, 3.911388482660475*^9}, {3.911388787674255*^9, + 3.911388979350903*^9}, {3.911389141187207*^9, 3.911389159323999*^9}, { + 3.911390630736039*^9, 3.911390698837728*^9}, {3.911408926773992*^9, + 3.911408926935534*^9}, {3.916935312155489*^9, 3.916935312305293*^9}, { + 3.9173824759156227`*^9, 3.917382476601667*^9}, {3.91738376350004*^9, + 3.917383784452558*^9}, {3.917383943744508*^9, 3.917383954282363*^9}, { + 3.9173839922487173`*^9, 3.9173839928360653`*^9}, {3.9173844534077587`*^9, + 3.91738450986141*^9}, {3.917384708602298*^9, 3.917384711107472*^9}, { + 3.917384741504918*^9, 3.917384745117815*^9}, {3.917384781098084*^9, + 3.917384801570612*^9}, {3.917384922013281*^9, 3.917384925581356*^9}, { + 3.9173850860945387`*^9, 3.917385090363779*^9}, + 3.917385467785697*^9},ExpressionUUID->"0716117c-5381-46be-8b57-\ +f2cefa727879"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{"YIn", " ", "=", " ", "10"}], ";"}], "\n", + RowBox[{ + RowBox[{"XOut", " ", "=", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{"YIn", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{"XOut", ",", " ", "\"\\""}], "]"}], ";"}], "\n", + RowBox[{"(*", + RowBox[{ + RowBox[{"DeltaL", " ", "=", " ", + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{"YIn", ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ";"}], "*)"}]}], "\n", + RowBox[{ + RowBox[{"DeltaL", " ", "=", " ", + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"YIn", ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], "+", "XOut"}], ",", + RowBox[{ + SubscriptBox["y", "0"], "+", "YIn"}], ",", + RowBox[{ + SubscriptBox["L", "0"], "+", + RowBox[{ + FractionBox["1", + SubscriptBox["K", "0"]], "DeltaL"}]}], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n"}], "\n", + RowBox[{ + RowBox[{"XIn", " ", "=", " ", "10"}], ";"}], "\n", + RowBox[{ + RowBox[{"YOut", " ", "=", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{"XIn", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{"YOut", ",", " ", "\"\\""}], "]"}], ";"}], "\n", + RowBox[{"(*", + RowBox[{ + RowBox[{"DeltaL", " ", "=", " ", + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{"XIn", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ";"}], "*)"}]}], "\n", + RowBox[{ + RowBox[{"DeltaL", " ", "=", " ", + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{"XIn", ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], "+", "XIn"}], ",", + RowBox[{ + SubscriptBox["y", "0"], "+", "YOut"}], ",", + RowBox[{ + SubscriptBox["L", "0"], "+", "DeltaL"}], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"2", "/", + RowBox[{"(", + RowBox[{"YOut", "/", "XIn"}], ")"}]}], ",", " ", + "\"\<2/\!\(\*FractionBox[SubscriptBox[\(Y\), \(out\)], \ +SubscriptBox[\(X\), \(in\)]]\) = \>\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{ + RowBox[{"(", + RowBox[{"YIn", "/", "XOut"}], ")"}], "/", "2"}], ",", " ", + "\"\<\!\(\*FractionBox[SubscriptBox[\(Y\), \(in\)], SubscriptBox[\(X\), \ +\(out\)]]\)/2 = \>\""}], "]"}], ";"}]}], "Code", + CellChangeTimes->{{3.9173824881246443`*^9, 3.917382640107789*^9}, { + 3.917382703512905*^9, 3.917382797160448*^9}, {3.917382957143201*^9, + 3.9173829787289667`*^9}, {3.917383009866159*^9, 3.91738301413713*^9}, { + 3.9173830595966473`*^9, 3.9173830608297663`*^9}, {3.917383133177814*^9, + 3.917383139655548*^9}, {3.91738319090906*^9, 3.9173832152140627`*^9}, { + 3.917383329695533*^9, 3.9173833441047373`*^9}, {3.917383592136142*^9, + 3.917383601902347*^9}, {3.917383788771337*^9, 3.9173838368765507`*^9}, { + 3.917383998912529*^9, 3.917384002782464*^9}, {3.917384361112628*^9, + 3.917384432792912*^9}, {3.917384584058999*^9, 3.917384619281192*^9}, { + 3.9173846522116756`*^9, 3.9173846873539762`*^9}, {3.9173849883607492`*^9, + 3.917384990884163*^9}, {3.917385341574011*^9, 3.917385423584772*^9}}, + CellLabel-> + "In[789]:=",ExpressionUUID->"2687c350-1150-4951-bcf0-28364fa5bf73"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"XOut = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "4.981498792389971`"}]}]], "Echo", + CellChangeTimes->{ + 3.91738542395758*^9},ExpressionUUID->"1aea5154-7487-4053-9b87-eaebfcd6471a"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"Validation = \"\>", + "EchoLabel"], " ", "0.`"}]], "Echo", + CellChangeTimes->{ + 3.917385423988958*^9},ExpressionUUID->"a705af7b-dd8d-4843-9013-\ +b64731e90a11"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"YOut = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "19.900212359436182`"}]}]], "Echo", + CellChangeTimes->{ + 3.917385423997478*^9},ExpressionUUID->"d4db3b60-bed3-4a41-b647-\ +914ae220d498"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"Validation = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "1.1102230246251565`*^-16"}]}]], "Echo", + CellChangeTimes->{ + 3.917385424017386*^9},ExpressionUUID->"66263894-11e5-431a-bd4e-\ +56e199c15a5b"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"2/\\!\\(\\*FractionBox[SubscriptBox[\\(Y\\), \\(out\\)], \ +SubscriptBox[\\(X\\), \\(in\\)]]\\) = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "1.0050144007893715`"}]}]], "Echo", + CellChangeTimes->{ + 3.9173854240261383`*^9},ExpressionUUID->"77e6086f-c8ed-4881-ac7b-\ +1121513e1951"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"\\!\\(\\*FractionBox[SubscriptBox[\\(Y\\), \\(in\\)], \ +SubscriptBox[\\(X\\), \\(out\\)]]\\)/2 = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "1.0037139841604084`"}]}]], "Echo", + CellChangeTimes->{ + 3.9173854240418663`*^9},ExpressionUUID->"35ae76a0-b666-481e-9dfe-\ +b6888da9c15f"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Arbitrage", "Section", + CellChangeTimes->{{3.91138759286382*^9, 3.9113876060914783`*^9}, { + 3.911387637205267*^9, + 3.911387638219921*^9}},ExpressionUUID->"65d2b88d-22b2-481a-935c-\ +71bdce9f21f1"], + +Cell[TextData[{ + "We will assume there is some external price ", + Cell[BoxData[ + FormBox[ + SubscriptBox["S", "ext"], TraditionalForm]],ExpressionUUID-> + "cd8c38a7-d91f-4b2c-a735-67538238c600"], + "that we are given and decide whether or not to perform an arbitrage and, if \ +so, to get the optimal trade size. That is, the trade that gives the \ +arbitrageur maximal profit." +}], "Text", + CellChangeTimes->{{3.9113876414292507`*^9, 3.9113877131079063`*^9}, { + 3.911388488238481*^9, + 3.911388489476202*^9}},ExpressionUUID->"f20cba79-bbb2-4d1b-9349-\ +a349e8b0b7a4"], + +Cell[CellGroupData[{ + +Cell[TextData[{ + "We will need the marginal price ", + Cell[BoxData[ + FormBox[ + SubscriptBox["P", "M"], TraditionalForm]], + FormatType->TraditionalForm,ExpressionUUID-> + "17089434-c32f-45ea-a26f-0d3ed9139695"], + " of a swap to compute optimal arbitrages and a profit calculation ", + Cell[BoxData[ + FormBox[ + SubscriptBox["V", "A"], TraditionalForm]], + FormatType->TraditionalForm,ExpressionUUID-> + "72aada08-6991-4530-9774-3dd0a302c916"] +}], "Subsubsection", + CellChangeTimes->{{3.9113884927083406`*^9, 3.911388517540121*^9}, { + 3.911388583492565*^9, 3.911388585552403*^9}, {3.9113886383414087`*^9, + 3.911388651317487*^9}},ExpressionUUID->"d7131855-64d1-451f-98f3-\ +152b4aa9f3a5"], + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{"dX_", ",", "dY_"}], "]"}], " ", ":=", " ", + FractionBox[ + RowBox[{"-", "dY"}], "dX"]}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{"Pm_", ",", "Pext_", ",", "\[CapitalDelta]_"}], "]"}], " ", ":=", + " ", + RowBox[{ + RowBox[{"(", + RowBox[{"Pm", " ", "-", " ", "Pext"}], ")"}], + "\[CapitalDelta]"}]}]}], "Code", + CellChangeTimes->{{3.911388520734275*^9, 3.911388754553933*^9}, { + 3.911408038142099*^9, 3.9114080663589067`*^9}, {3.9114081240293818`*^9, + 3.91140812426967*^9}}, + CellLabel-> + "In[616]:=",ExpressionUUID->"fadd5b7c-a968-401d-9e42-d6ca30b3a2a6"] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Lower External Price:", "Subsection", + CellChangeTimes->{{3.911387716836122*^9, 3.9113877303598022`*^9}, { + 3.911389282458209*^9, 3.911389285697858*^9}, {3.9119143659239197`*^9, + 3.911914366787615*^9}},ExpressionUUID->"eed8b815-af5d-458f-8082-\ +a956f0fb88b9"], + +Cell[CellGroupData[{ + +Cell[TextData[{ + "We\[CloseCurlyQuote]ll let ", + Cell[BoxData[ + FormBox[ + SubscriptBox["O", "X"], TraditionalForm]],ExpressionUUID-> + "bea8f527-9f1f-453d-b766-3832796355bb"], + " be the optimal amount of X token to tender to achieve maximal arbitrage \ +profit." +}], "Subsubsection", + CellChangeTimes->{{3.911389287836197*^9, 3.911389310066874*^9}, { + 3.911389351175222*^9, + 3.911389351682972*^9}},ExpressionUUID->"b20dcf41-6dfe-404c-8167-\ +50b070efca5f"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["S", "ext"], " ", "=", " ", "1.8"}], ";", " ", + RowBox[{"Assert", "[", + RowBox[{ + SubscriptBox["S", "ext"], " ", "<", " ", + SubscriptBox["S", "0"]}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Lower"], "[", "in_", "]"}], " ", ":=", " ", + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{"in", ",", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{"in", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], "]"}], ",", " ", + SubscriptBox["S", "ext"], ",", " ", "in"}], "]"}]}], "\n", + RowBox[{"Plot", "[", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Lower"], "[", "v", "]"}], ",", " ", + RowBox[{"{", + RowBox[{"v", ",", "0", ",", "0.2"}], "}"}]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{ + SubscriptBox["O", "X"], " ", "=", " ", + RowBox[{"ArgMax", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Lower"], "[", "x", "]"}], ",", " ", + RowBox[{"0", "<=", "x", "<=", + RowBox[{ + SubscriptBox["L", "0"], "-", + SubscriptBox["x", "0"]}]}]}], "}"}], ",", " ", "x"}], "]"}]}], + ";"}], " "}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["O", "X"], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + SubscriptBox["O", "X"]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}]}], "}"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["P", "F"], " ", "=", " ", + RowBox[{ + SubscriptBox["P", "X"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + SubscriptBox["O", "X"]}], ",", " ", + RowBox[{ + SubscriptBox["L", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[Delta]", "Liq"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + SubscriptBox["K", "0"], ",", " ", + SubscriptBox["\[Sigma]", "0"], ",", " ", + SubscriptBox["\[Tau]", "0"]}], "]"}]}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["P", "F"], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"FullSimplify", "[", + RowBox[{"D", "[", + RowBox[{ + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{"v", ",", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + "v", ",", "x", ",", "y", ",", "L", ",", "K", ",", "\[Sigma]", + ",", "\[Tau]", ",", "\[Gamma]"}], "]"}]}], "]"}], ",", " ", "S", + ",", " ", "v"}], "]"}], ",", "v"}], "]"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], + "\n", + RowBox[{"(*", " ", + RowBox[{ + "Check", " ", "that", " ", "the", " ", "trading", " ", "function", " ", + "is", " ", "invariant", " ", "under", " ", "the", " ", "swap"}], " ", + "*)"}]}], "\n", + RowBox[{ + RowBox[{"Assert", "[", + RowBox[{ + RowBox[{"Abs", "[", + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + SubscriptBox["O", "X"]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "Y"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + RowBox[{ + SubscriptBox["L", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{ + SubscriptBox["O", "X"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}], "]"}], " ", "<", " ", + SuperscriptBox["10", + RowBox[{"-", "15"}]]}], "]"}], "\n"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"checkLower", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "K_", ",", + "\[Sigma]_", ",", "\[Tau]_", ",", "\[Gamma]_"}], "]"}], ":=", + RowBox[{ + RowBox[{"-", "S"}], "+", + FractionBox[ + RowBox[{ + SuperscriptBox["\[ExponentialE]", + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{ + SuperscriptBox["\[Sigma]", "2"], " ", "\[Tau]"}], "2"]}], "+", + RowBox[{ + SqrtBox["2"], " ", "\[Sigma]", " ", + SqrtBox["\[Tau]"], " ", + RowBox[{"InverseErfc", "[", + FractionBox[ + RowBox[{"2", " ", "x", " ", + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}]}], + RowBox[{"L", " ", + RowBox[{"(", + RowBox[{"v", "+", "x", "-", + RowBox[{"v", " ", "\[Gamma]"}]}], ")"}]}]], "]"}]}]}]], " ", + "K", " ", "x", " ", "\[Gamma]"}], + RowBox[{"v", "+", "x", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]], "+", + FractionBox[ + RowBox[{"K", " ", "L", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}], " ", + RowBox[{"Erfc", "[", + RowBox[{ + FractionBox[ + RowBox[{"\[Sigma]", " ", + SqrtBox["\[Tau]"]}], + SqrtBox["2"]], "-", + RowBox[{"InverseErfc", "[", + FractionBox[ + RowBox[{"2", " ", "x", " ", + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}]}], + RowBox[{"L", " ", + RowBox[{"(", + RowBox[{"v", "+", "x", "-", + RowBox[{"v", " ", "\[Gamma]"}]}], ")"}]}]], "]"}]}], "]"}]}], + RowBox[{"2", " ", "x"}]]}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"numOne", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "K_", ",", + "\[Sigma]_", ",", "\[Tau]_", ",", "\[Gamma]_"}], "]"}], ":=", + RowBox[{ + SuperscriptBox["\[ExponentialE]", + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{ + SuperscriptBox["\[Sigma]", "2"], " ", "\[Tau]"}], "2"]}], "+", + RowBox[{ + SqrtBox["2"], " ", "\[Sigma]", " ", + SqrtBox["\[Tau]"], " ", + RowBox[{"InverseErfc", "[", + FractionBox[ + RowBox[{"2", " ", "x", " ", + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}]}], + RowBox[{"L", " ", + RowBox[{"(", + RowBox[{"v", "+", "x", "-", + RowBox[{"v", " ", "\[Gamma]"}]}], ")"}]}]], "]"}]}]}]], " ", "K", + " ", "x", " ", "\[Gamma]"}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"denomOne", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "K_", ",", + "\[Sigma]_", ",", "\[Tau]_", ",", "\[Gamma]_"}], "]"}], ":=", + RowBox[{"v", "+", "x", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"numTwo", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "K_", ",", + "\[Sigma]_", ",", "\[Tau]_", ",", "\[Gamma]_"}], "]"}], ":=", + RowBox[{"K", " ", "L", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}], " ", + RowBox[{"Erfc", "[", + RowBox[{ + FractionBox[ + RowBox[{"\[Sigma]", " ", + SqrtBox["\[Tau]"]}], + SqrtBox["2"]], "-", + RowBox[{"InverseErfc", "[", + FractionBox[ + RowBox[{"2", " ", "x", " ", + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}]}], + RowBox[{"L", " ", + RowBox[{"(", + RowBox[{"v", "+", "x", "-", + RowBox[{"v", " ", "\[Gamma]"}]}], ")"}]}]], "]"}]}], "]"}]}]}], + ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"denomTwo", "[", + RowBox[{ + "v_", ",", "x_", ",", "y_", ",", "L_", ",", "S_", ",", "K_", ",", + "\[Sigma]_", ",", "\[Tau]_", ",", "\[Gamma]_"}], "]"}], ":=", " ", + RowBox[{"2", " ", "x"}]}], ";"}], "\n"}], "Code", + CellChangeTimes->{{3.9113877530057907`*^9, 3.911387759870617*^9}, { + 3.911387791900612*^9, 3.911387835019555*^9}, {3.911389040938622*^9, + 3.911389111156786*^9}, {3.911389254777446*^9, 3.9113892749054213`*^9}, { + 3.911389313552825*^9, 3.9113896479421587`*^9}, {3.911389684738289*^9, + 3.911389710567501*^9}, {3.911389764399426*^9, 3.911390120184866*^9}, { + 3.911390172200013*^9, 3.9113903097104073`*^9}, {3.9113903414495697`*^9, + 3.911390422476118*^9}, {3.9113904688729887`*^9, 3.911390469654806*^9}, { + 3.911390530287198*^9, 3.9113905408414717`*^9}, {3.9113907054945307`*^9, + 3.91139073520191*^9}, {3.91139090146146*^9, 3.911390906904234*^9}, { + 3.911390946256706*^9, 3.911391064802693*^9}, {3.911391222082168*^9, + 3.9113912438598137`*^9}, {3.9114061934461813`*^9, 3.911406197897942*^9}, { + 3.911409265595838*^9, 3.911409282641177*^9}, {3.9114093384435053`*^9, + 3.911409346040655*^9}, {3.911409904932541*^9, 3.911409910625359*^9}, + 3.911410010310408*^9, {3.9114111732761717`*^9, 3.911411210958044*^9}, { + 3.911411248268466*^9, 3.911411313752475*^9}, {3.911413086350491*^9, + 3.9114131282498713`*^9}, {3.91141319914225*^9, 3.911413480385025*^9}, { + 3.91675072235946*^9, 3.916750736241868*^9}, {3.916750835562142*^9, + 3.916750853604291*^9}, {3.916933983207768*^9, 3.916933985584363*^9}, { + 3.916934589170532*^9, 3.916934742188787*^9}, {3.91738501952264*^9, + 3.917385025286654*^9}}, + CellLabel-> + "In[618]:=",ExpressionUUID->"6bec84e7-f813-4bb5-9a1e-8a3d86e897da"], + +Cell[BoxData[ + GraphicsBox[{{{}, {}, + TagBox[ + {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[ + 1.], LineBox[CompressedData[" +1:eJwV0Gs0lAkAxvESOiI5mlxmdOHgoLK2mi5qPdJUW2or5JZby+5QCTXROq6t +SqEMM0ajUeZVZCUjxWjRNC69SsIJSQw1lcuYSC5F1n54zv/L8+ln/HuI0x8q +8+bN2z+3/yscELMaL/5sp8t3E+Z6a9odU1n2uISig5M6xzNXGvXbjRtEFl+l +rMKTZ8Y5n2hTdttyCy1iKDZgWkaLn9M00NNfG3CGYo9tHQWTlTRDiJJbVMIo +B5F/TzJdSrMEtbuj+STFD660lD13aVvwQt1LHEwJBb1ZdwFB2wNK736PFEkc +Ij4zvvZZeiJsXdY7NXkiOjgti+NC/LGClaRoCkmFIuKo2oqCIHwLOzpbKOWA ++2OTuYIeiiJLbYOsxkycC46yXeJ9Gm6qrbsMrQVIu8vhV9eHIytRX49SeRPd +B1+6R5hEYmLQRsu0SojYVXRd1o5ovPBzXRw1kAueTKYy6xwH9rqP7K6R2zCp +X1b1Z388QgXSMDVlPux9VxW3hP+NBsNCr3D9fzDcIxOrmp+HzpfZBiX1LqTj +j9Q9yy+g+a0vQ7TnHkzH+TOsE4loLz6fvLysGPp5wfM5BpexzZhd/uGhCOuH +bRrb8pLgzTcZcH5egqnlFyq63VPwVRLkvbPpPprfxd9fpLgCx9GNbZ0fS2FA +jt2LPpQKa+WdKJfvD6D/l5f5WQs2LvBbApymH4LOcpSrjrBx/bd4pzHdcmT4 +B4lPN6TBQiSPp+qLsTRba5LFTYeDTNltqlcBb1EP/6wXB4YGcdtbrR7hfbme +js8GLpg/auVqa/9FpKbEpm2Gi9MK9tUuRiWOOPUO/dSRAa07C5g8typQTtlO +JhXxQF26Oq7NrRp9XVdGIsMz8cXhRFPXxscY2qri4HjgGjitgtjU8sfQ++Au +LDLkI2qvcNfDTRLMBhZzKTI+pLVBOkUSCTbLkgRHyrKw00DrO9PhCS4KF43T +467DLCTs05fGJ9DzYKwZ8RDAXiAa335QijpP61cwy4ZQVENTeSnFXnqOFXso +G/4N/B0czxqoqvZSpTU34FvhmPzpTQ2U2qG+jN03UVFU3a4dWItJrrM/r/Qm +vC6p2+aN1IKp8a1kcGUOtmy1qJx/qg4BJi0zGgk5YI1o7bCeqcNluot75ucc +DMQ87zeKrceGkwuqPx8WIm/UJy/6Rz0c0wPT94qFkB4rZRYnPkVCCc2VYkaA +WvH+11saJBgTgTvzLxGYiValyjVJ9I31eAclEZBtNx001SYRPeoYbpVC4Dbp +n5KrS6JMoZZXmEpg/eu+ZoJGYnXA1EIRj8C+SZmncC0JnUOd9eJbBKI3vj1x +4xCJjwVpeCYh4Pdt+pceZxLxFvddk6UEGFVGS1a6zv3NyeD9tQQW7fISZXuS +2Gf8KqvpKYGMw2++CvxJ1PECJ1qbCBSxXsdcP0PiQQK7sOstAfbmqQNdESRc +zi2UCnoIsKYNjI0iSShjQ1/79BKwTXCXZsWQMPtuqt77nkB9evvCrIskeGGa +vvJBAgVuEx2dl0jQQ6zO3FYQuELTL6Amk2gZQhJTScCFcN3HTyWhFbi7rH+U +wCZm+PLONBL5ctvGgrE5v9UZw4ZcEvb+pu+Oj8/5DT+o9uCRkPupTK2ZnPMr +eZV67RqJsz7t2sNTBP4DDMpfbg== + "]]}, + Annotation[#, "Charting`Private`Tag$57056#1"]& ]}, {}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + Axes->{True, True}, + AxesLabel->{None, None}, + AxesOrigin->{0, 0}, + DisplayFunction->Identity, + Frame->{{False, False}, {False, False}}, + FrameLabel->{{None, None}, {None, None}}, + FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}}, + GridLines->{None, None}, + GridLinesStyle->Directive[ + GrayLevel[0.5, 0.4]], + ImagePadding->All, + Method->{ + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, "DefaultMeshStyle" -> + AbsolutePointSize[6], "ScalingFunctions" -> None, + "CoordinatesToolOptions" -> {"DisplayFunction" -> ({ + (Identity[#]& )[ + Part[#, 1]], + (Identity[#]& )[ + Part[#, 2]]}& ), "CopiedValueFunction" -> ({ + (Identity[#]& )[ + Part[#, 1]], + (Identity[#]& )[ + Part[#, 2]]}& )}}, + PlotRange->{{0, 0.2}, {0., 0.03901618891876252}}, + PlotRangeClipping->True, + PlotRangePadding->{{ + Scaled[0.02], + Scaled[0.02]}, { + Scaled[0.05], + Scaled[0.05]}}, + Ticks->{Automatic, Automatic}]], "Output", + CellChangeTimes->{ + 3.917383563255979*^9, 3.917384872931774*^9, {3.9173849757089787`*^9, + 3.9173850261946993`*^9}, 3.917385114645734*^9}, + CellLabel-> + "Out[620]=",ExpressionUUID->"88457644-f8dc-4649-adb3-9b54c9fd1c06"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The optimal amount of X to tender is: \\!\\(\\*SubscriptBox[\\(\ +\[CapitalDelta]\\), \\(X\\)]\\) = \"\>", + "EchoLabel"], " ", "202.20119150794815`"}]], "Echo", + CellChangeTimes->{ + 3.917385114735537*^9},ExpressionUUID->"d1f17eb9-1e3f-45fe-8a49-\ +8b9eefc03ffb"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The amount out is: \\!\\(\\*SubscriptBox[\\(\[CapitalDelta]\\), \ +\\(Y\\)]\\) = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "383.25524969204025`"}]}]], "Echo", + CellChangeTimes->{ + 3.9173851147430677`*^9},ExpressionUUID->"62407cb0-a174-480a-8d16-\ +3a55f4b36678"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The resulting reserves are: (\\!\\(\\*SubscriptBox[\\(x\\), \ +\\(1\\)]\\),\\!\\(\\*SubscriptBox[\\(y\\), \\(1\\)]\\)) = \"\>", + "EchoLabel"], " ", + RowBox[{"{", + RowBox[{"1202.2011915079481`", ",", "1616.74475030796`"}], "}"}]}]], "Echo",\ + + CellChangeTimes->{ + 3.91738511476458*^9},ExpressionUUID->"d6ae3e9d-138a-4eac-9161-a39196238226"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The final price of the pool is: P = \"\>", + "EchoLabel"], " ", "1.8049533724284241`"}]], "Echo", + CellChangeTimes->{ + 3.9173851147720413`*^9},ExpressionUUID->"a954a63c-1072-4dd1-a3b7-\ +6fea2ecdbf38"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The equation to do root finding with is: \"\>", + "EchoLabel"], " ", + TemplateBox[{ + RowBox[{ + RowBox[{"-", "S"}], "+", + FractionBox[ + RowBox[{ + SuperscriptBox["\[ExponentialE]", + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{ + SuperscriptBox["\[Sigma]", "2"], " ", "\[Tau]"}], "2"]}], + "+", + RowBox[{ + SqrtBox["2"], " ", "\[Sigma]", " ", + SqrtBox["\[Tau]"], " ", + RowBox[{"InverseErfc", "[", + FractionBox[ + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}]}], + RowBox[{"L", "+", "v", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]], "]"}]}]}]], " ", "K", + " ", + RowBox[{"(", + RowBox[{"L", "+", + RowBox[{"x", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}], + + RowBox[{"L", "+", "v", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]], "+", + RowBox[{ + FractionBox["1", "2"], " ", "K", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}], " ", + RowBox[{"Erfc", "[", + RowBox[{ + FractionBox[ + RowBox[{"\[Sigma]", " ", + SqrtBox["\[Tau]"]}], + SqrtBox["2"]], "-", + RowBox[{"InverseErfc", "[", + FractionBox[ + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{"v", "+", "x"}], ")"}]}], + RowBox[{"L", "+", "v", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]], "]"}]}], "]"}]}]}], + RowBox[{"0", "\[LessEqual]", + FractionBox[ + RowBox[{"v", "+", "x"}], + RowBox[{"L", "+", "v", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]], "\[LessEqual]", "1"}]}, + "ConditionalExpression"]}]], "Echo", + CellChangeTimes->{ + 3.91738511509683*^9},ExpressionUUID->"fca08186-95ea-4887-8401-ad9d766f2ded"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Raise External Price:", "Subsection", + CellChangeTimes->{{3.9114058960816593`*^9, + 3.911405902149222*^9}},ExpressionUUID->"d44a8cc6-b4f0-4204-b250-\ +e68ad4e19d99"], + +Cell[CellGroupData[{ + +Cell[TextData[{ + "Let ", + Cell[BoxData[ + FormBox[ + SubscriptBox["O", "Y"], TraditionalForm]], + FormatType->TraditionalForm,ExpressionUUID-> + "daf8aba3-0522-4fdc-b0f6-095c37f44dc7"], + " be the optimal amount of Y token to tender to get max arbitrage profit." +}], "Subsubsection", + CellChangeTimes->{{3.9114059041043043`*^9, + 3.9114059228094807`*^9}},ExpressionUUID->"800e047e-b69c-4509-bda4-\ +30799fa9a63e"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + SubscriptBox["S", "ext"], " ", "=", " ", "2.2"}], ";", " ", + RowBox[{"Assert", "[", + RowBox[{ + SubscriptBox["S", "ext"], " ", ">", " ", + SubscriptBox["S", "0"]}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Raise"], "[", "in_", "]"}], " ", ":=", " ", + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{"in", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], ",", "in"}], "]"}], ",", " ", + + SubscriptBox["S", "ext"], ",", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{"in", ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], "]"}]}], "\n", + RowBox[{"Plot", "[", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Raise"], "[", "v", "]"}], ",", " ", + RowBox[{"{", + RowBox[{"v", ",", "0", ",", "0.2"}], "}"}]}], "]"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{ + SubscriptBox["O", "Y"], " ", "=", " ", + RowBox[{"ArgMax", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["Prof", "Raise"], "[", "y", "]"}], ",", " ", + RowBox[{"0", "<=", "y", "<=", + RowBox[{ + RowBox[{ + SubscriptBox["K", "0"], + SubscriptBox["L", "0"]}], "-", + SubscriptBox["y", "0"]}]}]}], "}"}], ",", " ", "y"}], "]"}]}], + ";"}], " "}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + SubscriptBox["O", "Y"]}]}], "}"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["P", "F"], " ", "=", " ", + RowBox[{ + SubscriptBox["P", "Y"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + SubscriptBox["O", "Y"]}], ",", " ", + RowBox[{ + SubscriptBox["L", "0"], " ", "+", " ", + RowBox[{ + FractionBox["1", + SubscriptBox["K", "0"]], + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}]}], ",", " ", + SubscriptBox["K", "0"], ",", " ", + SubscriptBox["\[Sigma]", "0"], ",", " ", + SubscriptBox["\[Tau]", "0"]}], "]"}]}], ";", " ", + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["P", "F"], ",", " ", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"FullSimplify", "[", + RowBox[{"D", "[", + RowBox[{ + RowBox[{ + SubscriptBox["V", "A"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["P", "M"], "[", + RowBox[{ + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + "v", ",", "x", ",", "y", ",", "L", ",", "K", ",", "\[Sigma]", + ",", "\[Tau]", ",", "\[Gamma]"}], "]"}], ",", "v"}], "]"}], ",", + " ", "S", ",", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + "v", ",", "x", ",", "y", ",", "L", ",", "K", ",", "\[Sigma]", ",", + "\[Tau]", ",", "\[Gamma]"}], "]"}]}], "]"}], ",", "v"}], "]"}], + "]"}], ",", " ", "\"\\""}], + "]"}], ";"}], "\n", + RowBox[{"(*", " ", + RowBox[{ + "Check", " ", "that", " ", "the", " ", "trading", " ", "function", " ", + "is", " ", "invariant", " ", "under", " ", "the", " ", "swap"}], " ", + "*)"}]}], "\n", + RowBox[{"Assert", "[", + RowBox[{ + RowBox[{"Abs", "[", + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + RowBox[{ + SubscriptBox["x", "0"], " ", "+", " ", + RowBox[{ + SubscriptBox["\[CapitalDelta]", "X"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", + SubscriptBox["L", "0"], ",", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}], ",", " ", + RowBox[{ + SubscriptBox["y", "0"], " ", "+", " ", + SubscriptBox["O", "Y"]}], ",", " ", + RowBox[{ + SubscriptBox["L", "0"], " ", "+", " ", + RowBox[{ + FractionBox["1", + SubscriptBox["K", "0"]], + RowBox[{ + SubscriptBox["\[Delta]", "in"], "[", + RowBox[{ + SubscriptBox["O", "Y"], ",", + SubscriptBox["\[Gamma]", "0"]}], "]"}]}]}], ",", " ", + SubscriptBox["K", "0"], ",", + SubscriptBox["\[Sigma]", "0"], ",", + SubscriptBox["\[Tau]", "0"]}], "]"}], "]"}], " ", "<", " ", + SuperscriptBox["10", + RowBox[{"-", "14"}]]}], "]"}]}], "Code", + CellChangeTimes->CompressedData[" +1:eJwdxU0oQwEAB/D3nsumRlKGcVhtIsVFESPPmNmBfFxmiqxZjWFoDcUFS5NW +aj7bYUQ+pmjJVsJuyhSJ5OsiankjbT5Ww/u/w6+fuL2nQUcRBJHBwr1iQZ5B +wtA+5bQCS3yaOnznza3H/kBRC247W+B+Jt19eCRqHOBeGq/oZNe8CuSYP1da +jQvMWiWmnVVNODz43Yq3RZdarJ+eMODQvH0K1+g8DuyaTL3FjvDMPfY+lr/g +DtnaF1YcrsRw9/AH0cWefUVc4LHfo2scv296NLLv2mxPuKycTNdKGdoel8Yd +pJngYh5Dq+SWN2xeLiGX2BWhUQqH1L+mCDujPO/DTuGbFYcbrVP4L0DNYnKH +z12Zs+HEN7xt7hRV4ip2FWdy77nM5Ce79NRN4droQQoeSxIJMWHTF+KwLVmG +Le/rm+f5DM2LqLew/6ffg5mEB27LUPMxDsWyTvA//Rnfcg== + "], + CellLabel-> + "In[683]:=",ExpressionUUID->"7ca95c98-841f-4a4d-8646-7ee5087c0cbe"], + +Cell[BoxData[ + GraphicsBox[{{{}, {}, + TagBox[ + {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[ + 1.], LineBox[CompressedData[" +1:eJwV0nk41AkAxnH3VjOsh5GZIWrXdklbrVLE60oyZUWRUmzaBmUZDZWwM+Ws +IeNnKdKhlhw7a2yE1tWMaX9K0uEYR5aQI0fpcmTtH+/z/f/zvMsOB7n+rKSg +oLBrfv83e6ic2xC33sogIXXggPO0ZYCSTk0xTRMZ1N48O2qb1Qd6eNFF2lJQ +W6QG6tRBq623CldG0dZBJ0GJO0H5bPVysO5IKM0aomlzs17KQogFT5U4NBdI +FY02tlMYYHa1Nv1C84H58JegF5RVeKzmVR5IC8YH70KVRsoW0P7d5ZlYy8OB ++GHbQIYTOBsye1X74lFwjTHG8nWDAffCm8agZHhNDAcsyPDEFOenuUJJKkyD +uTmksQ9EqzTomQ2XMEVX7fzk4gsPlWcOjLVZcO2Ma0gqP4rMeN3FtMrr8Az7 +dsVmrQB8HF5HNarKhnJueytrfSAe+7irRwzdwrT3XHPPjmAINwwIOyZyMNKk +pb23i4PgLAlHdew2DEWmzk0BJ1DPKPQK0y2A00PZbgVGKDTfzdWPMf/AaAN9 +9Eh+GJo6ve3FO/7Eq5OhiyMOnkJLUYxgyd0i+Ff3Lc9aEI6ty4Rl/aVinDJk +MCbTzuBgxjdDbo+KobWCvXPWIRLva/0Pbmv8C+PaN2K3yqPAerupWT5wBwWB +BT1p23lYO5YXsWe6BBuXWkXTDPiIzXh6xHWmFC3Gs7tM+vm44sx3ndQqQ7WR +9aRB9VmsFPfxmbrleJ8X+KIg4Rxsu8e6jBZXIDHdosvSJRoMOs/m2ep7UKbW +Xr29IgbsL3V9qiZ/wzdnpFI0HoMTb4QXO+wr8XwqNyyxPhbUPGV2ukcVRHe5 +LM71ODC1jXnNHtUgFUJujrPj8c72eGPHphpsNvMLcrROQOqzrF+Ty2ow8RlN +FovOI8Ip26HUrBYO+45zTZ+ch6TOX1NUWwvdlpGjqrkXsI1OnWbb3odezxut +kCABvgvivH7XcB9V6ozxUsdEWGeJP9i4SLBwTfjldO0kZIulekpPJNBkICVS +ngTf+gy71P1SFC0/mm5RfBHeFSzB63YprsnsZPWWyagQVbdo+NXBr3Lgbm/+ +/K8S1MxzJ+qwvITDmtMRYovFykrFEBmuC5wHX58WgjtBtVs7K8NM4rFjVv1C +DEU9GtT/9QGGLdYoHmalIPftodzILw+gZhDLihelQBJwh10U/w88kmvYTCYB +ZsUrx98XkvA9fCYvPIrAbKQKs49CghdW027OI9BtYzRspEHiyiIFjWk+gRzS +N/GWFglThl/ImRgCP7T1NN3UI7FFedI8QkBg56fu/dkmJFqDJ+sjMwhEbuo8 +fm03iahifj+vlIDP1IzlSzcSV2UUuk0ZAfsq/a8N3UkUyM/vUKwgsMjBS3x1 +PwlH/5OF/EoCaXvb32f5ktjjphtyVkpAxG2LuhJKIlW+eubcUwLCzZ9/7DhJ +Qmevu4n9cwLcGfoy/XASpNLpQyrNBMyj90kyo0gIpYU10W0EHhAtX2XGkbgk +ehgd000g3+NjqzyBhHZeXcm2HgJJerr5TAEJSXNpv+orAntuuu/MSCZxg57o +GDtAwIwdtkSeQmK7LPC0w+C8n3HaKOO3eR91p3y14Xm/0ZJqz3QSrvcM22Uj +837FL5IvXybxvf5bStwogf8AM+pSBQ== + "]]}, + Annotation[#, "Charting`Private`Tag$100831#1"]& ]}, {}}, + AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], + Axes->{True, True}, + AxesLabel->{None, None}, + AxesOrigin->{0, 0}, + DisplayFunction->Identity, + Frame->{{False, False}, {False, False}}, + FrameLabel->{{None, None}, {None, None}}, + FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}}, + GridLines->{None, None}, + GridLinesStyle->Directive[ + GrayLevel[0.5, 0.4]], + ImagePadding->All, + Method->{ + "DefaultBoundaryStyle" -> Automatic, + "DefaultGraphicsInteraction" -> { + "Version" -> 1.2, "TrackMousePosition" -> {True, False}, + "Effects" -> { + "Highlight" -> {"ratio" -> 2}, "HighlightPoint" -> {"ratio" -> 2}, + "Droplines" -> { + "freeformCursorMode" -> True, + "placement" -> {"x" -> "All", "y" -> "None"}}}}, "DefaultMeshStyle" -> + AbsolutePointSize[6], "ScalingFunctions" -> None, + "CoordinatesToolOptions" -> {"DisplayFunction" -> ({ + (Identity[#]& )[ + Part[#, 1]], + (Identity[#]& )[ + Part[#, 2]]}& ), "CopiedValueFunction" -> ({ + (Identity[#]& )[ + Part[#, 1]], + (Identity[#]& )[ + Part[#, 2]]}& )}}, + PlotRange->{{0, 0.2}, {0., 0.01946459780131365}}, + PlotRangeClipping->True, + PlotRangePadding->{{ + Scaled[0.02], + Scaled[0.02]}, { + Scaled[0.05], + Scaled[0.05]}}, + Ticks->{Automatic, Automatic}]], "Output", + CellChangeTimes->{ + 3.9173835690887947`*^9, 3.917385059548512*^9, {3.9173851196395884`*^9, + 3.917385128134555*^9}, 3.9173852324926853`*^9, 3.917385290081284*^9}, + CellLabel-> + "Out[685]=",ExpressionUUID->"1f3d487e-7d60-4563-a2b3-f3aa65c1d146"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The optimal amount of Y to tender is: \\!\\(\\*SubscriptBox[\\(\ +\[CapitalDelta]\\), \\(Y\\)]\\) = \"\>", + "EchoLabel"], " ", "364.4731544001954`"}]], "Echo", + CellChangeTimes->{ + 3.917385290172243*^9},ExpressionUUID->"20a8471e-d48d-4dc1-8a0f-\ +2b45a51698ee"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The amount out is: \\!\\(\\*SubscriptBox[\\(\[CapitalDelta]\\), \ +\\(X\\)]\\) = \"\>", + "EchoLabel"], " ", + RowBox[{"-", "173.56889322451593`"}]}]], "Echo", + CellChangeTimes->{ + 3.917385290180708*^9},ExpressionUUID->"5cd69ac1-3ee9-4f3c-b5cf-\ +95d07eb0ff1c"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The resulting reserves are: (\\!\\(\\*SubscriptBox[\\(x\\), \ +\\(1\\)]\\),\\!\\(\\*SubscriptBox[\\(y\\), \\(1\\)]\\)) = \"\>", + "EchoLabel"], " ", + RowBox[{"{", + RowBox[{"826.4311067754841`", ",", "2364.4731544001957`"}], + "}"}]}]], "Echo", + CellChangeTimes->{ + 3.917385290202286*^9},ExpressionUUID->"0834851c-ee77-4202-aa72-\ +ad7a0f04c869"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The final price of the pool is: P = \"\>", + "EchoLabel"], " ", "2.194468360784738`"}]], "Echo", + CellChangeTimes->{ + 3.917385290210438*^9},ExpressionUUID->"e88a31f0-9ce3-43a8-a4fe-\ +062f673969b4"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The equation to do root finding with is: \"\>", + "EchoLabel"], " ", + TemplateBox[{ + RowBox[{ + RowBox[{"-", "1"}], "+", + FractionBox[ + RowBox[{ + SuperscriptBox["\[ExponentialE]", + RowBox[{ + RowBox[{"-", + FractionBox[ + RowBox[{ + SuperscriptBox["\[Sigma]", "2"], " ", "\[Tau]"}], "2"]}], + "+", + RowBox[{ + SqrtBox["2"], " ", "\[Sigma]", " ", + SqrtBox["\[Tau]"], " ", + RowBox[{"InverseErfc", "[", + FractionBox[ + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}]}], + RowBox[{ + RowBox[{"K", " ", "L"}], "+", "v", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]], "]"}]}]}]], " ", "S", + " ", + RowBox[{"(", + RowBox[{ + RowBox[{"K", " ", "L"}], "+", + RowBox[{"y", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}]}]}], ")"}]}], + + RowBox[{"K", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"K", " ", "L"}], "+", "v", "-", + RowBox[{"v", " ", "\[Gamma]"}]}], ")"}]}]], "+", + FractionBox[ + RowBox[{"S", " ", + RowBox[{"(", + RowBox[{ + RowBox[{"-", "1"}], "+", "\[Gamma]"}], ")"}], " ", + RowBox[{"Erfc", "[", + RowBox[{ + FractionBox[ + RowBox[{"\[Sigma]", " ", + SqrtBox["\[Tau]"]}], + SqrtBox["2"]], "-", + RowBox[{"InverseErfc", "[", + FractionBox[ + RowBox[{"2", " ", + RowBox[{"(", + RowBox[{"v", "+", "y"}], ")"}]}], + RowBox[{ + RowBox[{"K", " ", "L"}], "+", "v", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]], "]"}]}], "]"}]}], + RowBox[{"2", " ", "K"}]]}], + RowBox[{"0", "\[LessEqual]", + FractionBox[ + RowBox[{"v", "+", "y"}], + RowBox[{ + RowBox[{"K", " ", "L"}], "+", "v", "-", + RowBox[{"v", " ", "\[Gamma]"}]}]], "\[LessEqual]", "1"}]}, + "ConditionalExpression"]}]], "Echo", + CellChangeTimes->{ + 3.917385290654476*^9},ExpressionUUID->"24b12cbb-7a22-45fd-bb9e-\ +d5824114ff9b"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]], + +Cell[CellGroupData[{ + +Cell["Parameter Updates", "Section", + CellChangeTimes->{{3.9114106614664173`*^9, + 3.911410663603334*^9}},ExpressionUUID->"b9760121-93f2-4105-bc65-\ +e6b3dbe04aec"], + +Cell[CellGroupData[{ + +Cell["\<\ +We want to let parameters change, then determine the new L from them.\ +\>", "Subsection", + CellChangeTimes->{{3.9114115124928417`*^9, + 3.911411520281617*^9}},ExpressionUUID->"bf3ecf5a-6ea2-4f9a-a236-\ +2d3956e9c134"], + +Cell[CellGroupData[{ + +Cell[BoxData[{ + RowBox[{ + RowBox[{ + RowBox[{"{", + RowBox[{ + SubscriptBox["K", "1"], ",", + SubscriptBox["\[Sigma]", "1"], ",", + SubscriptBox["\[Tau]", "1"]}], "}"}], " ", "=", " ", + RowBox[{"{", + RowBox[{ + RowBox[{ + SubscriptBox["K", "0"], " ", "+", " ", + FractionBox["1", "10"]}], ",", " ", + RowBox[{ + SubscriptBox["\[Sigma]", "0"], " ", "-", " ", + FractionBox["1", "20"]}], ",", " ", + SubscriptBox["\[Tau]", "0"]}], "}"}]}], ";"}], "\n", + RowBox[{ + RowBox[{ + SubscriptBox["L", "1"], " ", "=", " ", + RowBox[{"L", " ", "/.", " ", + RowBox[{"FindRoot", "[", + RowBox[{ + RowBox[{"\[CurlyPhi]", "[", + RowBox[{ + SubscriptBox["x", "0"], ",", + SubscriptBox["y", "0"], ",", "L", ",", + SubscriptBox["K", "1"], ",", + SubscriptBox["\[Sigma]", "1"], ",", + SubscriptBox["\[Tau]", "1"]}], "]"}], ",", " ", + RowBox[{"{", + RowBox[{"L", ",", + SubscriptBox["L", "0"]}], "}"}]}], "]"}]}]}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["L", "0"], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}], "\n", + RowBox[{ + RowBox[{"Echo", "[", + RowBox[{ + RowBox[{"N", "[", + RowBox[{ + SubscriptBox["L", "1"], ",", "18"}], "]"}], ",", " ", + "\"\\""}], "]"}], ";"}]}], "Code", + CellChangeTimes->{{3.911411526467024*^9, 3.911411558889496*^9}, { + 3.911411603270329*^9, 3.911411726104031*^9}, {3.911411854447959*^9, + 3.911411871785728*^9}, {3.911412038711419*^9, 3.9114121340202703`*^9}, { + 3.911412179397016*^9, 3.91141220168312*^9}, {3.911412234164196*^9, + 3.9114122397709723`*^9}, {3.911412325036952*^9, 3.9114123356623907`*^9}, { + 3.91141236997156*^9, 3.911412427698132*^9}, {3.911412458150606*^9, + 3.911412466280922*^9}, {3.9114126475927057`*^9, 3.9114126927861547`*^9}}, + CellLabel-> + "In[477]:=",ExpressionUUID->"88153533-d3ba-42e3-8671-5c87d6eba466"], + +Cell[CellGroupData[{ + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The original liquidity was: \\!\\(\\*SubscriptBox[\\(L\\), \\(0\ +\\)]\\) = \"\>", + "EchoLabel"], " ", + "1.07205816303780375296378578465914117862`18."}]], "Echo", + CellChangeTimes->{ + 3.911412693179192*^9},ExpressionUUID->"9c86a598-6ad7-4cdc-b7d3-\ +f17754fbb4f8"], + +Cell[BoxData[ + RowBox[{ + TagBox["\<\"The new liquidity after parameter changes is: \ +\\!\\(\\*SubscriptBox[\\(L\\), \\(1\\)]\\) = \"\>", + "EchoLabel"], " ", "1.0633573081332175`"}]], "Echo", + CellChangeTimes->{ + 3.9114126932060432`*^9},ExpressionUUID->"edb1d49d-7246-436e-85d1-\ +f3028622cb8d"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +}, +WindowSize->{823, 1233}, +WindowMargins->{{Automatic, 12}, {-819, Automatic}}, +PrintingCopies->1, +PrintingPageRange->{1, Automatic}, +FrontEndVersion->"13.2 for Mac OS X ARM (64-bit) (January 31, 2023)", +StyleDefinitions->FrontEnd`FileName[{$RootDirectory, "Users", "colin", + "Documents"}, "DarkMode.nb", CharacterEncoding -> "UTF-8"], +ExpressionUUID->"13daad44-0d0d-4117-a120-aa865447a233" +] +(* End of Notebook Content *) + +(* Internal cache information *) +(*CellTagsOutline +CellTagsIndex->{} +*) +(*CellTagsIndex +CellTagsIndex->{} +*) +(*NotebookFileOutline +Notebook[{ +Cell[CellGroupData[{ +Cell[422, 15, 185, 3, 238, "Title",ExpressionUUID->"2003d08a-fff7-4f74-8623-7a0823c9cafa"], +Cell[CellGroupData[{ +Cell[632, 22, 221, 5, 158, "Section",ExpressionUUID->"514be430-48c5-4dc6-92af-6b1c3a5b8586"], +Cell[CellGroupData[{ +Cell[878, 31, 222, 5, 122, "Subsection",ExpressionUUID->"f16f1652-ed41-4414-8c9b-6b6d5d8061ac"], +Cell[1103, 38, 578, 14, 54, "Code",ExpressionUUID->"8255c47c-fa0b-4fdd-8638-752453aca613"] +}, Open ]], +Cell[CellGroupData[{ +Cell[1718, 57, 202, 3, 81, "Subsection",ExpressionUUID->"b3dd161e-0b53-4183-b30c-be7844f26477"], +Cell[1923, 62, 808, 19, 86, "Code",ExpressionUUID->"25d6c1c4-f902-41e0-8746-c63f6b03d94e"] +}, Open ]], +Cell[CellGroupData[{ +Cell[2768, 86, 307, 7, 122, "Subsection",ExpressionUUID->"f601d02f-f91e-4780-a166-a78097a54f48"], +Cell[3078, 95, 1093, 33, 161, "Code",ExpressionUUID->"d5d16a82-3e60-44ff-affc-b50eb9144304"] +}, Open ]], +Cell[CellGroupData[{ +Cell[4208, 133, 296, 7, 122, "Subsection",ExpressionUUID->"009a24ad-ebe5-4d73-bdda-a7839592332a"], +Cell[CellGroupData[{ +Cell[4529, 144, 244, 6, 106, "Subsubsection",ExpressionUUID->"3b15f5e3-f420-4095-899a-506c7286cc40"], +Cell[4776, 152, 2312, 63, 192, "Code",ExpressionUUID->"3950a1e9-9c32-45c4-b5ef-404c37d6ef65"] +}, Open ]], +Cell[CellGroupData[{ +Cell[7125, 220, 253, 6, 106, "Subsubsection",ExpressionUUID->"6228385e-cfd2-4bd0-97f4-58c98a5a994e"], +Cell[7381, 228, 1219, 36, 123, "Code",ExpressionUUID->"cdbca2c9-2426-4adf-8516-6c22e3b352b1"] +}, Open ]], +Cell[CellGroupData[{ +Cell[8637, 269, 186, 3, 67, "Subsubsection",ExpressionUUID->"18015876-38da-4fa9-82b7-a417d745ef90"], +Cell[8826, 274, 685, 19, 68, "Code",ExpressionUUID->"a65cb5ec-cdac-40e0-bb49-f3d8157592d9"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[9572, 300, 285, 7, 158, "Section",ExpressionUUID->"da815218-0c74-4720-a5c9-76f45781c5e2"], +Cell[CellGroupData[{ +Cell[9882, 311, 305, 7, 122, "Subsection",ExpressionUUID->"d461a415-44ca-4804-8248-6137a0f9449f"], +Cell[CellGroupData[{ +Cell[10212, 322, 2432, 60, 146, "Code",ExpressionUUID->"8d262a91-37a1-41fb-b1b3-ae8191b1ccda"], +Cell[CellGroupData[{ +Cell[12669, 386, 230, 6, 38, "Echo",ExpressionUUID->"af988e57-d45b-493e-8c77-aeb0d6754a04"], +Cell[12902, 394, 258, 7, 53, "Echo",ExpressionUUID->"7cbb943d-e136-42be-b7bf-17128b81f7f7"], +Cell[13163, 403, 235, 6, 38, "Echo",ExpressionUUID->"35bc58ee-e40e-4bf3-9e9f-061ba0d278fb"], +Cell[13401, 411, 242, 6, 38, "Echo",ExpressionUUID->"e144304b-6b21-4799-ac3b-3fa33013028a"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[13704, 424, 307, 7, 122, "Subsection",ExpressionUUID->"a6874bc0-590c-4cb3-9d20-f010a014a154"], +Cell[CellGroupData[{ +Cell[14036, 435, 1157, 29, 86, "Code",ExpressionUUID->"085ca656-cc94-43cf-a8c6-c116e23e4910"], +Cell[CellGroupData[{ +Cell[15218, 468, 271, 7, 38, "Echo",ExpressionUUID->"b0609413-5fee-4b86-aed9-380cc72ca5ad"], +Cell[15492, 477, 230, 6, 38, "Echo",ExpressionUUID->"0d8deb13-fecc-40d5-b792-e5be624a621e"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[15771, 489, 251, 6, 106, "Subsubsection",ExpressionUUID->"d0f44536-b00f-4974-8c75-dd65dd319645"], +Cell[CellGroupData[{ +Cell[16047, 499, 1719, 46, 86, "Code",ExpressionUUID->"57112165-db6f-447c-9713-f9c85c6d4828"], +Cell[CellGroupData[{ +Cell[17791, 549, 304, 7, 38, "Echo",ExpressionUUID->"4fd65137-02a9-41b3-ba18-0ebf41cc4e36"], +Cell[18098, 558, 314, 8, 38, "Echo",ExpressionUUID->"21eb62ab-27a6-41dd-a389-5142ff75a033"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[18473, 573, 224, 4, 67, "Subsubsection",ExpressionUUID->"0dabba71-0908-48dd-b11c-9fc06ac2d79b"], +Cell[CellGroupData[{ +Cell[18722, 581, 1319, 37, 86, "Code",ExpressionUUID->"05df5500-1e66-49a9-afd7-256365f8b6dc"], +Cell[20044, 620, 211, 6, 38, "Echo",ExpressionUUID->"15c46bab-62f8-4c23-be66-af5cfc278ceb"] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[20304, 632, 284, 6, 106, "Subsubsection",ExpressionUUID->"6c78f375-83c5-40c5-a26f-9dfafb83427b"], +Cell[20591, 640, 1387, 43, 98, "Code",ExpressionUUID->"05cdeb1a-e1b0-40a7-af51-51ab9b75cc2e"] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[22039, 690, 155, 3, 101, "Section",ExpressionUUID->"e0558e89-2c12-471a-af64-7b6a1457eb4d"], +Cell[CellGroupData[{ +Cell[22219, 697, 290, 7, 122, "Subsection",ExpressionUUID->"2f7348b3-443c-4a22-943e-943b7962999e"], +Cell[22512, 706, 3602, 93, 214, "Code",ExpressionUUID->"0716117c-5381-46be-8b57-f2cefa727879"], +Cell[CellGroupData[{ +Cell[26139, 803, 4710, 130, 602, "Code",ExpressionUUID->"2687c350-1150-4951-bcf0-28364fa5bf73"], +Cell[CellGroupData[{ +Cell[30874, 937, 224, 6, 38, "Echo",ExpressionUUID->"1aea5154-7487-4053-9b87-eaebfcd6471a"], +Cell[31101, 945, 200, 6, 38, "Echo",ExpressionUUID->"a705af7b-dd8d-4843-9013-b64731e90a11"], +Cell[31304, 953, 228, 7, 38, "Echo",ExpressionUUID->"d4db3b60-bed3-4a41-b647-914ae220d498"], +Cell[31535, 962, 239, 7, 38, "Echo",ExpressionUUID->"66263894-11e5-431a-bd4e-56e199c15a5b"], +Cell[31777, 971, 320, 8, 63, "Echo",ExpressionUUID->"77e6086f-c8ed-4881-ac7b-1121513e1951"], +Cell[32100, 981, 320, 8, 63, "Echo",ExpressionUUID->"35ae76a0-b666-481e-9dfe-b6888da9c15f"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[32493, 997, 204, 4, 101, "Section",ExpressionUUID->"65d2b88d-22b2-481a-935c-71bdce9f21f1"], +Cell[32700, 1003, 568, 13, 142, "Text",ExpressionUUID->"f20cba79-bbb2-4d1b-9349-a349e8b0b7a4"], +Cell[CellGroupData[{ +Cell[33293, 1020, 692, 17, 146, "Subsubsection",ExpressionUUID->"d7131855-64d1-451f-98f3-152b4aa9f3a5"], +Cell[33988, 1039, 684, 20, 107, "Code",ExpressionUUID->"fadd5b7c-a968-401d-9e42-d6ca30b3a2a6"] +}, Open ]], +Cell[CellGroupData[{ +Cell[34709, 1064, 268, 4, 81, "Subsection",ExpressionUUID->"eed8b815-af5d-458f-8082-a956f0fb88b9"], +Cell[CellGroupData[{ +Cell[35002, 1072, 460, 12, 107, "Subsubsection",ExpressionUUID->"b20dcf41-6dfe-404c-8167-50b070efca5f"], +Cell[CellGroupData[{ +Cell[35487, 1088, 11721, 323, 698, "Code",ExpressionUUID->"6bec84e7-f813-4bb5-9a1e-8a3d86e897da"], +Cell[47211, 1413, 3524, 78, 342, "Output",ExpressionUUID->"88457644-f8dc-4649-adb3-9b54c9fd1c06"], +Cell[CellGroupData[{ +Cell[50760, 1495, 302, 7, 38, "Echo",ExpressionUUID->"d1f17eb9-1e3f-45fe-8a49-8b9eefc03ffb"], +Cell[51065, 1504, 303, 8, 38, "Echo",ExpressionUUID->"62407cb0-a174-480a-8d16-3a55f4b36678"], +Cell[51371, 1514, 385, 9, 38, "Echo",ExpressionUUID->"d6ae3e9d-138a-4eac-9161-a39196238226"], +Cell[51759, 1525, 241, 6, 38, "Echo",ExpressionUUID->"a954a63c-1072-4dd1-a3b7-6fea2ecdbf38"], +Cell[52003, 1533, 2181, 61, 96, "Echo",ExpressionUUID->"fca08186-95ea-4887-8401-ad9d766f2ded"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[54257, 1602, 171, 3, 81, "Subsection",ExpressionUUID->"d44a8cc6-b4f0-4204-b250-e68ad4e19d99"], +Cell[CellGroupData[{ +Cell[54453, 1609, 413, 11, 68, "Subsubsection",ExpressionUUID->"800e047e-b69c-4509-bda4-30799fa9a63e"], +Cell[CellGroupData[{ +Cell[54891, 1624, 7526, 215, 417, "Code",ExpressionUUID->"7ca95c98-841f-4a4d-8646-7ee5087c0cbe"], +Cell[62420, 1841, 3553, 78, 338, "Output",ExpressionUUID->"1f3d487e-7d60-4563-a2b3-f3aa65c1d146"], +Cell[CellGroupData[{ +Cell[65998, 1923, 301, 7, 38, "Echo",ExpressionUUID->"20a8471e-d48d-4dc1-8a0f-2b45a51698ee"], +Cell[66302, 1932, 301, 8, 38, "Echo",ExpressionUUID->"5cd69ac1-3ee9-4f3c-b5cf-95d07eb0ff1c"], +Cell[66606, 1942, 391, 10, 38, "Echo",ExpressionUUID->"0834851c-ee77-4202-aa72-ad7a0f04c869"], +Cell[67000, 1954, 238, 6, 38, "Echo",ExpressionUUID->"e88a31f0-9ce3-43a8-a4fe-062f673969b4"], +Cell[67241, 1962, 2460, 70, 190, "Echo",ExpressionUUID->"24b12cbb-7a22-45fd-bb9e-d5824114ff9b"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]], +Cell[CellGroupData[{ +Cell[69786, 2041, 164, 3, 101, "Section",ExpressionUUID->"b9760121-93f2-4105-bc65-e6b3dbe04aec"], +Cell[CellGroupData[{ +Cell[69975, 2048, 227, 5, 81, "Subsection",ExpressionUUID->"bf3ecf5a-6ea2-4f9a-a236-2d3956e9c134"], +Cell[CellGroupData[{ +Cell[70227, 2057, 2145, 57, 168, "Code",ExpressionUUID->"88153533-d3ba-42e3-8671-5c87d6eba466"], +Cell[CellGroupData[{ +Cell[72397, 2118, 306, 8, 38, "Echo",ExpressionUUID->"9c86a598-6ad7-4cdc-b7d3-f17754fbb4f8"], +Cell[72706, 2128, 298, 7, 38, "Echo",ExpressionUUID->"edb1d49d-7246-436e-85d1-f3028622cb8d"] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +}, Open ]] +} +] +*) +