lsanschargrin / jbooktrader

Automatically exported from code.google.com/p/jbooktrader
0 stars 0 forks source link

Bug in handling of isFilled field of com.jbooktrader.platform.position.OpenOrder class #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. isFilled is not initialized to false in constructor
2. Note that once isFilled is set to true, it can never go to false

------------------------
What is the expected output? What do you see instead?

Found it by browsing code
------------------------
What version of the product are you using? On what operating system?

5.04, Windows
------------------------
Please provide any additional information below.

    public void add(Execution execution) {
        sharesFilled += execution.m_shares;
        avgFillPrice += execution.m_price * execution.m_shares;

        if (sharesFilled == order.m_totalQuantity) {
            avgFillPrice /= sharesFilled;
            date = strategy.getTime();
            isFilled = true;
        }
    }

Suppose that I have a position of 100 shares in Stock XYZ that has been
filled at an average price of $100.  Now, let's say that I decide to add to
that position by purchasing 1000 more shares at $100.  Before the 1000
shares purchase executes, isFilled is still true from the previous purchase
of the 100 shares, but this does not make sense.

Note that the isFilled field qualifies the avgFillPrice so that we know
when it is a meaningful quantity.

Original issue reported on code.google.com by endosc...@gmail.com on 29 Aug 2008 at 8:00

GoogleCodeExporter commented 9 years ago
This is not a bug. When 100 shares have been filled, the corresponding instance 
of
OpenOrder is discarded. When the next order to purchase 1000 more shares is
submitted, a new instance of OpenOrder is created. There is no need to 
explicitly
initialize the "isFilled" to false, as it happens by default when the new 
instance is
created.

Original comment by eugene.k...@gmail.com on 29 Aug 2008 at 11:37