You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Bob M <rg...@orcon.net.nz> on 2016/04/16 23:00:47 UTC

Processing a subset of records correctly - again

Hi again

I am still unable to get the desired result from my current coding
Basic idea - grab an ordered subset of records from the database
For the first record - use only the prediction to be compared with the
following record's actual 
For all the others - compare prediction (from prev record) with actual )from
current record) and do some maths

I seem to not be getting the predicted value correct?

Here is my coding
If you can see what could be wrong - let me know :)

Bob M
*********************************************
String Date5 = "";
int Time5 = 0;
try
{
rs = s.executeQuery("SELECT * FROM(SELECT * FROM xxxx WHERE TRADE_NO <>0
ORDER BY Trading_Date DESC,"
        + " Trading_Time DESC FETCH NEXT 103 ROWS ONLY) AS xxxx_Simulation
ORDER BY Trading_Date ASC, Trading_Time ASC");

int k = 0;
while (k < 100) {
rs.next();
// get class_current, predictions and profit from (k)th record
Date5 = rs.getString("Trading_Date");
Time5 = rs.getInt("Trading_Time");
class_current = rs.getString("class_current");
pred_test = rs.getString("Class_Predicted");
test_profit = rs.getDouble("Profit_Loss");

pred_test_curr = pred_test;

if (k < 1) {
    pred_test_prev = pred_test_curr;
    pred_test_curr = "";
    class_current = "";
    test_profit = 0;
}

if (k > 0) {
// 1) predicted and actual "UP"
// calculate pips won long
if((pred_test_prev.equals("Up")) && (class_current.equals("Up"))) { 
pips_won_long = test_profit;
sum_pips_won_long = sum_pips_won_long + pips_won_long;
}

// 2) predicted "UP" and actual "DOWN"
// calculate pips lost long
if((pred_test_prev.equals("Up")) && (class_current.equals("Down"))) { 
pips_lost_long = Math.abs(test_profit); 
sum_pips_lost_long = sum_pips_lost_long + pips_lost_long;
}

// 3) predicted and actual "DOWN"
// calculate pips won short
if((pred_test_prev.equals("Down")) && (class_current.equals("Down"))) { 
pips_won_short = test_profit;
sum_pips_won_short = sum_pips_won_short + pips_won_short;
}

// 4) predicted "DOWN" and actual "UP"
// calculate pips lost short
if((pred_test_prev.equals("Down")) && (class_current.equals("Up"))) { 
pips_lost_short = Math.abs(test_profit);
sum_pips_lost_short = sum_pips_lost_short + pips_lost_short;
}

pred_test_prev = pred_test_curr;
pred_test_curr = "";
class_current = "";
test_profit = 0;
pips_won_long = 0;
pips_lost_long= 0;
pips_won_short = 0;
pips_lost_short = 0;

}
 k++;
}
}
catch (SQLException e)
{
    myConsole.getOut().println(e);
} // end of simulation - 100 simulation records





--
View this message in context: http://apache-database.10148.n7.nabble.com/Processing-a-subset-of-records-correctly-again-tp145885.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Re: Processing a subset of records correctly - again

Posted by Bob M <rg...@orcon.net.nz>.
Hi Bryan
Thanks for the suggestion - a much better piece of
coding........................

Anyway I have finally seen what is going wrong!

The class_curr is correct in all cases BUT
the pred_test_prev is sometimes correct and sometimes wrong thus making the
final totals of pips won and lost wrong!

I do not know why this is happening - there seems to be no pattern but the
answer MUST lie in the fact that I am reading a prediction from one record
and comparing that prediction with what actually happened in the very next
record

Can you see where I may be going wrong ?

Thanks

Bob M



--
View this message in context: http://apache-database.10148.n7.nabble.com/Processing-a-subset-of-records-correctly-again-tp145885p145895.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Re: Processing a subset of records correctly - again

Posted by Bryan Pendleton <bp...@gmail.com>.
> For all the others - compare prediction (from prev record) with actual )from
> current record) and do some maths
>
> I seem to not be getting the predicted value correct?

Hi Bob,

I don't think you've really given us enough information to help you very much.

Perhaps you could provide more details about what you expected your program
to do, and what you observe that it is actually doing, and we could offer
more suggestions.

One thing that occurred to me as I read it: it appears that your program
is intended to face 4 possibilities, and do a particular series of computations
for each of those 4 possibilities.

Perhaps, either due to the data being presented to your program, or due
to a flaw in your program, you are either not performing any of those 4
possibilities, or you are performing more than 1 of them.

That is, you could try structuring your program as:

    if( case 1 )
    else if( case 2 )
    else if( case 3 )
    else if( case 4 )
    else print information about what data we actually saw that didn't fit.

Then if you ever see that "else" case, you have some clues about
why your data didn't match your program.

thanks,

bryan