Processing a subset of records correctly - again

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Processing a subset of records correctly - again

Bob M
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

Reply | Threaded
Open this post in threaded view
|

Re: Processing a subset of records correctly - again

Bryan Pendleton-3
> 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

Reply | Threaded
Open this post in threaded view
|

Re: Processing a subset of records correctly - again

Bob M
This post was updated on .
Hi Bryan
Thanks for the suggestion - a much better piece of coding........................

I have also realized that I don't have a problem - I was misunderstanding what I was trying to do :)

Many thanks

Bob M