Stocks or Gold? A Smart Investment Strategy to Help You Decide

Pál Baranyi junior portfolio manager 2025. August 14.

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:

The model then determines asset allocation based on these signals:

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.

Legal Notice: The operator of this blog is VIG Asset Management Hungary and the authors are employees of the Asset Management Company. This website contains commercial communication. The articles published on the blog reflect the subjective opinions of private individuals, are prepared for informational purposes only, and do not constitute investment analysis or investment advice, nor do they contain any investment recommendations. The authors of the blog may trade in their own name in financial instruments, funds, or other products about which they provide information or express an opinion in their articles. While the authors’ experience gained in stock exchange or over-the-counter trading may be reflected in their writings on this blog, such interests must not influence the information they provide. Articles, news, and information on the blog may feature companies that maintain business relations with VIG Asset Management Hungary or with the authors of the blog, either directly or through another company belonging to the VIG Group. The articles published on this blog do not provide complete information and do not replace the assessment of the suitability of an investment, which can only be determined by evaluating the individual circumstances of the given investor. To make a well-founded investment decision, please seek detailed information from multiple sources.

VIG Asset Management Hungary, the editors, and the authors of the blog accept no responsibility for the timeliness, possible omissions, or inaccuracies of the content on the blog, nor for any investment decisions made on the basis of the blog articles, or for any direct or indirect damage or cost arising from such investment decisions.