E-mail:    

Simple EUR/USD Trading System

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 after 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. The 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.


double NN_Prediction_i_simpleReturn_o_simpleReturn()

{

       RegressionDataset dataset = regression_i_simpleReturn_o_simpleReturn();

       FFNet<FastSigmoidNeuron,FastSigmoidNeuron> network;

       unsigned numInput=2;

       unsigned numHidden=2;

       unsigned numOutput=2;

       unsigned numberOfSteps=300;

       unsigned step;

       network.setStructure(numInput, numHidden, numOutput);

       initRandomUniform(network,-0.1,0.1);

       SquaredLoss<> loss;

       ErrorFunction error(dataset, &network,&loss);

       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);

       labels.element(0)[0] = 0;

       RegressionDataset datasetInput(inputs,labels);

       testOutput = network(datasetInput.inputs());

       if (testOutput.element(0)[0] > 0) return(1);

       if (testOutput.element(0)[0] < 0) return(-1);

       return(0);

}


Code Fragment 2. Function in C++ that creates, trains the neural network and obtains a prediction for the current bar.

<<Previous     Next>>