top of page
Arash Heidarian

Microsoft Stock Price Forecasting Using AICE

Updated: Jul 13, 2022





Introduction

In this post I show how I used AICE to predict Microsoft maximum stock price for 1 to 12 months ahead using AICE. if you have no clue what is AICE, I recommend to read my first post here.

In short, AICE (Artificial Intelligent Convergent Evolution) is a predictive algorithm, inspired by nature, convergent evolution. The algorithm is a multi-layer ensemble model, which takes historical data, selects right data, and derives valuable information out of them and can learn what is good and what is bad for its health, over the time, and improves itself. The model can be used for daily or monthly predictions, for any desired horizon (short, medium or long term).

I know predicting stock market look very ambitious. I wasn’t too sure if I want to showcase AICE power for the first time, on stock market prediction. We all know stock market fluctuations is not only influenced by companies’ assets and financial status, but world economical and political changes, can flip many things upside down in a night. During last year we have seen how lockdown policies to control Covid, or Ukraine war have surprised many investors in stock market. In this post I only use stock prices, but in my next post, I will also use News bias analysis too, to see if we can get a better prediction.


Motivation

In this post, I use Microsoft historical data, and the purpose is to predict maximum price per month. Why maximum monthly price? Well, last year I decided to make some minor investments in stock market. I realized that it requires lot of time and effort to analyze the market, reading News, checking all different financial and market indicators. That was time I started to think of using machine learning algorithms to make the life easier. I realized, if I want to keep the investment safe, quick, and easy, all I need to know, is whether the maximum price in next upcoming months will be higher or lower. All I wanted was to know, was:

  1. When to buy a share ? This month ? next month?

  2. If I buy a share lets say now, when would be a good time to sell it? How high the price could go in next upcoming months?

  3. The price fluctuates a lot in each month, if approximately I can see the monthly maximum price direction, I can be more confident to sell my share in next 3 months, or next 6 months! Shall I buy share from company X now ? Or the price will keep to drop up to next 3 months, so no buy from company X till next 3 months at least?

  4. Well having maximum price direction is good enough for me to start my investment, BUT if I can get even maximum prices predicted good enough (with low error rate), then, even I can set my buy/sell price per each month.

Considering these questions, I thought, well, what if I use AICE to predict the maximum price and minimum price for 1 to 12 months ahead. Then I know when to buy, when to sell and around how much?


Data

I downloaded Microsoft historical stock price from Yahoo Finance. The stock price datasets look like this :



I downloaded Microsoft daily stock price spreadsheet since Jan 2013 till April 2020. I passed the dataset to AICE, set my desired monthly aggregation to Max for AICE, and just waited for the prediction for 1 to 12 months ahead. AICE uses sophisticated methods to prepare the data and derive hundreds of features out of just limited given features/columns. I set the parameters as below, and that’s all I needed to do:

--company_name microsoft

--company_file_name MSFT.csv

--target_col close

--date_agg_level monthly

--aggregation_type max

--data_coverage_since 2013-01-01

--min_dataprep_date 2015-01-01

--max_dataprep_date 2020-09-01

--min_pred_date 2015-02-01

--max_pred_date 2020-09-01


Calculating Error Rate - MAPE

In order to interpret model accuracy or error rate, I decided to use Mean Absolute Percentage Error (MAPE) . MAPE can tell us how many percent the predicted error is different to actual. As an example, if actual value is 10, but predicted value is 110, the error rate here is 10%. Even if the predicted value is 9, the error rate is still 10%. So when we say error rate is 10% it means we are talking about MAPE. For those who love to see the calculations and examples, instead of reinventing the wheel, I suggest this link (great example) and this link (just Wikipedia).


Backtesting

Just in a case you are not familiar with back-testing term, according to investopedia backtesting is the general method for seeing how well a strategy or model would have done ex-post. Back-testing assesses the viability of a trading strategy by discovering how it would play out using historical data. If back-testing works, traders and analysts may have the confidence to employ it going forward.

For this work, we have done back-testing since Jan 2015 till Aprile 2021, for 1 to 12 months ahead predictions. We go through the results soon.


1-12 Months Prediction Backtesting Error Rates

The graph below shows median and average of error rate for 1-12 months ahead prediction. Obviously the further months ahead we predict, the higher error rate is expected. But I will show you that even though we see average error rates of above 7% since month 6th, we still get a reasonably handy and satisfactory price direction prediction.


Average and median MAPE error rate % for 1-12 months/horizons

Diagram below shows predictions vs actuals, and the dotted red line shows the MAPE error rate %, for 1 to 12 months. Have a look and I briefly explain how to interpret the graph.


1-12 months predictions vs actual with error rates (maximum price per month) - Each graph is marked with a number on top left, representing the horizon. For instance, when we look at the trend line for horizon 12, it means, every single value predicted in that graph, has been predicted using data from 12 months ago.

The diagram above shows how is prediction error rate and direction per each horizon. For instance, when we look at the trend line for horizon 12, it means, every single value predicted in that graph, has been predicted using data from 12 months ago. Let’s zoom in and have a closer look at horizon 12 in the graph below. The value for June 2021, has been predicted using data up to June 2020 (or in other words, in June 2020, we have used all available data to the date, to make prediction for June 2021).



12 months ahead predictions for maximum price per month

Another example is the graph below which shows 6 months horizon prediction. The value for December 2020, has been predicted using data up to June 2020 (or in other words, in June 2020, we have used all available data to the date, to make prediction for December 2020 which is 6 months ahead prediction).


6 months ahead predictions for maximum price per month

As we could see, for horizon 10,11 and 12, dotted red line (error rate) drops over the time. In these horizons, average and median error rate is high, and this drop of error rate over the time shows, the model learns from its mistake in past, and gets better and better. The other thing to notice is that, even though horizon 11 and 12 have high error rates, but the price directions have been predicted reasonably good.


1-12 Months Prediction from a certain date

So far we evaluated error rates and model accuracy for 1-12 months, over the course of five years (2016-2021), and we looked at separate graphs for each horizon. The other way of using the predations is to look at 1-12 months prediction since a particular date. It means, we want to see, if we are at Nov 2020, how the predictions would look like from Dec 2020 till Nov 2021. I have selected random dates and graphs below show how they look like. Based on my empirical analysis, I can see that we have four types of predictions:

  1. Error rate is good for closer horizons, and error rate goes higher when horizon gets further. Price direction is correct per majority of horizons.

  2. Error rate is high for all horizons, price direction is correct per majority of horizons.

  3. Error rate is low per majority of horizons, but price direction is not too reliable.

  4. Error rate is high and price directions are wrong in majority of horizons (this happens for early dates, where the model has been trained using limited data).



1-12 months price prediction as at Nov 2020

1-12 months price prediction as at Oct 2020

1-12 months price prediction as at June 2020

1-12 months price prediction as at Feb 2020

1-12 months price prediction as at Aug 2018

1-12 months price prediction as at Nov 2021

Summary

In this post, I showed how AICE can be used to predict maximum monthly price of Microsoft stock price for 1-12 months horizons. For backtesting, I applied AICE on five years of data (2016-2021), and I looked at the average and median error rates per each horizon. The results can be used in two different ways, either by looking at prediction graph of each horizon separately or looking at 1-12 months ahead prediction since a particular date. The result shows lower error rate on closer horizons, and error rates goes higher, as the horizon gets further. For further horizons like 11-12 months ahead predictions, even if the error rate is higher than average, we still can see the price directions are good enough to get a general idea what price we expect for the same month in next year. Stock price prediction is very ambituses as its volatility and fluctuations heavily relies on lot of external indicators and factors. However, I tried to apply AICE on this topic to show how AICE can deal with similar scenarios. In my next post, I will use AICE for demand forecasting. Remember, AICE is very easy to use. All you need to do, is to pass a dataset to it, and it generates the results for you.


125 views

Recent Posts

See All

Comments


bottom of page