The Kelly Criterion Epiphany

Ah, newsletters. The junk mail of the internet. I was deleting them one by one when I stumbled upon Mark's weekly techno-babble. Mark, the kind of guy who still thinks "Bitcoin millionaire" is a unique personality trait. His latest email was about DyDX, a decentralized crypto exchange. "AI and blockchain, together at last," I read aloud, like a preacher announcing the union of peanut butter and jelly. It was destiny, or at least, destiny wrapped in a nerdy API.

Automating crypto trading with DyDX's API was like setting a Roomba loose in a casino. The idea was so tantalizing that I already pictured myself in a hammock, sipping piña coladas while my bots did all the work. Ah yes, the Silicon Valley dream: Make money while being incredibly lazy.

Writing a trading bot for DyDX was a rollercoaster. Picture coding while riding a mechanical bull, and you're halfway there. I felt like Tony Stark, but without the billion-dollar budget or the cool facial hair.

In comes the Kelly Criterion, the mathematically blessed formula promising not to lose money. It's like the seatbelt of trading. Exciting? No. Necessary? Absolutely. I integrated it into my bot, and the profits started trickling in. I was basically the Warren Buffett of DyDX, minus several zeros and the old age.

Trusting My Gut—The Taco Bell Syndrome

Unfortunately, using Kelly criterion, I felt that it behaves too conservatively. The profits come in slow at the beginning, and as the market is getting volatile, it grew even slower. At one point, it stopped trading altogether. I feel like I can do better that this stupid algo. It is time to go rogue!

There's something exhilarating about tossing the rulebook out the window and saying, "You know what, gut? You're driving this bus now." At the beginning, trusting my gut felt like hitting a winning streak in Vegas. Trades were going my way, and it seemed like I had discovered the secret sauce to crypto riches. I was on fire, or at least smoldering pleasantly. Profits started to pile up high.

But as any seasoned gambler—or Taco Bell connoisseur—will tell you, what goes up must come down. My gut began betraying me, like a late-night Taco Bell run. You know the drill: it tastes fantastic going down, but oh, you'll pay for it later. And pay I did. Before I knew it, trades were going sideways, profits were dwindling, and my account looked sicker than someone who'd just downed a Mystery Meat Burrito with extra hot sauce.

The thing about gut feelings is they're a lot like fast food: quick, easy, and with a risk of indigestion. My so-called instincts had led me down a path of financial diarrhea, and I was left scrambling for the metaphorical Pepto-Bismol. Each bad trade felt like another digestive betrayal, leaving me to wonder: could I ever trust my gut again?

The answer was a resounding "maybe, but not without a hefty dose of skepticism and a side of antacids." It was a hard lesson learned, but one that I could chuckle about in hindsight. After all, they say laughter is the best medicine, but when it comes to trading, I'd say it's a close second to never, ever ignoring the math again. Oh, Kelly please forgive me for doubting you.

The Fall—Murderous Monday

Then came the final coup-de-grace, the Murderous Monday. My portfolio did the Titanic—big, unsinkable, and then suddenly at the bottom of the ocean. Liquidated, like a bad smoothie. My $2,500 fund vanished overnight, and I was left contemplating my life choices.

But hey, I've bombed on stage as a amateur stand up before, so bombing in the crypto world? Just another Tuesday. #NoBigDeal! I was as determined as a dog chasing a laser pointer. "Back to the drawing board!" I announced to no one in particular.

I decided to put everything in a Jupyter Notebook because, let's face it, Jupyter is the Instagram of data science. It's where you share your best work, filter out the bugs, and pretend everything's perfect.

Here is my code


import pandas as pd
import numpy as np

from scipy.stats import bernoulli, binom

import datetime as dt
import altair as alt

def kelly(p):
    #Calculates the optimal fraction according to the Kelly criterion.
    sizing = np.round((p - (1-p)),2) 
    return (0 if sizing < 0  else sizing)

p = win
X = bernoulli(p)
print(f"Win Rate : {np.round(X.pmf(1),2)}")
print(f"Lose Rate: {np.round(X.pmf(0),2)}")

kelly_size = kelly(p)

print(f"Kelly Sizing: {kelly_size:.2%}")

X_samples = X.rvs(rounds)


I went back to the Kelly Criterion, humbled and slightly embarrassed. I even included a graph, because nothing says "I've learned my lesson" like a well-plotted line graph. "Listen up, folks!" I wrote. "If you don't have an edge—anything above a 52% win rate—you might as well bet on unicorns racing against flying pigs. Capisce?"


%%time

# Itertuples
bets =  np.sort(list(set([ kelly_size , 0.50, 0.25])))

#need to create a new dataframe here
return_df = pd.DataFrame()

