NN median target predictions and how M5 charts react to them

To me, the target predictions (in blue), which were taken from a NARX neural network predicting the median price of the H4 bars of this USDCAD data, do not look like targets but more like support/resistance lines. Every 48 M5 closing points (one H4 closing point) the target price is updated with the network’s prediction.

I can’t make out what to possibly use this for, but they could be used as support/resistance guides. Any suggestions?

Part #2 – a decision support system

Error rate with the latest NARX simulations was moderately low. It was measured by dividing the difference between y-actual and y-predicted for the median price by the average length of the candle.

with H4 and H8 constructed bars, the lowest errors with respect to candle size was 18-21% in the case of some USDCAD data, and EURSEK (a very impressive 15%) which means that the average error between predicted and actual median was around only 15% of the average length of a bar.

Part #2 starts now:

Using that target prediction to create a profitable decision support system.

The main algorithm that I’m about to try is:

1. use NN to predict target for either H4 or H8

2. when target prediction is obtained, monitor the progression of the price:

if price moves away from target median by x pips (and a confirmation from indicator is obtained, if any), enter market.

3. exit market if either:

TP is hit

SL is hit

Target price candle is closed.

A PNN-based idea for a research

Probabilistic neural networks:

First of all, an idea originated from the work found in C.T.Lee and Y.P. Chen in Da-Yeh university in Taiwan (2007). They have used a back-propagation network to test the usefulness of stochastic indicators %K and %D.

Their mechanism of defining uptrend/neutral/downtrend regions certainly deserves more interest. Defining regions is always one of the hardest tasks one could accomplish, and it is always important to teach the network before it can generalize on other data.

This model can be used with a PNN, (or a self-organizing map) that is better at classification than a usual FFNN with backprop.

Another paper that might contribute to this idea is the work by Schumann and Lohrbach. It was a next-day price forecasting paper, yet they use a similarly useful classification system, for up days and down days, and what would be called a neutral day. It is similar to the threshold function used in my paper.

Left to decide, should the region classification be done manually or automatically? The first has the idea that we are using human cognition to divide regions. The disadvantage is that this kind of classification might slightly differ between one person or another, or might not have the greatest examples for a network to learn from.

Two NARX Daily results (during financial crisis time)

Note: window size here decreased to 3. It suited the Daily predicions better. Inputs used are median, close, macd and SMA5.

3 in-develoment strategies

So I haven’t posted in a few days, things have been completely hectic for me with all the new possibilities of data optimization and the new types of Neural Networks I’ve been using. To summarize what’s been going on with my research so far:

1. TP optimization with FFNN’s

Using 4 inputs (type of cross, MACD histogram value, MACD 9EMA value, and RSI 14) and one output (TP) in a Feed-Forward Neural Network has yielded an overall profit around 50% better than the regional optimal fixed TP, but less than the overall optimal fixed TP. This can be considered a good result given that a strategy using the overall optimal fixed TP relies on not more than 10% heavy hits that are not guaranteed to be sustained in every time span.

However, this result is still obtained with the MSE as a performance function, and without really smoothing the TP data. Next is to edit the MSE function to place more error weight on output higher than target, since those outputs result in a total miss even 1 point above target. Lowering the number of outputs above target will significantly lower the number of misses and therefore lead to a considerably greater performance that will be well above the overall optimal fixed TP. I will also attempt to map the set of outputs into a min-max region that is centered around either the overall optimal fixed TP or the lower local fixed TP, with a range of around 25% in each direction.

2. Hourly median price approximation with a NARX network

Performing one step ahead with a NARX network, with 4 inputs (Hourly median price, MACD histogram value, MACD 9EMA value, and RSI 14) and one output (Hourly median price) will approximate the next median price with an average goal error of 50%, but when plotted against a chart of high-low bars of the same prices, we find out that the 90-95% of the predicted prices fall within the next bar. This is phenomenal given that even with such random inputs that do not tell much about the circumstances of the trend, we can still give an answer that will have a 90-95% chance of being hit in the next hour. Shaping this method up could lead us to a result very close to a 100% hit, especially with a goal not targeted for over-fitting. Also, missed hits are pretty obvious to spot if you consider how outrageous it appears.

3. Clustering output with a Radial Based Probabilistic Neural Network

With a Radial Based Probabilistic Neural Network, one can classify the type of the next bar: an up, down, or flat bar, or type of candle (hammer, rising star, doji, etc..). I have not tried this yet, but it is very promising given the strength of PNN’s in classification, and the relatively high error tolerance (No need for 90% , 70% will still be highly profitable and well beyond any known trading system). I will try clustering soon with PNN’s and SOM’s (Self-Organizing Maps).

If any of the earlier 3 points seem extremely vague or not understandable, it’s perfectly OK. It will be much clearer when I get around to uploading charts and diagrams that will hopefully clear out the above-mentioned mumbo-jumbo.

Data/Targets modification solutions

After some brainstorming I came up with a few possible solutions that might help in giving the input data more meaning and relation to the targets, and making the targets cleaner, more “interpret-able” and “guessable”.

I. Possible additions to the trading strategy

