Australian (ASX) Stock Market Forum

Getting Started in Machine Learning for Trading

Why does a time series make it more difficult for machine learning? I don't really understand how they're teaching machine learning/AI to play video games or board games and it's nailing it after running overnight on thousands/millions of tries and by morning its better than any human, why can't that be done with trading, load as much history into it as you can and treat each day as a "level"(obviously intra-day data would be optimal) and let it go thousands or millions of times learning the different days, I know each day is different in trading but surely it would recognise patterns that we might not have noticed before or have a fair idea of what to expect from the training set?
 
Why does a time series make it more difficult for machine learning? I don't really understand how they're teaching machine learning/AI to play video games or board games and it's nailing it after running overnight on thousands/millions of tries and by morning its better than any human, why can't that be done with trading, load as much history into it as you can and treat each day as a "level"(obviously intra-day data would be optimal) and let it go thousands or millions of times learning the different days, I know each day is different in trading but surely it would recognise patterns that we might not have noticed before or have a fair idea of what to expect from the training set?
Hi TM --

Machine learning, as we will be using it, is a two step process.
1. Examine some data, looking for patterns that precede profitable trades. Fit a model to the data in such a way that the patterns are identified. For example, each day at the close of trading, identify whether the next day's close will be higher or lower.
2. Verify that the patterns persist. That they continue to exist in data that was not examined during development.

In many machine learning applications, such as determining / estimating / predicting whether a borrower will repay a loan or default, the data points are independent. Each data point is related to a single person and consists of his or her employment, residency, age, etc. We could write the data on slips of paper, one per person, put them in a big bowl, draw them out in any order, and treat them as being independent.

Time series data introduces a complication in that data points -- data for individual days -- are not independent. For one, we rely on comparisons between current data and previous data (did the RSI fall through 20?). For another, patterns that were profitable in the past may no longer be profitable. And, the data is very noisy (there may not be actual profit-indicating patterns -- it may all be noise).

So, in addition to the model fitting and validation process called for by the scientific process, the analysis of time series must take all of these extra issues into consideration. One of the concepts is "stationarity." My video, "The Importance of Being Stationary," might help:


Best regards
Howard
 
Hi TM --

Machine learning, as we will be using it, is a two step process.
1. Examine some data, looking for patterns that precede profitable trades. Fit a model to the data in such a way that the patterns are identified. For example, each day at the close of trading, identify whether the next day's close will be higher or lower.
2. Verify that the patterns persist. That they continue to exist in data that was not examined during development.

In many machine learning applications, such as determining / estimating / predicting whether a borrower will repay a loan or default, the data points are independent. Each data point is related to a single person and consists of his or her employment, residency, age, etc. We could write the data on slips of paper, one per person, put them in a big bowl, draw them out in any order, and treat them as being independent.

Time series data introduces a complication in that data points -- data for individual days -- are not independent. For one, we rely on comparisons between current data and previous data (did the RSI fall through 20?). For another, patterns that were profitable in the past may no longer be profitable. And, the data is very noisy (there may not be actual profit-indicating patterns -- it may all be noise).

So, in addition to the model fitting and validation process called for by the scientific process, the analysis of time series must take all of these extra issues into consideration. One of the concepts is "stationarity." My video, "The Importance of Being Stationary," might help:


Best regards
Howard


Hi Howard

Machine Learning -- Versus – AmiBroker Mechanical System

To get my head around the two systems am I correct assuming that they work completely different.

1. As with an AmiBroker mechanical system it searches for patterns that meets the condition of the Buy code

== whereas ==

2. Machine Learning looks for any pattern that precedes a profitable trade and once that pattern is repeatedly evaluated and found to be TRUE – then a Buy signal is generated.

In a nutshell what I'm fumbling to ask is – A mechanical system searches for a pattern specified in our Buy Formula and it generates a Buy Signal once that condition is met – whereas -- Machine Learning is looking for a multi-confirmed pattern that precedes a profitable trade and then a Buy signal is generated.

Meaning - Machine Learning is NOT looking for a 'specified pattern' as it's searches for ANY repeated pattern that end in a profitable trade.

Is this correct?
 
This is a Ducks explanation.

Amibroker can run systems tests on a pre defined formula,

Machine learning
Identifies patterns and learns how to improve the buy and sell signal by
Analysing data . It's a continuing process.

Systems are static.

Howard will make it sound really exciting and interesting.
 
Dudes. Traditionally systems are designed by decision trees.

