I spent the last few weeks improving and building a machine learning trading strategy for energy markets, which I started desember last year. Why? Because I wanted to prove to myself that I could take everything I’ve learned across physics, finance, and software engineering and build something real. I have learnt so much since desember.

The result? Mixed performance, tons of insights, and a much deeper understanding of why quantitative trading is harder than it looks.

Why Energy Markets?

This wasn’t a random choice. My Master’s thesis at UiO was on solar energy systems. I’ve spent years thinking about energy; how it’s produced, stored, and traded. When I started my quant finance studies at NHH, it felt natural to combine these interests.

Energy markets are fascinating from a quantitative perspective. They’re not like equities. They have physical constraints, seasonal patterns, geopolitical shocks, and genuinely bizarre supply-demand dynamics. Natural gas doesn’t care about your portfolio theory, it cares about whether Europe has enough storage for winter.

The Setup

I wanted to build something that showcased different parts of my skillset:

From my physics background: GARCH volatility modeling. I spent months on GARCH models for my thesis (Heston-Nandi option valuation), so I know these models inside out. Energy markets have volatility clustering; calm periods followed by explosive moves, which makes them perfect for GARCH.

From my finance background: Regime detection using Gaussian Mixture Models. Markets aren’t stationary. Sometimes they trend, sometimes they mean-revert, sometimes they just chop around. I wanted the strategy to adapt.

From my software engineering studies: Production-quality code. Proper modules, logging, testing, dynamic path management. The kind of code you could actually deploy.

The strategy trades five energy commodities: WTI Crude, Brent Crude, Natural Gas, Heating Oil, and Gasoline. It uses 147 engineered features per asset—momentum indicators, GARCH volatility forecasts, technical signals, and market context (VIX, US Dollar, yields).

Regime detection in action: GMM clustering identifies three distinct market states across WTI Crude’s 15-year history. The green “Medium Momentum” regime dominates (~60% of days), while red and blue regimes capture mean-reverting and trending periods.

The Research Process (Or: When Things Break)

Here’s what nobody tells you about building trading strategies: you’ll spend more time debugging data issues than writing clever algorithms.

Early on, Natural Gas was showing a 948% annual return with a -98% drawdown. Amazing and impossible. Turns out Yahoo Finance’s Natural Gas futures data (NG=F) has discontinuities from contract rollovers. Every month, when the front-month contract expires and rolls to the next month, you get artificial price jumps in contango markets.

I spent an entire day diagnosing this, eventually replacing NG=F with UNG (the United States Natural Gas Fund ETF), which handles rollovers internally. Boring? Maybe. But this is the reality of quantitative research. Data quality matters more than model sophistication.

The Results (The Honest Version)

I tested the strategy on out-of-sample data from 2023-2024. Here’s what happened:

Natural Gas: +2.5% annual return, but more importantly, +70% outperformance versus buy-and-hold. The strategy provided downside protection.

WTI Crude and Heating Oil: Small negative returns (-1.9% and -1.5%), but still outperformed buy-and-hold by 4% and 22% respectively. The strategy was less wrong than doing nothing.

WTI Crude performance over 2023-2024. Notice how the strategy (blue) tracks buy-and-hold (purple) closely in 2023, then diverges downward in 2024. The strategy took long positions during the wrong regimes. Trading signals (green/red bars) show the low-frequency nature—only 13 trades over two years.

Brent Crude and Gasoline: Got crushed. -13% returns. The strategy didn’t work here.

The full picture across all five assets. Natural Gas (green bars) was the only consistent winner. WTI and Heating Oil broke even. Brent and Gasoline lost badly. Notice how even losing strategies often outperformed buy-and-hold (bottom right chart)—the regime detection provided some downside protection.

This is not the success story I’d have liked to tell. But it’s an honest one.

What I Learned

1. Regime-Dependency is Real

The GMM clustering worked beautifully. It correctly identified three distinct market regimes (low/medium/high momentum) across 15 years of data. The problem? My Random Forest model learned patterns that were regime-specific.

WTI Crude and Heating Oil trend more consistently. Gasoline mean-reverts. Natural Gas does whatever it wants. A single model can’t handle all these dynamics equally well.