1. Large moving averages, such as SMA(100), SMA(200), SMA(300) to determine the overall trend, to help filter out whipsaws. Possible uses are also the slopes of those SMA’s and other characteristics that the NN can deduce on its own.

2. Stochastics, RSI, MACD, either left on their own or possibly combined into one indicator giving an output value of the [-1,+1] range. There can be several values of of each, not strictly limited to the defaults of RSI(14) and Stochastics (8,3,3) or (5,3,3), nor the MACD of (12,26,9). Of course I will need to create extra TA functions in MATLAB.

3. ADX (including ATR, both needing to be built), StdDev, both need to be created as well.

Most of those are trend definers such as ADX and the large value SMA’s, while others are confirmators and come second in order of importance, such as MACD, RSI, Stochastics. StdDev is just to measure how far away is a price straying, to help predict where the trend is going.

a uSDJPY H1 chart with SMA(100) in green, SMA(200) in yellow, with ADX, MACD, Stochastics and StdDev in widnows below.

A USDJPY H1 chart with SMA(100) in green, SMA(200) in yellow, with ADX, MACD, Stochastics and StdDev in widnows below.

II. Possible changes to the target data

1. Form target data into optimal TP/SL and not rely on an exit signal but on hitting either of them. Problems to solve would be to use multiple entries or not. Try to create a mechanism to use trailing stop as well.

2. Smooth TP data, making it more prediction friendly, instead of pure noise. That means a change to the output values in a way that will not distort their meaning but make them more uniform.

III. Changes into input methods

(By modified I mean that the data will have to pass through several filters and functions to create a certain meaning out that is not clearly deduced out of its raw value, before it’s fed to the network. By raw, I mean that the data will be presented as context-free numbers).

Method 1: Raw Inputs + Raw Targets

Method 2: Raw Input + Modified Targets

Method 3: Modified Inputs + Raw Targets

Method 4: Modified Inputs + Modified Targets

I’m more inclined towards Method 4, I’m also planning to use a NN to help attach a meaning to a combination of indicators.

MATLAB code to extract TP values and indicator data from an FTS


% moving prices to a matrix %
prc = fts2mat (TS);

% getting macd %
macdF = macd(TS);
macd_m = fts2mat (macdF);

% getting rsi %
rsiF = rsindex(TS);
rsi_m = fts2mat (rsiF);

% getting the MA's %
mov1F = tsmovavg(TS,'s',10);
mov2F = tsmovavg(TS,'s',20);
mov1_m = fts2mat (mov1F.CLOSE);
mov2_m = fts2mat (mov2F.CLOSE);

% MA's difference for crossing points %
mvdiff = mov1_m - mov2_m;

% getting the 1's and 0's %
[ro,co] = size(mvdiff);

pol(1)=0;

for i=2:ro
pol(i)=hardlim(mvdiff(i)/mvdiff(i-1)*-1);
end

pol = pol';

% getting the optimal TP levels %
for j=1:ro
if pol(j)==0
TP(j)=0;
elseif pol(j)==1 && mov1_m(j)
k=j+1;
TP(j)=prc(j,3)-prc(k,4);
k=j+2;
while(pol(k-1)~=1 && k<=ro)
if ((prc(j,3)-prc(k,4))>TP(j))
TP(j)= prc(j,3)-prc(k,4);
end
k=k+1;
end
elseif pol(j)==1 && mov1_m(j)>mov2_m(j) % upcrossing %

k=j+1;
TP(j)=prc(k,5)-prc(j,3);
k=j+2;

while(pol(k-1)~=1 && k<=ro)
if((prc(k,5)-prc(j,3)>TP(j)))
TP(j)=prc(k,5)-prc(j,3);
end
k=k+1;
end
end
end

TP = TP';

% creating an unclean ready matrix %
unclean = [macd_m rsi_m TP];

% cleaning out zero rows %
j=1;
for i=1:ro
if (unclean(i,4)~=0)
clean(j,1)=unclean(i,1);
clean(j,2)=unclean(i,2);
clean(j,3)=unclean(i,3);
clean(j,4)=unclean(i,4);
j=j+1;
end
end

% getting inputs and outputs ready %
tinp = clean(:,1:3);
targ = clean(:,4);

Getting ready for first preliminary test

Update 2:

I’ve ran a couple of simulations on the data, but I have no idea what kind of results I got. I need to read a little more into the neural network 900+ page book before I know what I’m doing. That’s for tomorrow though.

Update 1:

Matrix is ready! 4 columns, Columns 1 and 2 are MACD’s values (histogram + EMA(9)) + column 3 is RSI(14) and column 4 is the best TP value at until the next crossing. Getting ready to fit this into a neural network!

I will try to get a simulation ready today. For now, I will get some data ready, and then try to test for the targets with a simple neural network and see what results I get (and in what form).

I will also try to create a script file to test the data, so that I wouldn’t have to do the same steps over and over again every time.

The data I want to collect today is simple daily data, the last 10 years of the USDCHF. It seems appropriate to start testing on daily data since the indicators and NNs were designed for that first. Then, I will move on to hourly data.

Results are in a later post!