Market Modelling with Nelder-Mead Optimisation in Python
Out of pure curiosity and in an attempt to hone my data analysis skills, I decided to write a program to find the best weighted-average of various economic parameters to predict stock market returns. To begin, I downloaded data from the Federal Reserve Bank of St. Louis's economic database, specifically 28 economic parameters that I arbitrarily chose, including Continued Claims (Insured Unemployment), Total Business Inventories, Moody's Seasoned Aaa Corporate Bond Yield, Federal Funds Effective Rate, GDP, Total Business: Inventories to Sales Ratio, Velocity of M2 Money Stock, 30-Year Fixed Rate Mortgage Average, Commercial and Industrial Loans, M1, M2, Producer Price Index by Commodity: All Commodities, and many more.
To find the best-weighted average, I used the Nelder-Mead algorithm, which is a commonly used optimisation technique that is particularly useful in high-dimensional spaces. Essentially, the algorithm works by creating a set of "vertices" that represent different solu…Thanks to ChatGPT for the info, I’m not going to pretend I understood any of it.
Despite my limited comprehension of the algorithm's inner workings, I ran 10 Nelder-Mead algorithms in parallel, each with different starting values, in an attempt to find the best local minimum. After just a few minutes of processing, processor 7 on my computer computed a weighted average with a correlation to the NASDAQ between 2021 and now of 0.9875616872944877. This is a significant achievement as the correlation was computed with a 2-month prediction time, indicating that the weighted average preceded the actual data by 2 months.
As part of an effort to evaluate the efficacy of the model and ensure that it is not simply an overfit with an attractive appearance, a subsequent training run was conducted using data only until January 2023. The aim was to verify if the model could correctly predict stock market performance for January, February, and March. To my surprise, the model performed well, closely tracking actual 2023 stock market data, with coefficients derived from earlier training data. This suggests that the model had sufficient training data from 2021-2022 to calibrate weights accurately and make successful predictions with a two-month buffer for the first months of 2023.
It's important to note that while this correlation is promising, the stock market is an incredibly complex system that cannot be accurately modelled using just 28 parameters. The idea that there is information out there that can accurately predict the stock price with a 2-month buffer time goes against the Efficient Market Hypothesis, which states that financial markets are efficient in processing and reflecting all available information in the prices of financial assets. Thus, the results of the model are unexpected and probably inconclusive. It is important to consider what factors may have influenced the model's performance, as well as the potential limitations and biases of the data used. I also believe the idea of a weighted average makes little sense in the context, as it assumes a linear relationship between all parameters. I will be working on implementing a genetic machine learning algorithm to find the best formula in the future. All limitations aside, this was a fun coding project for me to explore the idea of predicting the market with economic indicators. One always hears about fundamental analysis, so why not mathematically compute said fundamental analysis? I'm curious to see if the market will follow the prediction, and I will check back in 2 months.
Recommended by LinkedIn
Attached is a picture showing the correlation between the computed Weighted Average of the 28 economic indicators and the Market Data. Please note that the stock market data has been shifted by two months to better visualize the correlation. In reality, the Weighted Average precedes the stock data.
If you're interested in playing around with the code or examining the data, you can find all the relevant files at https://github.com/front-depiction/Nelder-Mead-Market-Modelling.git. Feel free to explore and tinker with the program as you wish!
TL;DR
Created a program to predict stock market returns using a weighted average of economic parameters. Used the Nelder-Mead algorithm to optimise the weighted average, achieving a correlation of 0.9875 with a 2-month prediction time. While promising, stock market prediction is complex and cannot be accurately modelled with just 28 parameters.
Awesome stuff Florien Lazaro !