<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.0.1">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2026-02-10T19:47:18-08:00</updated><id>http://localhost:4000/feed.xml</id><entry><title type="html">An Introduction to Auctions</title><link href="http://localhost:4000/blog/2024/10/02/first-an-introduction-to-auctions/" rel="alternate" type="text/html" title="An Introduction to Auctions" /><published>2024-10-02T00:00:00-07:00</published><updated>2024-10-02T00:00:00-07:00</updated><id>http://localhost:4000/blog/2024/10/02/first-an-introduction-to-auctions</id><content type="html" xml:base="http://localhost:4000/blog/2024/10/02/first-an-introduction-to-auctions/"><![CDATA[<!--
The average American is involved in approximately 420 auctions a day (Source: I made it up). Jokes aside, every time you load LinkedIn, Facebook/Instagram, or run a search, you trigger an auction. Yes, hundreds of advertisers are submitting bids competing for your attention every time you go into these sites. This market is huge. Hundreds of millions of dollars are spent every day through these auctions. 

This raises many interesting questions: How should platforms set the auction format? Are these auctions the same as the art auctions you and I are familiar with? How should advertisers bid to get the most bang for their buck? As you might expect, the answers to these questions are complicated. However, in this post, I lay out some of the auction basics so we can try to answer these questions in the near future.
-->

<figure class="centered-figure">
<img src="/images/intro_to_auctions/Dall E A gavel, minimalist style, soft colors, in paper with water colors.webp" alt="Dall-E: A gavel in minimalist style, with soft colors, painted on paper using watercolors." class="center-image max-width-50" />
<figcaption>A gavel, minimalist style, soft colors, in paper with water colors. Dall-E.</figcaption>
</figure>

<p>You may not have noticed, but there are hundreds of auctions being run on a daily basis because of you. Every time you open YouTube, Facebook, Instagram, Twitter, etc, within a fraction of a second, an auction is run to show you ads. This market is huge. Hundreds of millions of dollars are spent every day through these auctions.
In this post I will discuss auction basics. We will try to answer questions such as: Does the auction format matter? How should the auctioneer set it? Are some auction formats equivalent to each other? How should advertisers bid? Let’s dig in.</p>

<p>You are probably familiar with how art auctions are run, but if you need a reminder, or have a couple minutes to spare, I highly recommend you <a href="https://www.youtube.com/watch?v=3orkmMlSpmI">watch the auction for the most expensive painting ever sold</a>, Leonardo’s Salvator Mundi. This type of auction is an <em>open-bid</em> (meaning everyone can see everyone else’s bids), <em>ascending price</em> auction, sometimes also called an “English” Auction. But there are many, many other types of auctions: Dutch, Japanese, Brazilian, Scottish, and so on. In fact, the Wikipedia page for <a href="https://en.wikipedia.org/wiki/Auction">auction</a> links to 39 different types of auctions! You may be wondering, why are there so many types? What are their differences? These are excellent questions, but in this post, to start with the basics, I want to focus only on the following types:</p>

<ul>
  <li>Open-bid ascending-price auction (also known as an <em>English</em> auction): This is the “classic” art auction you are familiar with; bidders outbid each other until only one remains.</li>
  <li>Open-bid descending-price auction (also known as a <em>Dutch</em> auction). In this auction, the auctioneer starts with a high price and gradually reduces it. The first person to accept the price wins the auction.</li>
  <li>Sealed-bid first-price auction. Participants submit their bids in a sealed envelope and the auctioneer selects the winner as the highest bidder. The highest bidder pays the amount they bid.</li>
  <li>Sealed-bid second-price auction (also known as a <a href="https://en.wikipedia.org/wiki/Vickrey_auction"><em>Vickrey</em> auction</a>). Again, participants submit their bids in a sealed envelope and the auctioneer selects the winner as the highest bidder. This time, <em>the highest bidder pays only an amount equal to the second-highest bid</em>, hence the name, second-price.</li>
</ul>

<p>I’ve chosen to focus on these types because 1) they are easy to understand. 2) we can start building intuition on how to optimally bid in them, and 3) they are related to each other in some interesting ways.</p>

<p>In the next section, we will show that the English auction and the sealed-bid second-price auctions are equivalent. This result is pretty magical! Notice that all the back-and-forth of waiting for someone to bid and raising bids in the English auction can be eliminated, we can simply run a sealed-bid second-price auction! Moreover, the same argument can be used to show that the Dutch auction and the sealed-bid first-price auction are equivalent!</p>

<h1 id="the-english-auction-is-equivalent-to-a-sealed-bid-second-price-auction">The English Auction Is Equivalent To A Sealed-bid Second-price Auction</h1>

<p>To see how the English auction is equivalent to the sealed-bid second-price auction (from here on, second-price auction) all we need to do is the following. Imagine an English auction is running. The person who values the item the most (let’s assume no ties) can always increase the current highest bid by 0.01 dollars. So, what will end up happening is, at some point in the auction there will only be two bidders left, and each will be raising their bid by one cent until the other bidder stops doing that. Now, when will the second-highest bidder decide to stop? If the second-highest bidder values the item at $v_2$ then they will not bid more than $v_2$ otherwise they will get negative utility and therefore will not do that. So, the highest the second-highest bidder will bid is $v_2 - 0.01$ (or $v_2$), then the person who values the item the most will bid an extra cent and <strong>pay $v_2$ (or $v_2 + 0.01$), the second-highest valuation among all the participants</strong>. Notice, however, that we have not proved equivalence between the English auction and the second-price one because we have not shown that in a second-price auction bidders bid their valuations. If we are able to prove this then we are done! We will do so in the next subsection.</p>

<h2 id="how-to-optimally-bid-in-a-second-price-auction">How To Optimally Bid in a Second-Price Auction</h2>
<p>Say you are participating in a second-price auction and you value the item at $v_1$. How much should you actually bid? More than $v_1$ in the hope that you win but the second-highest bidder bids less than $v_1$? Should you bid $v_1$ itself? What about bidding less than $v_1$? How much less would be appropriate if you want to maximize utility (defined as $v_1$ minus what you end up paying in case you win)?</p>

<p>The first thing to note is that bidding more than your valuation is never a good idea. Say you bid $v_{high} &gt; v_1$. If the second-highest bid $v_2$ is in the interval $(v_1, v_{high}]$, then your utility, $v_1 - v_2$, is less than 0, and if the second-highest bid is in the interval $[0, v_1]$ then your utility would be the same as if you had bid $v_1$. So you never want to bid more than your true valuation.</p>

<p>What about bidding less than $v_1$? Say we bid $b_1 = v_1 - c$ where $c &gt; 0$. Then there is some chance that someone’s bid is in $[b_1, v_1]$ if that is the case then you lose the item (and you wouldn’t have lost if you had bid your true valuation). The other scenario is where the second bid is in $[0, b_1]$, when this is the case your utility is the same whether you bid $v_1$ or $b_1$. So, to not risk losing the item, <strong>you should always bid your true valuation</strong>.</p>

<p>That’s it! <strong>We have shown that in sealed-bid second-price auction, participants should bid their true valuations.</strong> There is something remarkable about the argument we just made; notice we never went into the “If I think the other bidders’ valuation is bla, and they think that my valuation is blabla, then I should be bid bla because they think I’m going to bid blabla… and so on.” For some reason this  type auction admits a very simple strategy that doesn’t depend on the actions of other bidders. Economists and computer scientists like to call these kinds of mechanisms <a href="https://en.wikipedia.org/wiki/Incentive_compatibility">incentive compatible</a> (I will have more to say about incentive compatibility in a later section).</p>

<p>So, if we combine the fact that in second-price auctions participants should bid their true valuations, together with the fact that in an English auction the winner pays the second-highest valuation, <strong>this shows that the English and the sealed-bid second-price auction are outcome equivalent.</strong></p>

<p>Now it is your turn to convince yourself that the Dutch auction is equivalent to the sealed-bid first-price auction :)</p>

<h1 id="should-you-run-a-first-price-or-a-second-price-auction">Should You Run a First-Price or a Second-Price Auction?</h1>

<p>We’ve shown the equivalence between the open-bid and sealed-bid auctions discussed above. So now you may wonder, what type of auction should an auctioneer choose if they want to sell an item? A first-price or a second-price one? Which is more likely to yield a higher profit?</p>

<h2 id="how-to-optimally-bid-in-a-sealed-bid-first-price-auction">How to Optimally Bid In a Sealed-Bid First-Price Auction</h2>
<p>Think about it for a second. How would you do it? Should you bid your valuation just as in the second-price auction? The answer to the last question is no, this is because if you were to win the auction then your utility would be exactly 0. So you should bid less than your valuation, this also sometimes called <em>shading your bid</em>. But how much less? At this point, we need to start making assumptions and get more information. A good piece of information is the number of bidders that will participate in the auction. Intuitively, if we knew there was only one other bidder then we could probably risk it and bid significantly less than our true valuation (after all, what are the chances that the other bid is higher than our bid). However, if we knew there were one thousand bidders then we probably don’t want to shade our bid too much as it is more likely someone will bid higher than us.
From now on we will assume the number of bidders in the auction, $n$, is known. But knowing $n$ is not enough, we need a model for the population’s valuations. We will assume that the bidders’ valuations are sampled i.i.d. from a probability distribution with cdf $F(x)$, where $F(x) = P(X &lt; x)$ represents the probability that a (random) valuation $X$ is less than $x$.</p>

<p>Under this model, if our valuation is $v_1$, and we condition on the fact that we think we will win the auction. Then we want to bid one cent more than the expected maximum valuation (conditioned on the fact that all valuations are less than ours). The distribution for the maximum valuation is then</p>

<p>\begin{align}
G(x) &amp;= P(X &lt; x | X &lt; v_1)^{n-1} \cr
&amp;= (\frac{P(X &lt; x, X &lt; v_1))}{P(X &lt; v_1)})^{n-1} \cr
&amp;= (\frac{F(min(x, v_1))}{F(v_1)})^{n-1},
\end{align}</p>

<p>the first equality is true because for the maximum valuation to be less than $x$ we need $n-1$ valuations (conditioned on the fact that they are less than ours) to be less than $x$. The second equality uses the definition of conditional probability, and the third one is just using the definition of $F$. We should then bid $b = \mathbb{E}[Y]$ plus one cent, where $Y$ is a random variable with cdf $G$. By the <a href="https://math.stackexchange.com/questions/63756/tail-sum-for-expectation">tail sum formula</a>, we should bid $b = \mathbb{E}[Y] = \int_0^{v_1} (1 - G(x)) dx$. This is technically a closed-form expression for the optimal bid, but, to make this more concrete let’s go through a simple example.</p>

<p>Say we are now the auctioneer and we know that there are only 2 bidders in our auction, let’s also assume that the distribution of each of the bidder’s valuations is distributed uniformly in the interval [0, 1]. <em>What is our expected revenue from running the auction?</em>
Well, if $v_1$ and $v_2$ are the valuations of bidders 1 and 2 resp. Then player 1 will bid $\frac{v_1}{2}$ since a uniform random variable in [0, 1], conditioned on it being less than $v_1$, has the uniform distribution in $[0, v_1]$, and hence its expectation is $\frac{v_1}{2}$. Similarly, bidder 2 will bid $\frac{v_2}{2}$. So our expected revenue, since we are running a first price auction is</p>

<p>\begin{align}
\mathbb{E}[\max(\frac{v_1}{2}, \frac{v_2}{2})] &amp;= \frac{1}{2} E[\max(v_1, v_2)] \cr
&amp;= \frac{1}{2} \int_0^1  P(\max(v_1, v_2) &gt; x) dx \text{ by the tail sum formula} \cr
&amp;= \frac{1}{2} \int_0^1 (1 - P(\max(v_1, v_2) \leq x)) dx \cr
&amp;= \frac{1}{2} \int_0^1 (1 - P(v_1\leq x)P(v_2 \leq x)) dx \cr
&amp;= \frac{1}{2} \int_0^1 (1 - x^2) dx \cr
&amp;= \frac{1}{3}.
\end{align}</p>

<p>So, <strong>we expect to receive one third of a dollar in this first-price auction</strong>. Now, how does this compare with the revenue of a second-price auction? In a second-price auction our expected revenue is:</p>

<p>\begin{align}
\mathbb{E}[\min(v_1, v_2)] &amp;= \int_0^1  P(\min(v_1, v_2) &gt; x) dx \cr
&amp;= \int_0^1 P(v_1 &gt; x, v_2 &gt; x) dx \cr
&amp;= \int_0^1 P(v_1 &gt; x) P(v_2 &gt; x) dx \cr
&amp;= \int_0^1 (1 - P(v_1 \leq x)) (1 - P(v_2 \leq x)) dx \cr
&amp;= \int_0^1 (1-x)^2 dx \cr
&amp;= \frac{1}{3}.
\end{align}</p>

<p><strong>This is the same expected revenue as in the second-price auction!</strong> This is pretty nice, but, is it just a coincidence? Does the result only hold when $n=2$? Or is the assumption that valuations are uniformly distributed causing this?</p>

<p>It turns out this is <strong>not</strong> a coincidence, the expected revenues will be the same in both types of auctions regardless of $n$ and on the distribution of the valuations. This surprising (and beautiful) result is known as the Revenue Equivalence Theorem <a class="citation" href="#vickrey1961counterspeculation">(Vickrey, 1961)</a>. In the next section, we will state and prove this theorem.</p>

<h1 id="revenue-equivalence-theorem">Revenue Equivalence Theorem</h1>
<p>The statement of the theorem, and most of the proof, comes from <a class="citation" href="#klemperer1999auction">(Klemperer, 1999)</a>, but the first versions of this result come from <a class="citation" href="#vickrey1961counterspeculation">(Vickrey, 1961; Myerson, 1981; Riley &amp; Samuelson, 1981)</a>. I’ve added additional explanations where I think they were necessary.</p>

<p><strong>Theorem.</strong> Assume each of the $n$ risk-neutral bidders for an object has a privately-known valuation independently drawn from a common, strictly-increasing, atomless distribution and assume this function is known to everyone. Then, <strong>any auction mechanism</strong> in which:</p>

<ul>
  <li>(i) the object always goes to the buyer with the highest valuation, and</li>
  <li>(ii) any bidder with the lowest feasible signal expects zero utility</li>
</ul>

<p><strong>yields the same expected revenue for the auctioneer.</strong></p>

<p><strong>Proof</strong>. For simplicity I will restrict our attention to mechanisms such that each player submits a bid and the mechanism selects a single winner out of the $n$ players. So, in this case, a mechanism is a mapping $M: \mathbb{R}^n \rightarrow [n]$. Recall $[n] = {1, 2, …, n}$. I think the statement also holds for mechanisms in which players can have multiple interactions among themselves or the auctioneer, I’ve chosen not to consider these mechanisms for the sake of making the argument in the next paragraph a bit more rigorous.</p>

<p>The first observation is that, since the number of players $n$ as well as the distribution of valuations $F: [\underline{v}, \overline{v}]$ are know to all bidders, then the optimal bidding function $b(v)$ (recall $v$ represents a valuation) is known to all of the players.</p>

<p>For every $i$, let $b_i = b(v_i)$. The item will then be assigned to whatever $M(b_1, b_2, …, b_n)$ evaluates to, and since $M$ is such that the object always goes to the buyer with the highest valuation, then the probability of player $i$ winning, $P_i(v_i)$ is the probability that player $i$ has the highest valuation, so $P_i(v_i) = F(v_i)^{n - 1}$. Notice how the probability of winning is the same regardless of the mechanism (as long as it satisfies (i) of course)! I’ve heard many times that when trying to solve a hard math problem one has to find the invariants, well here is your invariant :)</p>

<p>Now, to proceed with the proof we have to write some sort of equilibrium condition. For those with optimization backgrounds, what follows is the equivalent of writing the optimality condition for your problem and then deriving a consequence out of it.</p>

<p>Let $S_i(v_i)$ be the expected utility of player $i$ in equilibrium when their valuation is $v_i$. We have that $S_i(v_i) = v_i P_i(v_i) - E_M(v_i)$ where $E_M(v_i)$ represents the expected payment of player $i$ when the bid according to valuation $v_i$. If player $i$ were to report a different valuation, $\tilde{v}$, in hopes of being strategic, then its surplus would be $v_i P_i(\tilde{v}) - E_M(\tilde{v})$.
Since we are in equilibrium, and player $i$ is risk-neutral, we have that:</p>

<p>\begin{align}
S_i(v_i) &amp;\geq v_i P_i(\tilde{v}) - E_M(\tilde{v}) \cr
&amp;= v_i P_i(\tilde{v}) - E_M(\tilde{v}) + S_i(\tilde{v}) - \tilde{v} P_i(\tilde{v}) + E_M(\tilde{v}) \cr
&amp;= S_i(\tilde{v}) + (v_i - \tilde{v}) P_i(\tilde{v}).
\end{align}</p>

<p>Plugging in $\tilde{v} = v_i + dv_i$ above we get:</p>

<p>\begin{align}
S_i(v_i) \geq S_i(v_i + dv_i) - dv_i P_i(v_i + dv_i). \tag{1}
\end{align}</p>

<p>Applying the same argument, when the actual valuation of the player is $v_i + dv_i$ instead of $v_i$, we have that</p>

<p>\begin{align}
S_i(v_i + dv_i) \geq S_i(v_i) + dv_i P_i(v_i). \tag{2}
\end{align}</p>

<p>Rearranging terms in (1) and (2) we get</p>

<p>\begin{align}
P_i(v + dv) \geq \frac{S_i(v_i + dv_i) - S_i(v_i)}{dv_i} \geq P_i(v_i).
\end{align}</p>

<p>Taking the limit as $dv_i \rightarrow 0$ we get</p>

<p>\begin{align}
\frac{dS_i}{dv_i}(v_i) = P_i(v_i),
\end{align}</p>

<p>since we assumed that $F$ was strictly-increasing and atomless, and these properties also apply to $P_i$.</p>

<p>Taking the integral we have</p>

<p>\begin{align}
S_i(v_i) = S_i(\underline{v}) + \int_{\underline{v}}^{v_i} P_i(x) dx.
\end{align}</p>

<p>By assumption (ii), $S_i(\underline{v}) = 0$. This means that the function that describes the expected utility as a function of the player’s valuation is fully determined by the probability of winning as a function of the valuation $P_i(v_i)$.</p>

<p>Let’s focus on any player $i$, and its type $v_i$. Recall that any two mechanisms will have the same $P_i(v_i)$, it follows that they must have the same utility functions $S_i(v_i)$, and since $S_i(v_i) = v_i P_i(v_i) - E_M(v_i)$, for any two mechansims $M_1$ and $M_2$ it must be the case that $E_{M_1}(v_i) = E_{M_2}(v_i)$. Since the expected payment is equal across two different mechanisms holds for any player $i$ and for any valuation $v_i$, it will also hold when the valuation of player $i$ is randomized. This is also true for all players, so it must be that case that the auctioneer receives the same expected payment regardless of the mechanism they choose. Q.E.D.</p>

<p>This is pretty cool! The result implies that the auction format does not really matter at all! The facts that the second-price auction is incentive compatible, or that in first-price auctions participants shade their bids are not important for the auctioneer, in expectation the revenue they will receive is the same in both auctions.</p>

<p>But we have to be really careful with how we interpret the result. The Revenue Equivalence Theorem implies that if the auctioneer were to run many auctions in which <em>different bidders</em> with i.i.d. valuations show up to bid (let me call this setting i.i.d. auctions), then the risk-neutral auctioneer should be indifferent between auction formats as long as they satisfy (i) and (ii). Notice that the theorem does not say anything about <em>repeated auctions</em> i.e. when the auctioneer will sequentially auction many items to a fixed set of bidders with i.i.d. valuations.</p>

<h1 id="repeated-auctions-and-incentive-compatibility">Repeated Auctions and Incentive Compatibility</h1>
<p>The previous paragraph raises the question: in the repeated auctions setting, does the (incentive compatible) second-price auction prevent participants from shading their bids? The following example shows that this is not the case. Consider two players with valuations $v_1$ and $v_2$ who will participate in 3 second-price auctions, for simplicity let’s set $v_1=1$ and $v_2=.9$. If they were to bid truthfully in all three rounds then player one’s surplus is $.3$, player two’s is $0$, and revenue for the auctioneer is $2.7$. But what if both players play according to the following strategy:</p>
<ul>
  <li>In the first round I will bid truthfully.</li>
  <li>In the second round, if I won the first auction I will bid one cent less than the other player’s bid in the first round. If I lost the first round I will continue to bid truthfully.</li>
  <li>In the last round, if I am the player with the highest valuation I will bid truthfully, if I am not, I will bid .01 as a form of gratitude to the player who let me win the second auction.</li>
</ul>

<p>Using this strategy, player one’s surplus is $.1 + .99 &gt; .3$, player two’s surplus is $.01 &gt; 0$ (and this is the reason they will not bid truthfully) and the revenue for the auctioneer is $.9 + .01 &lt; 2.7$. The fact that the second-price auction is incentive compatible does not prevent players from shading their bids in the repeated auction setting!</p>

<p>This is all I have to say about repeated auctions for now. In practice, to prevent scenarios like the one above the auctioneer may decide to introduce a “reserve price”, you can think of it as the minimum bid the auctioneer wants to receive during the auction.</p>

