TRADING SYSTEMS What is a Neural Network?
A neural network is a type of machine learning algorithm. The simplest classic neural network is composed of an input layer, a hidden layer and an output layer, where each layer contains a given number of “neurons”.
Each neuron in the
input layer gets a value, processes it using a function and passes it to one or several neurons in the hidden layer with a given set of weights, the neurons then repeat the process and pass the values to one or several output neurons. In essence the neural network takes some input values and delivers some output values by processing the inputs through its functional structure. Neurons are nothing but functional processing
Code Fragment 1. Function in C++ that creates 84 examples using 2 returns as inputs and the next bar’s return as output
RegressionDataset regression_i_ simpleReturn_o_simpleReturn(){
Data<RealVector>
inputs(84,RealVector(2)); Data<RealVector>
labels(84,RealVector(1)); int i = 0;
for(i=0;i<84;i++){
inputs.element(i)[0] = (cOpen(1+i)- cOpen(2+i))/cOpen(2+i);
inputs.element(i)[1] = (cOpen(2+i)- cOpen(3+i))/cOpen(3+i);
labels.element(i)[0] = (cOpen(i)- cOpen(i+1))/cOpen(i+1); }
RegressionDataset
dataset(inputs,labels); return dataset;
}
units that pass values multiplied by certain weights to other units. ( Code Fragment 1. )
However a neural network does not know how to process inputs from the start
since it does not know
the weights that are given to each neural network connection. This is why we need to “train” a neural network using a given set of inputs and output values so that the weights that define the connections between neurons can be properly defined. We then use a trained neural network to predict the outcomes on unknown data, which is where we can obtain a benefit by predicting some outcome related with price data.
Simple EUR/USD System
Trading
SquaredLoss<> loss; ErrorFunction error(dataset, &network,&loss);
We are going to create a very simple trading system on the EUR/USD daily timeframe that will attempt to predict the return of the current day on the EUR/USD right aſter the open. In this system we will be using the returns of the past two daily candles as inputs and we will be obtaining the return expected by the network for the current day as output. Te neural network has an input layer with 2 neurons, a hidden layer with 2 additional neurons and an output layer with a single neuron. To reduce bias and ensure the system adapts constantly to changing market conditions
the neural network is
retrained on each day using the past 84 available examples. ( Code Fragment 2.)
RpropMinus optimizer;
optimizer.init(error); for(step = 0; step <
numberOfSteps; ++step){
optimizer.step(error); }
network.
setParameterVector(
optimizer.solution(). point);
Data<RealVector> testOutput; Data<RealVector>
inputs(1,RealVector(2)); Data<RealVector>
labels(1,RealVector(1));
inputs.element(0)[0] = (cOpen(0)-cOpen(1))/cOpen(1); inputs.element(0)[1] = (cOpen(1)-cOpen(2))/cOpen(2);
FX
Code Fragment 2. Function in C++ that creates, trains the neural network and obtains a prediction for the current bar.
double NN_Prediction_i_ simpleReturn_o_simpleReturn() {
RegressionDataset dataset
= regression_i_simpleReturn_o_ simpleReturn();
FFNet<FastSigmoidNeuron,FastS igmoidNeuron> network;
unsigned numInput=2; unsigned numHidden=2; unsigned numOutput=2; unsigned numberOfSteps=300; unsigned step;
network.setStructure(numInput,
numHidden, numOutput); initRandomUniform(netwo
rk,-0.1,0.1);
FX TRADER MAGAZINE April - June 2016 23
Page 1 |
Page 2 |
Page 3 |
Page 4 |
Page 5 |
Page 6 |
Page 7 |
Page 8 |
Page 9 |
Page 10 |
Page 11 |
Page 12 |
Page 13 |
Page 14 |
Page 15 |
Page 16 |
Page 17 |
Page 18 |
Page 19 |
Page 20 |
Page 21 |
Page 22 |
Page 23 |
Page 24 |
Page 25 |
Page 26 |
Page 27 |
Page 28 |
Page 29 |
Page 30 |
Page 31 |
Page 32 |
Page 33 |
Page 34 |
Page 35 |
Page 36 |
Page 37 |
Page 38 |
Page 39 |
Page 40 |
Page 41 |
Page 42 |
Page 43 |
Page 44 |
Page 45 |
Page 46 |
Page 47 |
Page 48 |
Page 49 |
Page 50 |
Page 51 |
Page 52 |
Page 53 |
Page 54 |
Page 55 |
Page 56 |
Page 57 |
Page 58 |
Page 59 |
Page 60 |
Page 61 |
Page 62 |
Page 63 |
Page 64 |
Page 65 |
Page 66 |
Page 67 |
Page 68 |
Page 69 |
Page 70 |
Page 71 |
Page 72 |
Page 73 |
Page 74 |
Page 75 |
Page 76 |
Page 77 |
Page 78 |
Page 79 |
Page 80 |
Page 81 |
Page 82 |
Page 83 |
Page 84 |
Page 85 |
Page 86 |
Page 87 |
Page 88 |
Page 89 |
Page 90 |
Page 91 |
Page 92 |
Page 93 |
Page 94 |
Page 95