13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

277

This motivates the concept of a loss function, which quantitatively compares the difference

between the true values with the predicted values.

Assume that we have created an estimate ˆf of the underlying relationship f. ˆf might be a

linear regression or a Random Forest model, for instance. ˆf will have been trained on a particular

data set, τ, which contains predictor-response pairs. If there are n such pairs then τ is given by:

τ = {(x 1 , y 1 ), ..., (x n , y n )} (20.2)

The x i represent the prediction factors, which could be prior lagged prices for a series or

some other factors, as mentioned above. The y i could be the predictions for our stock prices

in the following period. In this instance, n represents the number of days of data that we have

available.

The loss function is denoted by L(y, ˆf(x)). Its job is to compare the predictions made by ˆf

at particular values of x to their true values given by y. A common choice for L is the absolute

error:

L(y, ˆf(x)) = |y − ˆf(x)| (20.3)

Another popular choice is the squared error:

L(y, ˆf(x)) = (y − ˆf(x)) 2 (20.4)

Note that both choices of loss function are non-negative. Hence the "best" loss for a model

is zero, that is, there is no difference between the prediction and the true value.

Training Error versus Test Error

Now that we have a loss function we need some way of aggregating the various differences between

the true values and the predicted values. One way to do this is to define the Mean Squared

Error (MSE), which is simply the average, or expectation value, of the squared loss:

MSE := 1 n∑

(y i −

n

ˆf(x i )) 2 (20.5)

i=1

The definition simply states that the Mean Squared Error is the average of all of the squared

differences between the true values y i and the predicted values ˆf(x i ). A smaller MSE means

that the estimate is more accurate.

It is important to realise that this MSE value is computed using only the training data. That

is, it is computed using only the data that the model was fitted on. Hence, it is actually known

as the training MSE.

In practice this value is of little interest to us. What we are really concerned about is how

well the model can predict values on new unseen data.

For instance, we are not really interested in how well the model can predict past stock prices of

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!