<h1 id="so-how-are-ad-auctions-run">So, How Are Ad Auctions Run?</h1>
<p>Yes, I have gone on a detour and not yet told you how Ad auctions are actually run, but its been a fun ride hasn’t it? Ad auctions are typically implemented as <a href="https://en.wikipedia.org/wiki/Generalized_second-price_auction">generalized second-price (GSP) auctions</a>. GSPs are very similar to second-price ones except that the player’s bids are multiplied by the probability of you clicking that particular Ad. By incorporating the probability of you clicking an ad, the auctioneer attempts to, not just show to the ads corresponding to the highest bids, but also those that are the most relevant to you. I will have a lot more to say about GSPs but I’ll leave that for a future post.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[&lt;!– The average American is involved in approximately 420 auctions a day (Source: I made it up). Jokes aside, every time you load LinkedIn, Facebook/Instagram, or run a search, you trigger an auction. Yes, hundreds of advertisers are submitting bids competing for your attention every time you go into these sites. This market is huge. Hundreds of millions of dollars are spent every day through these auctions.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/intro_to_auctions/Dall%20E%20A%20gavel,%20minimalist%20style,%20soft%20colors,%20in%20paper%20with%20water%20colors.webp" /><media:content medium="image" url="http://localhost:4000/images/intro_to_auctions/Dall%20E%20A%20gavel,%20minimalist%20style,%20soft%20colors,%20in%20paper%20with%20water%20colors.webp" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">*Why* Does The Lasso Induce Sparsity?</title><link href="http://localhost:4000/blog/2024/06/01/why-does-the-lasso-induce-sparsity-copy/" rel="alternate" type="text/html" title="*Why* Does The Lasso Induce Sparsity?" /><published>2024-06-01T00:00:00-07:00</published><updated>2024-06-01T00:00:00-07:00</updated><id>http://localhost:4000/blog/2024/06/01/why-does-the-lasso-induce-sparsity%20copy</id><content type="html" xml:base="http://localhost:4000/blog/2024/06/01/why-does-the-lasso-induce-sparsity-copy/"><![CDATA[<p>I was recently asked “Why does <a href="https://en.wikipedia.org/wiki/Lasso_(statistics)">the Lasso</a> induce sparsity?” My reflex was to proceed to describe the image we have all seen in our stats/ML classes:</p>

<figure class="centered-figure">
<img src="/images/lasso-sparsity/classic_lasso_image.png" class="center-image max-width-75" />
<figcaption>
Figure 1. The classic explanation for why the Lasso induces sparsity. The blue diamond represents the 2-dimensional $l_1$ ball, the blue ball represents the $l_2$ ball, and the ellipses represent the level sets of the function we are trying to optimize. From <a class="citation" href="#hastie2009elements">(Hastie et al., 2009)</a>.
</figcaption>
</figure>

<p>I said something like: “On the left, the <a href="https://en.wikipedia.org/wiki/Level_set">level set</a> of the function we are trying to minimize hits the $l_1$ ball right in one of the corners, which induces sparsity; the same thing happens in higher dimensions. When you use the $l_2$ norm, there is no reason you should expect sparsity, as shown in the right side of the image.” This person replied with “well that’s actually not a good explanation…” Not gonna lie, I was surprised by their answer.</p>

<p>I’ve had many interactions with people regarding sparsity and the Lasso, and every single time my explanation had sufficed (to the point where I believed it was a good explanation). Seeing I was stumped, this person asked me if I was familiar with the “soft-thresholding” operator. This sounded familiar but I couldn’t really use the hint to improve my explanation.</p>

<p>If my memory doesn’t fail me, I think I got out of trouble by saying something like: “Well, we should probably look at the optimality conditions and analyze them. With this we should be able to explain why sparsity arises,” and thankfully we moved on to talk about something else.</p>

<p>Later I came back to think about this question and tried to come up with a good explanation. After spending a couple hours, I was unsuccessful (if you are curious, my failed attempt is in the Appendix). However, something good that came out of doing all this thinking is that I realized I had fooled myself into thinking I understood something just because someone showed me a pretty picture and told me that was the right explanation. This reminded me of Feynman’s quote: “The first principle is that you must not fool yourself and you are the easiest person to fool.”</p>

<h1 id="the-lasso">The Lasso</h1>
<p>Let me stop for a second and revisit the Lasso. Suppose you have $n$ samples $(x_i, y_i) \in \mathbb{R}^p \times \mathbb{R}$. You want to solve the following optimization problem:</p>

<p>\begin{align}
\min_{\beta} \sum_{i=1}^n (y_i - x_i^\top \beta)^2 \cr
\Vert \beta \Vert_1 \leq k \tag{1}
\end{align}</p>

<p>for some $k \in \mathbb{R}_+$. Equivalently (by relaxing the constraint) we have</p>

<p>\begin{align}
\min_{\beta} \sum_{i=1}^n (y_i - x_i^\top \beta)^2 + \lambda \Vert \beta \Vert_1 \tag{2}
\end{align}</p>

<p>for some $\lambda \in \mathbb{R}_+$. So the question we want to answer is: If $\beta^* \in \mathbb{R}^p$ is the optimal solution to the Lasso problem, why will $\beta^{\star}$ have many entries exactly equal to zero?</p>

<h1 id="why-is-the-picture-a-bad-explanation">Why Is The Picture a Bad Explanation?</h1>
<p>So, why is Figure 1 a bad explanation? At first glance it does seem to show how, in this specific example, that the level-set of the function we are trying to minimize touches the $l_1$ ball in one of the corners. However, there are plenty of other problems (with corresponding level-sets) that will intersect the $l_1$ ball in the middle of a line segment (to see this, just think about dragging around the function around so that its level set touches the edge of the $l_1$ ball).</p>

<p>Additionally, the image is trying to make an argument that relies on the <em>shape</em> of the $l_1$ ball to explain sparsity. But we know that shrinking $k$ in Eq. 1 (or increasing $\lambda$ in Eq. 2) leads to sparser solutions. An argument for sparsity that relies solely on the shape of the ball fails to explain why shrinking $k$ (increasing $\lambda$) induces more sparsity. You could argue that the smaller $k$ is, the smaller the faces of the $l_1$ ball are, so the higher the chance the level set hits the ball in a kink. However, this is still very hand-wavy, and I don’t think is a good explanation.</p>

<h1 id="a-slightly-better-explanation">A Slightly Better Explanation</h1>
<p>As I mentioned earlier, I tried to come up with an explanation for the sparsity of the Lasso by myself. But I didn’t make good progress in a reasonable amount of time so I went online in search for a good explanation. I came across <a href="https://www.stat.cmu.edu/~larry/=sml/Sparsity.pdf">these</a> notes by Ryan Tibshirani and found a mention of the “soft-thresholding operator”. It turns out that <em>under certain conditions</em>, which I’ll explain shortly, this “soft-thresholding operator” is indeed a good explanation for sparsity. Let’s explore why. The optimality condition on (2), i.e. setting the (sub)gradient equal to 0, tells us that for every $i=1,…, d$ we have that:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable width="100%"><mtr><mtd width="50%"></mtd><mtd><mrow><mo>−</mo><msub><mi>x</mi><mrow><mn>1</mn><mo separator="true">,</mo><mi>i</mi></mrow></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mn>1</mn></msub><mo>−</mo><msubsup><mi>x</mi><mn>1</mn><mi mathvariant="normal">⊤</mi></msubsup><msup><mi>β</mi><mo>∗</mo></msup><mo stretchy="false">)</mo><mo>−</mo><msub><mi>x</mi><mrow><mn>2</mn><mo separator="true">,</mo><mi>i</mi></mrow></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mn>2</mn></msub><mo>−</mo><msubsup><mi>x</mi><mn>2</mn><mi mathvariant="normal">⊤</mi></msubsup><msup><mi>β</mi><mo>∗</mo></msup><mo stretchy="false">)</mo><mo>−</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo>−</mo><msub><mi>x</mi><mrow><mi>n</mi><mo separator="true">,</mo><mi>i</mi></mrow></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mi>n</mi></msub><mo>−</mo><msubsup><mi>x</mi><mi>n</mi><mi mathvariant="normal">⊤</mi></msubsup><msup><mi>β</mi><mo>∗</mo></msup><mo stretchy="false">)</mo><mo>+</mo><mi>λ</mi><msub><mi>v</mi><mi>i</mi></msub><mo>=</mo><mn>0</mn></mrow></mtd><mtd width="50%"></mtd><mtd><mtext>(3)</mtext></mtd></mtr></mtable><annotation encoding="application/x-tex">
-x_{1, i} (y_1 - x_1^\top \beta^*) - x_{2, i} (y_2 - x_2^\top \beta^*) - ... - x_{n, i} (y_n - x_n^\top \beta^*) + \lambda v_i = 0 \tag{3}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.036108em;vertical-align:-0.286108em;"></span><span class="mord">−</span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight">i</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1491079999999998em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999998em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.738696em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.036108em;vertical-align:-0.286108em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight">i</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1491079999999998em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999998em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.738696em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.036108em;vertical-align:-0.286108em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">n</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight">i</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1491079999999998em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999998em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.738696em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.84444em;vertical-align:-0.15em;"></span><span class="mord mathdefault">λ</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span></span><span class="tag"><span class="strut" style="height:1.1852159999999998em;vertical-align:-0.286108em;"></span><span class="mord text"><span class="mord">(</span><span class="mord"><span class="mord">3</span></span><span class="mord">)</span></span></span></span></span></span></p>

<p>where $v_i$ is an element in the subdifferential of $\vert \cdot \vert$ at $\beta_i^*$. That is, $v_i$ is the set:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>v</mi><mi>i</mi></msub><mo>=</mo><mrow><mo fence="true">{</mo><mtable rowspacing="0.3599999999999999em" columnalign="left left" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo stretchy="false">{</mo><mo>−</mo><mn>1</mn><mo stretchy="false">}</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><msubsup><mi>β</mi><mi>i</mi><mo>∗</mo></msubsup><mo>&lt;</mo><mn>0</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo stretchy="false">{</mo><mn>1</mn><mo stretchy="false">}</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><msubsup><mi>β</mi><mi>i</mi><mo>∗</mo></msubsup><mo>&gt;</mo><mn>0</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo stretchy="false">[</mo><mo>−</mo><mn>1</mn><mo separator="true">,</mo><mn>1</mn><mo stretchy="false">]</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><msubsup><mi>β</mi><mi>i</mi><mo>∗</mo></msubsup><mo>=</mo><mn>0.</mn></mrow></mstyle></mtd></mtr></mtable></mrow></mrow><annotation encoding="application/x-tex">
v_i = \begin{cases} 
 \{-1\} &amp; \text{if } \beta_i^* &lt; 0 \\
 \{1\} &amp; \text{if } \beta_i^* &gt; 0 \\
 [-1, 1] &amp; \text{if } \beta_i^* = 0.
\end{cases}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:4.32em;vertical-align:-1.9099999999999997em;"></span><span class="minner"><span class="mopen"><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.35002em;"><span style="top:-2.19999em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎩</span></span></span><span style="top:-2.19499em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎪</span></span></span><span style="top:-2.20499em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎪</span></span></span><span style="top:-3.15001em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎨</span></span></span><span style="top:-4.2950099999999996em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎪</span></span></span><span style="top:-4.30501em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎪</span></span></span><span style="top:-4.60002em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎧</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.8500199999999998em;"><span></span></span></span></span></span></span><span class="mord"><span class="mtable"><span class="col-align-l"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.41em;"><span style="top:-4.41em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mopen">{</span><span class="mord">−</span><span class="mord">1</span><span class="mclose">}</span></span></span><span style="top:-2.97em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mopen">{</span><span class="mord">1</span><span class="mclose">}</span></span></span><span style="top:-1.5300000000000002em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mopen">[</span><span class="mord">−</span><span class="mord">1</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">1</span><span class="mclose">]</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.9099999999999997em;"><span></span></span></span></span></span><span class="arraycolsep" style="width:1em;"></span><span class="col-align-l"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.41em;"><span style="top:-4.41em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord text"><span class="mord">if </span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-2.441336em;margin-left:-0.05278em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.258664em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">&lt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord">0</span></span></span><span style="top:-2.97em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord text"><span class="mord">if </span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-2.441336em;margin-left:-0.05278em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.258664em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord">0</span></span></span><span style="top:-1.5300000000000002em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord text"><span class="mord">if </span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-2.441336em;margin-left:-0.05278em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.258664em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord">0</span><span class="mord">.</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.9099999999999997em;"><span></span></span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p>

<p>Now, let’s rewrite Equation 3 using matrix notation, we have that for all $i=1,…, d$</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>−</mo><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mo stretchy="false">(</mo><mi>y</mi><mo>−</mo><mi>X</mi><msup><mi>β</mi><mo>∗</mo></msup><mo stretchy="false">)</mo><mo>+</mo><mi>λ</mi><msub><mi>v</mi><mi>i</mi></msub><mo>=</mo><mn>0.</mn></mrow><annotation encoding="application/x-tex">
-X_i^\top (y - X \beta^*) + \lambda v_i = 0.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.1491079999999998em;vertical-align:-0.25em;"></span><span class="mord">−</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999998em;"><span style="top:-2.4530000000000003em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.738696em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.84444em;vertical-align:-0.15em;"></span><span class="mord mathdefault">λ</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span><span class="mord">.</span></span></span></span></span></p>

<p>Rearranging terms we get</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mi>y</mi><mo>−</mo><mi>λ</mi><msub><mi>v</mi><mi>i</mi></msub><mo>=</mo><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mi>X</mi><msup><mi>β</mi><mo>∗</mo></msup><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
X_i^\top y - \lambda v_i = X_i^\top X \beta^*.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.146108em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999998em;"><span style="top:-2.4530000000000003em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.84444em;vertical-align:-0.15em;"></span><span class="mord mathdefault">λ</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.146108em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999998em;"><span style="top:-2.4530000000000003em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.738696em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mord">.</span></span></span></span></span></p>

<p>Here is where those “certain conditions” I mentioned earlier are needed for us to arrive to the “soft-thresholding operator”. When the columns of $X$ are orthogonal to each other (we will explore what this intuitively means is a sec), that is $X_j^\top X_k = 0$ for $j\neq k$, and $X_j^\top X_j = 1$, we have that:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable width="100%"><mtr><mtd width="50%"></mtd><mtd><mrow><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mi>y</mi><mo>−</mo><mi>λ</mi><msub><mi>v</mi><mi>i</mi></msub><mo>=</mo><msubsup><mi>β</mi><mi>i</mi><mo>∗</mo></msubsup><mi mathvariant="normal">.</mi></mrow></mtd><mtd width="50%"></mtd><mtd><mtext>(4)</mtext></mtd></mtr></mtable><annotation encoding="application/x-tex">
X_i^\top y - \lambda v_i = \beta^*_i \tag{4}.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.146108em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999998em;"><span style="top:-2.4530000000000003em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.84444em;vertical-align:-0.15em;"></span><span class="mord mathdefault">λ</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.9856959999999999em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:-0.05278em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord">.</span></span><span class="tag"><span class="strut" style="height:1.1491079999999998em;vertical-align:-0.25em;"></span><span class="mord text"><span class="mord">(</span><span class="mord"><span class="mord">4</span></span><span class="mord">)</span></span></span></span></span></span></p>

<p>And now, we have three cases.</p>

<p>Case 1. If $\beta^*_i &gt; 0$, then $v_i = 1$, by Eq. 4 it must be that $\beta_i= X_i^\top y -\lambda $, which of course only happens when $X_i^\top y &gt; \lambda$.</p>

<p>Case 2. If $\beta^*_i &lt; 0$, then $v_i = -1$, by Eq. 4 it must be that $\beta_i= X_i^\top y +\lambda $, which of course only happens when $X_i^\top y &lt; -\lambda$.</p>

<p>Case 3. If $\beta^*_i = 0$ then $v_i \in [-1, 1]$, by Eq. 4 this can only happen when $\frac{X_i^\top y}{\lambda} = v_i$ for some $v_i \in [-1, 1]$. Which can only be true if and only if $\vert X_i^\top y \vert \leq \lambda$.</p>

<p>We have shown that when the columns of $X$ are orthogonal to each other and $X_i^\top X_i = 1$ for $i=1,…,p$, then</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>β</mi><mi>i</mi><mo>∗</mo></msubsup><mo>=</mo><mrow><mo fence="true">{</mo><mtable rowspacing="0.3599999999999999em" columnalign="left left" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mi>y</mi><mo>−</mo><mi>λ</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mi>y</mi><mo>&gt;</mo><mi>λ</mi></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mi>y</mi><mo>+</mo><mi>λ</mi></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mi>y</mi><mo>&lt;</mo><mo>−</mo><mi>λ</mi></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mn>0</mn></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><mi mathvariant="normal">∣</mi><msubsup><mi>X</mi><mi>i</mi><mi mathvariant="normal">⊤</mi></msubsup><mi>y</mi><mi mathvariant="normal">∣</mi><mo>≤</mo><mi>λ</mi><mi mathvariant="normal">.</mi></mrow></mstyle></mtd></mtr></mtable></mrow></mrow><annotation encoding="application/x-tex">
\beta^*_i = \begin{cases} 
 X_i^\top y -\lambda &amp; \text{if } X_i^\top y &gt; \lambda\\
 X_i^\top y +\lambda &amp; \text{if } X_i^\top y &lt; -\lambda \\
 0 &amp; \text{if } \vert X_i^\top y \vert \leq \lambda.
\end{cases}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.9856959999999999em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05278em;">β</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7386959999999999em;"><span style="top:-2.4530000000000003em;margin-left:-0.05278em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:4.32em;vertical-align:-1.9099999999999997em;"></span><span class="minner"><span class="mopen"><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.35002em;"><span style="top:-2.19999em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎩</span></span></span><span style="top:-2.19499em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎪</span></span></span><span style="top:-2.20499em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎪</span></span></span><span style="top:-3.15001em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎨</span></span></span><span style="top:-4.2950099999999996em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎪</span></span></span><span style="top:-4.30501em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎪</span></span></span><span style="top:-4.60002em;"><span class="pstrut" style="height:3.15em;"></span><span class="delimsizinginner delim-size4"><span>⎧</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.8500199999999998em;"><span></span></span></span></span></span></span><span class="mord"><span class="mtable"><span class="col-align-l"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.41em;"><span style="top:-4.41em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.849108em;"><span style="top:-2.441336em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.258664em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord mathdefault">λ</span></span></span><span style="top:-2.97em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.849108em;"><span style="top:-2.441336em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.258664em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord mathdefault">λ</span></span></span><span style="top:-1.5300000000000002em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.9099999999999997em;"><span></span></span></span></span></span><span class="arraycolsep" style="width:1em;"></span><span class="col-align-l"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.41em;"><span style="top:-4.41em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord text"><span class="mord">if </span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.849108em;"><span style="top:-2.441336em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.258664em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord mathdefault">λ</span></span></span><span style="top:-2.97em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord text"><span class="mord">if </span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.849108em;"><span style="top:-2.441336em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.258664em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">&lt;</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord">−</span><span class="mord mathdefault">λ</span></span></span><span style="top:-1.5300000000000002em;"><span class="pstrut" style="height:3.008em;"></span><span class="mord"><span class="mord text"><span class="mord">if </span></span><span class="mord">∣</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07847em;">X</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.849108em;"><span style="top:-2.441336em;margin-left:-0.07847em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.258664em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord mathdefault">λ</span><span class="mord">.</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.9099999999999997em;"><span></span></span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span></p>

<p>Notice that when $\vert X_i^\top y \vert \leq \lambda$, $\beta_i$ is thresholded to 0, when $X_i^\top y &gt; \lambda$ and the term $X_i^\top y$ increases then so does $\beta_i$, finally, when $X_i^\top y &lt; \lambda$ and $X_i^\top y$ decreases, so does $\beta_i$. This is where the “soft-tresholding” name comes from.</p>

<p>I’d say that we now have a better explanation of why the Lasso induces sparsity, however, the explanation is not complete. It only works when the columns of $X$ are orthogonal to each other and $X_i^\top X_i = 1$ for $i=1,…,p$. The second part, $X_i^\top X_i = 1$, is not a big deal since we would still get soft thresholding but with a different constant. However, in the context of regression, what does it mean for the columns of $X$ to be orthogonal? Is this a strong assumption? I think the answer is yes. When every feature has been mean-cenetered, when $j\neq k$ then $X_j^\top X_k = 0$ is equivalent to $\sum_{i=1}^n x_{i,j} x_{i,k} = 0$ which just means that features $j$ and $k$ are uncorrelated. This is a strong assumption, so I think that at this point, our “soft thresholding operator” explanation for sparisty is still limited. What happens if some of our features are not uncorrelated, will the Lasso still force sparsity?</p>

<h1 id="the-correct-explanation">The Correct Explanation</h1>
<p>In <a href="https://fleuret.org/dlc/materials/dlc-slides-5-4-l2-l1-penalties.pdf">these slides</a> from François Fleuret I found the cleanest explanation for why Lasso induces sparsity. It turns out sparsity is a property of regularizing using the $l_1$-norm rather than something specific to the Lasso problem, i.e. the $\sum_{i=1}^n (y_i - x_i^\top \beta)^2$ term does not matter too much (except that it is convex in $\beta$). He states the following:</p>

<p><strong>Lemma.</strong> Let $\mathcal{L}(w)$ be a convex function and let $w^* \in \arg \min_{w \in \mathbb{R}^p} \mathcal{L}(w) + \lambda \Vert w \Vert_1$. Assume that $\mathcal{L}(w)$ is differentiable at $w^\star$ (I think this can be relaxed, but makes the argument messier). Then, if $-\lambda &lt; \frac{d\mathcal{L}(w^*)}{dw_i} &lt; \lambda$ for any $i=1,…, p$, we have that $w^{\star}_i = 0$.</p>

<p><strong>Proof.</strong> By optimality conditions (setting the subgradient to 0) we have that for every $i=1,…, p$</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mrow><mi mathvariant="normal">∂</mi><mi>L</mi><mo stretchy="false">(</mo><msup><mi>w</mi><mo>∗</mo></msup><mo stretchy="false">)</mo></mrow><mrow><mi mathvariant="normal">∂</mi><msub><mi>w</mi><mi>i</mi></msub></mrow></mfrac><mo>+</mo><mi>λ</mi><msub><mi>v</mi><mi>i</mi></msub><mo>=</mo><mn>0</mn><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">
\frac{\partial L(w^*)}{\partial w_i} + \lambda v_i = 0,
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:2.263em;vertical-align:-0.8360000000000001em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.3139999999999996em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord" style="margin-right:0.05556em;">∂</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.02691em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord" style="margin-right:0.05556em;">∂</span><span class="mord mathdefault">L</span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.688696em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mclose">)</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.8360000000000001em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.84444em;vertical-align:-0.15em;"></span><span class="mord mathdefault">λ</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8388800000000001em;vertical-align:-0.19444em;"></span><span class="mord">0</span><span class="mpunct">,</span></span></span></span></span></p>

<p>where you should recall that $v_i$ is an element in the subdifferential of $\vert \cdot \vert$ at $w_i^*$. Rearranging terms we get that for every $i=1,…, p$</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>v</mi><mi>i</mi></msub><mo>=</mo><mfrac><mrow><mo>−</mo><mfrac><mrow><mi mathvariant="normal">∂</mi><mi>L</mi><mo stretchy="false">(</mo><msup><mi>w</mi><mo>∗</mo></msup><mo stretchy="false">)</mo></mrow><mrow><mi mathvariant="normal">∂</mi><msub><mi>w</mi><mi>i</mi></msub></mrow></mfrac></mrow><mi>λ</mi></mfrac><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">
v_i = \frac{-\frac{\partial L(w^*)}{\partial w_i}}{\lambda},
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.58056em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">v</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.54044em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.8544399999999999em;"><span style="top:-2.3333399999999997em;"><span class="pstrut" style="height:3.0193399999999997em;"></span><span class="mord"><span class="mord mathdefault">λ</span></span></span><span style="top:-3.2493399999999997em;"><span class="pstrut" style="height:3.0193399999999997em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.85444em;"><span class="pstrut" style="height:3.0193399999999997em;"></span><span class="mord"><span class="mord">−</span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.01934em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight" style="margin-right:0.05556em;">∂</span><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3280857142857143em;"><span style="top:-2.357em;margin-left:-0.02691em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.143em;"><span></span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.485em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight" style="margin-right:0.05556em;">∂</span><span class="mord mathdefault mtight">L</span><span class="mopen mtight">(</span><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7633428571428571em;"><span style="top:-2.931em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mclose mtight">)</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.44509999999999994em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mpunct">,</span></span></span></span></span></p>

<p>so that when $-\lambda &lt; \frac{d\mathcal{L}(w^*)}{dw_i} &lt; \lambda$ it must be the case that $v_i \in (-1,1)$ which implies that $w_i=0$. $\square$</p>

<p>Beautiful :)</p>

<h1 id="final-thoughts">Final Thoughts</h1>
<p>I find it interesting that what I’m calling “the correct explanation” is, in my opinion, the shortest and easiest argument to follow. This could be because the statement of the Lemma was given to us (and coming up with the statement was actually the hard part), and once you know what must be proved the proof is easy.</p>

<p>Something else I find interesting is that the correct explanation does not make the soft thresholding operator pop up. So, I wonder if the person who posed the question understands the reason for sparsity in the same way that we do now.</p>

<p>My last thought is that I should think about Feynman’s quote more often: “The first principle is that you must not fool yourself and you are the easiest person to fool.”</p>

<h1 id="appendix">Appendix</h1>

<h2 id="my-failed-attempt">My Failed Attempt</h2>
<p>I only briefly describe my attempt since I don’t think it’s that insightful. The main reason I write it down is so that you, the reader, who is probably incredibly curious and tried explaining the sparsity of the Lasso yourself (or let’s face it, you have a crush on me and that’s why you are reading even the Appendix of this blog post), does not feel discouraged. Math is hard for most of us, but so what, it’s a beautiful endeavor and we are struggling together. Ok, enough nonsense, let me describe my failed attempt.</p>

<p>I started by looking at the formulation described by Equation 2. My first reaction was that I did not like the sum of absolute values in the objective, so I reformulated the problem into</p>

<p>\begin{align}
\min_{\beta, t} \sum_{i=1}^n (y_i - x_i^\top \beta)^2 + \lambda (t_1 + … + t_p) \cr
\beta_i \leq t_i, i=1,…, p \cr
-t_i \leq \beta_i, i=1,…, p.
\end{align}</p>

<p>Then, I wrote the corresponding saddle point problem (this is Lagrangian Duality)</p>

<p>\begin{align}
\max_{\theta \geq 0, w \geq 0} \min_{\beta, t} \sum_{i=1}^n (y_i - x_i^\top \beta)^2 + \lambda (t_1 + … + t_p)  + \sum_{i=1}^p\theta_i (\beta_i - t_i) + w_i (-t_i - \beta_i).
\end{align}</p>

<p>Notice we were able to get rid of the absolute value! From here I wrote KKT conditions, but essentially ended up with something like:
“If I knew the sign of every non-zero coefficient, then I could find a closed form solution for $\beta$.” But I dont think there is a way to know the signs of the coefficents before you’ve solved the problem. So, to continue the argument I would have to guess (and) solve an exponential number of linear systems. This was obviously going in the wrong direction, so I decided to stop. In hindsight, I shouldn’t have been afraid of dealing with the non-differentiability of the absolute value, with just the knowledge of subgradients I (maybe) could have arrived at a solution myself.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[I was recently asked “Why does the Lasso induce sparsity?” My reflex was to proceed to describe the image we have all seen in our stats/ML classes:]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/lasso-sparsity/classic_lasso_image.png" /><media:content medium="image" url="http://localhost:4000/images/lasso-sparsity/classic_lasso_image.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">How to Optimally Trap Points in High-Dimensional Spaces Inside Ellipsoids</title><link href="http://localhost:4000/blog/2024/02/19/minimum_volume_ellipsoid/" rel="alternate" type="text/html" title="How to Optimally Trap Points in High-Dimensional Spaces Inside Ellipsoids" /><published>2024-02-19T00:00:00-08:00</published><updated>2024-02-19T00:00:00-08:00</updated><id>http://localhost:4000/blog/2024/02/19/minimum_volume_ellipsoid</id><content type="html" xml:base="http://localhost:4000/blog/2024/02/19/minimum_volume_ellipsoid/"><![CDATA[<!--
In this post, I show how to describe ellipsoids and formulate an optimization problem to enclose sets of points inside an ellipsoid with minimal volume. This technique will be useful for building the uncertainty sets required to create Robust Markowitz Portfolios.
 -->
<p>In this post we study how to trap a set of points in high dimensions inside an ellipsoid with minimal volume <a class="citation" href="#john2014extremum">(John, 1948)</a>. This problem has applications in statistics and outlier detection, but my motivation for studying this problem is to be able to represent “uncertainty sets” for doing Robust Optimization. Please see <a href="/blog/2024/02/12/robust_markowitz/">this post</a> if the terms “uncertainty sets” and Robust Optimization are new to you, if all you care is about learning geometry and optimization just keep reading.</p>

