Machine learning is a broad part of artificial intelligence, exploring algorithms that can learn. Machine learning is useful when we don’t know the specific algorithm for solving a problem; such problems can be related to text recognition, prediction of customer behaviour (e.g. churn predictions, lifetime-values etc), stock analysis, medical diagnoses and many others.

A lot of these problems we solve everyday using more traditional accounting methods, but automating the solution using conventional sequential computer algorithms is impossible or vastly expensive.

Generally speaking, learning algorithms are divided into two broad groups - a supervised and unsupervised approach, but we will in fact also consider learning algorithms with reinforcement.

In this post we’ll be discussing portfolio optimization using more conventional supervised methods and in the next we will discuss the more complicated reinforcement learning algorithms.

Let's first talk about training with a “teacher”, known as supervised learning.

# Supervised Learning

We use a few known examples of situations/problems to "teach" the algorithm the correct response/solution that we want. In most cases, while we know there is some correlation between the data and the response, the exact relationship is unknown or too labor intensive to find out for every case.

We use this type of Machine Learning, when we have a relatively small set of labelled data - with "situation, answer" pairs [this is known as the training sample]. Based on this learning, we want to predict the answers for new data automatically.

## Supervised Learning in Investment

Let’s consider, a typical problem where supervised learning solutions would be helpful - "making an investment decision on the financial market."

In this task, the ability to make good predictions turns directly into profit.

Typically, a broker tries to forecast the future price of stock, based on a mixture of experience, knowledge, and conventional data analysis. By correctly predicting the direction of future price changes, the broker can garner profit.

We can attack the automation of good trading strategies as a classification problem - a particular sub-category of machine learning.

In the simplest case, we try to classify a given stock into three classes, corresponding to possible solutions:

## Information that can we use to educate the algorithm:

- Training data for customizing trading strategies:
- the historical data of the movement of prices and volumes for a period of time;
- the rate of inflation;
- profitability;
- currency fluctuations
- and anything that might correlate to the nuances of the problem.

By learning from this training data, we can create an automatic algorithm to buy and sell hundreds of stocks a second without any need for human interaction.

In particular, modern stock market technical analysis has hundreds of parametric and non-parametric trading strategies, with parameters adjusted by the criterion of maximum profit in the selected interval of history.

Standard algorithms that are usually used in supervised learning:

- K-Means,
- Linear and Logistic Regression
- Random Forest, Neural Nets, and SVMs for classification and regression problems

## How to Determine a Good Algorithm

Since a raw accuracy prediction is less important than the best profit maximisation strategy, we can construct backtesting algorithms using hold-out sets of the data to test our model on a portfolio of stocks on which you have data.

By basically holding out the last year’s worth of labelled data in the training phase, we can use our classification algorithm and see how much profit we would actually have made.

## Final Thoughts

We have discussed supervised machine learning and how a simple classification problem can be used to solve one of the most common financial tasks of stock prediction. By using rigorous back-testing, we can construct an optimized algorithm to generate the most profit from a portfolio of stocks in this way.

In the next financial post, we’ll be looking at a more complicated example where algorithms learn from their environment without need for a specifically labelled training set. This is hugely useful where we, as humans, might not even know the optimal strategy to take to maximize a portfolio’s profit.