Skip to content
All library documents

Portfolio Optimization with Historical Returns and Moving Average Signals

Article MQL5 articles

Summary

The article describes portfolio allocation in Python and MQL5 using historical daily prices from MetaTrader 5. Its Python example calculates asset returns, estimates average returns and covariance, then maximizes expected return minus a variance penalty under fully invested, long-only constraints. It plots the resulting weights and shows an example allocation concentrated in Amazon for the stated 2023 sample.

It then applies a moving average crossover signal and scales each asset’s returns by the prior-period position before optimizing again. The example still favors Amazon, with changed expected return and reported risk, which the article attributes to that asset’s strong trend during the sample. The article advocates comparing assets and applying risk management, but offers limited validation: the example uses one historical period and does not assess out-of-sample performance, transaction costs, or robustness. Its MQL5 section is truncated in the supplied text, so the implementation details and comparability of the two versions cannot be fully assessed.

Key ideas

  • The Python workflow estimates mean returns and covariance from historical daily prices before optimizing portfolio weights.
  • The optimization maximizes expected return less a variance penalty, with weights constrained to sum to one and remain nonnegative.
  • A moving average crossover can be used to adjust asset returns before portfolio optimization.
  • The example’s concentration in Amazon is attributed to its strong trend over the sample period.
  • A single historical example does not establish that the allocation method will generalize to future markets.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.