<p>Pictorially, what I’m trying to do is, find a description of the ellipsoid shown in the picture below.</p>

<figure class="centered-figure">
<img src="/images/minimal_volume_ellipsoid/john_ellipsoid.png" class="center-image max-width-75" />
<figcaption>
Minimal volume ellipsoid enclosing a set of points. From <a href="https://en.wikipedia.org/wiki/File:Lowner_Ellipse.webm" target="_blank"> Wikipedia</a>.
</figcaption>
</figure>

<p>This post is organized as follows, first I will show how to concisely represent/describe ellipsoids using matrices, then I’ll present an alternative parametrization of ellipsoids that is useful for entering the problem into a solver. Finally I will pose the Minimal Volume Enclosing Ellipsoid (MVEE) problem as a convex optimization problem.</p>

<h1 id="a-primer-on-ellipsoids">A Primer On Ellipsoids</h1>
<p>Before we discuss ellipsoids lets get comfortable describing their simplest form, unit balls. You probably remember from school that in two dimensions the ball of radius 1, can be represented as the set of all points $x_1, x_2$ such that</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>x</mi><mn>1</mn><mn>2</mn></msubsup><mo>+</mo><msubsup><mi>x</mi><mn>2</mn><mn>2</mn></msubsup><mo>≤</mo><mn>1.</mn></mrow><annotation encoding="application/x-tex">
x_1^2 + x_2^2 \leq 1.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.1111079999999998em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1111079999999998em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span><span class="mord">.</span></span></span></span></span></p>

<p>That is the two-dimensional unit ball is $\mathcal{B}_2 = \lbrace x_1, x_2 \in \mathbb{R}: x_1^2 + x_2^2 \leq 1 \rbrace$. In $n$ dimensions, we have</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mi>x</mi><mn>1</mn><mn>2</mn></msubsup><mo>+</mo><msubsup><mi>x</mi><mn>2</mn><mn>2</mn></msubsup><mo>+</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo>+</mo><msubsup><mi>x</mi><mi>n</mi><mn>2</mn></msubsup><mo>≤</mo><mn>1.</mn></mrow><annotation encoding="application/x-tex">
x_1^2 + x_2^2+ ... + x_n^2 \leq 1.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.1111079999999998em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1111079999999998em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="mord">.</span><span class="mord">.</span><span class="mord">.</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1111079999999998em;vertical-align:-0.247em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span><span class="mord">.</span></span></span></span></span></p>

<p>It is annoying to work with these large equations so, if $x \in \mathbb{R}^n$ is is the column vector with entries $x_1, x_2, …, x_n$ we can simply write $\mathcal{B}_n = \lbrace x \in \mathbb{R}^n: x^\top x \leq 1 \rbrace$.</p>

<p>Great, now, to go from a unit ball to an ellipsoid (lets focus on ellipsoids centered around the origin) all we have to do is “squish it” and rotate it. A great way to represent, squishing and rotating a set of points is through applying linear functions of the form $f(x) = Ax$ where $A$ is an $n$ by $n$ matrix. For example, imagine applying pressure to the top of the unit ball so it no longer reaches 1 but instead it only reaches .5 (keeping its width constant), and then rotating counterclockwise 45 degrees. This transformation is equivalent to first sending the unit vector pointing upwards from $[0; 1]$ to $[0; .5]$, then the 45 degree rotation sends $[1; 0] \rightarrow [\frac{1}{\sqrt{2}}; \frac{1}{\sqrt{2}}]$ and $[0; .5] \rightarrow [-\frac{1}{2\sqrt{2}} ; \frac{1}{2\sqrt{2}}]$. The matrix that represents this transformation is</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi><mo>=</mo><mrow><mo fence="true">[</mo><mtable rowspacing="0.15999999999999992em" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mfrac><mn>1</mn><msqrt><mn>2</mn></msqrt></mfrac></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo>−</mo><mfrac><mn>1</mn><mrow><mn>2</mn><msqrt><mn>2</mn></msqrt></mrow></mfrac></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mfrac><mn>1</mn><msqrt><mn>2</mn></msqrt></mfrac></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mfrac><mn>1</mn><mrow><mn>2</mn><msqrt><mn>2</mn></msqrt></mrow></mfrac></mstyle></mtd></mtr></mtable><mo fence="true">]</mo></mrow><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
A = 
\begin{bmatrix}
   \frac{1}{\sqrt{2}} &amp; -\frac{1}{2\sqrt{2}} \\
   \frac{1}{\sqrt{2}} &amp; \frac{1}{2\sqrt{2}}
\end{bmatrix}.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathdefault">A</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:3.0000299999999998em;vertical-align:-1.25003em;"></span><span class="minner"><span class="mopen delimcenter" style="top:0em;"><span class="delimsizing size4">[</span></span><span class="mord"><span class="mtable"><span class="col-align-c"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.633108em;"><span style="top:-3.788em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.845108em;"><span style="top:-2.5510085em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord sqrt mtight"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.912845em;"><span class="svg-align" style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mtight" style="padding-left:0.833em;"><span class="mord mtight">2</span></span></span><span style="top:-2.872845em;"><span class="pstrut" style="height:3em;"></span><span class="hide-tail mtight" style="min-width:0.853em;height:1.08em;"><svg width="400em" height="1.08em" viewBox="0 0 400000 1080" preserveAspectRatio="xMinYMin slice"><path d="M95,702 c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 s173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429 c69,-144,104.5,-217.7,106.5,-221 l0 -0 c5.3,-9.3,12,-14,20,-14 H400000v40H845.2724 s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z M834 80h400000v40h-400000z"></path></svg></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.12715500000000002em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.5379999999999999em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span><span style="top:-2.404892em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.845108em;"><span style="top:-2.5510085em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord sqrt mtight"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.912845em;"><span class="svg-align" style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mtight" style="padding-left:0.833em;"><span class="mord mtight">2</span></span></span><span style="top:-2.872845em;"><span class="pstrut" style="height:3em;"></span><span class="hide-tail mtight" style="min-width:0.853em;height:1.08em;"><svg width="400em" height="1.08em" viewBox="0 0 400000 1080" preserveAspectRatio="xMinYMin slice"><path d="M95,702 c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 s173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429 c69,-144,104.5,-217.7,106.5,-221 l0 -0 c5.3,-9.3,12,-14,20,-14 H400000v40H845.2724 s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z M834 80h400000v40h-400000z"></path></svg></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.12715500000000002em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.5379999999999999em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.133108em;"><span></span></span></span></span></span><span class="arraycolsep" style="width:0.5em;"></span><span class="arraycolsep" style="width:0.5em;"></span><span class="col-align-c"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.633108em;"><span style="top:-3.788em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">−</span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.845108em;"><span style="top:-2.5510085em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span><span class="mord sqrt mtight"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.912845em;"><span class="svg-align" style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mtight" style="padding-left:0.833em;"><span class="mord mtight">2</span></span></span><span style="top:-2.872845em;"><span class="pstrut" style="height:3em;"></span><span class="hide-tail mtight" style="min-width:0.853em;height:1.08em;"><svg width="400em" height="1.08em" viewBox="0 0 400000 1080" preserveAspectRatio="xMinYMin slice"><path d="M95,702 c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 s173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429 c69,-144,104.5,-217.7,106.5,-221 l0 -0 c5.3,-9.3,12,-14,20,-14 H400000v40H845.2724 s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z M834 80h400000v40h-400000z"></path></svg></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.12715500000000002em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.5379999999999999em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span><span style="top:-2.404892em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.845108em;"><span style="top:-2.5510085em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span><span class="mord sqrt mtight"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.912845em;"><span class="svg-align" style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mtight" style="padding-left:0.833em;"><span class="mord mtight">2</span></span></span><span style="top:-2.872845em;"><span class="pstrut" style="height:3em;"></span><span class="hide-tail mtight" style="min-width:0.853em;height:1.08em;"><svg width="400em" height="1.08em" viewBox="0 0 400000 1080" preserveAspectRatio="xMinYMin slice"><path d="M95,702 c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 s173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429 c69,-144,104.5,-217.7,106.5,-221 l0 -0 c5.3,-9.3,12,-14,20,-14 H400000v40H845.2724 s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z M834 80h400000v40h-400000z"></path></svg></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.12715500000000002em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.5379999999999999em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.133108em;"><span></span></span></span></span></span></span></span><span class="mclose delimcenter" style="top:0em;"><span class="delimsizing size4">]</span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">.</span></span></span></span></span></p>

<p>That’s right, the first column of the matrix tells you where the unit vector $[1; 0]$ gets mapped to, and the second column tells you where the other unit vector $[0; 1]$ gets mapped to. The previous is not a coincidence, by the way, if you feel like digging deeper into why this is true I highly recommend <a href="https://gregorygundersen.com/blog/2018/10/24/matrices/">this post</a> from Gregory Gundersen’s blog, which I’ve obviously drawn inspiration (and template files (with his permission)) from.</p>

<p>So, our ellipse $\mathcal{E}$ is the set of all points $y$ such that $y = Ax$ where $x$ is in the unit ball. Since we are interested in “full dimensional” ellipsoids in $\mathbb{R}^n$, that is we are not interested in representing a 2-d circle in 3-d space, the matrix $A$ is assumed to be invertible. More formally our ellipsoid is</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">E</mi><mo>=</mo><mo stretchy="false">{</mo><mi>y</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>n</mi></msup><mo separator="true">,</mo><mi mathvariant="normal">∃</mi><mi>x</mi><msup><mi mathvariant="double-struck">R</mi><mi>n</mi></msup><mo>:</mo><mi>y</mi><mo>=</mo><mi>A</mi><mi>x</mi><mo separator="true">,</mo><msup><mi>x</mi><mi mathvariant="normal">⊤</mi></msup><mi>x</mi><mo>≤</mo><mn>1</mn><mo stretchy="false">}</mo><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
\mathcal{E} = \lbrace y \in \mathbb{R}^n, \exists x \mathbb{R}^n: y = Ax, x^\top x \leq 1 \rbrace.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathcal" style="margin-right:0.08944em;">E</span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.9088319999999999em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord"><span class="mord mathbb">R</span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7143919999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">∃</span><span class="mord mathdefault">x</span><span class="mord"><span class="mord"><span class="mord mathbb">R</span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7143919999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.093548em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">A</span><span class="mord mathdefault">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span></span></span></span></span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">}</span><span class="mord">.</span></span></span></span></span></p>

<p>Since A is invertible we have</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable width="100%"><mtr><mtd width="50%"></mtd><mtd><mrow><mi>x</mi><mo>=</mo><msup><mi>A</mi><mrow><mo>−</mo><mn>1</mn></mrow></msup><mi>y</mi></mrow></mtd><mtd width="50%"></mtd><mtd><mtext>(1)</mtext></mtd></mtr></mtable><annotation encoding="application/x-tex">
x = A^{-1} y \tag{1}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.058548em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathdefault">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">−</span><span class="mord mtight">1</span></span></span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span></span><span class="tag"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord text"><span class="mord">(</span><span class="mord"><span class="mord">1</span></span><span class="mord">)</span></span></span></span></span></span></p>

<p>so that</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">E</mi><mo>=</mo><mo stretchy="false">{</mo><mi>y</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>n</mi></msup><mo>:</mo><msup><mi>y</mi><mi mathvariant="normal">⊤</mi></msup><msup><mi>A</mi><mrow><mo>−</mo><mi mathvariant="normal">⊤</mi></mrow></msup><msup><mi>A</mi><mrow><mo>−</mo><mn>1</mn></mrow></msup><mi>y</mi><mo>≤</mo><mn>1</mn><mo stretchy="false">}</mo><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
\mathcal{E} = \lbrace y \in \mathbb{R}^n: y^\top A^{-\top}A^{-1} y \leq 1 \rbrace.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathcal" style="margin-right:0.08944em;">E</span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.7143919999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord"><span class="mord mathbb">R</span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7143919999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.093548em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">−</span><span class="mord mtight">⊤</span></span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">−</span><span class="mord mtight">1</span></span></span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">}</span><span class="mord">.</span></span></span></span></span></p>

<p>Back to our numerical example, computing $A^{-\top}A^{-1}$ we get $B = \frac{1}{2}[[5, -3];[-3, 5]]$, so that $x^\top A^{-\top}A^{-1} x = \frac{5}{2}(x^2+y^2) - 3xy$ and this is what the ellipsoid looks like:</p>

<figure class="centered-figure">
<img src="/images/minimal_volume_ellipsoid/rotated_squished.png" class="center-image max-width-75" />
<figcaption>
An ellipsoid formed by mapping the unit ball with a matrix that squishes the top of the ball to .5, and then rotates 45 degrees counter-clockwise.
</figcaption>
</figure>
<p>just like we designed it; squished at the top, then rotated 45 degrees counter-clockwise.</p>

<p>It is common in the literature to see $n$-dimensional ellipsoids parametrized with a symmetric positive-semidefinite (I’ll explain in a sec) matrix $B\in \mathbb{R}^{n\times n}$ via</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">E</mi><mo>=</mo><mo stretchy="false">{</mo><mi>x</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>n</mi></msup><mo>:</mo><msup><mi>x</mi><mi mathvariant="normal">⊤</mi></msup><mi>B</mi><mi>x</mi><mo>≤</mo><mn>1</mn><mo stretchy="false">}</mo><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
\mathcal{E} = \lbrace x \in \mathbb{R}^n: x^\top B x \leq 1 \rbrace.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathcal" style="margin-right:0.08944em;">E</span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.7143919999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord"><span class="mord mathbb">R</span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7143919999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.035078em;vertical-align:-0.13597em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">}</span><span class="mord">.</span></span></span></span></span></p>

<p>So, if we ever encounter a parametrization of this kind we know that if we can factorize $B$ as</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable width="100%"><mtr><mtd width="50%"></mtd><mtd><mrow><mi>B</mi><mo>=</mo><msup><mi>A</mi><mrow><mo>−</mo><mi mathvariant="normal">⊤</mi></mrow></msup><msup><mi>A</mi><mrow><mo>−</mo><mn>1</mn></mrow></msup><mo separator="true">,</mo></mrow></mtd><mtd width="50%"></mtd><mtd><mtext>(2)</mtext></mtd></mtr></mtable><annotation encoding="application/x-tex">
B = A^{-\top} A^{-1}, \tag{2}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.093548em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathdefault">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">−</span><span class="mord mtight">⊤</span></span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault">A</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">−</span><span class="mord mtight">1</span></span></span></span></span></span></span></span></span><span class="mpunct">,</span></span><span class="tag"><span class="strut" style="height:1.149108em;vertical-align:-0.25em;"></span><span class="mord text"><span class="mord">(</span><span class="mord"><span class="mord">2</span></span><span class="mord">)</span></span></span></span></span></span></p>

<p>then $A$ tells us how a unit ball is being transformed to create the ellipsoid. Intuitively, a matrix $B$ is <a href="https://www.google.com/search?q=positive+semidefinite+matrix&amp;oq=positive+se&amp;aqs=chrome.2.69i59j69i57j35i39i512i650j0i433i512l2j0i131i433i512j0i512j69i60.3283j0j7&amp;sourceid=chrome&amp;ie=UTF-8">positive-semidefinite</a> (PSD) if there exists a decomposition of the form $B = A^{-\top} A^{-1}$ where A squishes and/or rotates but does not collapse dimensions. Now, what if we don’t want our ellipsoids to be centered at $0$, what if we want them centered at $b\in \mathbb{R}^n$? All we have to do is:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable width="100%"><mtr><mtd width="50%"></mtd><mtd><mrow><mi mathvariant="script">E</mi><mo>=</mo><mo stretchy="false">{</mo><mi>x</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>n</mi></msup><mo>:</mo><mo stretchy="false">(</mo><mi>x</mi><mo>−</mo><mi>b</mi><msup><mo stretchy="false">)</mo><mi mathvariant="normal">⊤</mi></msup><mi>B</mi><mo stretchy="false">(</mo><mi>x</mi><mo>−</mo><mi>b</mi><mo stretchy="false">)</mo><mo>≤</mo><mn>1</mn><mo stretchy="false">}</mo><mi mathvariant="normal">.</mi></mrow></mtd><mtd width="50%"></mtd><mtd><mtext>(3)</mtext></mtd></mtr></mtable><annotation encoding="application/x-tex">
\mathcal{E} = \lbrace x \in \mathbb{R}^n: (x-b)^\top B (x-b) \leq 1 \rbrace \tag{3}.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathcal" style="margin-right:0.08944em;">E</span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.7143919999999999em;vertical-align:0em;"></span><span class="mord"><span class="mord"><span class="mord mathbb">R</span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7143919999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.149108em;vertical-align:-0.25em;"></span><span class="mord mathdefault">b</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span><span class="mopen">(</span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault">b</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose">}</span><span class="mord">.</span></span><span class="tag"><span class="strut" style="height:1.149108em;vertical-align:-0.25em;"></span><span class="mord text"><span class="mord">(</span><span class="mord"><span class="mord">3</span></span><span class="mord">)</span></span></span></span></span></span></p>

<p>To see why this is true think that if before the translation of the ellipsoid you had a point inside it: $\bar{x}$ (and thus it satisfied $\bar{x}^\top B \bar{x} \leq 1$), after translation you have to plug in $\bar{x} + b$ to get $(\bar{x} + b - b)^\top B (\bar{x} + b - b) =  \bar{x}^\top B \bar{x} \leq 1$.</p>

<h1 id="an-alternative-parametrization-of-ellipsoids">An Alternative Parametrization Of Ellipsoids</h1>
<p>Another way to parametrize an ellipsoid is via a PSD matrix $C \in \mathbb{R}^{n\times n}$ and a vector $c \in \mathbb{R}^n$. The parametrization is all $x\in \mathbb{R}^n$ such that:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∥</mi><mi>C</mi><mi>x</mi><mo>+</mo><mi>c</mi><msubsup><mi mathvariant="normal">∥</mi><mn>2</mn><mn>2</mn></msubsup><mo>≤</mo><mn>1.</mn></mrow><annotation encoding="application/x-tex">
\Vert C x + c\Vert_2^2 \leq 1.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∥</span><span class="mord mathdefault" style="margin-right:0.07153em;">C</span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord mathdefault">c</span><span class="mord"><span class="mord">∥</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span><span class="mord">.</span></span></span></span></span></p>

<p>How does this parametrization relate to the one in (3)? Lets expand:</p>

<p>\begin{align}
\Vert C x + c\Vert_2^2 &amp; = (C x + c)^\top (C x + c) \cr
&amp; = x^\top C^\top C x + 2 x^\top C^\top c + c^\top c.
\end{align}</p>

<p>Expanding (3) we get</p>

<p>\begin{align}
(x-b)^\top B (x-b) = x^\top B x - 2x^\top B b + b^\top b,
\end{align}</p>

<p>it must follow that if we are referring to same elipsoid with two different representations the following must hold:
$B = C^\top C$, and $C c = b$. More importantly, because of (2) it must hold that</p>

<p>\begin{align}
C = A^{-1} \tag{4}.
\end{align}</p>

<p>Why equation (4) is important will be explained in a minute.</p>

<h1 id="minimal-volume-ellipsoid">Minimal Volume Ellipsoid</h1>
<p>Recall the problem we are trying to solve. We have been given a set of $N$ points $x_1, x_2, …, x_N$ in $\mathbb{R}^n$ and we want to find the ellipsoid of smallest volume that contains it. Using our second parametrization of ellipsoids, we know that we are looking for $C$ in the set of all PSD matrices and $c \in \mathbb{R}^n$ such that:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∥</mi><mi>C</mi><msub><mi>x</mi><mi>n</mi></msub><mo>+</mo><mi>c</mi><msubsup><mi mathvariant="normal">∥</mi><mn>2</mn><mn>2</mn></msubsup><mo>≤</mo><mn>1</mn><mspace width="2em"></mspace><mi mathvariant="normal">∀</mi><mi>n</mi><mo>∈</mo><mo stretchy="false">[</mo><mi>N</mi><mo stretchy="false">]</mo><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
\Vert C x_n + c\Vert_2^2 \leq 1 \qquad \forall n \in [N].
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∥</span><span class="mord mathdefault" style="margin-right:0.07153em;">C</span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord mathdefault">c</span><span class="mord"><span class="mord">∥</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.73354em;vertical-align:-0.0391em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:2em;"></span><span class="mord">∀</span><span class="mord mathdefault">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">[</span><span class="mord mathdefault" style="margin-right:0.10903em;">N</span><span class="mclose">]</span><span class="mord">.</span></span></span></span></span></p>

<p>But how do express that we want the ellipsoid of smallest volume? The trick is to remember from linear algebra that the <a href="https://en.wikipedia.org/wiki/Determinant">determinant</a> of a matrix is proportional to how the linear transformation increases/decreases volume. Remember how two sections ago we were thinking about creating ellipsoids by squishing and rotating unit balls by applying the mapping $A$? We want to minimize $\det(A)$, but how are $C$ and $A$ related? Well, we established this relation in equation (4). So our problem formulation is:</p>

<p>\begin{align}
\min_{C, c} \quad &amp; \det(C^{-1}) \cr
&amp; \Vert C x_n + c\Vert_2^2 \leq 1 \qquad \forall n \in [N].
\end{align}</p>

<p>We have a formulation for the MVEE optimization problem, but is this problem convex? Do there exist algorithms to efficiently solve this problem? The answer to the first question is no, this is because $\det(\cdot)$ is neither convex nor concave over the set of PSD matrices <a href="https://math.stackexchange.com/questions/2112803/is-the-function-a-mapsto-deta-convex-over-the-set-of-positive-definite-mat">(see F_G’s answer)</a>. But we are in luck, because $\log(\det(\cdot))$ <a href="https://math.stackexchange.com/questions/1192329/log-determinant-concavity-proof?noredirect=1&amp;lq=1">is concave</a>. So, if we modify our objective function to be $\log(\det(C^{-1})) = \log(\frac{1}{\det(C)}) = - \log(\det(C))$, we are minimizing a convex function! To conclude that the whole optimization problem is a convex one we would have to show two more things, that the set of PSD matrices is convex, and that each of the sets $\lbrace C : \Vert C x_n + c\Vert_2^2 \leq 1  \rbrace$ is convex. Turns out both statements are true, unfortunately I won’t prove them right now because I want to focus on trying to build robust portfolios. But if you want to learn how to prove this I recommend these <a href="\https://inst.eecs.berkeley.edu/~ee127/sp21/livebook/l_sdp_main.html">lecture notes</a> on Semidefinite Programming or Ch. 8 from <a class="citation" href="#boyd2004convex">(Boyd &amp; Vandenberghe, 2004)</a>.</p>

<h1 id="final-thoughts">Final Thoughts</h1>
<p>To summarize, the MVEE can be formulated as the following (convex) Semidefinite Program</p>

<p>\begin{align}
\min_{C, c} \quad &amp; - \log(\det(C)) \cr
&amp; \Vert C x_n + c\Vert_2^2 \leq 1 \qquad \forall n \in [N].
\end{align}</p>

<p>This formulation is useful because there exist general purpose algorithms for solving these kinds of problems. In the next post I will show how given samples of asset returns (these will be the points $\lbrace x_n \rbrace$) we can use a MVEE to find uncertainty sets which we can then incorporate into our robust formulation of the mean-variance portfolio problem.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[In this post we study how to trap a set of points in high dimensions inside an ellipsoid with minimal volume (John, 1948). This problem has applications in statistics and outlier detection, but my motivation for studying this problem is to be able to represent “uncertainty sets” for doing Robust Optimization. Please see this post if the terms “uncertainty sets” and Robust Optimization are new to you, if all you care is about learning geometry and optimization just keep reading.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/minimal_volume_ellipsoid/john_ellipsoid.png" /><media:content medium="image" url="http://localhost:4000/images/minimal_volume_ellipsoid/john_ellipsoid.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Searching for Robust Markowitz Portfolios: Part I</title><link href="http://localhost:4000/blog/2024/02/12/robust_markowitz/" rel="alternate" type="text/html" title="Searching for Robust Markowitz Portfolios: Part I" /><published>2024-02-12T00:00:00-08:00</published><updated>2024-02-12T00:00:00-08:00</updated><id>http://localhost:4000/blog/2024/02/12/robust_markowitz</id><content type="html" xml:base="http://localhost:4000/blog/2024/02/12/robust_markowitz/"><![CDATA[<!-- In this new post I explore whether the framework of Robust Optimization can help us create good portfolios when we are uncertain about future returns -->

<figure class="centered-figure">
<img src="/images/robust_markowitz/a_portfolio_in_the_style_of_rene_magritte.png" alt="Stable Diffusion XL: A Portfolio In The Style Of Rene Magritte" class="center-image max-width-50" />
<figcaption>Stable Diffusion XL: A Portfolio In The Style Of Rene Magritte</figcaption>
</figure>

<p>In a <a href="/blog/2024/01/27/markowitz_sample_efficiency/">previous post</a> we explored what happens when we try to build Mean Variance (also known as Markowitz) Portfolios using a finite number of samples from the distribution of returns. The results were discouraging, unless you have a prohibitively large number of samples, the resulting portfolios will be very far from the optimal one. In this post, we explore whether the Robust Optimization framework can address these issues.</p>

<h1 id="review-of-mean-variance-portfolios">Review of Mean Variance Portfolios</h1>
<p>Before introducing Robust Optimization let’s review the problem we want to solve. We are faced with the problem of allocating our wealth across a number of assets but we are uncertain about what their returns are going to be. If the asset returns were Gaussian with mean $\mu$ and covariance matrix $\Sigma$, then allocating our wealth according to the solution of the mean-variance portfolio (MVP) problem</p>

<p>\begin{align}
\max_{w} \thinspace &amp; \mu^\top w - \frac{1}{2} w^\top \Sigma w \cr
s. t.\thinspace &amp;1^\top w = 1, \tag{1}
\end{align}</p>

<p>would guarantee that (asymptotically) our wealth would grow exponentially quickly and at the fastest possible rate. If you are used to seeing $\lambda$ instead of $\frac{1}{2}$ in the objective please review <a href="/blog/2024/01/15/kelly_vs_markowitz/">this post</a>.</p>

<p>In practice, we don’t have knowledge of $\mu$ and $\Sigma$, so typically, we would estimate them and then plug the estimates $\hat{\mu}, \hat{\Sigma}$ into (1). <a href="/blog/2024/01/27/markowitz_sample_efficiency/">Previously</a> we saw how even with 1,000 years worth of daily returns the MVP would produce terrible portfolios. As a reminder, the simulation consisted of 100 assets, all of them with independent and identically distributed return distributions, for which the optimal portfolio consists of allocating $\frac{1}{100}$ of your wealth on each asset. Instead this is the allocation Markowitz produced:</p>

<figure class="centered-figure">
<img src="/images/markowitz_sample_efficiency/allocation_1000_year_samples.png" class="center-image max-width-75" />
<figcaption>
Portfolio allocation using 1,000 years worth of daily returns to estimate the mean returns and covariance matrix.
</figcaption>
</figure>

<p>If you think about it, we were being wasteful with our samples. We were estimating $\hat{\mu}, \hat{\Sigma}$ but using only their point estimates; with all the samples we could compute confidence intervals of each of these quantifies and somehow try to modify the optimization problem so that it takes this information into account. This is exactly the idea we will explore in the rest of this post.</p>

<h1 id="robust-optimization">Robust Optimization</h1>
<p>Robust Optimization (RO) <a class="citation" href="#ben2009robust">(Ben-Tal et al., 2009)</a> is a <em>worst case</em> approach to modeling optimization problems where there is uncertainty in the parameters of the problem (in our example we are uncertain about $\mu$ and $\Sigma$). In the RO framework we must specify an “uncertainty set” for our parameters, that is, we must specify a set $\mathcal{U}$ in which we think that the true problem parameters $\mu, \Sigma$ live. The robust formulation of the MVP will be:</p>

<p>\begin{align}
\max_{w} \min_{(\mu, \Sigma)\in \mathcal{U}} \thinspace &amp; \mu^\top w - \frac{1}{2} w^\top \Sigma w \cr
s. t.\thinspace &amp;1^\top w = 1, \tag{2}
\end{align}</p>

<p>What the above formulation says is that we must pick a portfolio $w$ knowing that and adversary is going to try to hurt us by picking the worst possible return vector $\mu$ and covariance matrix $\Sigma$ in the uncertainty set $\mathcal{U}$. As I mentioned earlier this is a worst case approach to handling uncertainty, but in the context of finance I think it’s reasonable, we better be safe than sorry.</p>

<h1 id="modeling-the-uncertainty">Modeling The Uncertainty</h1>
<p>To apply the framework of RO to portfolio construction we must specify the uncertainty set $\mathcal{U}$. The following specification of the uncertainty set comes from <a class="citation" href="#boyd2017multi">(Boyd et al., 2017)</a>. I must say, I don’t love the specification and I think modeling the uncertainty via ellipsoids will be better but I’ll explore that in another post since I thought it’d be important to understand Boyd et al’s specification first.</p>

<p>$\mathcal{U}$ will be such that the expected return of asset $i$, $\mu_i$ lives inside a box. We set $\mu_i = \bar{\mu}_i + \delta_i$ with $\delta_i \leq \vert \rho_i \vert$ where $\bar{\mu}_i$, $\rho_i$ are real values specified by us. The uncertainty in the covariance matrix will be modeled as $\Sigma = \bar{\Sigma} + \Delta$ where $\bar{\Sigma}$ is the “nominal” covariance matrix and $\Delta$ is a symmetric matrix satisying</p>

<p>\begin{align}
\Delta_{ij} \leq \kappa \vert \bar{\Sigma_{ii}} \bar{\Sigma_{jj}}\vert. \tag{3}
\end{align}</p>

<p>With this uncertainty model, we must provide actual values for $\mu, \rho \in \mathbb{R}^n$, $\bar{\Sigma}, \Delta \in \mathbb{R}^{n\times n}$. In the rest of this post I will refer to entries of a covariance matrix $\Sigma$ as $\sigma_{ij}$ when $i \neq j$ and as $\sigma^2_i$ when $i=j$.</p>

<p>Before we attempt to go back to (2) and try to solve it using our model for $\mathcal{U}$, let’s examine the intuition behind (3). Equation (3) implies that</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable width="100%"><mtr><mtd width="50%"></mtd><mtd><mrow><msub><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>j</mi></mrow></msub><mo>−</mo><mi>κ</mi><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow><mn>2</mn></msubsup><mo>≤</mo><msub><mi>σ</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><mo>≤</mo><msub><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>j</mi></mrow></msub><mo>+</mo><mi>κ</mi><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow><mn>2</mn></msubsup></mrow></mtd><mtd width="50%"></mtd><mtd><mtext>(4)</mtext></mtd></mtr></mtable><annotation encoding="application/x-tex">
\bar{\sigma}_{ij} - \kappa \bar{\sigma}^2_{ii} \bar{\sigma}^2_{jj} \leq \sigma_{ij} \leq \bar{\sigma}_{ij} + \kappa \bar{\sigma}^2_{ii} \bar{\sigma}^2_{jj} \tag{4}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8694379999999999em;vertical-align:-0.286108em;"></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.2472159999999999em;vertical-align:-0.383108em;"></span><span class="mord mathdefault">κ</span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-3.1130000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.383108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.922078em;vertical-align:-0.286108em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8694379999999999em;vertical-align:-0.286108em;"></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.2472159999999999em;vertical-align:-0.383108em;"></span><span class="mord mathdefault">κ</span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-3.1130000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.383108em;"><span></span></span></span></span></span></span></span><span class="tag"><span class="strut" style="height:1.2472159999999999em;vertical-align:-0.383108em;"></span><span class="mord text"><span class="mord">(</span><span class="mord"><span class="mord">4</span></span><span class="mord">)</span></span></span></span></span></span></p>

<p>So that when $i = j$, we have</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>κ</mi><mo stretchy="false">)</mo><mo>≤</mo><msubsup><mi>σ</mi><mrow><mi>i</mi><mi>j</mi></mrow><mn>2</mn></msubsup><mo>≤</mo><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mi>κ</mi><mo stretchy="false">)</mo><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">
\bar{\sigma}^2_{ii} (1 - \kappa) \leq \sigma^2_{ij} \leq \bar{\sigma}^2_{ii} (1 + \kappa),
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault">κ</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.2472159999999999em;vertical-align:-0.383108em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-2.4530000000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-3.1130000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.383108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault">κ</span><span class="mclose">)</span><span class="mpunct">,</span></span></span></span></span></p>