Production takeaway: Asset-specific models. Or at minimum, regime-specific position sizing.

2. Transaction Costs Kill Low-Frequency Strategies

At 0.1% transaction costs per trade and only 9-13 trades per asset over two years, costs eat a meaningful chunk of returns. High-frequency strategies can absorb these costs through volume. Low-frequency strategies need higher conviction signals or lower costs.

Production takeaway: Trade less or trade cheaper (direct market access, futures vs ETFs).

3. Backtesting is Not Enough

My backtest was clean: no look-ahead bias, proper train/test split, realistic costs. But it still doesn’t capture regime shifts that weren’t in the training data, geopolitical shocks (imagine backtesting pre-Ukraine war), or changing market microstructure.

Production takeaway: Live paper trading before risking real capital. Always.

4. Data Quality is Everything

I probably spent 40% of my time on data issues. The Natural Gas rollover problem. Ensuring feature/price separation to avoid leakage. Validating that momentum calculations didn’t peek forward. Not glamorous, but critical.

Production takeaway: Never trust data. Validate everything. Twice.

Why This Still Matters

Mixed results aside, this project demonstrates something important: I can build end-to-end quantitative research pipelines.

I can take a research idea (regime-adaptive momentum trading), implement it with proper software engineering practices (modular code, logging, testing), apply advanced quantitative methods (GARCH, GMM, ensemble ML), backtest it realistically, and interpret the results honestly.

In my conversations with people working at Danske Commodities, Statkraft, and other Nordic energy trading firms, this is exactly what they do. Research. Build. Test. Learn. Iterate.

Not every strategy works. But every strategy teaches you something.

The Technical Deep Dive

If you’re interested in the implementation details:

GARCH Volatility Forecasting: I used arch library’s GARCH(1,1) to generate conditional volatility forecasts for each asset. These forecasts became features in the ML model. Energy markets show strong volatility clustering, so GARCH was a natural fit.

Regime Detection: GMM with 3 components on momentum features. I tried different configurations (2, 3, 4 regimes) and found 3 gave the clearest separation. The regimes map to directional signals: low momentum → short, medium → flat, high → long.

Feature Engineering: 147 features per asset including multi-period momentum, realized volatility, RSI, Bollinger Bands, moving average ratios, plus market context (VIX, DXY, yield curve). I was careful to exclude price columns from ML features to prevent leakage.

ML Models: Random Forest as primary (robust, interpretable), with Gradient Boosting and LightGBM for comparison. 5-fold time series cross-validation during training. No hyperparameter optimization (yet); I wanted to see baseline performance first.

Backtesting: 20% position sizing, 0.1% transaction costs, no leverage. Trade on next day’s open after signal. Simple but realistic.

The full code is on GitHub if you want to dig deeper.

What’s Next

For this specific project? Probably nothing. It served its purpose—demonstrating capability and generating insights.

But the learnings feed into my next projects:

  1. Asset-specific models: Train separate Random Forests for each commodity instead of one universal model.
  2. Fundamental integration: Energy markets are driven by fundamentals. EIA inventory reports, OPEC production decisions, weather forecasts. These matter more than technical signals.
  3. Multi-timeframe confirmation: Don’t trade on daily signals alone. Confirm with weekly/monthly regime.
  4. Nordic power markets: My real target. Spot prices, forward curves, hydro reservoir levels, wind forecasts. This is where my energy physics background becomes a true differentiator.

Final Thoughts

Building this strategy taught me more than any course or textbook could. I learned GARCH theory in my thesis, but implementing it for real market data is different. I studied machine learning algorithms in lectures and projects, but debugging why a Random Forest overfits on Gasoline but works on WTI required new types of problem-solving.

The strategy didn’t make money. But it made me a better quantitative researcher.

And honestly? That was the point.

If you’re working in Nordic energy trading and want to talk about regime detection, GARCH model or something else that rocks your boat, reach out on LinkedIn or leave a comment below. I’m actively looking for quantitative analyst roles where I can apply this kind of thinking to real market problems.


Leave a Reply

Trending

Discover more from Convergence Point

Subscribe now to keep reading and get access to the full archive.

Continue reading