Issue in wholesale market_transaction analysis

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Issue in wholesale market_transaction analysis

SPOT
Hello everyone,

I am having some trouble in decomposing the total wholesale buy and sell values in the wholesalemarket.

In the logtool analyzer, I am using the MarketTransactionHandler for this purpose. I have some quires. (Please correct me if I am wrong anywhere!)

Query 1: In the MarketTransactionHandler (mt) object, if (mt.getMWh() >= 0) then I am buying energy and if (mt.getMWh() < 0), I am selling energy.

I can also figure my buy and sell by looking into the mt.getPrice() value as mt.getPrice() and mt.getMWh(), these two will always have opposite values. So,  if (mt.getPrice() >= 0) then I am selling energy (because money is coming to brokers account). if (mt.getPrice() < 0), I am buying energy.

So I can separately track my net_wholesale_buy and net_wholesale_sell by the following logic.

if ((mt.getPrice() * Math.abs(mt.getMWh())) >= 0) {
                                        // Sold Energy
                                        net_wholesale_sell += (mt.getPrice() * Math.abs(mt.getMWh()));
                                }
                                else {
                                        // Bought energy
                                        net_wholesale_buy+= ((mt.getPrice() * Math.abs(mt.getMWh())));
                                }

Now I can say, net_wholesale_transaction1 = net_wholesale_sell + net_wholesale_buy.

Query 2: I can also just add up all the values of MarketTransaction object values to get the net_wholesale_transaction e.g. net_wholesale_transaction2 += (mt.getPrice() * Math.abs(mt.getMWh()) (without checking if I am buying or selling energy).

Now the problem is: net_wholesale_transaction1  and net_wholesale_transaction2 doesn't match! Am I doing something wrong? These two values should match right?

Here is my full method, FYI:

        class MarketTransactionHandler implements NewObjectListener {

                @Override
                public void handleNewObject(Object thing) {
                        // Working System.out.println("8");
                        if (ignoreCount > 0) {
                                return; // nothing to do yet
                        }
                        MarketTransaction mt = (MarketTransaction) thing;
                        int target = mt.getPostedTimeslot().getSerialNumber();
                        SimulationDataPerTimeSlot cmt = marketData.get(target);

                        if (null == cmt) {
                                cmt = new SimulationDataPerTimeSlot();

                        }
                        double brokerid = mt.getBroker().getId();
                        int brokerIndex = getBrokerIndex(brokerid);
                       
                        if(brokerIndex > 0){
                               
                                if((mt.getMWh() > 0 && mt.getPrice() > 0) || (mt.getMWh() < 0 && mt.getPrice() < 0))
                                        System.out.println("THIS SHOULD NOT HAPPEN! mt.getPrice() ->" + mt.getPrice() + " mt.getMWh() -> " + mt.getMWh());
                                       
                                if (mt.getMWh() >= 0) {
                                        // bought energy
                                        cmt.arrenergyBought[brokerIndex] += Math.abs(mt.getMWh());
                                } else {
                                        // sold energy
                                        cmt.arrenergySold[brokerIndex] += Math.abs(mt.getMWh());
                                }
       
                                if ((mt.getPrice() * Math.abs(mt.getMWh())) >= 0) {
                                        cmt.arrmarketGain[brokerIndex] += (mt.getPrice() * Math.abs(mt.getMWh()));
                                }
                                else {
                                        cmt.arrmarketCost[brokerIndex] += ((mt.getPrice() * Math.abs(mt.getMWh())));
                                }
       
                                cmt.market[brokerIndex] += (mt.getPrice() * Math.abs(mt.getMWh()));
                               
                                marketData.put(target, cmt);
                        }
                }
        }


At the end, the value I get from cmt.market[brokerIndex] doesn't match with the summation of cmt.arrmarketGain[brokerIndex]+cmt.arrmarketCost[brokerIndex].

Can anyone help please?

Thanks in advance,
Porag