<p>this means that in our uncertainty model we allow for misspecifying all variances by at most a factor of $\kappa$. When $i \neq j$ the consequence is that the (almost) correlation is bounded by an additive factor of $\kappa$, that is</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><mfrac><msubsup><mi>σ</mi><mrow><mi>i</mi><mi>j</mi></mrow><mn>2</mn></msubsup><mrow><msub><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow></msub><msub><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow></msub></mrow></mfrac><mi mathvariant="normal">∣</mi><mo>≤</mo><msub><mover accent="true"><mi>ρ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mo separator="true">,</mo><mi>j</mi></mrow></msub><mo>+</mo><mi>κ</mi><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">
\vert \frac{\sigma^2_{ij}}{\bar{\sigma}_{ii}\bar{\sigma}_{jj}}\vert \leq \bar{\rho}_{i,j} + \kappa,
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:2.570988em;vertical-align:-0.972108em;"></span><span class="mord">∣</span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.5988799999999999em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.7847720000000002em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-2.441336em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.394772em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.972108em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8694379999999999em;vertical-align:-0.286108em;"></span><span class="mord"><span class="mord accent"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault">ρ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.16666em;"><span class="mord">ˉ</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.19444em;"><span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">κ</span><span class="mpunct">,</span></span></span></span></span></p>

<p>where $\bar{\rho_{i,j}}$ is the correlation coefficient computed from $\bar{\Sigma}$. Hopefully this gives you a better intuition of what (3) implies.</p>

<p>You should be wondering, why is a single $\kappa$ value allowed? What if we were more confident about the variances of some assets vs others? Could we have a $\kappa_{i,j}$ for every $i,j$ pair?</p>

<h2 id="the-robust-counterpart-of-mean-variance-portfolios">The Robust Counterpart of Mean-Variance Portfolios</h2>
<p>We turn our attention back to the minimax problem</p>

<p>\begin{align}
\max_{w} \min_{(\mu, \Sigma)\in \mathcal{U}} \thinspace &amp; \mu^\top w - \frac{1}{2} w^\top \Sigma w \cr
s. t.\thinspace &amp;1^\top w = 1
\end{align}</p>

<p>but this time with the uncertainty set that we defined in the previous section</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="script">U</mi><mo>=</mo><mo stretchy="false">{</mo><mo stretchy="false">(</mo><mi>μ</mi><mo separator="true">,</mo><mi mathvariant="normal">Σ</mi><mo stretchy="false">)</mo><mo>:</mo><mi mathvariant="normal">∃</mi><mi>δ</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>n</mi></msup><mo separator="true">,</mo><mi mathvariant="normal">Δ</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mrow><mi>n</mi><mo>×</mo><mi>n</mi></mrow></msup><mo>:</mo><mi>μ</mi><mo>=</mo><mover accent="true"><mi>μ</mi><mo>^</mo></mover><mo>+</mo><mi>δ</mi><mo separator="true">,</mo><mi mathvariant="normal">Σ</mi><mo>=</mo><mover accent="true"><mi mathvariant="normal">Σ</mi><mo>ˉ</mo></mover><mo>+</mo><mi mathvariant="normal">Δ</mi><mo separator="true">,</mo><mi mathvariant="normal">∣</mi><mi>δ</mi><mi mathvariant="normal">∣</mi><mo>≤</mo><mi>ρ</mi><mo separator="true">,</mo><msub><mi mathvariant="normal">Δ</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><mo>≤</mo><mi>κ</mi><mi mathvariant="normal">∣</mi><mover accent="true"><msub><mi mathvariant="normal">Σ</mi><mrow><mi>i</mi><mi>i</mi></mrow></msub><mo>ˉ</mo></mover><mover accent="true"><msub><mi mathvariant="normal">Σ</mi><mrow><mi>j</mi><mi>j</mi></mrow></msub><mo>ˉ</mo></mover><mi mathvariant="normal">∣</mi><mo stretchy="false">}</mo><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
\mathcal{U} = \{(\mu, \Sigma): \exists \delta \in \mathbb{R}^n, \Delta \in \mathbb{R}^{n \times n}: \mu = \hat{\mu} + \delta, \Sigma = \bar{\Sigma} + \Delta, \vert \delta \vert \leq \rho, \Delta_{ij} \leq \kappa \vert \bar{\Sigma_{ii}} \bar{\Sigma_{jj}}\vert\}.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord"><span class="mord mathcal" style="margin-right:0.09931em;">U</span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mopen">(</span><span class="mord mathdefault">μ</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">Σ</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.73354em;vertical-align:-0.0391em;"></span><span class="mord">∃</span><span class="mord mathdefault" style="margin-right:0.03785em;">δ</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.9088319999999999em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord"><span class="mord mathbb">R</span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7143919999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">Δ</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.821331em;vertical-align:0em;"></span><span class="mord"><span class="mord"><span class="mord mathbb">R</span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.821331em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">n</span><span class="mbin mtight">×</span><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.625em;vertical-align:-0.19444em;"></span><span class="mord mathdefault">μ</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord accent"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.69444em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault">μ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.22222em;"><span class="mord">^</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.19444em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord mathdefault" style="margin-right:0.03785em;">δ</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">Σ</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.9034399999999999em;vertical-align:-0.08333em;"></span><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8201099999999999em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">Σ</span></span></span><span style="top:-3.25233em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">Δ</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">∣</span><span class="mord mathdefault" style="margin-right:0.03785em;">δ</span><span class="mord">∣</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.969438em;vertical-align:-0.286108em;"></span><span class="mord mathdefault">ρ</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord">Δ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≤</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.106218em;vertical-align:-0.286108em;"></span><span class="mord mathdefault">κ</span><span class="mord">∣</span><span class="mord accent"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8201099999999999em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord">Σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.25233em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span><span class="mord accent"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8201099999999999em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord">Σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.25233em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span><span class="mord">∣</span><span class="mclose">}</span><span class="mord">.</span></span></span></span></span></p>

<p>As we will see shortly, the inner problem admits a closed form expression for its solution, so we will be able to find a robust portfolio by a solving convex problem instead of a minimax game! This means we don’t have to pay a computational complexity cost for solving the robust version of the problem! This situation does not happen in general, but in this case the uncertainty set was designed so that this would happen.</p>

<p>Let us now solve</p>

<p>\begin{align}
\min_{(\mu, \Sigma)\in \mathcal{U}} \thinspace &amp; \mu^\top w - \frac{1}{2} w^\top \Sigma w.
\end{align}</p>

<p>Notice that the problem decouples so we can first minimize the first term by finding the worst $\mu$ in the uncertainty set and independently, we can find the $\Sigma$ that maximizes (note the minus sign) $w^\top \Sigma w$.
For the first term we have</p>

<p>\begin{align}
&amp;\min_{\mu\in \mathcal{U}} \thinspace \mu^\top w \cr
&amp;= \min_{\mu\in \mathcal{U}} \thinspace (\bar{\mu} + \delta)^\top w \cr
&amp;= \min_{\vert \delta_i\vert \leq \rho_i} (\bar{\mu} + \delta)^\top w \cr
&amp;= \min_{\vert \delta_i\vert \leq \rho_i} \bar{\mu}^\top w + \delta^\top w \cr
&amp;= \bar{\mu}^\top w - \sum_{i\in[n]} \rho_i \vert w_i \vert \tag{5}.
\end{align}</p>

<p>The last equality is true because if we asign a positive weight for $w_i$ the adversary picks $\delta_i = -\rho_i$ and if the weight for $w_i$ is negative, the adversary can pick $\delta_i = \rho_i$. So regardless of the sign of our portfolio weight the adversary damages us with $-\rho_i \vert w_i \vert$. Before we move on, notice that Eq. (5) is the usual mean return of the portfolio $\bar{\mu}^\top w$ but now we have a regularization term where we get penalized by how uncertain we are about the asset returns.</p>

<p>Let’s now examine the variance term:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><munder><mo><mi>max</mi><mo>⁡</mo></mo><mrow><mi mathvariant="normal">Σ</mi><mo>∈</mo><mi mathvariant="script">U</mi></mrow></munder><mtext> </mtext><msup><mi>w</mi><mi mathvariant="normal">⊤</mi></msup><mi mathvariant="normal">Σ</mi><mi>w</mi><mo>=</mo><msup><mi>w</mi><mi mathvariant="normal">⊤</mi></msup><mover accent="true"><mi mathvariant="normal">Σ</mi><mo>ˉ</mo></mover><mi>w</mi><mo>+</mo><munder><mo><mi>max</mi><mo>⁡</mo></mo><mrow><mi mathvariant="normal">∣</mi><msub><mi mathvariant="normal">Δ</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><mi mathvariant="normal">∣</mi><mo>≤</mo><mi>κ</mi><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow><mn>2</mn></msubsup></mrow></munder><mtext> </mtext><msup><mi>w</mi><mi mathvariant="normal">⊤</mi></msup><mi mathvariant="normal">Δ</mi><mi>w</mi></mrow><annotation encoding="application/x-tex">
\max_{\Sigma\in \mathcal{U}} \thinspace w^\top \Sigma w = w^\top \bar{\Sigma} w + \max_{\vert \Delta_{ij} \vert \leq \kappa \bar{\sigma}^2_{ii} \bar{\sigma}^2_{jj}} \thinspace w^\top \Delta w
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.6708089999999998em;vertical-align:-0.771701em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.43055999999999994em;"><span style="top:-2.355669em;margin-left:0em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">Σ</span><span class="mrel mtight">∈</span><span class="mord mtight"><span class="mord mathcal mtight" style="margin-right:0.09931em;">U</span></span></span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span><span class="mop">max</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.771701em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span></span></span></span></span><span class="mord">Σ</span><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.9824379999999999em;vertical-align:-0.08333em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span></span></span></span></span><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8201099999999999em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">Σ</span></span></span><span style="top:-3.25233em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:2.051508em;vertical-align:-1.1524em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.43055999999999994em;"><span style="top:-2.27042em;margin-left:0em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∣</span><span class="mord mtight"><span class="mord mtight">Δ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3280857142857143em;"><span style="top:-2.357em;margin-left:0em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2818857142857143em;"><span></span></span></span></span></span></span><span class="mord mtight">∣</span><span class="mrel mtight">≤</span><span class="mord mathdefault mtight">κ</span><span class="mord mtight"><span class="mord accent mtight"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord mtight">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8051142857142857em;"><span style="top:-2.177714285714286em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-2.8448em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.3222857142857143em;"><span></span></span></span></span></span></span><span class="mord mtight"><span class="mord accent mtight"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord mtight">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8051142857142857em;"><span style="top:-2.177714285714286em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-2.8448em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.46117142857142857em;"><span></span></span></span></span></span></span></span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span><span class="mop">max</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.1524em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span></span></span></span></span><span class="mord">Δ</span><span class="mord mathdefault" style="margin-right:0.02691em;">w</span></span></span></span></span></p>

<p>and focus on the $\max$. Expanding $w^\top \Delta w$ we have that</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><munder><mo><mi>max</mi><mo>⁡</mo></mo><mrow><mi mathvariant="normal">∣</mi><msub><mi mathvariant="normal">Δ</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><mi mathvariant="normal">∣</mi><mo>≤</mo><mi>κ</mi><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow><mn>2</mn></msubsup></mrow></munder><mtext> </mtext><msup><mi>w</mi><mi mathvariant="normal">⊤</mi></msup><mi mathvariant="normal">Δ</mi><mi>w</mi><mspace linebreak="newline"></mspace><mo>=</mo><munder><mo><mi>max</mi><mo>⁡</mo></mo><mrow><mi mathvariant="normal">∣</mi><msub><mi mathvariant="normal">Δ</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><mi mathvariant="normal">∣</mi><mo>≤</mo><mi>κ</mi><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow><mn>2</mn></msubsup></mrow></munder><munder><mo>∑</mo><mrow><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo>∈</mo><mo stretchy="false">[</mo><mi>n</mi><mo stretchy="false">]</mo></mrow></munder><msub><mi>w</mi><mi>i</mi></msub><msub><mi>w</mi><mi>j</mi></msub><msub><mi mathvariant="normal">Δ</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><mspace linebreak="newline"></mspace><mo>=</mo><munder><mo>∑</mo><mrow><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo>∈</mo><mo stretchy="false">[</mo><mi>n</mi><mo stretchy="false">]</mo></mrow></munder><mi mathvariant="normal">∣</mi><msub><mi>w</mi><mi>i</mi></msub><msub><mi>w</mi><mi>j</mi></msub><mi mathvariant="normal">∣</mi><mi>κ</mi><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow><mn>2</mn></msubsup><mspace linebreak="newline"></mspace><mo>=</mo><mi>κ</mi><munder><mo>∑</mo><mrow><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo>∈</mo><mo stretchy="false">[</mo><mi>n</mi><mo stretchy="false">]</mo></mrow></munder><mi mathvariant="normal">∣</mi><msub><mi>w</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi><mi mathvariant="normal">∣</mi><msub><mi>w</mi><mi>j</mi></msub><mi mathvariant="normal">∣</mi><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow><mn>2</mn></msubsup><mspace linebreak="newline"></mspace><mo>=</mo><mi>κ</mi><mo stretchy="false">(</mo><munder><mo>∑</mo><mrow><mi>i</mi><mo>∈</mo><mo stretchy="false">[</mo><mi>n</mi><mo stretchy="false">]</mo></mrow></munder><mi mathvariant="normal">∣</mi><msub><mi>w</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msup><mo stretchy="false">)</mo><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">
\max_{\vert \Delta_{ij} \vert \leq \kappa \bar{\sigma}^2_{ii} \bar{\sigma}^2_{jj}} \thinspace w^\top \Delta w \\
= \max_{\vert \Delta_{ij} \vert \leq \kappa \bar{\sigma}^2_{ii} \bar{\sigma}^2_{jj}} \sum_{i,j \in [n]}  w_i w_j \Delta_{ij} \\
= \sum_{i,j \in [n]}  \vert w_i w_j \vert \kappa \bar{\sigma}^2_{ii} \bar{\sigma}^2_{jj} \\
= \kappa \sum_{i,j \in [n]}  \vert w_i\vert \vert w_j \vert  \bar{\sigma}^2_{ii} \bar{\sigma}^2_{jj} \\
= \kappa (\sum_{i \in [n]} \vert w_i \vert \bar{\sigma}^2_{ii})^2
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:2.051508em;vertical-align:-1.1524em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.43055999999999994em;"><span style="top:-2.27042em;margin-left:0em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∣</span><span class="mord mtight"><span class="mord mtight">Δ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3280857142857143em;"><span style="top:-2.357em;margin-left:0em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2818857142857143em;"><span></span></span></span></span></span></span><span class="mord mtight">∣</span><span class="mrel mtight">≤</span><span class="mord mathdefault mtight">κ</span><span class="mord mtight"><span class="mord accent mtight"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord mtight">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8051142857142857em;"><span style="top:-2.177714285714286em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-2.8448em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.3222857142857143em;"><span></span></span></span></span></span></span><span class="mord mtight"><span class="mord accent mtight"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord mtight">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8051142857142857em;"><span style="top:-2.177714285714286em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-2.8448em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.46117142857142857em;"><span></span></span></span></span></span></span></span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span><span class="mop">max</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.1524em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">⊤</span></span></span></span></span></span></span></span><span class="mord">Δ</span><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.5660100000000003em;vertical-align:-1.516005em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.43055999999999994em;"><span style="top:-2.27042em;margin-left:0em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∣</span><span class="mord mtight"><span class="mord mtight">Δ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3280857142857143em;"><span style="top:-2.357em;margin-left:0em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.2818857142857143em;"><span></span></span></span></span></span></span><span class="mord mtight">∣</span><span class="mrel mtight">≤</span><span class="mord mathdefault mtight">κ</span><span class="mord mtight"><span class="mord accent mtight"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord mtight">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8051142857142857em;"><span style="top:-2.177714285714286em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-2.8448em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.3222857142857143em;"><span></span></span></span></span></span></span><span class="mord mtight"><span class="mord accent mtight"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-2.7em;"><span class="pstrut" style="height:2.7em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord mtight">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8051142857142857em;"><span style="top:-2.177714285714286em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-2.8448em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.46117142857142857em;"><span></span></span></span></span></span></span></span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span><span class="mop">max</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.1524em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.050005em;"><span style="top:-1.808995em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mrel mtight">∈</span><span class="mopen mtight">[</span><span class="mord mathdefault mtight">n</span><span class="mclose mtight">]</span></span></span></span><span style="top:-3.0500049999999996em;"><span class="pstrut" style="height:3.05em;"></span><span><span class="mop op-symbol large-op">∑</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.516005em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.02691em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:-0.02691em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord">Δ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.5660100000000003em;vertical-align:-1.516005em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.050005em;"><span style="top:-1.808995em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mrel mtight">∈</span><span class="mopen mtight">[</span><span class="mord mathdefault mtight">n</span><span class="mclose mtight">]</span></span></span></span><span style="top:-3.0500049999999996em;"><span class="pstrut" style="height:3.05em;"></span><span><span class="mop op-symbol large-op">∑</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.516005em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">∣</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.02691em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:-0.02691em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mord">∣</span><span class="mord mathdefault">κ</span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-3.1130000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.383108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.5660100000000003em;vertical-align:-1.516005em;"></span><span class="mord mathdefault">κ</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.050005em;"><span style="top:-1.808995em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mrel mtight">∈</span><span class="mopen mtight">[</span><span class="mord mathdefault mtight">n</span><span class="mclose mtight">]</span></span></span></span><span style="top:-3.0500049999999996em;"><span class="pstrut" style="height:3.05em;"></span><span><span class="mop op-symbol large-op">∑</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.516005em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">∣</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.02691em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord">∣</span><span class="mord">∣</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.311664em;"><span style="top:-2.5500000000000003em;margin-left:-0.02691em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.286108em;"><span></span></span></span></span></span></span><span class="mord">∣</span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-3.1130000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.383108em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="mspace newline"></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.5660100000000003em;vertical-align:-1.516005em;"></span><span class="mord mathdefault">κ</span><span class="mopen">(</span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.050005em;"><span style="top:-1.808995em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mrel mtight">∈</span><span class="mopen mtight">[</span><span class="mord mathdefault mtight">n</span><span class="mclose mtight">]</span></span></span></span><span style="top:-3.0500049999999996em;"><span class="pstrut" style="height:3.05em;"></span><span><span class="mop op-symbol large-op">∑</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.516005em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">∣</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02691em;">w</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.31166399999999994em;"><span style="top:-2.5500000000000003em;margin-left:-0.02691em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">i</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord">∣</span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-2.4530000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.247em;"><span></span></span></span></span></span></span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span></span></span></p>

<p>Where the second equality follows by the same reasoning we used for Eq. (5). Before we move on, can you see why we cannot use a $\kappa_{ij}$ in our uncertainty set and must use a single $\kappa$? The answer is that we wouldn’t be able to factor it out in the second to last line and that function would not necesarily be convex.</p>

<p>We are done, we have successfully reformulated the minimax game (2) into the following convex problem</p>

<p>\begin{align}
\max_{w} \thinspace &amp; \bar{\mu}^\top w - \sum_{i\in[n]} \rho_i \vert w_i \vert - \frac{1}{2} w^\top \hat{\Sigma} w - \frac{1}{2}\kappa (\sum_{i \in [n]} \vert w_i \vert \bar{\sigma}^2_{ii})^2 \cr
s. t.\thinspace &amp;1^\top w = 1. \tag{6}
\end{align}</p>

<p>It is now time to test the quality of these Robust Markowitz Portfolios (RMP).</p>

<h1 id="simulations">Simulations</h1>
<h2 id="setup">Setup</h2>
<p>We will use the same simulation setup we used in the <a href="/blog/2024/01/27/markowitz_sample_efficiency/">previous post</a>. As a reminder, there are 100 assets, all of them with Gaussian returns with mean zero and standard deviation equal to .1, all returns are independent from each other. If we were to have acess to the true vector of expected returns $\mu$ and the true covariance matix $\Sigma$, the optimal portfolio according to (1) is the uniform allocation, that is, allocate 1% of our wealth to every asset.</p>

<p>In real life we don’t have access to $\mu$ and $\Sigma$ so in the rest of this post we explore how to build portfolios using only daily samples from the distribution of returns. The most straightforward thing to do given a finite number of samples is to create estimates $\hat{\mu}, \hat{\Sigma}$ and plug them into (1). Unfortunately, as shown in <a href="/blog/2024/01/27/markowitz_sample_efficiency/">this previous post</a> even with thousands of years worth of data the resulting portfolios were very far from the optimal allocation and performed poorly.</p>

<p>Notice, that we were being wasteful, we were only creating point estimates for $\hat{\mu}$ and $\hat{\Sigma}$ when we could have actually built confidence intervals for $\mu$ and $\Sigma$ and somehow try to incorporate them into (1). Back then we didn’t have the framework of Robust Optimization so incorporating the uncertainty into the problem wasn’t traightforward. But now we do, all we have to do is use our samples to come up with values for $\rho, \bar{\mu}, \bar{\Sigma}$ and $\kappa$ and then just plug them into our robust version of the mean-variance portfolio (6). We will estimate these parameters using the bootstrap.</p>

<h2 id="using-the-bootstrap-to-build-uncertainty-sets">Using the Bootstrap to Build Uncertainty Sets</h2>
<p>There are probably many ways to come up with values for $\rho, \bar{\mu}, \bar{\Sigma}$ and $\kappa$. In this post we will use the <a href="https://en.wikipedia.org/wiki/Bootstrapping_(statistics)">bootstrap</a> (creating “new” datasets by sampling, with replacement, from the samples we are given) to come up with values for $\rho, \bar{\mu}, \bar{\Sigma}$ and $\kappa$. I did not see the results change too much once I started using more than 1000 bootstrap samples, so I will not discuss this point further. We  set $\bar{\mu}_i = \frac{\mu_i^{min} + \mu_i^{max}}{2}$ for every asset $i \in [n]$ where $\mu_i^{min}$ is the smallest expected return using the bootstrap samples, $\mu_i^{max}$ is defined similarly. Additionally, we set $\rho_i = \frac{\mu_i^{max} - \mu_i^{min}}{2}$ and let $\bar{\Sigma}$ be the sample covariance matrix. Finally,</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>κ</mi><mo>=</mo><mi>m</mi><mi>a</mi><msub><mi>x</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>j</mi><mo>∈</mo><mo stretchy="false">[</mo><mi>n</mi><mo stretchy="false">]</mo><mo separator="true">,</mo><mi>k</mi></mrow></msub><mi mathvariant="normal">∣</mi><mfrac><mrow><msubsup><mi>σ</mi><mrow><mi>i</mi><mi>j</mi><mi>k</mi></mrow><mn>2</mn></msubsup><mo>−</mo><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>j</mi></mrow><mn>2</mn></msubsup></mrow><mrow><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>i</mi><mi>i</mi></mrow><mn>2</mn></msubsup><msubsup><mover accent="true"><mi>σ</mi><mo>ˉ</mo></mover><mrow><mi>j</mi><mi>j</mi></mrow><mn>2</mn></msubsup></mrow></mfrac><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">
\kappa = max_{i,j\in[n], k} \vert \frac{\sigma^2_{ijk} - \bar{\sigma}^2_{ij}}{\bar{\sigma}^2_{ii}\bar{\sigma}^2_{jj}}\vert
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">κ</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.7222959999999996em;vertical-align:-1.0989719999999998em;"></span><span class="mord mathdefault">m</span><span class="mord mathdefault">a</span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.34480000000000005em;"><span style="top:-2.5198em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mrel mtight">∈</span><span class="mopen mtight">[</span><span class="mord mathdefault mtight">n</span><span class="mclose mtight">]</span><span class="mpunct mtight">,</span><span class="mord mathdefault mtight" style="margin-right:0.03148em;">k</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.3551999999999999em;"><span></span></span></span></span></span></span><span class="mord">∣</span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.6233239999999998em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7959080000000001em;"><span style="top:-2.4231360000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight">i</span></span></span></span><span style="top:-3.0448000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.27686399999999994em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.795908em;"><span style="top:-2.4231360000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-3.0448000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.4129719999999999em;"><span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.809216em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-2.4168920000000003em;margin-left:-0.03588em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span><span class="mord mathdefault mtight" style="margin-right:0.03148em;">k</span></span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.4192159999999999em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord accent"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.56778em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">σ</span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.25em;"><span class="mord">ˉ</span></span></span></span></span></span></span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-2.441336em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">i</span><span class="mord mathdefault mtight" style="margin-right:0.05724em;">j</span></span></span></span><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.394772em;"><span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.0989719999999998em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord">∣</span></span></span></span></span></p>

<p>where $\sigma^2_{ijk}$ is the $ij$-th entry of the sample covariance matrix that uses the $k$-th bootstrap sample. For more details on the simulations please see the <a href="https://github.com/adrianriv/blog-code/blob/master/robust_markowitz/robust_markowitz.ipynb">Github repo</a>.</p>

<h2 id="simulation-results">Simulation Results</h2>
<p>Using daily observations of returns for one year and building the Robust Markowitz Portfolio this is the allocation we get:</p>

<figure class="centered-figure">
<img src="/images/robust_markowitz/allocation_1_year_samples.png" class="center-image max-width-75" />
<figcaption>
Allocation from the Robust Markowitz Portolio using 1 year of daily returns, and 5000 bootstrap samples to estimate the parameters of the uncertainty set.
</figcaption>
</figure>
<p>The allocation is telling us to go short a few stocks (some with ~50% of our initial wealth), and to long a few other ones using leverage. This allocation is clearly very different from the optimal (uniform) allocation that has access to the true values of $\mu$ and $\Sigma$. A somewhat interesting phenomenon is that the way we accounted for uncertainty in the expected returns lead us to add $- \sum_{i\in[n]} \rho_i \vert w_i \vert$ to the objective, this $l$-1 norm is inducing sparcity into the portfolio forcing us to not allocate any capital to ~90% of the assets.</p>

<p>The above robust portfolio is bad, does it get better if we use daily returns for a longer time period? Unfortunately, that does not seem to be the case. Here is the allocation using 10,000 years worth of data:</p>
<figure class="centered-figure">
<img src="/images/robust_markowitz/allocation_10000_year_samples.png" class="center-image max-width-75" />
<figcaption>
Allocation from the Robust Markowitz Portolio using 10000 years of daily returns, and 5000 bootstrap samples to estimate the parameters of the uncertainty set.
</figcaption>
</figure>
<p>Sadly, no noticeable improvements at all from using Robust Optimization…</p>

<h1 id="final-thoughts">Final Thoughts</h1>
<p>Unfortunately, it looks like using Robust Optimization and the uncertainty sets from <a class="citation" href="#boyd2017multi">(Boyd et al., 2017)</a> do not yield a much better approach to building portfolios than the original formulation. But we should not be discouraged by this, at least we know we shouldn’t use this techique in the real world!</p>

<p>Before wrapping up, I have to say that I still have some hope at making Mean Variance portfolios work – I think that using ellipsoids to represent the uncertainty set is an idea worth trying. The reason for this is that with ellipsoids we can capture relationships in the uncertainty that we can not capture with “boxes” like we did in this post, moreover the $l$-1 penalty which induces sparsity will probably disappear. We will explore this idea in detail in a future post.</p>

<p><strong>Disclaimer</strong>: The content provided on this blog is for educational purposes only and is not intended to be financial advice. The views and opinions expressed here are solely those of the authors and should not be construed as professional financial advice. Readers are encouraged to consult with a qualified financial advisor before making any financial decisions based on the information provided on this blog.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/robust_markowitz/a_portfolio_in_the_style_of_rene_magritte.png" /><media:content medium="image" url="http://localhost:4000/images/robust_markowitz/a_portfolio_in_the_style_of_rene_magritte.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">The Sample Efficiency of Markowitz Portfolios</title><link href="http://localhost:4000/blog/2024/01/27/markowitz_sample_efficiency/" rel="alternate" type="text/html" title="The Sample Efficiency of Markowitz Portfolios" /><published>2024-01-27T00:00:00-08:00</published><updated>2024-01-27T00:00:00-08:00</updated><id>http://localhost:4000/blog/2024/01/27/markowitz_sample_efficiency</id><content type="html" xml:base="http://localhost:4000/blog/2024/01/27/markowitz_sample_efficiency/"><![CDATA[<!-- 
Building Markowitz portfolios with noisy estimates for the mean and covariance matrix results in "peculiar" portfolios...
-->

<p>In this post we explore what happens when we try to create a Mean Variance Portfolio (MVP) using a finite number of samples from the true distribution of returns. This post is inspired by Chapter 6 of <a class="citation" href="#paleologo2021advanced">(Paleologo, 2021)</a></p>

<p>Recall that the MVP is the solution to the following optimization problem:</p>

<p>\begin{align}
\max_{w} \thinspace &amp; \mu^\top w - \lambda w^\top \Sigma w \cr
s. t.\thinspace &amp;1^\top w = 1. \tag{1}
\end{align}</p>

<p>When $\lambda = \frac{1}{2}$, the asset returns are normally distributed with mean $\mu$ and covariance matrix $\Sigma$, we know that (if the optimal value to the aforemention optimiation problem is greater than 0) this portfolio asymptotically grows our wealth at an exponential rate, and that it is the fastest rate possible <a href="/blog/2024/01/15/kelly_vs_markowitz/">(see this post for a reminder)</a>.</p>

<p>However, in practice, we don’t have knowledge of $\mu$ and $\Sigma$, so a reasonable thing to do is to estimate them given a finite number of samples, and then plug in the estimates into (1). In the rest of this post we explore how reasonable this approach is via some simulations.</p>

<h1 id="simulations">Simulations</h1>
<p>The setup is simple, and borrowed from Giuseppes’ book. As usual, you find the code on <a href="https://github.com/adrianriv/blog-code/tree/master/finite_sample_portfolio_construction">Github</a>. There are 100 assets, each assets’ returns are normally distributed with mean 0 and standard deviation .1, each assets’ returns are independent from all other assets’. It is not hard to convince yourself that the optimal portfolio invests $\frac{1}{100}$ of the capital in each of the assets.</p>

<p>Let’s look at what happens when we use daily observations of returns for 1 year, and remember we are allowing shorting (e.g. $w_i$ can be negative):</p>

<figure class="centered-figure">
<img src="/images/markowitz_sample_efficiency/allocation_1_year_samples.png" class="center-image max-width-75" />
<figcaption>
Portfolio allocation using 1 year worth of daily returns to estimate the mean returns and covariance matrix.
</figcaption>
</figure>

<p>As you can see, this allocation is far from the equal weights allocation. If we had 100 dollars to invest we should allocate 1 dollar in each of the assests. This allocation is telling us we some times have to allocate 300 dollars to some of the assets!</p>

<p>Let’s look at the allocation when we use 100 years of data:</p>

<figure class="centered-figure">
<img src="/images/markowitz_sample_efficiency/allocation_100_year_samples.png" class="center-image max-width-75" />
<figcaption>
Portfolio allocation using 100 years worth of daily returns to estimate the mean returns and covariance matrix.
</figcaption>
</figure>

<p>Still very far from the uniform allocation.</p>

<p>With 1,000 years of data:</p>
<figure class="centered-figure">
<img src="/images/markowitz_sample_efficiency/allocation_1000_year_samples.png" class="center-image max-width-75" />
<figcaption>
Portfolio allocation using 1,000 years worth of daily returns to estimate the mean returns and covariance matrix.
</figcaption>
</figure>
<p>Still off. With 25,000 years of data:</p>

<figure class="centered-figure">
<img src="/images/markowitz_sample_efficiency/allocation_25000_year_samples.png" class="center-image max-width-75" />
<figcaption>
Portfolio allocation using 25,000 years worth of daily returns to estimate the mean returns and covariance matrix.
</figcaption>
</figure>

<p>Ok, it’s finally starting to get there. We only had to wait 25,000 years…</p>

<p>You may argue that the portfolio allocation does not need to be close to the optimal, in order for the allocation to achieve similar performance. That is, we don’t really care that our allocations are off if they guarantee close to the same returns as the uniform allocation. So let’s plot the wealth trajectories of the allocations we just found:</p>
<figure class="centered-figure">
<img src="/images/markowitz_sample_efficiency/wealth_trajectories.png" class="center-image max-width-75" />
<figcaption>
Wealth trajectories of allocations that use different number of samples to estimate returns and covariance matrix
</figcaption>
</figure>

<p>For an allocation to be good, it should be following the “equal weights” trajectory, as you can see this only starts happenning when we use more that 10,000 years worth of data.</p>

<p>We need so many samples to start building reasonable portfolios!</p>

<h1 id="the-source-of-error">The Source of Error</h1>
<p>Why are the allocations so bad? Where is the error coming from? If you plug in the true covariance matrix and use only 4 years of data, you get a similar allocation than if you use 25,000 years and estimatate the returns and covariance matrix:</p>

<figure class="centered-figure">
<img src="/images/markowitz_sample_efficiency/allocation_true_covariance_4_year_samples.png" class="center-image max-width-75" />
<figcaption>
Portfolio allocation using 4 years worth of daily returns to estimate the mean returns but using the true covariance matrix.
</figcaption>
</figure>

<p>So you may think that the misallocation comes from our noisy covariance estimate. But if we plug in the true expected returns and the estimated covariance matrix you get a very similar allocation:</p>

<figure class="centered-figure">
<img src="/images/markowitz_sample_efficiency/allocation_true_mean_4_year_samples.png" class="center-image max-width-75" />
<figcaption>
Portfolio allocation using 4 years worth of daily returns to estimate the covariance matrix but using the true expected returns.
</figcaption>
</figure>

<p>So, you really need accuate estimates for both the expected returns and the covarainace matrix for the mean variance portfolio to be good.</p>

<h1 id="final-thoughts">Final Thoughts</h1>
<p>These simulations show one of the big caveats of mean variance portfolios – they are very sensitive to the input expected rewards and covariance matrix. Over estimating some returns may result in highly concentrated portfolios. To make things worse, in these simulations we used the Gaussian distribution to model returns, in the real world you will encounter fait tails which will only make these issues worse.</p>

<p><strong>Disclaimer</strong>: The content provided on this blog is for educational purposes only and is not intended to be financial advice. The views and opinions expressed here are solely those of the authors and should not be construed as professional financial advice. Readers are encouraged to consult with a qualified financial advisor before making any financial decisions based on the information provided on this blog.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/markowitz_sample_efficiency/allocation_100_year_samples.png" /><media:content medium="image" url="http://localhost:4000/images/markowitz_sample_efficiency/allocation_100_year_samples.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">The Sharpe Ratio: It Ain’t That Sharp</title><link href="http://localhost:4000/blog/2024/01/20/sharpe_ratio/" rel="alternate" type="text/html" title="The Sharpe Ratio: It Ain’t That Sharp" /><published>2024-01-20T00:00:00-08:00</published><updated>2024-01-20T00:00:00-08:00</updated><id>http://localhost:4000/blog/2024/01/20/sharpe_ratio</id><content type="html" xml:base="http://localhost:4000/blog/2024/01/20/sharpe_ratio/"><![CDATA[<!--
In this new post I review the Sharpe ratio, a widely used metric to measure portfolio performance. I  
1. Give an example of how it can be useful.
2. Show how to build a portfolio that maximizes Sharpe (and show this portfolio is actually not that good)
3. Build 2 strategies with the same Sharpe, one that accumulates wealth exponentially, and another one that leads to ruin.
 -->
<figure class="centered-figure">
<img src="/images/sharpe_ratio/a_dull_knife_resting_minimalist_style_soft_colors_more_dull.png" alt="DALL-E: A dull knife, resting, minimalist style, soft colors, more dull." class="center-image max-width-50" />
<figcaption>DALL-E: A dull knife, resting, minimalist style, soft colors, more dull.</figcaption>
</figure>

<h1 id="a-brief-review-of-the-sharpe-ratio">A Brief Review of The Sharpe Ratio</h1>
<p>The Sharpe ratio <a class="citation" href="#sharpe1966mutual">(Sharpe, 1966)</a> is a metric traders and portfolio managers use to measure their performance. At a high level, the ratio quantifies the expected returns of a strategy per unit of “risk”. Here “risk” will be measured using the square root of the variance of the returns, sometimes also called “volatility”.
There are two flavors of it, the ex-post Sharpe ratio:</p>

<p>\begin{align}
S = \frac{ \hat{r} - r_{free}}{\sqrt{\hat{\sigma}^2}},
\end{align}</p>

<p>where $\hat{r} = \frac{1}{N} \sum_{i=1}^N r_i$ is the sample mean of your strategies’ realized daily returns $r_1, …, r_N$, $\hat{\sigma}^2 = \frac{1}{N}  \sum_{i=1}^N (r_i - \hat{r})^2$ is the sample variance, and $r_{free}$ is the risk free rate. Similarly, the ex-ante Sharpe ratio is defined as:</p>

<p>\begin{align}
S = \frac{\mathbb{E}[r] - r_{free}}{\sqrt{\mathbb{V}[r]}},
\end{align}</p>

<p>where $r$ is the random variable representing the return of your strategy, $\mathbb{E}[r]$ is the expected return of your strategy, and $\mathbb{V}[r]$ is the variance.</p>

<p>If you are a trader, your boss may use the ex-post version to measure your past performance, so if you know you will be judged by the ex-post version you may want to find a strategy to maximize the ex-ante version.</p>

<h3 id="first-thoughts">First Thoughts</h3>
<p>A few things jump to mind about the definition of Sharpe ratio. The first one is that measuring “risk” with the standard deviation is not great because it penalizes large gains. The second one is that there may be trading strategies that have extremely high ratios, until they don’t. For example someone selling naked out of the money options will consistently be receiving a steady “income” until they blow up. Up until the point they blow up, the ex post will be high. The last thing that jumps to me is: why use the (arithmetic) mean return as the numerator when you could be using the (geometric) mean return? This will most likely prevent us from accumulating wealth in the long run.</p>

<h3 id="organization-of-this-post">Organization of This Post</h3>
<p>The rest of this post has three sections. The first section shows why people think this quantity is a good metric for measuring performance. The second section shows how to build a portfolio that maximizes this metric by transforming a non-convex problem into a convex one. The second section also shows how this portfolio accumulates wealth in the long run (spoiler alert, it’s not as good as the Kelly portfolio). In the last section (my favorite) I show how it is possible to have strategies with the same Sharpe ratio where some grow your wealth at an exponential rate and others lead you straight to ruin. As usual, you can find the code for this post on <a href="https://github.com/adrianriv/blog-code/tree/master/sharpe_ratio">Github</a>.</p>

<h2 id="using-the-sharpe-ratio-to-pick-between-strategies">Using The Sharpe Ratio To Pick Between Strategies</h2>

<p>Let’s assume we have two good assets to allocate money on. Asset 1 has expected return $\mu_1 = .05$ and std. deviation $\sigma_1 = .1$, asset 2 has $\mu_2 = .04$ and $\sigma_2 = .05$, both asset’ returns are normally distributed. So, asset 1 has higher expected returns compared to asset 2 but it also has a larger variance. Assuming the risk free rate is equal to 0, the Sharpe ratios are $S_1 = \frac{.05}{.1} = .5$ and $S_2 = \frac{.04}{.05} = .8$. So, asset 2 seems to be a better risk adjusted return.</p>

<p>Imagine your portfolio’s initial dollar value is 1, it is allowed to have at most .1 units of risk (measured by its volatility), and you have access to leverage. If this is the case you can borrow another dollar and invest two dollars on asset 2 (let’s call this strategy 2), your portfolio will have volatility equal to $2 *\sigma_2 = .1$ but its expected return will be $2 * .04 = .08$, which is greater than if you just invested your unit of wealth on asset 1 (remember you maxed out your risk so you can borrow). Let strategy 1 be investing your dollar into asset 1.</p>

<p>Now, truth is, you and I do not get paid in “Sharpe ratio units”, we get paid in dollars. You should be wondering, how does the Sharpe ratio translate into actual money? If we lock our money into these strategies for 2000 rounds, this is what our log wealth would look like:</p>

<figure class="centered-figure">
<img src="/images/sharpe_ratio/wealth_of_two_strategies_with_different_sharpe_ratios_and_equal_variance.png" class="center-image max-width-75" />
<figcaption>Wealth of two strategies with different sharpe ratios and equal variance. The orange line leverages and invests in asset 2, the blue line does not leverage and invests everything in asset 1.</figcaption>
</figure>

<p>In this situation, the Sharpe ratio seems to be doing something useful.</p>

<p>A reasonable question is: can we do better than by just leveraging and investing everything in asset #2? If you’ve read my previous <a href="/blog/2024/01/15/kelly_vs_markowitz/">post</a> on portfolio optimization you may be wondering what happens when we build a portfolio that maximizes expcected log wealth (the Kelly portfolio) and has volatility equal to .1. In this particular example, to find the Kelly portfolio we can just solve the following convex problem</p>

<p>\begin{align}
\max_{w} \thinspace &amp; \mu^\top w - \frac{1}{2} w^\top \Sigma w, \cr
s. t.\thinspace &amp; w^\top \Sigma w \leq \sigma_{allowed}^2,
\end{align}</p>

<p>with the appropriate parameters. If you don’t remember why this objective is a good approximation to maximizing log wealth please review <a href="/blog/2024/01/15/kelly_vs_markowitz/">this previous post</a>.</p>

<p>Assuming our two assets are uncorrelated we get that we should invest 53% of our wealth on asset 1 and 170% of our wealth on asset 2 (remember we are allowed to take on leverage as long as the volatility of our portfolio is less than .1). This is what our log wealth would look like for the three strategies we just discussed:</p>

<figure class="centered-figure">
<img src="/images/sharpe_ratio/wealth_of_three_strategies_with_different_sharpe_ratios_and_equal_variance.png" class="center-image max-width-75" />
<figcaption>Wealth of three strategies with different sharpe ratios and equal variance. The orange line leverages and invests in asset 2, the blue line does not leverage and invests everything in asset 1, the green line leverages invest 53% of our wealth on asset 1 and 170% of our wealth on asset 2</figcaption>
</figure>

<p>So, the Kelly portfolio seems to be a good idea. Moreover, the Sharpe ratio for the Kelly portfolio is $\approx 0.96$ which is greater that the $.8$ from strategy #2.</p>

<p>The Sharpe ratio seems to be useful, and it looks like it correlates with making more money. But is this relationship actually true? Does maximizing the (ex-ante) Sharpe ratio guarantee we are maximizing our wealth in the long run? We answer this question negatively in the next section.</p>

<h1 id="the-sharpe-ratio-maximizing-portfolio">The Sharpe Ratio Maximizing Portfolio</h1>
<p>We are interested in the properties of the portfolio that is the solution to the following (nonconvex) optimization problem</p>

<p>\begin{align}
\max_{w} \thinspace &amp; \frac{\mu^\top w}{w^\top \Sigma w} \cr
s. t.\thinspace &amp; 1^\top w = 1. \tag{1}
\end{align}</p>

<p>In particular, we want to know whether it maximizes long term wealth (i.e. it is equivalent to the Kelly portfolio or not). At first glance we have a problem because the objective is nonconvex, the good news is that we can translate it into a convex problem.</p>

<h3 id="the-convex-equivalent-problem-for-finding-the-maximum-sharpe-ratio-portfolio">The (Convex) Equivalent Problem for Finding the Maximum Sharpe Ratio Portfolio</h3>
<p>This trick comes from Theo Diamanis’ blog <a href="https://theodiamandis.com/blog/2022/sharpe/">post</a>. Multiply the numerator of the objective function by any $\alpha &gt; 0$ (this changes the objective value but not the optimal solution), then we add the constraint $\mu^\top \alpha w = 1$ and the objective becomes $\max \frac{1}{w^\top \Sigma w}$, but this is equivalent to $\min w^\top \Sigma w$. We have transformed our problem to:</p>

<p>\begin{align}
\min_{w} \thinspace &amp; w^\top \Sigma w \cr
s. t. \thinspace &amp; 1^\top w = 1 \cr
&amp; \mu^\top \alpha w = 1
\end{align}</p>

<p>Changing to decision variables $y = \alpha w$, this problem is equivalent to</p>

<p>\begin{align}
\min_{w} \thinspace &amp; y^\top \Sigma y \cr
s. t. \thinspace &amp; 1^\top (\frac{1}{\alpha} y) = 1 \cr
&amp; \mu^\top y = 1.
\end{align}</p>

<p>Now, notice that $1^\top (\frac{1}{\alpha} y) = 1$ is equivalent to $1^\top y = \alpha$, and we haven’t picked a specific value for $\alpha$. So, if we set $\alpha = 1^\top y$, the constraint becomes $1^\top y =  1^\top y$, which is redundant, so we don’t need to include it in the formulation of the problem. We are done, to solve (1) all we need to do is to solve the following convex problem</p>

<p>\begin{align}
\min_{w} \thinspace &amp; y^\top \Sigma y \cr
s. t. \thinspace &amp; \mu^\top y = 1.
\end{align}</p>

<p>to get $y_{opt}$, and then set $w_{sharpe} = \frac{y_{opt}}{1^\top y_{opt}}$.</p>

<h3 id="is-maximizing-the-sharpe-ratio-best-for-long-term-wealth">Is Maximizing the Sharpe Ratio Best For Long Term Wealth?</h3>
<p>In our specific example, the Kelly portfolio will invest 100% of its wealth on asset 1 since it has higher expected returns and its variance is not large enough to wipe us out, its Sharpe ratio is around 0.46 and compounds around .0414% per period. The maximum sharpe ratio portfolio invests 24% on asset 1 and 76% on asset 2, its sharpe ratio is 0.95 and it compounds around .0412% per period. <strong>With this we conclude that maximizing Sharpe ratio is not the best receipe maximizing for long run wealth.</strong></p>

<h1 id="the-sharpe-ratio-can-be-the-same-for-winning-and-losing-strategies">The Sharpe Ratio Can be The Same For Winning and Losing Strategies</h1>
<p>Let’s examine the Sharpe ratios of three strategies in our favorite <a href="/blog/2023/11/23/kelly1/">coin betting game</a>. The set up of the game is that there is a coin which turns up heads with probability .6 and tails with probability .4, you are allowed to wager as much of your wealth as you want on the outcome of the coin. If the coin turns out heads you double your money, and if it comes out tails you lose it all. What fraction of your wealth do you bet on heads coming out in each round?</p>

<p>As we saw in the previous post, the optimal strategy to maximize wealth in the long run is to bet 20% of your wealth in every round of the game, this strategy is called full-Kelly. If we bet 10% (half-Kelly) our wealth will also grow at an exponential rate, albeit a smaller rate. If we bet anything more than 38% our our wealth in every round we, will go bust. These is what some wealth trajectories may look like:</p>

<figure class="centered-figure">
<img src="/images/sharpe_ratio/wealth_trajectories_coin_betting.png" class="center-image max-width-75" />
<figcaption>Wealth trajectories of three betting strategies in the biased coin game</figcaption>
</figure>

<p><strong>So what do the Sharpe ratios look like for these three different strategies? Full Kelly: .02, Half Kelly: .02, Double Kelly: .02.</strong> What!?! To see why this happens let’s look at the returns of Kelly, they will look something like: .2, .2, -.2, .2, -.2, along the same trajectory those for half Kelly will look like .1, .1, -.1, .1, -.1, and something similar for double Kelly. So, for one strategy the returns are just a scaled version of one of the other strategies. When $r_{free}=0$, plugging $r’=a r$ into the definition of Sharpe ratio we get</p>

<p>\begin{align}
\frac{\mathbb{E}[ar] }{\sqrt{\mathbb{V}[ar]}} &amp;= \frac{a\mathbb{E}[r]}{\sqrt{a^2\mathbb{V}[r]}} \cr
&amp;= \frac{a\mathbb{E}[r] }{a\sqrt{\mathbb{V}[r]}} \cr 
&amp;= \frac{\mathbb{E}[r]}{\sqrt{\mathbb{V}[r]}},
\end{align}</p>

<p>which explains the behavior. <strong>Very profitable strategies can have the same Sharpe ratio as losing strategies!</strong>
In contrast, the geometric returns are, Full Kelly: 1.96%, Half Kelly: 1.82%, Double Kelly: -4%, which clearly describe what is going on with these three strategies.</p>

<h1 id="final-thoughts">Final Thoughts</h1>
<p>I hope this convinces you that the Sharpe ratio is a somewhat lousy metric. But the truth is, people use it in practice. I can only speculate why, but my best guess is the following. In a world where returns look Gaussian most of the time, the Sharpe ratio can indeed be used to increase returns (as we saw in the earlier example). Moreover, by penalizing large variances, it encourages people to size smaller than Kelly and take on less risk (actually, this may not be true, maybe it is possible to build a portfolio with high Sharpe ratio that over bets and leads to ruin when returns are Gaussian). So, when a “black swan” happens, most of the Sharpe ratio investors won’t get wiped out, whereas the Kelly ones will be, as we saw on <a href="/blog/2023/11/23/kelly1/">this post</a>.</p>

<p><strong>Disclaimer</strong>: The content provided on this blog is for educational purposes only and is not intended to be financial advice. The views and opinions expressed here are solely those of the authors and should not be construed as professional financial advice. Readers are encouraged to consult with a qualified financial advisor before making any financial decisions based on the information provided on this blog.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[DALL-E: A dull knife, resting, minimalist style, soft colors, more dull.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/sharpe_ratio/a_dull_knife_resting_minimalist_style_soft_colors_more_dull.png" /><media:content medium="image" url="http://localhost:4000/images/sharpe_ratio/a_dull_knife_resting_minimalist_style_soft_colors_more_dull.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Portfolio Construction: Kelly vs Markowitz</title><link href="http://localhost:4000/blog/2024/01/15/kelly_vs_markowitz/" rel="alternate" type="text/html" title="Portfolio Construction: Kelly vs Markowitz" /><published>2024-01-15T00:00:00-08:00</published><updated>2024-01-15T00:00:00-08:00</updated><id>http://localhost:4000/blog/2024/01/15/kelly_vs_markowitz</id><content type="html" xml:base="http://localhost:4000/blog/2024/01/15/kelly_vs_markowitz/"><![CDATA[<!-- 
In this post I explore how the Kelly criterion, a strategy for optimally betting on biased coins, can be used to build portfolios. I also prove that, in some situations, the Kelly portfolio is one of the mean-variance portfolios proposed by Harry Markowitz, the father of Modern Portfolio Theory. Finally, with simulations, I show how how one can get wrecked using these tools under the presence of fat tails.
 -->

<figure class="centered-figure">
<img src="/images/kelly_vs_markowitz/ceci_nest_pas_un_portfolio.png" alt="Stable Diffusion XL: Ceci n'est pas un portfolio" class="center-image max-width-50" />
<figcaption>Stable Diffusion XL: Ceci n'est pas un portfolio</figcaption>
</figure>

<h1 id="a-brief-review-of-modern-portfolio-theory">A Brief Review of Modern Portfolio Theory</h1>
<p>A short summary of Modern Portfolio Theory <a class="citation" href="#markowitz1952portfolio">(Markowitz, 1952)</a> is the following. The “risk” of a portfolio is measured by its variance and its “reward” is measured by the expected value of the portfolio itself. Now fix the value of variance, it is possible there are many portfolios with variance equal to the fixed value, MPT tells us that among all these portfolios we should pick the one with the largest expected value (which makes sense).</p>

<p>More formally, if there are $n$ assets with (random) returns $r_i$ where $\mu_i = \mathbb{E}[r_i]$ for $i \in [n]$, the covariance matrix is given by $\Sigma$, and $w_i$ is the fraction of our portfolio we allocate to asset $i \in [n]$, then it is easy to check that the expected return of our portfolio is given by $\mu^\top w$ and its variance is given by $w^\top \Sigma w$, where $\mu$ and $w$ are the vectors of returns and weights. So, for a given portfolio variance, $\sigma^2_{portfolio}$, we need to solve the following optimization problem:</p>

<p>\begin{align}
\max_{w} \thinspace &amp; \mu^\top w \cr
s. t.\thinspace &amp; w^\top \Sigma w = \sigma^2_{portfolio} \cr
&amp; 1^\top w = 1. \tag{1}
\end{align}</p>

<p>Note we are allowing the portfolio to short certain stocks by not enforcing $w \geq 0$. These portfolios are called “efficient”, and if we plot the maximum expected value portfolio for every possible value of the variance, we get what is called the “efficient frontier” as the following image shows.</p>

<figure class="centered-figure">
<img src="/images/kelly_vs_markowitz/efficient_frontier.png" class="center-image max-width-75" />
<figcaption>Representation of the efficient frontier: Orange dots represent securites and the blue line represents the efficient frontier.</figcaption>
</figure>

<p>As a side note, you may be familiar with the following formulation for finding efficient portfolios:</p>

<p>\begin{align}
\max_{w} \thinspace &amp; \mu^\top w - \lambda w^\top \Sigma w, \cr
s. t.\thinspace &amp;1^\top w = 1. \tag{2}
\end{align}</p>

<p>where $\lambda$ expresses the risk preferences of the portfolio manager. This formulation and the one I presented in (1) are equivalent (I’ll let  you prove it yourself).</p>

<p>Our ultimate goal when we are thinking about portfolio construction, is to actually build a portfolio, yet MPT has not provided us one. MPT has given us a set of portfolios that seem to be reasonable (in a later section I will show with an example that not all of them are), and academics will tell you that the right portfolio to pick will depend on each person’s risk preferences. But I have never met anyone who can actually describe their risk preferences… Additionally, in this setting, risk preferences must be specified as a value for the variance of the portfolio, but it is possible to have a large variance due to really large gains, so a large variance is not necessarily a bad thing.</p>

<p>Our goal is to build a portfolio, unfortunately we have not been able to do so. In a previous <a href="/blog/2023/11/23/kelly1/">post</a>, we discussed how to bet optimally on the outcome of a biased coin using the Kelly criterion. Is there a way we can apply those learnings to building portfolios? Before we answer these questions let me convince you that there can be portfolios in the efficient frontier that will ruin you.</p>

<h3 id="some-efficient-portfolios-lead-to-ruin">Some Efficient Portfolios Lead To Ruin</h3>
<p>Consider the “economy” where we have two assets. The first asset doubles your investment with probability .6 and fully loses your investment with probability .4, so $\mu_1 = \mathbb{E}[r_1] = .2$. The second asset guarantees you will not make or lose any money so $\mu_2 = 0$. In this economy the covariance matrix is all zeros except for the top left entry which has the value .96. Plugging these values into (2) to get an efficient portfolio we need to solve</p>

<p>\begin{align}
\max_{\lVert w \rVert = 1} .2 w_1 - \lambda .96 w_1^2.
\end{align}</p>

<p>Setting the derivative w.r.t. $w_1$ equal to 0 and solving for it we get $w_1=\frac{1}{9.6 \lambda}$. In the previous post we saw that choosing to bet more that 38% of our wealth in the coin will most certainly lead us to ruin in the long run. So, picking any risk preference parameter lambda such that $\frac{1}{9.6 \lambda} &gt; .38$ gives us an efficient portfolio that will lead us to ruin. This is a short cautionary tale to be careful when picking parameters for high-stake decision problems.</p>

<h1 id="using-the-kelly-criterion-for-portfolio-construction">Using the Kelly Criterion for Portfolio Construction</h1>
<p>Let us assume our initial wealth is 1, let $o_i = 1 +r_i$ for $i \in [n]$, so that $\sum_{i \in [n]}o_i w_i = o^\top w$ is the random variable expressing our wealth.</p>

<p>In <a href="/blog/2023/11/23/kelly1/">this</a> post we showed that when a coin is biased in our favor and the bets are even odds, it is possible to grow our wealth exponentially quickly by maximizing the expected log wealth, and that this is the fastest growth rate. So, why don’t we do the same for portfolio construction? That is, what happens when we use the optimal solution to the following optimization problem</p>

<p>\begin{align}
\max_{w} &amp; \mathbb{E}[\ln(o^\top w)] \tag{3},
\end{align}</p>

<p>as the weights for our portfolio? How does this portfolio compare to those prescribed by MPT? Is the Kelly portfolio any good?</p>

<p>I will show shortly, under certain conditions, $w^*$ the solution to (3), which I call the Kelly portfolio, is a good approximation to <strong>one</strong> of the portfolios in the efficient frontier. Then I will state two important properties that the Kelly portfolio has.</p>

<p>The discussion that follows comes from <a class="citation" href="#thorp1975portfolio">(Thorp, 1975)</a> and <a class="citation" href="#breiman1961optimal">(Breiman, 1961)</a>. I highly recomend you read them as I skip details. Also, since I’m rederiving results myself so I can internalize them, the notation may not be consistent with the one in these papers.</p>

<h1 id="the-kelly-portfolio-is-sometimes-in-the-efficient-frontier">The Kelly Portfolio Is (Sometimes) In The Efficient Frontier</h1>

<p>We now establish the connection between the Kelly portfolio and MPT. Using the Taylor series expansion: $f(x) = f(y) + \frac{f’(y)(x-y)}{1!} + \frac{f’‘(y)(x-y)^2}{2!} + \frac{f’’‘(y)(x-y)^3}{3!}+…$ of $\ln$ around $(1+\mu)^\top w$. We get</p>

<p>\begin{align}
&amp;\ln(o^\top w) \cr
 &amp;= \ln((1+r)^\top w) \cr
 &amp;= \ln((1+\mu)^\top w) + \frac{1}{2(1+\mu)^\top w} ((1+r)^\top w - (1+\mu)^\top w) - \cr
 &amp; \qquad  \frac{1}{2((1+\mu)^\top w)^2} ((1+r)^\top w - (1+\mu)^\top w)^2 + \text{h.o. terms}.
\end{align}</p>

<p>If we ignore the higher order terms, take expectation, and simplify a bit we have</p>

<p>\begin{align}
\mathbb{E}[\ln(o^\top w)] &amp;\approx \ln((1+\mu)^\top w) - \frac{1}{2((1+\mu)^\top w)^2} \mathbb{E}[(r^\top w - \mu^\top w)^2].
\end{align}</p>

<p>So that when we do not allow leverage, i.e. $1^\top w =1$, and $\mu^\top w$ is small, we have $\ln((1+\mu)^\top w) = \ln(1 + \mu^\top w) \approx \mu^\top w$ and $((1+\mu)^\top w)^2 \approx 1$.</p>

<p>Under all the assumptions, we have that:</p>

<p>\begin{align}
\mathbb{E}[\ln(o^\top w)] &amp;\approx \mu^\top w - \frac{1}{2} w^\top \Sigma w.
\end{align}</p>

<p>We have shown that if the returns are small and moments &gt; 2 are small, then Kelly portfolio, which maximizes $\mathbb{E}[\ln(o^\top w)]$, is equivalent to the Markowitz portfolio (2), with risk parameter $\lambda = \frac{1}{2}$.
Conversely, if the returns of the assets you are considering investing in, have potentially very large gains/loses or have nonnegligible higher moments you should think twice before using MPT and $\lambda = .5$. After all, MPT does not even take as input these higher order moments.</p>

<h1 id="two-important-properties-of-the-kelly-portfolio">Two Important Properties of the Kelly Portfolio</h1>

<p>We’ve shown an nice conection between the Kelly portfolio and MPT. But is the Kelly portfolio actually good? Will it make money?</p>

<p><a class="citation" href="#breiman1961optimal">(Breiman, 1961)</a> showed that, when the market is “favorable” (an equivalent condition to (3) being positive), there are two good properties the Kelly portfolio has (informally):</p>

<ol>
  <li>Asymptotically, any portfolio strategy that does not approach the value $\max_{w} \mathbb{E}[\ln(o^\top w)]$ will perform infinitely worse than the Kelly portfolio almost surely.</li>
  <li>Let $x$ be our desired wealth level, and $\mathbb{E}[T_x(w)]$ the expected number of periods required to exceed our desired wealth level, then as $x\rightarrow \infty$, the Kelly portfolio minimizes $\mathbb{E}[T_x(w)]$.</li>
</ol>

<p>These properties suggest that using the Kelly portfolio is reasonable. The proofs for these claims are quite long, so I won’t include them here.</p>

<h1 id="practical-aspects-of-portfolio-construction">Practical Aspects of Portfolio Construction</h1>
<p>The discussion so far has been detached from reality. In practice we can’t solve either (2) or (3) because we don’t know the distribution of returns. However, something we can do is to estimate the distribution/parameters from historical data and then plug these estimates into (2) and (3). Notice that by doing this we are assuming the distribution of returns is stationary (which is probably not true). Let’s see what happens when we follow this approach in a simulated market. As usual, you can find the code on <a href="https://github.com/adrianriv/blog-code/blob/master/kelly_vs_markowitz/kelly_vs_markowitz_simulations.ipynb">Github</a>.</p>

<h2 id="the-markowitz-portfolio-under-gaussian-returns">The Markowitz Portfolio Under Gaussian Returns</h2>
<p>In these simulations we will sample returns from a multivariate Gaussian distribution with $\mu = [0, .05, -.04]$, and</p>

<p>\begin{align}
\Sigma = \begin{bmatrix}
   0 &amp; 0 &amp; 0 \cr
   0 &amp; 0.0101 &amp; 0.009\cr
   0 &amp; 0.009 &amp; 0.0164
\end{bmatrix}.
\end{align}</p>

<p>The first asset is equivalent to holding cash, the second one is a stock with positive returns, and the last one is a stock with negative returns.
The simulation is setup as follows. Using two years of monthly data (24 observations), we estimate the mean returns, and covariance matrix to solve (2) with $\lambda = .5$, to find our portfolio weights. Then we sample from the distribution to get our realized returns, with these we can compute our wealth, and update our mean and covariance estimates. This process repeats for 600 months. The next figure shows in blue 30 wealth trajectories of following this procedure. For each of the aforementioned trajectories we also plot what our wealth would be if we used the true mean and covariance matrix to find the portfolio weights. As you can see, the method of plugging in the estimated parameters works well in this setting.</p>
<figure class="centered-figure">
<img src="/images/kelly_vs_markowitz/wealth_trajectories_under_normal.png" class="center-image max-width-75" />
<figcaption>Thirty wealth trajectories of Markowitz portolios with $\lambda=.5$. The returns are generated by a multivariate Gaussian distribution. In blue the portfolio is created by solving (2) using estimates for the mean returns and covariance matrix. In orange we have the trajectories using the solution to (2) when we plug in the true means and covariance matrix. As can be seen the first set of trajectories performs equally well as if we knew the true parameters.</figcaption>
</figure>

<p>Unfortunately, the multivariate Gaussian assumption for the returns is not realistic in practice. In the next subsection we explore what happens when the returns are generated from a multivariate Student’s-t distribution.</p>

<h2 id="the-markowitz-portfolio-under-fat-tails">The Markowitz Portfolio Under Fat Tails</h2>
<p>The setup is the same as in the last subsection except that the returns are distributed according to a multivariate <a href="https://en.wikipedia.org/wiki/Student%27s_t-distribution">Student-t</a> distribution with the same mean and variance as in the previous subsection, and 4 degrees of freedom (still finite variance). The reason for choosing Student’s-t is that it has fatter tails than the Gaussian, so this is a slightly more realistic model.</p>

<p>This is what the trajectories look like:</p>
<figure class="centered-figure">
<img src="/images/kelly_vs_markowitz/wealth_trajectories_under_students_t.png" class="center-image max-width-75" />
<figcaption>Thirty wealth trajectories of Markowitz portolios with $\lambda=.5$. The returns are generated by a multivariate Student's t distribution. In blue the portfolio is created by solving (2) using estimates for the mean returns and covariance matrix. In orange we have the trajectories using the solution to (2) when we plug in the true means and covariance matrix.</figcaption>
</figure>

<p>Ouch! See those 7 trajectories where wealth drastically drops? Those drastic losses come from the fat tails of the Student’s t distribution. The large loses don’t show up that often so they don’t really enter into our estimates of mean and variance until it’s too late. But why did this happen? Recall we are using (2) with $\lambda = .5$ to build our portfolio (motivated by the earlier section), but we are no longer in a setting where the higher order (in particular 4-th) moments can be ignored. So, we are obviously over betting. Can this be remedied? This example shows what happens when the Markowitz approximation to the Kelly portfolio fails. What if we solve the Kelly portfolio directly instead of the Markowitz approximation?</p>

<h2 id="the-kelly-portfolio-under-fat-tails">The Kelly Portfolio Under Fat Tails</h2>
<p>The Kelly portfolio in this example most likely involves betting a very small fraction of your wealth on stock #1 and keeping the remaining fraction of your wealth in cash (just as in the biased coin example from the last post). To determine the actual fraction we could try to compute (3) by using integration and the pdf of the Student’s t distribution. Another approach could be to solve the Sample Average Approximation:</p>

<p>\begin{align}
\max_{w} \sum_{n=1}^N \frac{1}{N} \ln(w_0 + r_{1,n} w_1 + r_{2,n} w_2)
\end{align}</p>

<p>Where $r_{1,n}, r_{2,n}$ for $n\in[N]$ are $N$ samples from the distribution of returns. The question is, how many samples do we need? I suspect the amount is prohibitive in practice (for this particular problem at least). Because of the possibilty of 100% losses where if $w_1$ happens to be close to $1$ you will get a gradient with huge magnitude that will most likely make the numerical method you are using to solve the problem fail. In fact, this is what I observed when I tried solving the problem using cvxpy, an optimization solver for Python.</p>

<p>Taking a step back, we want to solve the portfolio allocation problem when we only have 24 monthly samples, so the SAA approach will not work for us. At this point, it is unclear how to proceed. The integral is probably computable but the method does not really translate into a practical one because in practice we wouldn’t know how to estimate parameters given such a small number of samples. Risk and portolio management is hard…</p>

<p>Thorpe was a big proponent of Kelly sizing, however I think this is because he had a huge edge, see his example in the last section of <a class="citation" href="#thorp1975portfolio">(Thorp, 1975)</a>. Time to end this post. The take away is that although the theory of Kelly portfolios is quite nice, using it in practice is very hard. This section only dealt with returns with fat tails but let’s not forget that in the real world we also have skewness, nonstationarity, etc.</p>

<p><strong>Disclaimer</strong>: The content provided on this blog is for educational purposes only and is not intended to be financial advice. The views and opinions expressed here are solely those of the authors and should not be construed as professional financial advice. Readers are encouraged to consult with a qualified financial advisor before making any financial decisions based on the information provided on this blog.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/kelly_vs_markowitz/ceci_nest_pas_un_portfolio.png" /><media:content medium="image" url="http://localhost:4000/images/kelly_vs_markowitz/ceci_nest_pas_un_portfolio.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">The Art of Optimal Betting</title><link href="http://localhost:4000/blog/2023/11/23/kelly1/" rel="alternate" type="text/html" title="The Art of Optimal Betting" /><published>2023-11-23T00:00:00-08:00</published><updated>2023-11-23T00:00:00-08:00</updated><id>http://localhost:4000/blog/2023/11/23/kelly1</id><content type="html" xml:base="http://localhost:4000/blog/2023/11/23/kelly1/"><![CDATA[<figure class="centered-figure">
<img src="/images/kelly1/coin_flipping_through_the_air_in_motion_in_the_style_of_Dalis_the_persistence_of_memory.png" alt="Stable Diffusion XL: Coin flipping through the air, in motion, in the style of Dali's The Persistence of Memory" class="center-image max-width-50" />
<figcaption>Stable Diffusion XL: Coin flipping through the air, in motion, in the style of Dali's The Persistence of Memory</figcaption>
</figure>

<h1 id="a-bit-of-history">A Bit Of History</h1>
<p>This blog post is based on one of my favorite papers of all time: “A New Interpretation of Information Rate” <a class="citation" href="#kelly1956new">(Kelly, 1956)</a>. The paper, written by John L. Kelly, derives a formula for gambling optimally which is now known as the “Kelly Criterion”. Mathematician turned hedge fund manager, Ed Thorpe, is famously known for using this formula at his hedge fund. Thorpe’s fund outperformed the S&amp;P500 by a factor of ~3 over a span of 20 years <a class="citation" href="#fortunesformulaThorpapossHedge">(<i>Fortunesformula.com</i>, n.d.)</a>.</p>

<p>If after reading this post you want to learn more about the history of this formula, I highly recommend <a class="citation" href="#poundstone2010fortune">(Poundstone, 2010)</a>. In it, you can read about how Thorpe and Shannon created the first wearable computer to beat the casinos at roulette, how Thorpe beat the casinos at blackjack, and how he later moved on to opening up a hedge fund.</p>

<h2 id="the-problem-setup">The Problem Setup</h2>
<p>We will study the following problem:</p>

<p><strong>There is biased coin and you know its probability of landing heads is .6. Someone offers you the chance to bet as much money as you want on the outcome of a toss of the biased coin. The bet is 1-to-1 odds (if you bet 10 dollars and lose, you lose those 10 and if you win you end up with 20 dolars in your pocket). You can play this game for 100 rounds. How much money should you bet in each round?</strong></p>

<p>Now, stop reading and think about how much you would bet. Seriously, take your time to think about it. Write it down in a piece of paper.</p>

<p>I’ve asked this question to many people and very few (~15%) get something that is roughly right. Most people end up leaving a lot of money on the table and unfortunately many people, some with PhDs in probability related fields, go bust.</p>

<p>Let’s first answer a simpler question: Should you even bet at all? If you bet $x$ dollars on heads your expected payoff is $p_{win} * x + p_{lose} (-x) = .6x - .4x = .2x$ dollars, which is positive, so yes, you should definetely bet (on heads!). Let $W_0$ be your initial wealth and $f \in [0, 1]$ the fraction of your wealth that you are going to bet. Your expected wealth after the first round of gambling is:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><munder><munder><mrow><msub><mi>W</mi><mn>0</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>f</mi><mo stretchy="false">)</mo></mrow><mo stretchy="true">⏟</mo></munder><mtext>the amount of wealth you don’t bet</mtext></munder><mo>+</mo><munder><munder><mrow><mo stretchy="false">(</mo><mi mathvariant="normal">.</mi><mn>6</mn><mo stretchy="false">)</mo><mo>∗</mo><mn>2</mn><msub><mi>W</mi><mn>0</mn></msub><mi>f</mi></mrow><mo stretchy="true">⏟</mo></munder><mrow><mtext>probability of winning </mtext><mstyle scriptlevel="0" displaystyle="false"><mo>×</mo></mstyle><mtext> prize if you win</mtext></mrow></munder><mo>+</mo><munder><munder><mrow><mo stretchy="false">(</mo><mi mathvariant="normal">.</mi><mn>4</mn><mo stretchy="false">)</mo><mo>∗</mo><mn>0</mn></mrow><mo stretchy="true">⏟</mo></munder><mrow><mtext>probability of losing </mtext><mstyle scriptlevel="0" displaystyle="false"><mo>×</mo></mstyle><mtext> prize if you lose</mtext></mrow></munder></mrow><annotation encoding="application/x-tex">
\underbrace{W_0(1-f)}_{\text{the amount of wealth you don&#x27;t bet}} + 
\underbrace{(.6) * 2 W_0 f}_{\text{probability of winning $\times$ prize if you win}} + 
\underbrace{(.4) * 0}_{\text{probability of losing $\times$ prize if you lose}}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:2.4702159999999997em;vertical-align:-1.720216em;"></span><span class="mord munder"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.75em;"><span style="top:-1.415892em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord text mtight"><span class="mord mtight">the amount of wealth you don’t bet</span></span></span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord munder"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.75em;"><span class="svg-align" style="top:-2.102em;"><span class="pstrut" style="height:3em;"></span><span class="stretchy" style="height:0.548em;min-width:1.6em;"><span class="brace-left" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMinYMin slice"><path d="M0 6l6-6h17c12.688 0 19.313.3 20 1 4 4 7.313 8.3 10 13  35.313 51.3 80.813 93.8 136.5 127.5 55.688 33.7 117.188 55.8 184.5 66.5.688  0 2 .3 4 1 18.688 2.7 76 4.3 172 5h399450v120H429l-6-1c-124.688-8-235-61.7 -331-161C60.687 138.7 32.312 99.3 7 54L0 41V6z"></path></svg></span><span class="brace-center" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMidYMin slice"><path d="M199572 214 c100.7 8.3 195.3 44 280 108 55.3 42 101.7 93 139 153l9 14c2.7-4 5.7-8.7 9-14  53.3-86.7 123.7-153 211-199 66.7-36 137.3-56.3 212-62h199568v120H200432c-178.3  11.7-311.7 78.3-403 201-6 8-9.7 12-11 12-.7.7-6.7 1-18 1s-17.3-.3-18-1c-1.3 0 -5-4-11-12-44.7-59.3-101.3-106.3-170-141s-145.3-54.3-229-60H0V214z"></path></svg></span><span class="brace-right" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMaxYMin slice"><path d="M399994 0l6 6v35l-6 11c-56 104-135.3 181.3-238 232-57.3  28.7-117 45-179 50H-300V214h399897c43.3-7 81-15 113-26 100.7-33 179.7-91 237 -174 2.7-5 6-9 10-13 .7-1 7.3-1 20-1h17z"></path></svg></span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathdefault" style="margin-right:0.13889em;">W</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mclose">)</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.898em;"><span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.720216em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:2.567438em;vertical-align:-1.8174379999999999em;"></span><span class="mord munder"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7500000000000002em;"><span style="top:-1.31867em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord text mtight"><span class="mord mtight">probability of winning </span><span class="mspace mtight" style="margin-right:0.26022222222222224em;"></span><span class="mbin sizing reset-size3 size6">×</span><span class="mord mtight"> prize if you win</span></span></span></span></span><span style="top:-3.0000000000000004em;"><span class="pstrut" style="height:3em;"></span><span class="mord munder"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.75em;"><span class="svg-align" style="top:-2.102em;"><span class="pstrut" style="height:3em;"></span><span class="stretchy" style="height:0.548em;min-width:1.6em;"><span class="brace-left" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMinYMin slice"><path d="M0 6l6-6h17c12.688 0 19.313.3 20 1 4 4 7.313 8.3 10 13  35.313 51.3 80.813 93.8 136.5 127.5 55.688 33.7 117.188 55.8 184.5 66.5.688  0 2 .3 4 1 18.688 2.7 76 4.3 172 5h399450v120H429l-6-1c-124.688-8-235-61.7 -331-161C60.687 138.7 32.312 99.3 7 54L0 41V6z"></path></svg></span><span class="brace-center" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMidYMin slice"><path d="M199572 214 c100.7 8.3 195.3 44 280 108 55.3 42 101.7 93 139 153l9 14c2.7-4 5.7-8.7 9-14  53.3-86.7 123.7-153 211-199 66.7-36 137.3-56.3 212-62h199568v120H200432c-178.3  11.7-311.7 78.3-403 201-6 8-9.7 12-11 12-.7.7-6.7 1-18 1s-17.3-.3-18-1c-1.3 0 -5-4-11-12-44.7-59.3-101.3-106.3-170-141s-145.3-54.3-229-60H0V214z"></path></svg></span><span class="brace-right" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMaxYMin slice"><path d="M399994 0l6 6v35l-6 11c-56 104-135.3 181.3-238 232-57.3  28.7-117 45-179 50H-300V214h399897c43.3-7 81-15 113-26 100.7-33 179.7-91 237 -174 2.7-5 6-9 10-13 .7-1 7.3-1 20-1h17z"></path></svg></span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mopen">(</span><span class="mord">.</span><span class="mord">6</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">2</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.13889em;">W</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.898em;"><span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.8174379999999999em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:2.567438em;vertical-align:-1.8174379999999999em;"></span><span class="mord munder"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.7500000000000002em;"><span style="top:-1.31867em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord text mtight"><span class="mord mtight">probability of losing </span><span class="mspace mtight" style="margin-right:0.26022222222222224em;"></span><span class="mbin sizing reset-size3 size6">×</span><span class="mord mtight"> prize if you lose</span></span></span></span></span><span style="top:-3.0000000000000004em;"><span class="pstrut" style="height:3em;"></span><span class="mord munder"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.75em;"><span class="svg-align" style="top:-2.102em;"><span class="pstrut" style="height:3em;"></span><span class="stretchy" style="height:0.548em;min-width:1.6em;"><span class="brace-left" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMinYMin slice"><path d="M0 6l6-6h17c12.688 0 19.313.3 20 1 4 4 7.313 8.3 10 13  35.313 51.3 80.813 93.8 136.5 127.5 55.688 33.7 117.188 55.8 184.5 66.5.688  0 2 .3 4 1 18.688 2.7 76 4.3 172 5h399450v120H429l-6-1c-124.688-8-235-61.7 -331-161C60.687 138.7 32.312 99.3 7 54L0 41V6z"></path></svg></span><span class="brace-center" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMidYMin slice"><path d="M199572 214 c100.7 8.3 195.3 44 280 108 55.3 42 101.7 93 139 153l9 14c2.7-4 5.7-8.7 9-14  53.3-86.7 123.7-153 211-199 66.7-36 137.3-56.3 212-62h199568v120H200432c-178.3  11.7-311.7 78.3-403 201-6 8-9.7 12-11 12-.7.7-6.7 1-18 1s-17.3-.3-18-1c-1.3 0 -5-4-11-12-44.7-59.3-101.3-106.3-170-141s-145.3-54.3-229-60H0V214z"></path></svg></span><span class="brace-right" style="height:0.548em;"><svg width="400em" height="0.548em" viewBox="0 0 400000 548" preserveAspectRatio="xMaxYMin slice"><path d="M399994 0l6 6v35l-6 11c-56 104-135.3 181.3-238 232-57.3  28.7-117 45-179 50H-300V214h399897c43.3-7 81-15 113-26 100.7-33 179.7-91 237 -174 2.7-5 6-9 10-13 .7-1 7.3-1 20-1h17z"></path></svg></span></span></span><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mopen">(</span><span class="mord">.</span><span class="mord">4</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">∗</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.898em;"><span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.8174379999999999em;"><span></span></span></span></span></span></span></span></span></span></p>

<p>This simplifies to $W_0 + .2 W_0 f$, which is a simple linear function which is maximized at $f^* = 1$. So, to maximize your expected wealth you should bet your entire wealth in the first round…</p>

<p>Well, this is idiotic for obvious reasons, we don’t want to lose all our hard-earned savings in a single round of a stupid game! But somehow “the math” is telling us to do so… Let this be a lesson to not always follow what the math says, or what some “expert” using fancy math says. Always think and analyze by yourself, make sure your results align with your intuition. And if you are going to use math to justify high-stake decisions you better understand the math really well!</p>

<p>So, why are we getting an obviously wrong answer if our math is “correct”? My take is that this is just an artifact of the definition of expected value, the definition itself (together with taking the maximum) does not capture the aspect of reality that we want it to capture. –&gt;</p>

<h2 id="finding-the-optimal-fraction-to-bet">Finding the Optimal Fraction to Bet</h2>

<p>Before we do the math to figure out how much to actually bet, let’s set up some notation so that we can apply our learnings to similar problems. Let $W_i$ be your wealth in round $i$ (your initial wealth is $W_0$), $u$ be your % gains if you win the bet, $d$ your % loses if you lose the bet, $p$ the probability of winning the bet, and $q = 1-p$ be the probability of losing the bet. In our biased coin example we have $p=.6, q=.4, u=1$, and $d=1$.</p>

<p>Let’s compute our wealth $W_1$ in the scenario where the coin lands on heads. We decided to wager $W_0 f$ dollars and since we won the bet we’ve turned that into $W_0 f (1+u)$, at the same time we kept $W_0 (1-f)$ in our pocket, so $W_1 = W_0 f (1+u) + W_0 (1-f) = W_0 (1+f u)$. Similarly, if the coin lands tails $W_1$ would be: $W_0 (1- f d)$. It is not too hard to see that our wealth in the last round will be equal to:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>W</mi><mn>100</mn></msub><mo>=</mo><msub><mi>W</mi><mn>0</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mi>f</mi><mi>u</mi><msup><mo stretchy="false">)</mo><mtext>numberOfHeads</mtext></msup><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>f</mi><mi>d</mi><msup><mo stretchy="false">)</mo><mtext>numberOfTails</mtext></msup><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">
W_{100} = W_0 (1+fu)^{\text{numberOfHeads}}(1-fd)^{\text{numberOfTails}},
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.13889em;">W</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span><span class="mord mtight">0</span><span class="mord mtight">0</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.13889em;">W</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.149108em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mord mathdefault">u</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord text mtight"><span class="mord mtight">numberOfHeads</span></span></span></span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.149108em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mord mathdefault">d</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8991079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord text mtight"><span class="mord mtight">numberOfTails</span></span></span></span></span></span></span></span></span></span><span class="mpunct">,</span></span></span></span></span></p>

<p>where $\text{numberOfHeads}$ is the number of times we got heads in the 100 rounds we played, and $\text{numberOfTails}$ is defined similarly. In expectation $\text{numberOfHeads} = 100 p$  and $\text{numberOfTails} = 100 q$. So we want to maximize</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable width="100%"><mtr><mtd width="50%"></mtd><mtd><mrow><msub><mi>W</mi><mn>0</mn></msub><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mi>f</mi><mi>u</mi><msup><mo stretchy="false">)</mo><mrow><mn>100</mn><mi>p</mi></mrow></msup><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>f</mi><mi>d</mi><msup><mo stretchy="false">)</mo><mrow><mn>100</mn><mi>q</mi></mrow></msup><mi mathvariant="normal">.</mi></mrow></mtd><mtd width="50%"></mtd><mtd><mtext>(1)</mtext></mtd></mtr></mtable><annotation encoding="application/x-tex">
W_0 (1+fu)^{100 p}(1-fd)^{100 q} \tag{1}.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.13889em;">W</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mord mathdefault">u</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-3.1130000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span><span class="mord mtight">0</span><span class="mord mtight">0</span><span class="mord mathdefault mtight">p</span></span></span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mord mathdefault">d</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-3.1130000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span><span class="mord mtight">0</span><span class="mord mtight">0</span><span class="mord mathdefault mtight" style="margin-right:0.03588em;">q</span></span></span></span></span></span></span></span></span><span class="mord">.</span></span><span class="tag"><span class="strut" style="height:1.1141079999999999em;vertical-align:-0.25em;"></span><span class="mord text"><span class="mord">(</span><span class="mord"><span class="mord">1</span></span><span class="mord">)</span></span></span></span></span></span></p>

