Skip to content

What I Found Cleaning Up My PhD Code

· 3 min

Trying to make my PhD code reproducible taught me more about it than writing the thesis did.

I rewrote three of my four empirical chapters in Python and put each on GitHub with documented notebooks and a README a stranger could follow. The thesis ran on R and EViews. My examiner wanted clearer figures. Python solved that and brought the code closer to what industry actually uses. The rewriting was straightforward. What I found during the process was not.

My thesis, Bitcoin in the Macroeconomic Landscape, uses three different VAR frameworks. The first two chapters tackle fairly specific questions: what drives Bitcoin price1, and whether Bitcoin returns have any measurable effect on CPI inflation across countries2. Both produced results that survived the cleanup.

The third chapter is the one I’m most proud of. Markets behave differently in crises than in calm periods, and a single-regime model gives you one set of coefficients for two different worlds. My Markov-Switching VAR identifies two regimes from the data. Bond yield shocks barely touch Bitcoin when markets are calm, but hit hard during crises. If this sounds like Hidden Markov Models, it is3.

Those are the three that made it to GitHub. The fourth didn’t.

When I reimplemented my EGARCH and DCC-GARCH models in Python with public data sources, some coefficients didn’t match what the thesis reported. Rather than publish code that contradicts the paper, I pulled it. I’m tracking down the discrepancy now.

That’s when I realized what open-sourcing actually is. It’s an audit.

My code was worse than I remembered. Hardcoded file paths. Uncommented magic numbers. A variable called temp2 that turned out to be critical for the entire analysis. I thought I understood this code. I wrote it. But translating it into Python a year later, I understood it differently.

I also had to rebuild one data pipeline because the original sources weren’t publicly available. The new sample ended up slightly different (2,031 vs 2,266 observations), but the core results held. That’s actually a stronger result: it means the findings aren’t an artifact of one dataset.

And I learned that a thesis examiner and a GitHub visitor are different audiences entirely. A thesis examiner has committed to reading your work. A GitHub visitor gives you 30 seconds. I rewrote each README three times.

Next: the full thesis goes on SSRN. Longer-term, I’m building a Regime-Switching Volatility Toolkit, a Python package for MS-GARCH estimation and out-of-sample forecasting. That’s a few months away.

If you’re a PhD student wondering whether open-sourcing your work is worth the time: it is. Not because someone will use your code, though they might. Because you’ll find things about your own research that you never would have found otherwise. My fourth chapter is proof. And if you find something broken, that’s the point.

The repos are at github.com/liefsun.


Footnotes#

  1. Seven macro/crypto variables, five policy dummies, Generalised IRFs so ordering doesn’t matter. The main finding: Google searches Granger-cause Bitcoin returns, and Bitcoin returns Granger-cause Google searches. Attention drives price drives attention. Repo: bitcoin-var-determinants.

  2. Bitcoin trades daily, CPI is monthly. Most studies just aggregate to monthly. I used a Mixed-Frequency VAR that preserves the within-month dynamics. Bitcoin returns Granger-cause CPI inflation in the US, South Korea, and Japan, about 7-11% of forecast error variance. Small, but no longer zero. Repo: bitcoin-inflation-mfvar.

  3. MS-VAR is an HMM with economic structure baked in: the hidden states are market regimes, the emissions are VAR residuals, and the transition matrix tells you how likely crises are to persist. Repo: bitcoin-regime-switching.