View Single Post
  #627 (permalink)  
Old 01-24-2009, 11:45 PM
finimej finimej is offline
Senior Member
 
Join Date: Dec 2008
Posts: 132
finimej is on a distinguished road
Here is the Parzen window classification math equations and here is the
The PNN EA code implemenation. However the PNN EA is doing good in backtest, because the trainer has calculated the bar price and put a buy or sell class for every bar there. Therefore the backtest will always be ok.

For the forward testing, the PNN EA seems not do the classfication right at all. Here is his classification code.
default is -1 for sesultClass. if the parzen window PDF here is his fx[i+1]>fx[i], then the result is in the window, and return a result. However, here comes the problem, the orginal code return the counter i. It shall return a class buy or sell in fact. So later the forwarding test will have problem, when the current bar price is sent for classfication. Can someone who understand the code check it out and correct it? Thanks.

The end there, return (resultClass) there is the sucker, it only returned value 0, so the backtesting for the comming period, is all buying operation.

Quote:
**
* Classify a vector in one class.
*/
int PNNClassifyVector(double vector[]) {
double length = ArrayRange(vector, 0);
double result = -99999999999999999999;
int resultClass = -1;
double fx[2] = {0, 0};
double classVectorCount[2] = {0, 0};
for (int i = 0; i < ArrayRange(pnn, 0); i++) {

int class = pnn[i][0];
double classVector[60];
for (int j = 0; j < length; j++) {
classVector[j] = pnn[i][j + 1];
}
classVectorCount[class]++;

fx[class] += MathExp((-1)
* euclideanScalarProduct(vector,
classVector) / (2 * MathPow(SIGMA, 2)));
}
for (i = 0; i < ArrayRange(fx, 0); i++) {
fx[i] *= 1 / (MathPow(2 * 3.14159265, length / 2)
* MathPow(SIGMA, length))
* (1 / classVectorCount[i]);
if (fx[i] > result) {
result = fx[i];
resultClass = i;
}
}
return (resultClass);
}
Attached Files
File Type: zip PNN.zip (3.8 KB, 75 views)

Last edited by finimej; 01-25-2009 at 12:13 PM.
Reply With Quote