<p>Taking natural logs on both sides of the equation we have</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ln</mi><mo>⁡</mo><mo stretchy="false">(</mo><msub><mi>W</mi><mn>0</mn></msub><mo stretchy="false">)</mo><mo>+</mo><mn>100</mn><mi>p</mi><mi>ln</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><mi>f</mi><mi>u</mi><mo stretchy="false">)</mo><mo>+</mo><mn>100</mn><mi>q</mi><mi>ln</mi><mo>⁡</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>f</mi><mi>d</mi><mo stretchy="false">)</mo><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
\ln(W_0)+ 100 p \ln(1+fu) + 100 q \ln(1-fd).
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mop">ln</span><span class="mopen">(</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.13889em;">W</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mord">0</span><span class="mord">0</span><span class="mord mathdefault">p</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop">ln</span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mord mathdefault">u</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mord">0</span><span class="mord">0</span><span class="mord mathdefault" style="margin-right:0.03588em;">q</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop">ln</span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mord mathdefault">d</span><span class="mclose">)</span><span class="mord">.</span></span></span></span></span></p>

<p>This is for sure a concave function on $f$ as long as $d &lt; 1$ i.e. we can’t lose more than we actually bet (I’ll let you double check the second derivative). So we can take the gradient with respect to $f$ and set it equal to 0.</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mrow><mn>100</mn><mi>p</mi><mi>u</mi></mrow><mrow><mo stretchy="false">(</mo><mn>1</mn><mo>+</mo><msup><mi>f</mi><mo>∗</mo></msup><mi>u</mi><mo stretchy="false">)</mo></mrow></mfrac><mo>−</mo><mfrac><mrow><mn>100</mn><mi>q</mi><mi>d</mi></mrow><mrow><mn>1</mn><mo>−</mo><msup><mi>f</mi><mo>∗</mo></msup><mi>d</mi></mrow></mfrac><mo>=</mo><mn>0.</mn></mrow><annotation encoding="application/x-tex">
\frac{100pu}{(1+f^*u)} - \frac{100qd}{1-f^*d} = 0.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:2.25744em;vertical-align:-0.936em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.6146959999999999em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mord mathdefault">u</span><span class="mclose">)</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span><span class="mord">0</span><span class="mord">0</span><span class="mord mathdefault">p</span><span class="mord mathdefault">u</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.936em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:2.25188em;vertical-align:-0.8804400000000001em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3714399999999998em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.6146959999999999em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mord mathdefault">d</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span><span class="mord">0</span><span class="mord">0</span><span class="mord mathdefault" style="margin-right:0.03588em;">q</span><span class="mord mathdefault">d</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.8804400000000001em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">0</span><span class="mord">.</span></span></span></span></span></p>