If A = X and B = Y then do C else do D

ML is a collection of standard algos based on multiple statistical and modelling methods. Literally 10 to 100s of differant methods. Some simple like linear regression, some have some serious maths behind them like some of the Classification and Clustering algos. Very few of them have a direct link to tradition trading models though there is a ML algo based on decision trees.

Simple ML applications work very well with classifying data that is not time series. The classic ML data set is of 3 species of Iris.

Code:
Fisher's Iris Data
Sepal length    Sepal width    Petal length    Petal width    Species
5.1                     3.5              1.4                 0.2       I. setosa
4.9                     3.0              1.4                 0.2      I. setosa
4.7                     3.2              1.3                 0.2      I. setosa
7.0                     3.2              4.7                 1.4     I. versicolor
6.4                     3.2              4.5                 1.5      I. versicolor
6.9                      3.1             4.9                1.5      I. versicolor
etc
As you can see it's just rows of independent data.

Others that work very well are medical test data like cancer screen test or as Howard has mentioned credit scores. Where one row of data is not linked to what procced it or what will follow. And the difference between what you are trying to find is very clear as you can see by the Petal width in the above.

Market data is nothing like this. Every row of data is linked to what was behind it and what you are trying to predict is what is not yet seen. Even more so market data is very noisy as we all know. Most of the ML algo are just **** when you feed daily or intraday data and expect a result.

If you want to have a look at what algos are used one of the main collections are the Scikit-Learn algos,
http://scikit-learn.org/stable/

Screen Shot 05-04-17 at 08.05 PM.PNG
If you want to use these to force in market data you are going to have to be very smart and creative to make it work.

The algos probably hold the most promise in classification of market regimes etc rather than finding patterns.
 
This is a Ducks explanation.

Amibroker can run systems tests on a pre defined formula,

Machine learning
Identifies patterns and learns how to improve the buy and sell signal by
Analysing data . It's a continuing process.

Systems are static.

Howard will make it sound really exciting and interesting.

Hi Tech/a, and all --

Modeling data is exciting and interesting, in a nerdy sort of way.

Pardon me for repeating myself. I have already posted most of what follows in one or more ASF threads, but I'll make a few comments for the benefit of new readers.

1. In general, a system is a combination of a model and some data. The model consists of the rules, indicators, parameters, etc. The purpose of the model is to identify some aspect of the data -- often identification of patterns that are important to the person who will be using the system. Changing either the model or the data creates a new system.

2. We are developing trading systems. Assume it is a system to trade IBM stock using daily data. The data is the IBM price series (and perhaps volume), along with perhaps some auxiliary data series. The model is the set of rules that identify good times to buy and sell.

3. There are many -- dozens to hundreds -- of possible models templates. As simple as linear regression. As complex as deep neural networks. One of the possible models is decision trees.

4. The purpose of the system is to identify some important "signal" in the data. There are two general approaches. One. Compute some indicator, then see what happens later. Two. Identify some important events, then see what happened earlier.

5. Traditional trading system development platforms (including TradeStation, NinjaTrader, AmiBroker, WealthLab, etc) use a single model type -- decision tree. Traditional platforms are primarily of the "indicator first" approach.

6. Machine learning system development (such as those supported in scikit-learn or R) give the person developing the systems a very wide choice of models. Machine learning is primarily the "identify something important first" approach.

7. There is no general rule, and no way to determine in advance, which model will best identify the signal in a set of data. Try dozens and rank them. Single decision tree is rarely (in my experience, never) among the top performers.

8. Most trading systems tried and tested using either traditional or machine learning are worthless. The gold standard is use of the scientific method, including one-time testing of data that is more recent than that used to fit the model to the data.

Best regards, Howard
 
One more thing. Time series systems add a considerable complexity. They are not stationary. They are not static. They are dynamic. No matter how the system was developed (traditional platform or machine learning), there will be periods where the signal is clearly identified and can be profitably traded. And periods where it is inaccurate and is not profitable. We cannot tell whether a period of poor performance is a temporary loss of synchronization between the model and the data and will recover; or the first indications that the system is broken and will never recover. Prudent system management reduces position size in response to poor performance. The relationship between the recent trades and the safe position size that results in the highest wealth over a period of time is itself a system -- the trading management system.

Best, Howard
 
