<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ryan James Kim on Medium]]></title>
        <description><![CDATA[Stories by Ryan James Kim on Medium]]></description>
        <link>https://medium.com/@ryanjameskim?source=rss-92f22254dea0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nzylCU12FG9g_wao0nHOlA.jpeg</url>
            <title>Stories by Ryan James Kim on Medium</title>
            <link>https://medium.com/@ryanjameskim?source=rss-92f22254dea0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 22:52:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ryanjameskim/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What is the options market expecting for BTC volatility in 2024? A primer on forward volatility]]></title>
            <link>https://ryanjameskim.medium.com/what-is-the-options-market-expecting-for-btc-volatility-in-2024-a-primer-on-forward-volatility-4dff028582c6?source=rss-92f22254dea0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dff028582c6</guid>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[options]]></category>
            <category><![CDATA[2024]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[volatility]]></category>
            <dc:creator><![CDATA[Ryan James Kim]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 14:15:38 GMT</pubDate>
            <atom:updated>2023-11-17T00:03:35.894Z</atom:updated>
            <content:encoded><![CDATA[<p>Several important events are slated for Bitcoin in 2024, particularly the ‘halvening’ in April 2024 which will see the amount of BTC rewards that miners receive reduced by 50%. Past episodes of BTC halvening have seen increased volatility in the lead up to the event and higher overall prices for bitcoin after. Economically, the intuition here is that with less supply growth, prices for a good should adjust higher if demand stays constant. Currently, the market is anticipating the 2024 halvening to be a volatile period for bitcoin.</p><p>What has occurred in the past? The table below shows the BTC price 6 months before, the day of, and the price 6 months after past halvenings. In addition, we include the realized volatility during the six months before and the six months after the three previous halvenings. While the rise in prices can be clearly seen, the results on volatility are mixed. The past two events saw less realized volatility post-halvening while the first event showed greatly increased volatility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NsOcyPcS3J5ecq6Y" /></figure><p>Realized volatilities are backward-looking — they can only tell us what actually happened. There’s no guarantee about what will happen in the future. So what can we say here at the end of 2023 about what will happen in 2024? This is where options come in. Options prices can be used to make a prediction about future volatility (what will come).</p><p>How? Let’s review the relationship between volatility and options without using too much math. Options are a contract that gives you the right but not obligation to buy or sell an underlying asset, in this case bitcoin. When the price of the underlying asset is very uncertain or very volatile, having this right to buy or sell at a predetermined price is very valuable.</p><p>This means that one of the most important factors to the price of an option is the expectation of how volatile the underlying asset will be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/0*bUVUL-LNaC6ltIAD" /></figure><p>Let’s use an example. Say your neighbor has a limited edition widget that she just bought for $100. She tells you that in six months time, you can buy it from her for $150 but that you will need to pay her $10 today for her to guarantee this right for you. Is this is a good deal?</p><p>If you expect the company who produces the widget to just start selling them in 6 months time at $100, this isn’t a very good deal. Why? Because you expect prices to be stable ($100 now and $100 in six months) and therefore paying to secure this right to buy at $150 from your neighbor is probably not worth it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ylx6Waga1L6xleOu" /><figcaption>A widget</figcaption></figure><p>However, what if the widget company doesn’t plan to make any more and you think that the price of the widget could be $200 in six months? Then the right to buy at $150 is very valuable. <strong>The underlying expectation of how different the price of the widget could be in the future is directly tied to how costly a price guarantee or option is.</strong></p><p>This is where the famous Black Scholes model comes in. The BS model provides a mathematical framework to quantify this relationship between expected volatility and prices of options. This relationship is so common that options traders often talk about trading an option’s implied volatility rather than its raw premium price. The relationship works in reverse too: we can infer what the market’s expectations of future volatility from the prices of those options.</p><p>So what is the bitcoin options market saying right now about 2024 volatility and where bitcoin price could end up? If we just graph the implied volatility of June 2024 options, this will only tell us what the total expected volatility from now to that date is. In order to strip out what the market expects for the rest of 2023, we need to calculate the <strong>forward volatility</strong> using following variance formula (math warning):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*Kt0kPXS_iQ0BYnysizlYKA.png" /></figure><p>The variance formula helps us strip out the effects of 2023 and make an apples to apples comparison to answer the question: how has the options market priced 2024 volatility so far? In the graph below, we see that the Q1 ’24 and Q2 ’24 forward vol has had a fairly large range so far this year and that the recent rally in BTC spurred by hopes of a BTC spot ETF has returned vols back to where they were near the start of the year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tFeTrnxQabeZazj-" /></figure><p>What this chart is telling us is that expectations of how volatile BTC will be in 2024 have drastically reset from just 2 months ago. BTC options are saying that there is a much higher chance now of BTC going back to its all time highs in 2024 than two months ago. Finally, while vols are higher than they were before, this chart shows us that forward vols are about as high as they were near the beginning of the year.</p><p>Let’s explore the concept of forward volatility intuitively. While the formula itself tells us that the variance (volatility squared) is linear by time, where AF is each date’s annualization factor, it’s sometimes easier to see this using a monte carlo simulation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8qZVgrHAmPSGjK9y" /></figure><p>The above graphic shows that if we run a year long simulation with a constant volatility 1000 times, the distribution of ending prices is very close to the ending results of a different simulation where we have a lower starting volatility for 6 months and a higher one (calculated by the forward volatility formula) for the next 6 months. In other words, the histograms on the right are essentially the same despite the two different scenarios.</p><p>Let’s say that 365 day BTC implied volatility was 60%. The top graph in purple shows that our 1y distribution of values is around +/- 60% if we keep vol constant. But the same ending distribution can be achieved if we simulate volatility at 40% for 180 days and then increase it to 74.8% for 180 days. This also means that if I know that 1y vol is 60% and that 6m vol is 40%, then I automatically know that 6m vol in six month’s time is 74.8%. The three things must be internally consistent.</p><p>So let’s put it all together. With forward vols at roughly ~61%, the options market is saying that if we end 2023 at $37,000, there is a ~7.79% probability that we reach all-time highs again by mid-year. Those investors who think the chance is greater than that might look into buying options to express that view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v4tQi9v_ksxYVDfI" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dff028582c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is crypto becoming more institutional? Evidence from options]]></title>
            <link>https://ryanjameskim.medium.com/is-crypto-becoming-more-institutional-evidence-from-options-acbcc8fa3ea9?source=rss-92f22254dea0------2</link>
            <guid isPermaLink="false">https://medium.com/p/acbcc8fa3ea9</guid>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[volatility]]></category>
            <category><![CDATA[options]]></category>
            <dc:creator><![CDATA[Ryan James Kim]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 17:47:45 GMT</pubDate>
            <atom:updated>2023-10-19T17:47:45.339Z</atom:updated>
            <content:encoded><![CDATA[<p>Crypto winter and the declines in trading volumes in 2023 have accelerated a long term decline in implied volatilities in Bitcoin and Ethereum, bringing the crypto majors closer than ever to other macro assets like Gold. The increasing gap between weekday options and weekend options, the so-called “weekend effect”, suggests that some of the decline is a sign of maturation: the space is becoming more institutional, professional, and focused on prices during the week.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*nrXpMN531bsV4u5wK6oLCg.png" /></figure><p><em>What is the weekend effect?</em></p><p>The “weekend effect” in options markets is the observation that an option with a Sat, Sun, or Mon expiration is less expensive than a similar option that expires on a weekday, controlling for how much time there is left before expiry. In other words, if today is Friday, options that expire on Saturday are worth a lot less than the same options that expire on Tuesday if today were Monday.</p><p>This is so prevalent in traditional markets that are closed for trading on weekends that many volatility rules of thumb annualize based on the number of trading days in a year (252) rather than the number of calendar days (365). Since many traditional markets do not trade on the weekend, the weekend effect is typically interpolated from Monday options or using a sophisticated day-counting strategy.</p><p>Of course, crypto is different. Because much of crypto’s early history was driven by retail interest trading in free time, weekends often were the times of the most volatility. As such, crypto options had much less measurable weekend effect (there was less gap between weekday and weekend options).</p><p>Over the past 18 months though, we’ve seen an incredible compression of vols for both BTC and ETH. Whereas the median overnight BTC implied vol for a weekday was only 3.7% larger than an overnight expiring on a weekend,<strong> it is now 12.9%</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*5pkwJjxqsH0TrLs4Fy81rA.png" /></figure><p>The increasing gap over time suggests options market makers are increasingly <strong>pricing expectations of quiet weekends in crypto.</strong> Likewise, this presents an opportunity to buy significantly cheaper options for traders who want to play on events over the weekend.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acbcc8fa3ea9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ZK Series — Multilinear Expansion]]></title>
            <link>https://ryanjameskim.medium.com/zk-series-multilinear-expansion-5b387f56b184?source=rss-92f22254dea0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b387f56b184</guid>
            <category><![CDATA[zero-knowledge-proofs]]></category>
            <dc:creator><![CDATA[Ryan James Kim]]></dc:creator>
            <pubDate>Sat, 04 Dec 2021 22:15:59 GMT</pubDate>
            <atom:updated>2021-12-04T22:17:15.583Z</atom:updated>
            <content:encoded><![CDATA[<h3>ZK Series — Multilinear Expansion</h3><p>As part of the <a href="https://zeroknowledge.fm/zk-hack/">Zero Knowledge Hackathon</a>, I’ve been learning about the mechanism behind ZK proofs. Justin Thaler’s book <a href="https://people.cs.georgetown.edu/jthaler/ProofsArgsAndZK.pdf">Proofs, Arguments, and Zero-Knowledge</a> is a rigorous introduction to the material and has some great exercises that are worth doing to solidify understanding.</p><p>Here is a python script that I wrote as part of the book’s exercises. For any function that maps n-dimensions of binary numbers {0,1} to an integer, one can derive a unique multi-linear function which shares the original inputs → outputs, but also expands the domain of each dimension. In the example below for instance, f(0,1) = 4 in the original function. Likewise, g(0,1) = 4, but as you can see the domain areas have expanded from binary to a p=5 field. The exact equation is g(x1,x2) = 3–2(x_1) + 1(x_2) and it is the ONLY solution which has at most 1 degree for each x_i (no powers, but cross terms like x_1 * x_2 allowed).</p><p>ORIGINAL FUNCTION f(x1,x2)</p><p>| #0 | #1 |</p><p>#0 | 3 | 4 |</p><p>#1 | 1 | 2 |</p><p>Multi Linear Expansion g(x1,x2)</p><p>| #0 | #1 | #2 | #3 | #4 |</p><p>#0 | 3 | 4 | 0 | 1 | 2 |</p><p>#1 | 1 | 2 | 3 | 4 | 0 |</p><p>#2 | 4 | 0 | 1 | 2 | 3 |</p><p>#3 | 2 | 3 | 4 | 0 | 1 |</p><p>#4 | 0 | 1 | 2 | 3 | 4 |</p><p>This process is called multilinear expansion and is used in zero knowledge proofs to expand the collision area in which errors of an incorrect input become magnified and much easier to catch for a verifier.</p><p>The script calculates the multilinear expansion using two different methods of various speeds.</p><p>Something extra that the exercise did not call for but I found useful to do is the script uses a tree-like multiplication method to calculate the individual coefficients for each term to write out the equation nicely.</p><p><a href="https://github.com/ryanjameskim/public/blob/master/multinomialexpansion_final.py">https://github.com/ryanjameskim/public/blob/master/multinomialexpansion_final.py</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b387f56b184" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Uniswap v3 Part 2: Ticks and Fee Acounting Explainer (with toy example)]]></title>
            <link>https://ryanjameskim.medium.com/uniswap-v3-part-2-ticks-and-fee-acounting-explainer-with-toy-example-e9bf4d706884?source=rss-92f22254dea0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9bf4d706884</guid>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[uniswap-v3]]></category>
            <category><![CDATA[defi]]></category>
            <dc:creator><![CDATA[Ryan James Kim]]></dc:creator>
            <pubDate>Mon, 23 Aug 2021 20:38:54 GMT</pubDate>
            <atom:updated>2021-08-23T20:38:54.941Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://ryanjameskim.medium.com/uniswap-v3-options-hedge-explainer-with-toy-example-part-1-52fd53ea4279">my last post</a>, I laid out the major difference between Uniswap’s v3 from v2: the ability to provide liquidity to a particular range of prices. In this post, I will expand on how liquidity fee accounting has been greatly impacted by this change. This is one of the more complex changes with several mathematical formulas and computer science concepts, but it is particularly important in understanding expected return calculations, our ultimate goal.</p><p><strong>v2 Fee Calculation:</strong></p><p>Uniswap v2’s Fee system was fairly simple. Liquidity providers (LPs) were given ERC20 pool tokens that represented their proportional share of the liquidity pool. Fees were directly deposited into the total liquidity pool and thus distributed proportionally to all LPs. LPs implicitly collected these fees upon turning in their pool tokens for burning and receiving their proportion of the larger pool.</p><p>A rough calculation of expected turnovers of pool size required to achieve a certain Fee value or return could be derived under v2 by assuming continuous compounding and using logs as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/0*3fs5yWhUxxRe_HEm" /><figcaption>Number of turnovers (transaction volume as a multiple of pool size) needed to achieve a certain fee size</figcaption></figure><p>However, such an estimation system could not work under v3 because, outside of their price range, LPs are not entitled to the fees the pool generates.</p><p>For a concrete example, suppose LP Alice had set a price range of 2000–4000 DAI/ETH and the price of ETH is currently 4200. At this higher price, Alice’s entire stake has already been fully converted into DAI, and she is not actually providing any liquidity at all (she has no ETH to give in the swap between DAI and ETH). Thus, the fees when ETH is 4200 should not accrue to Alice’s contract, no matter what size of the overall pool Alice’s DAI is, even if it is quite large.</p><p>This situation necessitates two requirements, which are A) concrete demarcations (called ‘ticks’) of the price line to distinguish between points where liquidity providers do and do not provide liquidity, and B) a system to determine the distribution of fees by segment.</p><p>Because of the cost of gas, each of these must be done in as computational efficient a way as possible as to avoid unnecessary computation and storage. Computational efficiency is ultimately what motivates the somewhat convoluted solutions to these two problems.</p><p><strong>Solution to Requirement A: Ticks</strong></p><p>Prices from 0 to ∞ can be expressed in sharp enough granularity using a large-enough (int24) signed integer power of 1.0001, called a tick, such that each tick’s price is exactly .01% (1 basis point) away from its neighbor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/108/0*e5AwxwgMk5-odtGY" /></figure><p>Because many later calculations will involve multiplying by the square root of price which is expensive to compute, Uniswap pools actually track ticks using a base of the square root of 1.0001, such that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/0*-8MU-IPH-f4kkRIV" /></figure><p>For a concrete example, let’s suppose Alice wants to provide liquidity in the DAI/ETH pool from 2000 to 4000. The exact powers using base 1.0001 to get to exactly 44.7213595 and 63.24555 (the square roots of 2000 and 4000 respectively) are not integers. The closest <em>i</em>’s Alice could pick would be 76013 and 82945, so Alice’s price range would actually be from 2000.035002 to 4000.142653, depending on how granular the pool allows its indexes to be (they can be further restricted to be divisible by some integer).</p><p>In other words, a contract keeping track of any trading pair’s current price needs only know the current integer index number. In this way, the entire number line is split up into integer indexed segments that are computationally efficient and to which LPs can attach a min and max integer value.</p><p><strong>Solution to Requirement B: Last Touch Differencing</strong></p><p>One might imagine that with unlimited space and no computation restrictions, keeping a database of fees generated per tick point over time would be rather trivial as you could simply create an infinite matrix with tick points on one axis and an infinite time dimension on the other. For every square, fill in the amount of fees. Each square would also map to a liquidity column that showed the distribution of liquidity per tick at that one time. To sum an LP’s fees, simply find all its positions over time and calculate the fee * liquidity weight per square.</p><p>Obviously given the restrictions of the blockchain, this is not possible. Instead, the Uniswap v3 contracts use a much simpler but still accurate method which I call last-touch differencing to keep track of each position’s earned fees in real time.</p><p>This was probably one of the hardest concepts to understand for me personally, but I’m gonna do my best to try to explain my interpretation. Feel free to leave comments below if you’re confused (or if I am)!</p><p>First, imagine an ever-growing variable. It can be the growing amount of transactions fees, in the Uniswap v3 whitepaper called f_g, or even something like unix time, the number of seconds since Jan 1, 1970. The change in f_g is incremented by each new transaction as defined here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/0*6vyuNtBJTEJio6_u" /><figcaption>Source: Uniswap v3 whitepaper</figcaption></figure><p>But the important thing to consider for understanding last-touch differencing is that it is ever-increasing.</p><p>Let’s say the fee variable grows while at the same time, the price of a currency pair moves up and down through the integer ticks we described above. Call the largest tick that is LESS THAN the current price i_c. Again, this is the floored integer closest to the log (base root 1.0001) of the square root of the price.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*oTXdBtouLI29wm1I" /><figcaption>Source: Uniswap v3 whitepaper</figcaption></figure><p>Therefore as time goes on, various ticks become i_c in a sequential manner as the price moves to the right (up) and left (down).</p><p>Suppose also for a moment that every tick in the space keeps track of a number called f_o. f_o behaves as follows: if the tick becomes i_c from either the LEFT (prices rising) or the RIGHT (prices falling), f_o is updated to equal f_g minus the previous f_o.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/0*S-JHCrgeZzd-zRPi" /><figcaption>Source: Uniswap v3 whitepaper</figcaption></figure><p>What this operation means on a graphically level is that f_o represents the cumulative number of fees below i_c if it is to the LEFT of i_c and it represents the cumulative number of fees above i_c if it is to the RIGHT of i_c.</p><p>In our toy example graph below, we started with a 50-wide tick array with zeros across every tick. f_g was simulated by incrementing by +1 every tick moved, starting at 1. The price in this toy example moved i_c from tick 1 to tick 50 then back down to tick 31. The graph below shows each tick’s value of f_o which was updated following the rule above.</p><p>Code for this graph can be found on my <a href="https://github.com/ryanjameskim/medium/blob/main/210820%20Fee%20Graph.py">github</a>.</p><p>Notice that i_c (green line) is still tick 31, which is the FLOOR of the price, meaning tick 31’s f_o has not been updated and is still a LHS f_o. In the graph. blue means its interpretation is the sum of fees to the LEFT of the tick. Likewise, tick 32 is orange or rhs f_o, meaning its interpretation is the cumulative fees earned to the RIGHT of tick 32.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*br9KhJJ_UtjqXWHx" /><figcaption>Photo credit: @ryanjameskim, made using python and matplotlib</figcaption></figure><p>Notice also that the SUM of LHS f_o and the RHS f_o marked in the graph above equal the terminal value of f_g (66).</p><p>The Uniswap v3 whitepaper provides a function to calculate the fees generated within any two ticks as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/0*dIQp9PnplJcgiyNL" /><figcaption>Source: Uniswap v3 whitepaper</figcaption></figure><p>Here f_r means the total fees in a range defined by i_l, the lower tick, and i_u, the upper tick. It says the range’s fees are equal to the total fees generated minus the fees below (f_b) the range’s low tick and the fees above (f_a) the ranges high tick.</p><p>f_a and f_b are further defined by switch functions as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/0*qQB7tLCmFdRPOVOe" /><figcaption>Source: Uniswap v3 whitepaper</figcaption></figure><p>Let’s work through calculating the fees generated between a range (f_r) at various places in our toy example, labeled a, b, and c. Each corresponds to different scenarios with regard to relation to i_c.</p><p><strong>Range a:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/0*ZE4BJgonpphPT-I1" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/0*Od0mDoTL1BtsA1E0" /></figure><p><strong>Range b:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/132/0*O9TVHJGB7Mg1FiXX" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/194/0*E4vG6gpOyrQApQwk" /></figure><p><strong>Range c:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/140/0*f1OPLVy7j6obaDKo" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/0*mG4ySWeFE4VuuMqP" /></figure><p>As we can see, by simply keeping track of the continuously increasing variable and changing the value of a tick’s f_o only when it is crossed, we can calculate the fees generated within any range of ticks according to their relationship to the current tick.</p><p>There are some nuances here that complicate the interpretation of individual f_o’s with each other. Particularly, if a new position uses an <em>unused</em> tick for one of its boundaries, that tick initializes its f_o using the follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/0*V84jh28uwEfFB5yO" /><figcaption>Source: Uniswap v3 whitepaper</figcaption></figure><p>So because positions can come at various different times, individual tick f_o’s are not directly comparable. On a range level, last-touch differencing remains valid to use despite this initialization process though.</p><p>To see this, note that there can be three cases for a new position and its upper and lower ticks. None, one or both of the ticks can already be initialized.</p><p>In the case of none already initialized, f_r evaluates to 0 in each of the three i_c cases (above both i_l and i_u, below and between).</p><p>In the case of both already initiated, f_r evaluates to the latest running total. In the case of i_c above both i_l and i_u or below both i_l and i_u, f_r is the past accumulated already and won’t increment for the particular contract’s f_r calculation until one of the bounds is crossed. If i_c is between i_l and i_u, f_r reduces to f_g minus all the fees collected below and all the fees collected above, and collected fees increment immediately.</p><p>In the case of one of the points already initiated, we separate this by upper and lower is already initialized and then further by i_c’s position relative to i_l and i_u.</p><p>If the lower point f_o is already initialized, that means f_o for the upper tick is initialized to either 0 if i_c is below it or f_g if i_c is above. Say i_c is above both i_l and i_u, then f_r evaluates to the moment’s cumulative fees (f_g,t0) minus the lower tick’s f_o, in other words the total amount of fees made above the lower bound by that time, call this value X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/0*3itALJ_1jK_Ie_c9" /></figure><p>When i_c crosses into the upper bound, f_r evaluates into the cumulative total minus the lower tick’s f_o minus the fees collected above the upper bound above the crossing, call this value Y</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/0*cq2MardOQsdJUTK6" /></figure><p>The contract’s accumulated fees are Y — X, which is the difference between the current total minus when the amount when the upper tick was crossed (f_g,t1), which is what we want.</p><p>If i_c is below both, f_r evalues to the lower tick’s f_o, call this value X. X can be considered the amount of fees collected above the lower bound at time t0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/0*4puuNa0HVweS19Z1" /></figure><p>When i_c crosses into the lower bound, f_r evalues into the cumulative total minus the cumulative total when i_l was crossed plus X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/0*225YizJfA1F4tcvE" /></figure><p>The contract’s accumulated fees are Y-X, which again is the difference between the current total minus when the amount when the lower tick was crossed, again what we want.</p><p>Finally, if i_c is between, f_o for the upper tick is still initialized at 0, and f_r is evaluted to be the current amount of fees minus everything below the lower bound, call this X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/0*CLy6f9PUPVVgQO3V" /></figure><p>Fees begin accumulating immediately, but the structure of the calculation is the same</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/0*Qc690UnMlRyDg39O" /></figure><p>Thus again, Y-X is the current accumulated sum minus the sum at initiation.</p><p>Similar logic can be used to show the cases when the upper point f_o is already initialized and is omitted here.</p><p><strong>Contract Uncollected Fees:</strong></p><p>The cumulative totals above are actually kept in terms of per-liquidity unit, thus an individual contract’s fees are simply its liquidity value multiplied by the f_r calculation above.</p><p>We will discuss the liquidity calculation in our next post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9bf4d706884" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Uniswap v3 + Options Hedge explainer (with toy example) Part 1]]></title>
            <link>https://ryanjameskim.medium.com/uniswap-v3-options-hedge-explainer-with-toy-example-part-1-52fd53ea4279?source=rss-92f22254dea0------2</link>
            <guid isPermaLink="false">https://medium.com/p/52fd53ea4279</guid>
            <category><![CDATA[uniswap-v3]]></category>
            <category><![CDATA[crytpo]]></category>
            <category><![CDATA[uniswap]]></category>
            <dc:creator><![CDATA[Ryan James Kim]]></dc:creator>
            <pubDate>Tue, 17 Aug 2021 20:10:45 GMT</pubDate>
            <atom:updated>2021-08-17T20:41:06.809Z</atom:updated>
            <content:encoded><![CDATA[<p>Uniswap v3 adds new features to the core AMM product that give liquidity providers (LPs) more flexibility in allocating their capital for enhanced capital efficiency and higher fee tiers. Picking the optimal price range with a consistently managed options hedge can further enhance yield generation on digital assets and specifically target risk to focus on increased trade activity rather than simple price level.</p><p>This explainer will address the basic difference between Uniswap v3 and v2 and how one can use a simple options hedge to reduce impermanent loss.</p><p><strong>Uniswap v3</strong></p><p>Uniswap v3 is different than v2 in that LPs can specify a specific range of prices between two digital assets in which to provide liquidity. Before, v2 LPs by default provided capital along the whole x*y=k curve from 0 to infinity. What this means in practical terms is that a v3 LP will get fully converted into the less valuable asset of the pair at the top and bottom of her range, whereas a v2 LP would never be fully converted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*84PINERgs6T35deM_bVcbw.png" /><figcaption>Blue line: Standard X * Y = K curve to deterministically price pairs; Orange line: v3 bounded liquidity. Photo credit: @ryanjameskim, made using python and matplotlib</figcaption></figure><p><strong>Example:</strong></p><p>Suppose ETH/USDC is currently at $3,000, and suppose Alice and Bob are v3 and v2 users respectively. Both Alice and Bob each decide to stake 1 ETH and $3,000 USDC. Let’s compare how their outcomes differ between the two versions.</p><p>Alice the v3 user stakes 1 ETH and $3,000 USDC, amounting to $6,000 in liquidity. Additionally, she specifies a range of $2,000 to $4,500. The range means that if ETH/USDC trades down to $2,000, Alice’s whole portfolio is converted completely into 2.225 ETH and 0 USDC (worth $4,449)(left graph, red X). Likewise, if ETH/USDC trades up to $4,500, Alice’s whole portfolio is converted completely into 0 ETH and $6,674 USDC (worth $6,674) (left graph, green x).</p><p>For comparison, say Bob is a v2 user and stakes the same amount as Alice. At $2,000, Bob’s portfolio is roughly 1.225 ETH and $2449 USDC (worth $4,899) (left graph, purple x). At $4,500, Bob’s portfolio is roughly 0.816 ETH and $3,674 USDC (worth $7,348) (left graph, cyan x).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOBfPx5WzCJqjo7gvlXi4A.png" /><figcaption>A comparison of total holdings and portfolio value over the price range. Alice experiences far faster conversion and range of outcomes as well as sharper impermanent loss (dashed red lines). Photo credit: @ryanjameskim, made using python and matplotlib</figcaption></figure><p>What benefit does Alice receive in exchange for specifying the range and getting worse terminal outcomes? <strong>Leverage on fees.</strong> As long as ETH/USDC trades within her range, Alice’s share of the liquidity pool’s fees will be 5.45x that of Bob’s<strong> despite putting up the same amount of liquidity</strong>. This is what Uniswap means when they say v3 is more capital efficient.</p><p><strong>Using Options to hedge Impermanent Loss:</strong></p><p>In the above scenario, it is clear that by specifying the trading range, Alice’s impermanent loss is greater than Bob’s. However, because impermanent loss is a deterministic function of deviation from the initial spot price in both directions, we can use options to hedge some or all of this risk.</p><p>In the above scenario, Alice’s impermanent loss is $826 at $4500 ETH/USDC and $551 at $2000 ETH/USDC. Alice can completely cover this risk by buying 0.55 3000 straddles for roughly $1,265 in premium (100% vol), which represents 21% of her initial portfolio investment for one year’s worth of protection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*gnAHjLQlQHDRl0Bbexdjyw.png" /><figcaption>Alice’s hedged portfolio values versus ETH prices versus static. Photo credit: @ryanjameskim, made using python and matplotlib</figcaption></figure><p>While 21% of initial investment sounds like quite a bit, with a transaction compounding rate of 0.3%, this implies a transaction hurdle of 64x the notional value of the pool investment in order to make back the premium of the options. If Uniswap ETH/USDC pool’s transaction notional is about 1.5x the size of the pool in a day, this means the 1y options premium can be made up in 42.57 days. This calculation does not take into account the new liquidity fee calculation that came with Alice’s better capital efficiency.</p><p>This is just a simple example. As we can see, the cost of optionality is probably too steep to justify the benefit in this case. However, there are far more sophisticated ways in which to hedge out digital asset risks and enhance yield using more complicated options strategies. I hope to publish more articles about this topic in the future.</p><p>Code for building above graphs: <a href="https://github.com/ryanjameskim/medium">https://github.com/ryanjameskim/medium</a></p><p>If you liked this article or have a question, please give me a clap or leave a comment. I am always interested in learning more about DeFi and crypto and connecting with people in this space.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52fd53ea4279" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>