<p>Solving for $f^*$ we get</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>f</mi><mo>∗</mo></msup><mo>=</mo><mfrac><mi>p</mi><mi>d</mi></mfrac><mo>+</mo><mfrac><mi>q</mi><mi>u</mi></mfrac><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
f^* = \frac{p}{d} + \frac{q}{u}.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.933136em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.738696em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mbin mtight">∗</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.7935599999999998em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.1075599999999999em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault">d</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault">p</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1.7935599999999998em;vertical-align:-0.686em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.1075599999999999em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault">u</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">q</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord">.</span></span></span></span></span></p>

<p>This is the formula that is known as the Kelly Criterion. In our example, $u=d=1$, $p=.6$,  so we get that $f^* = .2$, according to the formula we should be betting $20$ % of your wealth in every round. Moreover, plugging in the optimal solution into equation (1) where 100 is replaced with $T$ rounds we get:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>W</mi><mn>0</mn></msub><mo stretchy="false">(</mo><mn>1.2</mn><msup><mo stretchy="false">)</mo><mrow><mi mathvariant="normal">.</mi><mn>6</mn><mi>T</mi></mrow></msup><mo stretchy="false">(</mo><mi mathvariant="normal">.</mi><mn>8</mn><msup><mo stretchy="false">)</mo><mrow><mi mathvariant="normal">.</mi><mn>4</mn><mi>T</mi></mrow></msup><mo>=</mo><msub><mi>W</mi><mn>0</mn></msub><msup><mi>e</mi><mrow><mi>l</mi><mi>o</mi><mi>g</mi><mo stretchy="false">(</mo><mn>1.</mn><msup><mn>2</mn><mrow><mi mathvariant="normal">.</mi><mn>6</mn><mi>T</mi></mrow></msup><mo stretchy="false">)</mo></mrow></msup><msup><mi>e</mi><mrow><mi>l</mi><mi>o</mi><mi>g</mi><mo stretchy="false">(</mo><mi mathvariant="normal">.</mi><msup><mn>8</mn><mrow><mi mathvariant="normal">.</mi><mn>4</mn><mi>T</mi></mrow></msup><mo stretchy="false">)</mo></mrow></msup><mo>≈</mo><msup><mi>e</mi><mrow><mi mathvariant="normal">.</mi><mn>02</mn><mi>T</mi></mrow></msup><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">
W_0 (1.2)^{.6T} (.8)^{.4T} = W_0 e^{log(1.2^{.6T})} e^{log(.8^{.4T})} \approx e^{.02T},
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1.1413309999999999em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.13889em;">W</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mord">.</span><span class="mord">2</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8913309999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">.</span><span class="mord mtight">6</span><span class="mord mathdefault mtight" style="margin-right:0.13889em;">T</span></span></span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">.</span><span class="mord">8</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8913309999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">.</span><span class="mord mtight">4</span><span class="mord mathdefault mtight" style="margin-right:0.13889em;">T</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.206365em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.13889em;">W</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.13889em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">0</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault">e</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:1.056365em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.01968em;">l</span><span class="mord mathdefault mtight">o</span><span class="mord mathdefault mtight" style="margin-right:0.03588em;">g</span><span class="mopen mtight">(</span><span class="mord mtight">1</span><span class="mord mtight">.</span><span class="mord mtight"><span class="mord mtight">2</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.9190928571428572em;"><span style="top:-2.931em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mtight">.</span><span class="mord mtight">6</span><span class="mord mathdefault mtight" style="margin-right:0.13889em;">T</span></span></span></span></span></span></span></span></span><span class="mclose mtight">)</span></span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault">e</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:1.056365em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.01968em;">l</span><span class="mord mathdefault mtight">o</span><span class="mord mathdefault mtight" style="margin-right:0.03588em;">g</span><span class="mopen mtight">(</span><span class="mord mtight">.</span><span class="mord mtight"><span class="mord mtight">8</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.9190928571428572em;"><span style="top:-2.931em;margin-right:0.07142857142857144em;"><span class="pstrut" style="height:2.5em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mtight">.</span><span class="mord mtight">4</span><span class="mord mathdefault mtight" style="margin-right:0.13889em;">T</span></span></span></span></span></span></span></span></span><span class="mclose mtight">)</span></span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">≈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.0857709999999998em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathdefault">e</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8913309999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">.</span><span class="mord mtight">0</span><span class="mord mtight">2</span><span class="mord mathdefault mtight" style="margin-right:0.13889em;">T</span></span></span></span></span></span></span></span></span><span class="mpunct">,</span></span></span></span></span></p>

<p>which means we should expect our wealth to grow exponentially fast!</p>

<p>This time we’ve arrived at an answer that actually makes sense. If we get unlucky and get a few tails in a row we won’t go broke, but it is aggressive enough to grow our wealth at an exponential rate.</p>

<p>Below is a plot of how much you should expect your wealth to grow by at the end of 100 rounds when you bet a constant fraction of it in every round. This is equation (1) in the case where $u=d=1$, and $p=.6$. If we bet $20$ % in every round we expect to grow our wealth by a factor of 7.5, not bad at all! But we have to be careful, if we bet more than $38$ % we will start loosing money, and if we are too aggressive and bet more than $50$ % in each round we will lose all our money!</p>

<figure class="centered-figure">
<img src="/images/kelly1/final_wealth_of_kelly_betting.png" class="center-image max-width-75" />
</figure>

<p>Tread carefully though, as I will show you later in some simulations, growing your money this quickly is not a walk in the park, using this betting strategy comes with big wealth swings.</p>

<p>You should be wondering how is it that the “math” gave us something reasonable this time. Careful inspection of the steps above will show you that this time we are solving $\max_{f \in [0,1]} \mathbb{E}[\ln(W_{100})]$, whereas the first time we were solving $\max_{f \in [0,1]} \mathbb{E}[W_{100}]$. What a big difference using logs makes in finance!</p>

<h2 id="learnings-from-kelly">Learnings From Kelly</h2>
<p>There are a few simple heuristics we can extract from Kelly’s formula. I think they are useful if you like games of chance, or if you happen to invest (gamble) in the stock market:</p>

<ol>
  <li>When you have a bad streak, you reduce how much money (in dollar terms) you are betting. In particular, <strong>you don’t double down!</strong> If you are one of those who like doubling down when you are losing, or keeps doubling down when a stock keeps going down I beg you to watch <a href="https://www.youtube.com/watch?v=zTsRGQj6VT4">this</a>.</li>
  <li>Never gamble/invest all your money, if you lose it all you won’t have the chance to recover, even when you have an edge!</li>
  <li>If $u = d$ and $p=q$ i.e. the game is even odds, $f^*$ is equal $0$. <strong>Do not bet if you don’t have an edge!</strong></li>
</ol>

<h2 id="simulations">Simulations</h2>
<p>Let’s now simulate a few trajectories where we bet $20$% of our wealth in each round. By the way, you can find the code for these plots <a href="https://github.com/adrianriv/blog-code/blob/master/kelly1/kelly1_simulations.ipynb">here</a>. Each trajectory shows our wealth across all 300 rounds of the game:</p>

<figure class="centered-figure">
<img src="/images/kelly1/kelly_paths_300_steps.png" class="center-image max-width-75" />
</figure>

<p>In the $y$-axis I’m using $log_2$, so a value greater than 0 means our wealth is larger than when we started, a value of 1 means we 2x our wealth, a value of 2 means we 4x it and so on, similarly a value of -1 means we lost half of it -2 means we lost $\frac{3}{4}$ of it etc. Focus on the values at 300 rounds, the green line is ~1 so in that trajectory we doubled our money, in the blue and purple trajectories we increased it by a factor of $2^{10} = 1024$, nice.</p>

<p>Notice however, that there is <strong>a lot</strong> of variance. Focus on the orange line, at round 50 you’ve 8x your wealth, you are ecstatic. Then by step 150 you have lost nearly 60 % of your initial wealth! Imagine starting with 100K, getting all the way up to 800K only to go back to 40K, really wild ride. Even knowing that you were betting optimally, would you have stomached it? Not sure I would have… This is why some people often don’t use full-Kelly and instead use half-Kelly, e.g. they bet $\frac{1}{2}f^*$, this results in lower variance and drawdowns, the cost is a slower rate growth in wealth.</p>

<p>After seeing the plot above I wondered if I’d made a mistake so I plotted a histogram of the final wealth when we play 100 rounds:</p>
<figure class="centered-figure">
<img src="/images/kelly1/distribution_of_wealth.png" class="center-image max-width-75" />
<figcaption>Distribution of $log_2$ final wealth after 100 rounds of the game using 4M trajectories.</figcaption>
</figure>
<p>The mean $log_2-$wealth was ~2.9 and $2^2.9 = 7.46$ which matches our expected growth factor. Notice the variance is huge, in ~18% of the trajectories you end up losing money. Additionally, there are some trajectories in which you end up with 1000 times more than what you started with!</p>

<p>It is important to remember that in this life we only live one trajectory, so gamble accordingly.</p>

<h1 id="the-cost-of-being-wrong">The Cost of Being Wrong</h1>
<p>Before we conclude, let me show you what happens when we are actually wrong about the probability of heads. Imagine that the actual probability of heads is .52, but we (for some reason) think it’s actually .6 so we decide to bet 20% of our wealth in every round, as Kelly says. This is what our wealth would look like in 10 trajectories:</p>
<figure class="centered-figure">
<img src="/images/kelly1/kelly_wrong_p.png" class="center-image max-width-75" />
</figure>
<p>There is only one lucky trajectory where we make money, in most of the other ones we are just setting our money on fire. So, if you are going to use full-Kelly make sure the parameters of the problem are what you think they are!</p>

<p><strong>Disclaimer</strong>: The content provided on this blog is for educational purposes only and is not intended to be financial advice. The views and opinions expressed here are solely those of the authors and should not be construed as professional financial advice. Readers are encouraged to consult with a qualified financial advisor before making any financial decisions based on the information provided on this blog.</p>]]></content><author><name></name></author><summary type="html"><![CDATA[Stable Diffusion XL: Coin flipping through the air, in motion, in the style of Dali's The Persistence of Memory]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/kelly1/coin_flipping_through_the_air_in_motion_in_the_style_of_Dalis_the_persistence_of_memory.png" /><media:content medium="image" url="http://localhost:4000/images/kelly1/coin_flipping_through_the_air_in_motion_in_the_style_of_Dalis_the_persistence_of_memory.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Why You Should Never Buy High Dimensional Watermelons</title><link href="http://localhost:4000/blog/2023/11/12/watermelons/" rel="alternate" type="text/html" title="Why You Should Never Buy High Dimensional Watermelons" /><published>2023-11-12T00:00:00-08:00</published><updated>2023-11-12T00:00:00-08:00</updated><id>http://localhost:4000/blog/2023/11/12/watermelons</id><content type="html" xml:base="http://localhost:4000/blog/2023/11/12/watermelons/"><![CDATA[<figure class="centered-figure">
<img src="/images/watermelons/high_dimensional_watermelon_oil_painting_cyberpunk.jpeg" alt="Stable Diffusion XL: High Dimensional Watermelon, Oil Painting, Cyberpunk" class="center-image max-width-50" />
<figcaption>High Dimensional Watermelon, Oil Painting, Cyberpunk</figcaption>
</figure>

<p>I was recently reading The Art of Doing Science and Engineering by Richard Hamming <a class="citation" href="#hamming2020art">(Hamming, 2020)</a>. In Chapter 9 he argues that most design problems scientists deal with involve working in $n$-dimensional space. Even though I deal with optimization and machine learning problems which can have very large number of parameters on a regular basis, Hamming’s book made me realize that I don’t have a great grasp on high dimensional objects. I may be able to visualize something in 3 dimensions, but as soon as I have to work on 4 I have to stop relying on visualization and must resort to using algebra, trigonometry, etc.</p>

<p><strong>In this blog post I will show that indeed, high dimensional objects are hard to reason about by exploring the following question: What fraction of the total volume of an n-dimensional sphere lies in its shell?</strong></p>

<p>I found the answer to be at odds with my intuition, hence this blog post.</p>

<h2 id="the-volume-of-n-dimensional-spheres">The Volume of $n$-dimensional Spheres</h2>
<p>We are concerned with computing the volume of high dimensional spheres. Before we dive into the details lets establish some notation. Let $n = 1, 2, …$ be the dimension of the space we are working in. Let  <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>S</mi><mi>n</mi></msub><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">{</mo><mi>x</mi><mo>∈</mo><msup><mi mathvariant="double-struck">R</mi><mi>n</mi></msup><mo>:</mo><mi mathvariant="normal">∥</mi><mi>x</mi><msub><mi mathvariant="normal">∥</mi><mn>2</mn></msub><mo>=</mo><mi>r</mi><mo stretchy="false">}</mo></mrow><annotation encoding="application/x-tex">S_n(r) = \{x \in \mathbb{R}^n: \|x\| _2 = r\}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.05764em;">S</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:-0.05764em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">∈</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68889em;vertical-align:0em;"></span><span class="mord"><span class="mord"><span class="mord mathbb">R</span></span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">∥</span><span class="mord mathdefault">x</span><span class="mord"><span class="mord">∥</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mclose">}</span></span></span></span>  be the $n$-dimensional sphere, $V_n$ be the volume enclosed by the sphere, and $A_n$ be its surface area.</p>

<p>Before we venture onto high dimensions lets review what we know in 1, 2, and 3 dimensions. In 1 dimension, $V_1(r)$ is just the length of the line segment $[-r, r]$, which is equal to $2r$. When n=2, from school you probably remember that the circumference of a circle of radius $r$ is $2 \pi r$. You also probably remember that its “area” (volume for us) is equal to $\pi r^2$, but why? This can be proved with some basic calculus. If you think about it, the volume of a circle can be computed by summing up the volumes of all the thin “shells” inside it, and each shell of radius $x$ has volume $2\pi x dx$. So</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>V</mi><mn>2</mn></msub><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo><mo>=</mo><msubsup><mo>∫</mo><mn>0</mn><mi>r</mi></msubsup><mn>2</mn><mi>π</mi><mi>x</mi><mi>d</mi><mi>x</mi><mo>=</mo><mi>π</mi><msup><mi>r</mi><mn>2</mn></msup><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
V_2(r) = \int_{0}^r 2\pi x dx = \pi r^2.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.22222em;">V</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.30110799999999993em;"><span style="top:-2.5500000000000003em;margin-left:-0.22222em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.326242em;vertical-align:-0.9119499999999999em;"></span><span class="mop"><span class="mop op-symbol large-op" style="margin-right:0.44445em;position:relative;top:-0.0011249999999999316em;">∫</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.414292em;"><span style="top:-1.7880500000000001em;margin-left:-0.44445em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">0</span></span></span></span><span style="top:-3.8129000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight" style="margin-right:0.02778em;">r</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.9119499999999999em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord">2</span><span class="mord mathdefault" style="margin-right:0.03588em;">π</span><span class="mord mathdefault">x</span><span class="mord mathdefault">d</span><span class="mord mathdefault">x</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.8641079999999999em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.03588em;">π</span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641079999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mord">.</span></span></span></span></span></p>

<p>Similarly, $V_3(r)$ can be computed by adding up the volume of all the 3-shells of radius $x$, $A_3(x) dx$, for $x\in [0, r]$. However, we don’t have an expression for $A_3(x)$, so we must do something else.</p>

<p>An alternate way of thinking about the volume of a $3$-dimensional sphere is to think of it as the sum of the volume of its “slices” where each slice is a thin disk. So once again, using calculus we will be able to compute the volume.
Our integral will integrate over $x\in [-r, r]$, and at every $x$ our volume will be $ \pi (r^2 - x^2) dx$ (The way I’m thinking of this integration is: draw in a piece of paper the circle $x^2 + y^2 = r^2$ and when you are at position $x$ you have a disk with volume $\pi y^2 dx$  sticking out of the page).
So</p>

<p>\begin{align}
V_3(r) &amp;= \int_{-r}^r \pi (r^2 - x^2) dx \cr
&amp;= 2 \pi \int_{0}^r (r^2 - x^2) dx \cr
&amp;= \frac{4}{3} \pi r^3.
\end{align}</p>

<p>Let’s recap what we have so far, we have shown that $V_1(r) = 2r$, $V_2(r) = \pi r^2$, and $V_3(r) = \frac{4}{3} \pi r^3$. So we should expect $V_n = C_n r^n$. But how do we find a general expression for $C_n$? Setting up the integral for $V_3$ required visualizing the 3-d sphere and its slices. However, I don’t trust my geometric intuition for setting up an integral for $V_4$ other than the “add up the shells” one <a href="Side Note 1">[Side Note 1]</a>. But as we saw when we tried to use this argument to compute $V_3$, we would need to have an expression for $A_3$, which we don’t have…</p>

<p>So, what now? I guess this is where being exposed to a wide variety of ideas/problems pays off, as people say: luck favors the prepared mind.</p>

<p>As you will see later in this post, we will be able to compute an expression for $C_n$ by making a connection with an integral that arises in probability. I must note that I did not make the connection myself, the ideas that follow are from Hamming’s book.</p>

<h2 id="the-gamma-function">The Gamma Function</h2>

<p>Let us divert our attention to the following integral, mathematicians refer to it as $\Gamma(n)$,</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">Γ</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>:</mo><mo>=</mo><msubsup><mo>∫</mo><mn>0</mn><mi mathvariant="normal">∞</mi></msubsup><msup><mi>x</mi><mrow><mi>n</mi><mo>−</mo><mn>1</mn></mrow></msup><msup><mi>e</mi><mrow><mo>−</mo><mi>x</mi></mrow></msup><mi>d</mi><mi>x</mi><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
\Gamma(n) := \int_{0}^{\infty} x^{n-1} e^{-x} dx.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">Γ</span><span class="mopen">(</span><span class="mord mathdefault">n</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span><span class="base"><span class="strut" style="height:0.36687em;vertical-align:0em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.326242em;vertical-align:-0.9119499999999999em;"></span><span class="mop"><span class="mop op-symbol large-op" style="margin-right:0.44445em;position:relative;top:-0.0011249999999999316em;">∫</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.414292em;"><span style="top:-1.7880500000000001em;margin-left:-0.44445em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">0</span></span></span></span><span style="top:-3.8129000000000004em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">∞</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.9119499999999999em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mord mathdefault">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.864108em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">n</span><span class="mbin mtight">−</span><span class="mord mtight">1</span></span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault">e</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.821331em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">−</span><span class="mord mathdefault mtight">x</span></span></span></span></span></span></span></span></span><span class="mord mathdefault">d</span><span class="mord mathdefault">x</span><span class="mord">.</span></span></span></span></span></p>

<p>If you are familiar with probability, you would notice that $\Gamma(n)$ is the $(n-1)$-th moment of a standard <a href="https://en.wikipedia.org/wiki/Exponential_distribution">exponential random variable</a>. Since $\Gamma(1)$ is just the integral of the pdf, we know that $\Gamma(1)=1$. If you were curious enough to compute $\Gamma(2)$, $\Gamma(3)$, $\Gamma(4)$, $\Gamma(5)$, $\Gamma(6)$ you would notice that the corresponding values are 1, 2, 6, 24, 120, which correspond to $1!, 2!, 3!, 4!, 5!$. So, it seems we’ve found a function that when evaluated at integers produces factorials! Let us prove this is the case.
Using integration by parts with $u=x^{n-1}$ and $dv = e^x dx$ we have:</p>

<p>\begin{align}
\Gamma(n) &amp;:= \int_{0}^{\infty} x^{n-1} e^{-x} dx \cr
&amp;= - x^{n-1} e^{-x} \big\vert_{0}^\infty - \int_{0}^{\infty} (n-1) x^{n-2} (-e^{-x}) dx \cr
&amp;= (-0 + 0) + (n-1) \Gamma(n-1) \cr
&amp;= (n-1) \Gamma(n-1).
\end{align}</p>

<p>Since we know that $\Gamma(1)=1$ we’ve shown that indeed when we evaluate the gamma function at the positive integers we will get factorials.</p>

<p>In my opinion this is a pretty magical result, and not sure how you would notice this pattern unless you had a lot of free a time to compute high order moments of probability distributions. After doing some digging around the history of the Gamma function, it turns out that the connection was not made the way I just implied. It turns out Leonard Euler, engineered this function (actually a variant of it) because he was trying to extend the definition of the factorial to the reals instead of just the positive integers. If you are interested in the history of the Gamma function, I highly recommend reading <a class="citation" href="#davis1959leonhard">(Davis, 1959)</a>.</p>

<h3 id="computing-gamma-frac12-">Computing $\Gamma( \frac{1}{2} )$</h3>
<p>Now let’s evaluate $\Gamma( \frac{1}{2} )$. Why at $\frac{1}{2}$? To be honest, I don’t know. I guess it makes sense since, with it, we could compute the value of $\Gamma$ at 1.5, 2.5, 3.5, … using the recursion $\Gamma(n) = (n-1) \Gamma(n-1)$. After all, Euler wanted to extend the factorial from the integers to the reals, so exploring what happens between two integers is reasonable.</p>

<p>Using the substitution $x = t^2$, $dx = 2 t dt$, we have</p>

<p>\begin{align}
\Gamma(\frac{1}{2}) &amp;:= \int_{0}^{\infty} x^{-\frac{1}{2}} e^{-x} dx \cr
&amp;=  2\int_{0}^{\infty} t^{-1} e^{-t^2} 2 t dt \cr
&amp; = \int_{-\infty}^{\infty} e^{-t^2} dt, \tag{1} 
\end{align}</p>

<p>where the last equality follows by the symmetry of $e^{-t^2}$ around $t=0$. Notice the term inside the integral resembles the pdf of a gausian random variable, except it’s missing some constants (that we know involve $\pi$). With this observation we should expect $\pi$ to appear soon, and with $\pi$ we should also think of circles and spheres. Now, how do we evaluate that integral? Hamming claims what follows is a standard trick but I certainly don’t remember it. Turns out its easier to compute $\Gamma(\frac{1}{2})^2$. Indeed:</p>

<p>\begin{align}
\Gamma(\frac{1}{2})^2 &amp;:= \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} e^{-(x^2 + y^2)} dx dy \cr
\end{align}</p>