for bet in bets:
    total = [initial_investment]
    if bet== kelly_size:
        return_cell = f"kelly ({bet:.0%})"
    else:       
        return_cell = f"{bet:.0%}"

    for row in df.itertuples():
        if row.outcome == 0:
            next_val = total[-1] - ( total[-1] * bet) 
        else:
            next_val = total[-1] + ( total[-1] * bet) 
        return_df.at[row.Index,return_cell] = np.round(next_val,2)
        total.append(np.round(next_val,2))


return_df = return_df.shift(fill_value=initial_investment)
return_df

Rising from Ashes

After documenting my DyDX saga in a Jupyter Notebook, I thought, "Why not share this mess with the world?" I mean, if people can get famous for eating a spoonful of cinnamon or planking in weird places, why not for losing money in crypto? I hit "Publish," and my notebook went live. Instantly, I became a minor celebrity in the DyDX community. Some hailed me as a hero for my transparency, while others treated me like a cautionary tale for their kids. "See, Timmy, this is why you should stick to Fortnite and leave crypto to the grown-ups."

Inspired by my newfound notoriety, I took to the stage during a local comedy night, armed with my DyDX anecdotes. "Anybody here trade crypto?" I asked, to which a few brave souls raised their hands. "Great! You'll understand when I say, trading crypto is like dating. It starts exciting, gets complicated, and usually ends in regret." The crowd roared. For the first time, my DyDX debacle was making people laugh for the right reasons.

Eager to rewrite my fate, I overhauled my bot. I named it "Phoenix," because, like me, it was rising from its own digital ashes. This time, the Kelly Criterion wasn't just a feature; it was the backbone. "Phoenix, meet Kelly. Kelly, meet Phoenix. Now, be nice to each other," I said, like a parent introducing a new pet to the family.

I joined DyDX Discord channels, Reddit threads, and even some very questionable Telegram groups. Some members were crypto philosophers, pondering the ethics of decentralization. Others were like weathermen, predicting market trends with about as much accuracy. And then there were the meme lords, whose entire trading strategy was based on the latest viral GIF. Ah, the internet—where wisdom and absurdity coexist in perfect harmony.

The Aftermath

Three months had passed since Phoenix's reboot, and it was time to take stock. I logged into my DyDX account with the kind of trepidation usually reserved for checking grades or texting an ex. To my surprise and immense relief, Phoenix had executed a series of successful trades. My account showed a recovery of about $1,000. It wasn't the jackpot, but it felt like finding a forgotten $20 bill in an old pair of jeans—multiplied by fifty.

The road to recovery was like a montage scene in an underdog sports movie. Imagine "Eye of the Tiger" playing in the background, but instead of Rocky Balboa punching meat, it's me staring at lines of code and sipping on endless cups of coffee. Phoenix, like its mythical namesake, had risen from the ashes of its former self. It was now a lean, mean, trading machine, executing trades with the precision of a sushi chef and the timing of a stand-up comedian.

While I was still in the red, something had changed: my confidence was buoyed, and my belief in the bot—and myself—was strengthened. For the first time in months, I felt like I was in control. It was as if the universe had given me a high-five, albeit a digital one. "Phoenix, you've done well," I told my screen, as if the bot could hear me. "But don't get cocky; we've got more mountains to climb."

And climb we would. With Phoenix's newfound success, I was more motivated than ever to fine-tune, optimize, and aim for new heights. The next phase of our journey was laid out before us, and it looked promising. I couldn't help but feel that the best was yet to come. After all, a phoenix doesn't just rise from the ashes—it soars.

What's Next? A GitHub Star or Hollywood Dreams

So, where do I go from here? Well, I'm working on a book, "The DyDX Diaries: How to Lose Money, Find Humor, and Maybe—Just Maybe—Get Rich in Crypto." Spoiler alert: It's a comedy. But wait, there's more! I've published my Kelly Criterion code on GitHub for the aspiring cryptopreneurs, the risk-takers, and the math nerds. You know, sharing is caring, especially when it can save someone else from a financial belly flop.

My next big leap? I'm linking Bayesian probability programming to Kelly sizing. Sounds like a mouthful, but think of it as creating a trading bot that's not just reactive, but also predictive. I'm talking Minority Report-level stuff, but for crypto trading. This bot won't just read the market; it will anticipate changes like a psychic with a crystal ball. Imagine a trader that can dodge market downturns like Neo dodges bullets in 'The Matrix.' As Neo once said, "When you're ready, you won't have to."

With these developments, my comeback story is shaping up to be epic. So epic that it might just catch Hollywood's eye. I can see it now: "From Liquidation to Levitation: The DyDX Diaries," a blockbuster hit starring an A-list actor struggling to capture my unique blend of nerdiness and cool (okay, mostly nerdiness). The climax? A real-time trade, executed by my futuristic bot, that turns the tide and makes me a crypto hero. Move over, 'The Social Network'; there's a new tech drama in town.

So stay tuned, because this journey is far from over. Whether it ends in a movie deal or just a really, really detailed Jupyter Notebook, one thing's for sure: it's going to be a story worth telling.