Hi Howard,
I see you recommended the course on ML from Dr. Andrew Ng's at Stanford Open Classroom.
Unfortunately, he works with a Windows version of Octave and I work in a Mac environment.
Do you know where I can find instructions to implement Octave for Mac in a way that would work within Dr Ng's course? Or if there is a forum or other communication channels for students of those courses?
Thanks,
Luis
 
Hi Howard,
I see you recommended the course on ML from Dr. Andrew Ng's at Stanford Open Classroom.
Unfortunately, he works with a Windows version of Octave and I work in a Mac environment.
Do you know where I can find instructions to implement Octave for Mac in a way that would work within Dr Ng's course? Or if there is a forum or other communication channels for students of those courses?
Thanks,
Luis
Do you mean GNU Octave? It's cross platform and so it works on Mac. https://www.gnu.org/software/octave/
 
Do you mean GNU Octave? It's cross platform and so it works on Mac. https://www.gnu.org/software/octave/
Thanks Indoril,
You're right, I asked about GNU Octave. I know there is a iOs version of it, but I'm not sure it'll work with the Openclassroom course. The course has a specific link from where download the Windows version that it's somehow linked to their servers, so you can lodge your exercises and get them corrected.
Anyway, I'll install it and give it a try.
Thanks
 
Is not data an issue? What data, where to get it, data authenticity, cost, readily available and all data or partial data.

How long before there's a point-and-click retail version of machine learning software? Something like Watson's Analytics for financial markets?
How would you use 'Watson Analytics' by IBM?
 
There are already two at least, retail machine learning platforms for trading.....been out for years.
 
Interesting research ...
 

Attachments

  • TakeuchiLee-ApplyingDeepLearningToEnhanceMomentumTradingStrategiesInStocks.pdf
    263.8 KB · Views: 15
I would be very skeptical about the ultimate usefulnessof such material. At best they are extreme oversimplification of the problems leaving you with a big hole in your applications and knowledge.

At the other end some are straight ripoffs. Like paying someone to teach you how to do a MA cross system and saying thats what hedge funds do!

Screenshot_2017-08-06-12-14-37-1.png
 
One more thing. Time series systems add a considerable complexity. They are not stationary. They are not static. They are dynamic. No matter how the system was developed (traditional platform or machine learning), there will be periods where the signal is clearly identified and can be profitably traded. And periods where it is inaccurate and is not profitable. We cannot tell whether a period of poor performance is a temporary loss of synchronization between the model and the data and will recover; or the first indications that the system is broken and will never recover. Prudent system management reduces position size in response to poor performance. The relationship between the recent trades and the safe position size that results in the highest wealth over a period of time is itself a system -- the trading management system.

Best, Howard
Thank you for your excellent series of posts in this thread!

Your web site videos and articles were greatly appreciated.

You have motivated me to learn the Python 3 language and to investigate some machine learning algorithms that may be useful for stock price movement prediction.

Your suggestions re holding stocks for 1 to 5 days was an eye-opener!

My Python program can now get and preprocess 20 years of price and volume data: is this time frame necessary or should I focus just on more recent data?

I have implemented some xgboost models (uses trees) and some Deep Neural Network models using keras as these two machine learning models seem to feature in the winning entries of many of the data prediction competitions (eg Kaggle).

I am currently pondering as to which features I could test with a view to being included in a model.
There are a plethora of simple and exponential moving averages but I am assuming their signals are already factored into the stock price and are unlikely to lead to an edge.

If you are still active on this site I would be grateful for any advice.
 
I haven't seen or heard from Howard in a long time. Last time i spoke to him he had stopped trading.

Personally i use RSI().
I also use c/ma(c,X) a lot ( in almost everything ), usually as a series to add a momentum input.

The 2 examples are auto normalising formulas, hence they will work on a variety of different instruments and classes. So to answer your question fully, use any indicator that self normalises, it makes life easier.

The timeframes you need to use are a LOT faster than what you would as a system trader. RSI() i would use 2 -> 5 on a daily. But there is no reason why you can't throw ALL of them in. The model should work out which is relevant and which isn't.

In that vein, any indicator that you overlay on a price chart ( bollinger bands, moving averages etc ) are out OR if you really want to use them you have to normalise them to the underlying price somehow.

You also need to input the underlying market as an input. This becomes another complex can of worms.

In terms of models I like Neural networks better. Most quants prefer trees because they can create a human readable system. THIS IS NOT THE POINT OF ML. More edges can be gained from ML models by finding patterns that humans can't and NN's are more adept at finding patterns. Trees are just repeating a process that quants have been working on for years.
 
Top