You are here:Home/User Post/Article/Algorithm and Prediction for Artificial Intelligence, Time Series Forecasting,...
Algorithm and Prediction for Artificial Intelligence, Time Series Forecasting, and Technical Analysis
Some contents omitted
Hence, the graphical user interface within the Excel is not dedicated for the specific purpose. Since we provide this article for the educational purpose, we do not mind to use Excel with VBA application. If you want to use this Market Forecasting Algorithm for your trading, you probably have to use them for low frequency trading or long-term prediction only. Please use the Market Forecasting Algorithm at your own risk.
To start this tutorial, firstly, download Market Forecasting Algorithm Excel file from our website. Below is the download link to the zip file.
Unzip the Excel file and run the Excel file. In the Market Forecasting Algorithm, we provide the algorithms for the time series forecasting and the technical analysis. We do not provide the Artificial intelligence algorithm. There are some reasons for this. Model building practice for artificial intelligence is notoriously subjective. As we have mentioned in the third point, the artificial intelligence model requires the tedious optimization for both the weights and the architecture. The choice of final model tends to be highly subjective per user. We have learnt that high subjectivity is bad for our trading. For the day by day practical trading, its benefit might be limited in comparing to its downside like complexity and slow computation. If you really want to educate yourself with artificial intelligence, then we recommend starting with some free artificial intelligence applications. There are some free ones on the internet. For example, Weka and TensorFlow are the free artificial intelligence application.
Now let us start our tutorial with the downloaded Excel file. In your decompressed folder, run the Market Forecasting Algorithm Excel file.
Figure 15-1: Run the Excel file in the decompressed folder
In the Excel file, you can load the graphical user interface of the time series forecasting and technical analysis algorithm by clicking the two buttons in the main worksheet.
Figure 15-2: How to access the time series forecasting and technical analysis
You can also access the algorithm from the Excel Macro directly. This approach is useful when you want to use the time series forecasting and technical analysis in the worksheet with no buttons.
Figure 15-3: Access the algorithm without buttons
In the Macro list, choose Lunch_AM1 to use the technical analysis. Choose Lunch_AM2 to use the time series forecasting.
Figure 15-4: Macro List in Excel file
Before you start any computation with these algorithms, you need to add Solver Add-Ins and Technical Analysis in your Add-Ins list. If you do not add them in your Add-Ins list, then you can not use both time series forecasting and technical analysis. To add these Add-Ins, go to File >> Options >> Add-Ins in Excel 2013. Later version of Excel, this configuration might be different. On the bottom of Add-Ins page, find “Manage: Excel Add-Ins”. Click on “Go” button to see the Add-Ins list below.
Figure 15-5: Add-Ins List in Excel file
To add TechnicalAnalysis.xll file, click on “Browse” button. Choose TechnicalAnalysis.xll file.
Figure 15-6: Include Technical Analysis Add-In
After the two Add-Ins are included, you are ready to use both time series forecasting and technical analysis. When you click on the button for the technical analysis, the graphical user interface for technical analysis will be loaded. Then you will follow these five steps to compute the technical indicators for your data.
Step 1: Choose technical indicator from the list
Step 2: Edit indicator settings and click “Add Indicator” button
Step 3: Choose data range in your worksheet
Step 4: Check your data column arrangement in your data
Step 5: Finally, click on “Calculate” button
Figure 15-7: Graphical user interface for the technical analysis
Let us say that you want to apply Bollinger Bands with 50 period and RSI indicator with 20 period in your chart. The indicator setup will look like below.
Figure 15-8: Steps to add technical indicators
Then click the range button to select the data range in your worksheet.
Figure 15-9: Select data range in the worksheet
In this example, we will use Microsoft stock data. Start the first cell in the top left corner in your data and then drag your mouse until you include the last cell in the bottom right corner.
Figure 15-10: Drag your mouse from top left to bottom right of your data
After the data is selected, tick on the box “Heading included in the range”. Then check if you have chosen the right data format. For example, choose “DOHLCV” if your data is arranged in the order of Date, Open, High, Low, Close, and Volume. Finally, click on “Calculate” button. Now everything is done.
Figure 15-11: Click Calculate button
Now you will see the Bollinger Bands and RSI computed for Microsoft stock data. Now you might ask the question what happens if the data format is wrong. If you feed the data with wrong format, then the calculated value could be wrong too. Sometimes, it can throw error. In any case, we recommend keeping the data with the following order of Date, Open, High, Low, Close, and Volume (i.e. DOHLCV format). When volume is not available, you might just use Date, Open, High, Low, and Close (i.e. DOHLC format). However, some technical indicators can throw some errors if they require volume data in their calculation.
Figure 15-12: Chart with Bollinger Bands and Relative Strength Index
Now, we covered the basics. Here is four tasks you should perform to complete this tutorial. For each task, measure the time taken to complete the computation with stopwatch. Compare the computation time for these four tasks.
Task 1: Calculate Bollinger Bands with 200 data sets.
Task 2: Calculate Bollinger Bands with 800 data sets.
Task 3: Calculate Bollinger Banks, RSI, and CCI with 200 data set.
Task 4: Calculate Bollinger Banks, RSI, and CCI with 800 data set.
The Market Forecasting Algorithm Excel file provides more than 20 technical indicators. We added the 20 most popular technical indicators including Moving Average, Relative Strength Index, Commodity Channel Index, and so on. The training for these technical indicators is widely available on the internet. Hence, we will not cover how to use them in this article. For this tutorial, we also provide the data for Standard & Poor 500 index and EURUSD. You can always use some free data source like Yahoo Finance or Google Finance to get price data. If you want to perform your own analysis, then copy and paste those data in the order of Date, Open, High, Low, Close, and Volume. Make sure that heading row is placed on the top. Latest data should be placed on the bottom.
Next, we will move on to how to use the algorithm for the time series forecasting. The graphical user interface for the time series forecasting looks like below the screenshot. We provide the specific forecasting method called Exponential-smoothing methods. Exponential smoothing methods are the main workhorse in the forecasting industry. In the forecasting industry as in the demand forecasting and business forecasting, exponential smoothing is popular tools like the Moving average indicator and Relative strength index in the technical analysis. In addition, ARIMA (Autoregressive Integrated Moving Average) and GARCH (Generalized Autoregressive Conditional Heteroscedasticity) models are other popular tools widely used in practice. However, their theory tends to be more complex than the exponential smoothing methods. Neural Networks are often considered as the alternative forecasting method against these common forecasting methods.
Figure 15-13: Graphical user interface for time series forecasting
In the model selection stage, you can choose nine different exponential smoothing forecasting models.
Model 1: No Trend, No Seasonality
Model 2: Additive Trend, No Seasonality
Model 3: Damped Additive Trend, No Seasonality
Model 4: No Trend, Additive Seasonality
Model 5: Additive Trend, Additive Seasonality
Model 6: Damped Additive Trend, Additive Seasonality
Model 7: No Trend, Multiplicative Seasonality
Model 8: Additive Trend, Multiplicative Seasonality
Model 9: Damped Additive Trend, Multiplicative Seasonality
The price patterns of these nine forecasting models are shown in Figure 15-14. Probably the price pattern table will provide you better understanding on these models. However, both price pattern table and the nine forecasting model names fit together logically.
Figure 15-14: The original Gardner’s table to visualize the characteristics of different time series data (Gardner, 1987, p175)
Let us try to make forecasting for EURUSD close data. We will be using Damped Additive Model with no seasonality. The steps for time series forecasting is like below:
Step 1: choose forecasting model
Step 2: Select Data to forecast
Step 3: Finally, click on “Calculate” button
Figure 15-15: Choose right forecasting model for your data
After you have clicked on Data Range button, you need to select your data. Only include one colum since forecasting algorithm only requires one time series data. Never include more than one column. It will throw error. In fact, you can choose to forecast any data as long as they are time series data, recorded in the fixed time interval. With time series forecasting, you can even forecast Open price or Volume or Relative Strength Indicator, and so on if you wish. In this tutorial, we have chosen to forecase the Close price of EURUSD for simplicity.
Figure 15-16: Select one column to forecast
Then tick on the box “Heading included in the range” because we included heading row. When you do not include heading row, then untick on the box “Heading included in the range”. If you do it the other way around, then it will throw error. Finally, click the “Calculate” button.
Figure 15-17: Click on Calculate button
If you have done everything correctly, then you will get the chart with forecasting with prediction interval. Please note that sometimes, you might have to change maximum and minimum scales of the price axis manually to fit the lines in the chart.
Figure 15-18: Forecasting with Damped Additive Trend Exponential smoothing model
In the next example, we will try to forecast the airline passenger data. Airline passenger data is the textbook example with seasonality and trend. Here is the screenshot for your information.
Figure 15-19: Forecast with airline passenger data
If you have done everything correctly, then you will have a forecasting chart like this. This forecasting chart shows how the airline passenger data will look like in next 10 month. As you see, the forecasting model adapted the seasonal patterns in the data.
Figure 15-20: Forecasting with damped additive trend additive seasonal exponential smoothing model
Here are some tasks you should perform to complete this tutorial. Of course, measure the time taken to complete the computation for each task. For your information, Task 6 and 7 can take some time to complete the computation. Do not disturb the running macro until they are completed.
Task 5: Forecast EURUSD close data with 200 data sets using damped Trend model.
Task 6: Forecast EURUSD close data with 800 data sets using damped Trend model.
Task 7: Forecast EURUSD close data with 800 data sets using damped Trend model + Box-Cox transformation.
Compare the computation time for all seven tasks. You can answer the following questions. Question 5 may be skipped if you prefer.
Question 1: Which task provides the slowest computation time?
Question 2: Which task provide the fastest computation time?
Question 3: Why Task 4 is much faster than Task 6?
Question 4: Why do you think Task 6 and Task 7 have marginally different computation time?
Question 5: How slow or fast Artificial intelligence model, for example Deep Machine Learning, could be in comparison to Task 7 when the same amounts of data set are used?
One thing you should notice in this tutorial is that the algorithm for time series forecasting uses optimization. This is why it takes longer to complete the task. Solver Add-In does the optimization to estimate parameters of forecasting model. In the forecasting algorithm, we use the nonlinear GRG method, which is known for the “Generalized Reduced Gradient”. This is one of the convex optimizations, we have discussed. It is also possible to use genetic algorithm or simulated annealing instead of the nonlinear GRG method. However, the efficiency of optimization could be different marginally per each optimization method and per each mathematical model. Hence, you have to choose the right method if you want to save the computation time. Comparing to artificial intelligence model, the time series forecasting is light and fast. Hence, if you are going to use time series forecasting for financial market, the recommended practice is to make new forecasting model whenever new data is included. In artificial intelligence, they often retain the same model for reuse for some period. In time series forecasting, never retain old forecasting model for reuse. We will keep creating the latest forecasting with latest data available. This is the one of the benefit of time series forecasting methods due to its light and fast algorithm. In fact, time series forecasting is a comprehensive topic in the Applied Statistics. There are many practitioners of the time series forecasting across many different industries. For the choice of forecasting models, you might have to use some other forecasting textbook to cover the basics.
If you are looking for further tips to load TechnicalAnalysis.xll file, then please visit the link below: