Select Language

Tree Ensemble Methods for Two-Asset Portfolio Optimization: A Machine Learning Case Study

Analysis of applying Random Forest and XGBoost to forecast S&P 500 and USD/GBP using macroeconomic data for constructing optimal two-asset portfolios.
forexrate.org | PDF Size: 1.0 MB
Rating: 4.5/5
Your Rating
You have already rated this document
PDF Document Cover - Tree Ensemble Methods for Two-Asset Portfolio Optimization: A Machine Learning Case Study

Table of Contents

1. Introduction

This study addresses the challenge of constructing an optimal two-asset investment portfolio using machine learning techniques. The research focuses on a portfolio consisting of the S&P 500 stock index and the USD/GBP currency pair. The primary objective is to leverage macroeconomic data at monthly and quarterly frequencies to forecast these assets' returns using tree ensemble methods—specifically Random Forest and XGBoost. These forecasts are then used as expected return inputs for modern portfolio theory (MPT) optimization. A secondary aim is to identify which macroeconomic variables exert significant influence on the forecasts. The study critically examines whether a portfolio built on ML-estimated data diverges meaningfully from one constructed using simple historical averages.

2. Methodology & Data

2.1 Data Collection & Preprocessing

The analysis utilizes time-series data for the S&P 500 index and the USD/GBP exchange rate. A suite of macroeconomic indicators is collected as potential predictive features, which may include variables such as interest rates, inflation indices, industrial production figures, and unemployment rates, sourced from databases like FRED. The data is split into training, validation, and test sets, with careful attention to avoiding look-ahead bias. Features are normalized or standardized as required by the models.

2.2 Tree Ensemble Models: Random Forest & XGBoost

Two advanced ensemble learning algorithms are employed for time-series forecasting:

These models are chosen for their ability to handle non-linear relationships and complex interactions among macroeconomic variables without stringent parametric assumptions.

2.3 Portfolio Construction Framework

The forecasted returns from the ML models serve as the expected return vector $\mu$ in the Markowitz mean-variance optimization framework. The portfolio weights $w$ for the two assets are determined by solving the optimization problem that maximizes the Sharpe ratio or minimizes variance for a target return. The covariance matrix $\Sigma$ is typically estimated from historical returns. The performance of the "ML-based portfolio" is then compared against a benchmark portfolio constructed using historical average returns.

3. Experimental Results & Analysis

3.1 Forecasting Performance

The tree ensemble models demonstrated a statistically significant ability to forecast the directional movement and, to a lesser extent, the magnitude of returns for both the S&P 500 and USD/GBP. Evaluation metrics such as Mean Absolute Error (MAE), Root Mean Square Error (RMSE), and directional accuracy were reported. XGBoost often showed a marginal edge over Random Forest in terms of predictive accuracy, particularly on the quarterly data, likely due to its more sophisticated boosting mechanism and regularization.

3.2 Portfolio Performance Comparison

Chart Description: A comparative line chart would show the cumulative returns of three portfolios over the out-of-sample test period: 1) The ML-forecast-based optimal portfolio, 2) The historical-mean-based optimal portfolio, and 3) An equally weighted benchmark.

The results indicated that the portfolio constructed using ML forecasts achieved a superior risk-adjusted return profile (higher Sharpe ratio) compared to the portfolio based on historical averages. The asset allocation weights between the S&P 500 and USD/GBP also differed meaningfully, suggesting the ML models captured time-varying expected returns that simple historical averages could not.

3.3 Feature Importance Analysis

Both Random Forest and XGBoost provide native feature importance scores. The analysis revealed that for the S&P 500, leading indicators like term spreads, consumer sentiment, and prior equity market volatility were among the top predictors. For USD/GBP, interest rate differentials, trade balance data, and broader dollar index movements were most influential. This insight is valuable for economic interpretation and model simplification.

4. Key Insights & Discussion

Core Insight

The paper's most compelling argument isn't that ML can beat the market—it's that even modest, explainable improvements in forecasting via tree ensembles can materially shift efficient frontier calculations for a simple two-asset portfolio. This challenges the passive "set-and-forget" allocation dogma for long-term investors in non-equity/bond mixes.

Logical Flow

The research logic is sound: 1) Use robust, non-parametric ML (RF/XGBoost) to digest macro data into return forecasts, sidestepping linear model pitfalls. 2) Feed these forecasts into the classical Markowitz engine. 3) Validate that the output portfolio differs from a naive historical benchmark. The flow from macro drivers to asset forecasts to portfolio weights is clear and replicable.

Strengths & Flaws

Strengths: Pragmatic focus on a tractable two-asset case enhances clarity. Using tree models provides inherent non-linearity and feature importance, adding economic interpretability often missing in deep learning finance papers. The comparison to a historical-mean baseline is fair and relevant.

