Stocks or Gold? A Smart Investment Strategy to Help You Decide
Data-driven allocation between risk and safety
One of the biggest questions in the world of investing is knowing when to take risks – and when to retreat to safer assets. The strategy presented in this article aims to do exactly that: it helps determine when it’s better to be invested in riskier equities and when it’s wiser to switch to gold, the traditional safe haven during periods of financial stress.
To illustrate this, we use the S&P 500 Index, which tracks the performance of the largest U.S. companies, as a proxy for the stock market. This is represented by the SPY ETF, a widely used exchange-traded fund. For gold, we use the GLD ETF. The core idea of the strategy is to monitor stock market movements and detect whether the market is currently in a “calm” or “stressed” regime.
To do this, we turn to mathematics. Specifically, we observe how far the SPY ETF has fallen from its previous peak – a measure known in financial jargon as drawdown. This indicator reflects how much the market is currently struggling.
But identifying trends isn’t left to guesswork: we use a machine learning algorithm known as a Hidden Markov Model (HMM). This model analyzes historical drawdown patterns to classify the current market regime. It distinguishes between two states:
- Calm market: When stock prices are stable or rising gradually.
- Stressed market: When drawdowns are deep and uncertainty is high.
The model then determines asset allocation based on these signals:
- If the market is calm, allocate 80% to SPY and 20% to GLD.
- If the market is stressed, reverse the allocation: 80% to GLD, 20% to SPY.
Source: Yahoo Finance 01.01.2005-07.11.2025
How the Strategy Performs in Practice
The chart below illustrates how an investment would have evolved using this HMM-based strategy (red line), compared to a passive buy-and-hold approach in U.S. equities (SPY – grey line) or gold (GLD – yellow line). The red shaded areas show the periods when the model identified a stressed market and shifted the allocation toward gold.
Over the entire period, the HMM strategy outperformed both traditional “buy & hold” approaches. It delivered a strong gross annual return of 8.52% on average and significantly better risk-adjusted performance than portfolios fully invested in either stocks or gold.

Source: Yahoo Finance 01.01.2005 – 07.11.2025
Key market shocks, such as the 2008 global financial crisis, the 2020 COVID panic, and the 2022 sell-off triggered by the Russia-Ukraine war, were effectively navigated by the model. In each case, the algorithm moved into gold at the right time, reducing losses. During stable periods, it reallocated to equities to benefit from market rebounds.
What makes the strategy especially practical is that it doesn’t overreact or trade excessively. Instead of constant buying and selling, it maintains positions for longer periods – helping reduce transaction costs.
The following chart visualizes the actual portfolio allocation over time. The blue bars represent periods when the model favored stocks (SPY), while the orange areas show when gold (GLD) was the dominant investment.

Source: Yahoo Finance 01.01.2005 – 07.11.2025
A Simple Rule, Powerful Results
Capital markets are often unpredictable – but you don’t have to get lost in the chaos. A well-structured, data-driven strategy like this one not only helps weather turbulent times but also maximizes opportunities during growth phases.
The HMM-based approach combines machine learning, behavioral insights, and practical asset allocation in a way that offers investors an intelligent, rules-based framework. Whether you’re a seasoned investor or just starting out, it’s a powerful example of how data and technology can work together to support better investment decisions.
Jogi nyilatkozat: A blog üzemeltetője a VIG Befektetési Alapkezelő Magyarország Zrt., a szerzői az Alapkezelő munkavállalói. A weboldal kereskedelmi kommunikációt tartalmaz. A blogon megjelenő cikkek magánszemélyek szubjektív véleményét tükrözik, tájékoztatási céllal készülnek és nem minősülnek befektetési elemzésnek vagy befektetési tanácsadásnak és nem tartalmaznak befektetési ajánlást. A blog szerzői saját nevükben kereskedhetnek olyan pénzügyi és pénzeszközzel vagy más termékkel, amelyről az általuk készített cikk közöl tájékoztatást vagy véleményt. Bár a szerzők tőzsdei vagy tőzsdén kívüli kereskedés során szerzett tapasztalata a jelen blogon szereplő írásaikban is megjelenhet, de érdekeltség nem befolyásolhatja az általuk közölt tájékoztatást. A blogon megjelenő cikkekben, hírekben és tájékoztatásokban megjelenhetnek olyan társaságok, amelyek üzleti kapcsolatot tartanak fenn a VIG Befektetési Alapkezelő Magyarország Zrt.-vel vagy a blog szerzőivel akár közvetlenül, akár a VIG Group cégcsoportba tartozó más vállalkozáson keresztül. Jelen blogon megjelent cikkek nem tartalmaznak teljes körű tájékoztatást, és nem helyettesítik a befektetés megfelelőségének vizsgálatát, amelyet csak az adott befektető egyedi körülményeinek értékelésével lehet megállapítani. A megalapozott befektetési döntés meghozatalához kérjük, hogy részletesen és több forrásból tájékozódjon!
A VIG Befektetési Alapkezelő Magyarország Zrt., a blog szerkesztői és szerzői nem vállalnak felelősséget a blogon szereplő tartalom naprakészségéért, esetleges hiányosságaiért vagy pontatlanságaiért, valamint a blogcikkek alapján hozott befektetési döntésekért és a befektetési döntésekből származó bármilyen közvetlen vagy közvetett kárért vagy költségért.