<p>and with the $x^2 + y^2$ term you should think of the equaltion of a circle of radius $r$, $x^2 + y^2 = r^2$. This suggests changing to polar coordinates $x = r cos(\theta), y = r sin(\theta)$, remember the new differential is $\det(J) dr d\theta$ where $\det(J)$ is the determinant of the Jacobian, in this case $r$.</p>

<p>\begin{align}
\int_{-\infty}^{\infty} \int_{-\infty}^{\infty} e^{-(x^2 + y^2)} dx dy &amp;=\int_{0}^{2\pi} \int_{0}^\infty e^{-r^2} \det(J) dr d\theta \cr
&amp; = \int_{0}^{2\pi} \int_{0}^\infty e^{-r^2} r dr d\theta \cr
&amp;= \int_{0}^{2\pi} d\theta \int_{0}^\infty e^{-r^2} r dr \cr
&amp;= \int_{0}^\infty e^{-r^2} 2 \pi r dr \tag{this line is key!} \cr
&amp;=  \int_{0}^\infty \pi e^{-u} du \cr
&amp;= \pi.
\end{align}</p>

<p>We have shown that $\Gamma(\frac{1}{2}) = \pi^{\frac{1}{2}}$.
The key insight from this proof is that we related $\Gamma(\frac{1}{2})$ to an integral we could compute that involves only the radius $r$ and the volume of the shell of a sphere. Look again closely at “this line is key!”, the $e^{-r^2}$ is equal to $e^{-(x^2+y^2)}$ because of the equation for a circle, and $2 \pi r dr$ is $A_1(r)dr$ is the volume of a shell of radius $r$.</p>

<h2 id="an-expression-for-c_n">An Expression for $C_n$</h2>
<p>At this point we have everything we need to derive an expression for $C_n$. We will make use of the following facts:</p>
<ul>
  <li>$\Gamma(\frac{1}{2})$ can be writen as (1).</li>
  <li>The volume of a sphere is equal to the sum of the volume of all its shells, i.e. the volume element of a shell is  $A_n(r) dr = (\frac{d}{dr}V_n(r))dr = n C_n r^{n-1} dr$.</li>
  <li>The equation of an $n$-dimensional sphere of radius $r$ is equal to $x_1^2+x_2^2+…+x_n^2=r^2$.</li>
  <li>$\Gamma(\frac{n}{2}+1) = \frac{n}{2}\Gamma(\frac{n}{2})$, just plug in $\frac{n}{2}+1$ into the recurrence relation of the Gamma function to see this.</li>
</ul>

<p>So, using $r^2 = t$, $dr = \frac{1}{2}t^{-\frac{1}{2}}dt$</p>

<p>\begin{align}
\Gamma(\frac{1}{2})^n &amp;= \int_{0}^\infty e^{-r^2} A_n(r) dr \cr
&amp;= \int_{0}^\infty e^{-r^2} n C_n r^{n-1} dr \cr
&amp;= \int_{0}^\infty e^{-t} n C_n t^{\frac{n-1}{2}} \frac{1}{2} t^{-\frac{1}{2}}dt \cr
&amp;= \frac{n C_n}{2} \int_{0}^\infty t^{\frac{n}{2}-1} e^{-t} dt \cr
&amp;= \frac{n C_n}{2} \Gamma(\frac{n}{2})\cr
&amp;= C_n \Gamma(\frac{n}{2}+1).
\end{align}</p>

<p>Plugging in $\Gamma(\frac{1}{2}) = \pi^{\frac{1}{2}}$ and solving for $C_n$ we get</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>C</mi><mi>n</mi></msub><mo>=</mo><mfrac><msup><mi>π</mi><mfrac><mi>n</mi><mn>2</mn></mfrac></msup><mrow><mi mathvariant="normal">Γ</mi><mo stretchy="false">(</mo><mfrac><mi>n</mi><mn>2</mn></mfrac><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo></mrow></mfrac><mi mathvariant="normal">.</mi></mrow><annotation encoding="application/x-tex">
C_n = \frac{\pi^{\frac{n}{2}}}{\Gamma(\frac{n}{2}+1)}.
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07153em;">C</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:-0.07153em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:2.5550800000000002em;vertical-align:-1.0310000000000001em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.52408em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">Γ</span><span class="mopen">(</span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.695392em;"><span style="top:-2.6550000000000002em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">1</span><span class="mclose">)</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathdefault" style="margin-right:0.03588em;">π</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.84708em;"><span style="top:-3.363em;margin-right:0.05em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight"><span class="mopen nulldelimiter sizing reset-size3 size6"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.6915428571428572em;"><span style="top:-2.656em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mtight">2</span></span></span></span><span style="top:-3.2255000000000003em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line mtight" style="border-bottom-width:0.049em;"></span></span><span style="top:-3.384em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size3 size1 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.344em;"><span></span></span></span></span></span><span class="mclose nulldelimiter sizing reset-size3 size6"></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.0310000000000001em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mord">.</span></span></span></span></span></p>

<p>So, we are done finding a closed for expression for $C_n$, nice!</p>

<h2 id="the-answer">The Answer</h2>
<p>We finally get to answer the intriguing question: “Why You Should Never Buy High Dimensional Watermelons”!
We’ve shown that the volume of an $n$-dimensional sphere of radius $r$ is equal to $C_n r^n$ so the volume of an $n$ dimensional shell of thickness $\epsilon &gt; 0$ is equal to $C_n r^n - C_n ((1-\epsilon)r)^n$. It follows that the ratio of the volume of the shell to the volume of the sphere is:</p>

<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mrow><msub><mi>C</mi><mi>n</mi></msub><msup><mi>r</mi><mi>n</mi></msup><mo>−</mo><msub><mi>C</mi><mi>n</mi></msub><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>ϵ</mi><msup><mo stretchy="false">)</mo><mi>n</mi></msup><msup><mi>r</mi><mi>n</mi></msup></mrow><mrow><msub><mi>C</mi><mi>n</mi></msub><msup><mi>r</mi><mi>n</mi></msup></mrow></mfrac><mo>=</mo><mn>1</mn><mo>−</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>ϵ</mi><msup><mo stretchy="false">)</mo><mi>n</mi></msup></mrow><annotation encoding="application/x-tex">
\frac{C_n r^n - C_n (1-\epsilon)^n r^n}{C_n r^n} = 1 - (1-\epsilon)^n
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:2.263em;vertical-align:-0.8360000000000001em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.427em;"><span style="top:-2.3139999999999996em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathdefault" style="margin-right:0.07153em;">C</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:-0.07153em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.590392em;"><span style="top:-2.9890000000000003em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathdefault" style="margin-right:0.07153em;">C</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:-0.07153em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.07153em;">C</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.151392em;"><span style="top:-2.5500000000000003em;margin-left:-0.07153em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord mathdefault">ϵ</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.8360000000000001em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.72777em;vertical-align:-0.08333em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault">ϵ</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.7143919999999999em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight">n</span></span></span></span></span></span></span></span></span></span></span></span></p>

<p><a href="Side Note 2">Side Note 2</a>. Since $(1-\epsilon)^n \rightarrow 0$ as $n\rightarrow \infty$ regardless of how small $\epsilon$ is, the ratio of the volumes tends to 1 as $n\rightarrow \infty$. So, high dimensional watermelons are almost all rind and no flesh! Tough luck for high dimensional beings…</p>

<h2 id="side-notes">Side Notes</h2>
<h3 id="side-note-1">Side Note 1</h3>
<p>Side note from the day after writing the section above: I actually went to bed thinking about this and I woke up realizing that maybe I do have some intuition about how to set up the integral for $V_4(r)$. To compute $V_3$, I argued you could think of it as adding up slices where each slice is a disk. So if you think about projecting the 4-sphere to the 2-d plane you will have a circle, and if you slice the circle in 2-d at $x$, its high dimensional (spherical) slice will have volume $\frac{4}{3}\pi (r^2 - x^2)^{\frac{3}{2}} dx$. So $V_4(r) = \int_{-r}^r \frac{4}{3}\pi (r^2 - x^2)^{\frac{3}{2}} dx$. Using the same line of reasoning in higher dimensions we can write:</p>

<p>\begin{align}
V_n(r) &amp;= \int_{-r}^r V_{n-1}(r^2 - x^2) dx.
\end{align}</p>

<p>Computing the $V_4$ integral can be done via a trigonometric substitution and then using power reduction formulas. I’d say that you could now compute $C_n$ for any $n$ using the recursion for $V_n$ above. However we don’t really have a closed form solution for $C_n$ and I’ve never seen a way to “solve” the $V_n$ recursion.</p>

<h3 id="side-note-2">Side Note 2</h3>
<p>You probably noticed that in the section where we showed almost all the volume of the sphere is in it’s surface we did not use the expression for $C_n$. We could have derived this conclusion right after noticing that $V_n(r) = C_n r^n$ for some constant $C_n$. So, why did I go through all the trouble of deriving an epxression for $C_n$? Partly, because it was fun, and because I learned some new math tricks along the way. But also, in his book, Hamming notes that for spheres of radius 1, when $n=2k$, $C_{n}=\frac{\pi^k}{k!}$ so $V_{2k}(1) \rightarrow 0$ as $k\rightarrow  \infty$. Read that again $V_{2k}(1) \rightarrow 0$, the volume tends to 0! This may sound shocking, it’s not. The reason is because volume is not a dimensionless quantity, think of how much “larger” a cubic meter is compared to a (linear) meter. So, at least intuitively, in high dimensions, the dimension (as in $\text{meter}^n$) of the volume makes up for the small values of $C_n$.</p>

<!-- Hao Yu pointed out that we assumed V_n = C_n r^n but never showed it.
Proof of this is not trivial. Cleanest idea I've had so far is to show that the 
l-1 ball is contained inside the l2 ball which is itself contained inside the l-infinity ball.
That the l-infinity ball has volume: a r^n for all n is obvious, showing the l-1 ball is b r^n
is not that obvious. it is easy to see that the l-1 ball is composed of 2^n n-dimensional simpleces. 
But what is the volume of each of the simplices? Not trivial, but best answer ive found seems to be this one: https://math.stackexchange.com/questions/1718021/intuition-for-volume-of-a-simplex-being-frac-1n
or this other one (which argues using probability)
or this other one https://math.stackexchange.com/questions/3813429/find-the-volume-formula-of-a-simplex-proving-that-int-01-int-01-x-n-int?rq=1
(which argues using calculus).
Anyways, when you have time you should go and fix the post
 -->]]></content><author><name></name></author><summary type="html"><![CDATA[High Dimensional Watermelon, Oil Painting, Cyberpunk]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://localhost:4000/images/watermelons/high_dimensional_watermelon_oil_painting_cyberpunk.jpeg" /><media:content medium="image" url="http://localhost:4000/images/watermelons/high_dimensional_watermelon_oil_painting_cyberpunk.jpeg" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>