Flaws: The elephant in the room is covariance estimation. The study uses historical covariance, which is notoriously unstable. An ML-forecasted covariance structure could be a logical next step but is absent. The two-asset simplification, while a strength for clarity, limits the diversification benefits ML could unlock in a multi-asset context. Transaction costs and the practical feasibility of monthly/quarterly rebalancing based on these signals are not addressed.

Actionable Insights

For practitioners: Don't overlook simple ensemble methods like XGBoost for return forecasting; they can be more robust and interpretable than neural nets for structured macro/financial data. The identified key macro drivers (e.g., term spreads for equities, rate diffs for FX) should be top-of-mind for analysts monitoring these asset classes. This approach is most justifiable for institutional investors or sophisticated individuals who can systematically implement and rebalance such a strategy, not for retail traders seeking short-term alpha.

5. Technical Details & Mathematical Framework

The core of the portfolio optimization is the Markowitz mean-variance model. The objective is to find the weight vector $w$ that solves one of two problems:

Maximum Sharpe Ratio:
$\max_{w} \frac{w^T \mu}{\sqrt{w^T \Sigma w}}$
subject to $\sum_i w_i = 1$, and potentially $w_i \ge 0$ for no short-selling.

Minimum Variance for Target Return $R_p$:
$\min_{w} w^T \Sigma w$
subject to $w^T \mu = R_p$ and $\sum_i w_i = 1$.

Where $\mu$ is the vector of expected returns (forecasted by RF/XGBoost) and $\Sigma$ is the covariance matrix of returns. The tree ensemble models themselves work by creating a set of $M$ trees (for Random Forest) or sequentially built trees (for XGBoost) that map input features $x$ to a predicted return $\hat{y}$. For a Random Forest, the prediction is an average: $\hat{y} = \frac{1}{M} \sum_{m=1}^{M} T_m(x)$. XGBoost's prediction is an additive model: $\hat{y} = \sum_{k=1}^{K} f_k(x)$, where each $f_k$ is a tree from the functional space $\mathcal{F}$, and the model is trained by minimizing a regularized objective: $\mathcal{L}(\phi) = \sum_i l(\hat{y}_i, y_i) + \sum_k \Omega(f_k)$, with $\Omega(f) = \gamma T + \frac{1}{2}\lambda ||w||^2$ controlling complexity.

6. Analysis Framework: Example Case

Scenario: An investment fund wants to allocate between US equities (proxied by SPY ETF) and the GBP/USD exchange rate (proxied by a forex position) for the next quarter.

Step 1 - Data Preparation: Collect the past 10 years of monthly data for SPY returns, GBP/USD returns, and 20 macroeconomic variables (e.g., US CPI, UK CPI, Fed Funds Rate, BoE Rate, US-UK 10Y yield spread, VIX, etc.). The target variable is the next period's return. The most recent 2 years are held out as a test set.

Step 2 - Model Training & Forecasting: Train an XGBoost model on the training data to predict SPY returns and a separate model for GBP/USD returns. Use hyperparameter tuning (via cross-validation) for parameters like `max_depth`, `learning_rate`, and `n_estimators`. Generate one-step-ahead forecasts for the test period.

Step 3 - Portfolio Optimization: For each month in the test set, use the XGBoost forecast as $\mu$ and the trailing 3-year historical returns to calculate the covariance matrix $\Sigma$. Solve for the tangency portfolio (max Sharpe ratio) weights.

Step 4 - Backtest & Evaluation: Calculate the cumulative return, volatility, and Sharpe ratio of the dynamically rebalanced ML-based portfolio. Compare it to a static 60/40 portfolio and a portfolio using historical average returns for $\mu$.

7. Future Applications & Research Directions

8. References

  1. Ahmed, N. K., Atiya, A. F., Gayar, N. E., & El-Shishiny, H. (2010). An empirical comparison of machine learning models for time series forecasting. Econometric Reviews, 29(5-6), 594-621.
  2. Breiman, L. (2001). Random forests. Machine Learning, 45(1), 5-32.
  3. Chen, T., & Guestrin, C. (2016). XGBoost: A scalable tree boosting system. Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 785-794.
  4. Markowitz, H. (1952). Portfolio selection. The Journal of Finance, 7(1), 77-91.
  5. Pham, H. (2025). [Relevant work on equity/bond strategies cited in the PDF].
  6. Ţiţan, A. G. (2015). The efficient market hypothesis: Review of specialized literature and empirical research. Procedia Economics and Finance, 32, 442-449.
  7. Zhu, J. Y., Park, T., Isola, P., & Efros, A. A. (2017). Unpaired image-to-image translation using cycle-consistent adversarial networks. Proceedings of the IEEE International Conference on Computer Vision, 2223-2232. (Cited as an example of a seminal ML architecture paper for conceptual reference).