Category Archives: Math

Notes on quantitative trading

I’ve been meaning to learn the math behind stock trading for a while, but I’ve found it’s hard to find quality information. Most of the stuff online is (1) non-technical, (2) trying to sell you something, or (3) both. So I decided to collect my own notes on modern portfolio theory (MPT). Here’s the pdf: Notes on Itô calculus and quantitative trading.

The information comes from various lecture slides and articles. I didn’t put specific references in there, since it’s standard, textbook stuff. Just search for any piece you’d like more information about.

Here is a rough outline:

  • How to select stocks, given their risk and return statistics
  • How to model risk and return in the first place

The first part takes the “Minimum Variance” approach due to Markowitz. To model stock prices, I give an overview of Itô calculus (one form of stochastic calculus) and geometric Brownian motion (GBM). This is the model used by the Black-Scholes formula for pricing derivatives.

I suspect that a simple index fund might beat a portfolio selected with this recipe. In the future, I’d like to test on historical data and find out if there really is an advantage to picking your own stocks.

Delivering bad news in O(N) time

Modified under a Creative Commons license. Source
Modified under a Creative Commons license. Source

I’ve invented a way to break bad news gradually, instead of all at once. Suppose there is a big question—“Are you breaking up with me?” or “Do I have hepatitis, Doc?” The traditional algorithm is decidedly O(1); the girlfriend or the doctor simply says “yes” or “no,” and the news is broken. It would be nice if we could delay the news, so that the answer became gradually more clear as time passed. Here’s a procedure to do just that.

At each timestep, the doctor (say) flips a coin and hides the outcome from the patient. If it is heads, he simply says “heads.” If it is tails and the patient has hepatitis, he says “heads.” If it is tails and the patient does not have hepatitis, he says “tails.”

Let’s analyze this from the patient’s point of view, supposing that both answers start out equally likely in his mind. That is, \mathrm{P(hep)}=\mathrm{P(no\ hep)}. Suppose there have been N timesteps. If the doctor ever says “tails,” then the patient knows he’s in the clear. So the interesting question is how the patient’s degree of belief changes when the doctor has said “heads” every time for N timesteps.

Using Bayes’s theorem and some algebra, you can show that \mathrm{P}(\mathrm{hep}|N) =\Big[\mathrm{P}(N|\textrm{no hep})+1\Big]^{-1}. In order to get N “heads” responses given no hepatitis, the coin would have to land heads-up N times. And we know that has probability (1/2)^N. After a line of algebra, we get

\mathrm{P}(\mathrm{hep}|N) =\frac{2^N}{2^N+1}.

This approaches 100% as N tends toward infinity, which is what we expected. On the other hand, if the patient doesn’t have hepatitis then we expect a “tails” to come up after only 2 timesteps.

How to make people angry about prime numbers

I discovered a new way to make people upset. Tell them, at an opportune moment, that the prime numbers are completely arbitrary because they would be different if we used a number base other than base-10. (Not just different representations, but different amounts as well.) This is, of course, completely wrong. Amounts themselves multiply just the same in any representation you want to use.

When your target objects, give them the following example:
Pick a prime number like 57, and put it in base 5. 5 squared is 25, so put 2 in the 25’s place to get 50, then put 1 in the 5’s place to get 55, then put 2 in the 1’s place to get 57 base 10 or 212 base 5. But look what happens if you multiply 34 and 3 in base-5:

prime2
Fig. 1 Definitely a prime number, I swear.

4 times 3 is 12 base 10, which is 22 base 5—carry the 2—then do 3 times 3 plus 2, which is 11 base 10 or 21 base 5, so all together you get 212.

My sincere apologies for this post go to Tom Lehrer, who wrote the song “New Math,” and Alexander Grothendieck, who invented the Grothendieck prime.