Profile Picture

Position management error handling

Posted By dplaisted 10 Years Ago
Message
Posted Monday January 15 2007
We are in the process of rewriting our position manager to be much more flexible, to support position resizing, pyramiding, and partial fills.  We want it to be as robust as possible.  So right now I am considering a "worst-case scenario" which will hopefully never happen to you, but if it does we want to handle it in the best way possible.  The issue is what to do if the position size goes "negative."

There might be various ways that this could happen, but here is one scenario.  You open a position with 100 shares and a profit target.  The profit target is implemented as a limit order to sell 100 shares.  Some time later, you decide to sell off half of the position.  So the order is sent to sell 50 shares.  Normally what would happen is that when you receive confirmation that the 50 shares have been sold, the profit target limit order will be canceled and a new one will be sent for 50 shares instead of 100.  But it is possible that the limit price would hit between the time that you send the sell order for 50 shares and the time that you receive the message that the shares have been sold and are able to resize the profit target order.  Since you sold 150 shares from a position that only had 100 shares, you are now short 50 shares.

At first glance it might seem like this situation is avoidable by resizing the profit target order before sending the order to sell 50 shares.  But you might want to sell the 50 shares with a limit order, and in that case you don't know if it will execute until you receive notification that it went through.

So, if something like this happens, what should the position manager do?  Right now I am thinking that it should just use a market order to get you back to zero shares.  This seems like what you would do anyway if you ended up with an unwanted position, and I'm not sure what else an automated system could do.

We welcome any feedback you may have.

Posted Tuesday January 16 2007
I'm posting this on behalf of phg.  For some reason he can't post to this topic:

Here’s what I wanted to say:

Interesting question. But using an 'extra' order bothers me. Besides, not everything is shortable (and not in odd lots?). It could get messy (which is why you asked the question). It's the order to sell 50 that potentially puts the account on a slippery slope. I assume account management is able to recognize the possibility before the order is accepted? My preference would be to reject any new order that would enable an imbalance result. Let the user adjust the limit order first. Bracket and OCA type orders might make record keeping tricky but I don't think RE is considering supporting those kinds of orders?

I guess the question could be turned around to ask "is there any strategic reason why account management should accept an order that has the potential for creating a negative balance?" (Aside from orders to go short specifically.)

My $0.02.

Posted Sunday January 21 2007
phg (1/16/2007)
I guess the question could be turned around to ask "is there any strategic reason why account management should accept an order that has the potential for creating a negative balance?" (Aside from orders to go short specifically.)

Yes, there is.  If we don't allow this we will be limiting your options.  And technically, any time you have a position with both a profit target and a stop loss you are creating this situation.  If the profit target and stop loss are very tight, then you could have a situation where both of them hit before you were able to cancel the second one.

Daniel

phg
Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)
Posted Sunday January 21 2007
Hmmm. Bracket and OCA (contingent) type orders in general are meant to deal with situations like this, but in the specific example you give, where an order is already working, it it not clear what the 'ideal' solution would involve. The 'best' I can see would be an order to modify the original order to sell 50 (from 100) with brackets to sell 50 (what you want to do now) and sell 50 above the currently working order. That gets complicated and I'm not sure all brokers support the mechanism.

(Are you thinking about supporting bracket and OCA order types with the RE interface? That would call for quite sophisticated order management, and would expose RE to more of the vagueries of how brokers (IB) modify their APIs haphazardly.)

-Pete

-Pete

See also Yahoo group about applying RE.

Posted Sunday January 21 2007
It also depends on the type of the account that the user is interacting with their broker. If the account that is being used has margin capabilities and user is allowed to short, maybe that is what the user wants. I am not sure what is available in each broker API, but depending on them you could implement accordingly. It should be noted that the brokers are usually not the end to this chain either, but rather the exchange floor/computers, Market Makers , etc ...

Most brokers that you have a margin account with, warn you that you have an open order for the position and is not complete and it's up to you to go ahead or not. As for auto trading such a positions, you can set an option (could be the default) to wait for each order before executing the next, if the “theoretical result of sum of all previous open orders” vs your positon could be negative. The option to sell at market the imbalance is usually not a good one, because if there is no bid at that moment (specially on illiquid securities), it could really cost the trader. If there is demand for such a feature (and there may well be), it should for sure be an option setting.

 

Posted Sunday January 21 2007
BTW,

For accounts that would want to be able to execute orders regardless of their previous orders, you may want to have a limit set on the negative positions as it would be done for regular setting at zero for the size of the theoretical positions (and the reciprocal on the positive side). This limit would not only be on positions size, but also could be in currency amounts. This would be nice for people who want to limit their exposure on the short side. Also, things would get even more interesting on futures with orders such an OCO (One cancels other)!

Posted Sunday January 21 2007
Not to "cop out" too much, but brackets and OCA or OCO orders aren't going to be a part of 1.0.  As you've both alluded to, this does complicate the order management code quite a bit.  However, with the recent significant changes to our architecture to support pyramiding and scaling out, this should be a possibility in the future.
phg
Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)Supreme Being (48,573 reputation)
Posted Sunday January 21 2007
I just can't see the situation under discussion cropping up very often. For release 1.0 I would vote for warning about market orders with this potential, maybe even require confirmation. As Daniel points out, 'close together' stop-loss and take-profit limit orders create an exposure. (In a cash account (IRA) the broker is going to deny the order that would make you short.) So, I would recommend warning the user about the possibility when order management detects it, but otherwise leave it up to the user to correct the situation once it has happened.

In the 'close together' example, if one side is executed, who lifts the other side, the user or order management? Is an execution reported to the user by means of a 'call back'? (I think I am in basic agreement with Siasb; if not let me know.)

-Pete

-Pete

See also Yahoo group about applying RE.

Posted Monday January 22 2007
phg (1/21/2007)
I just can't see the situation under discussion cropping up very often. For release 1.0 I would vote for warning about market orders with this potential, maybe even require confirmation. As Daniel points out, 'close together' stop-loss and take-profit limit orders create an exposure. (In a cash account (IRA) the broker is going to deny the order that would make you short.) So, I would recommend warning the user about the possibility when order management detects it, but otherwise leave it up to the user to correct the situation once it has happened.

In the 'close together' example, if one side is executed, who lifts the other side, the user or order management? Is an execution reported to the user by means of a 'call back'? (I think I am in basic agreement with Siasb; if not let me know.)

-Pete

You are correct, we don't expect this to crop up much, if at all.  But we want to make sure it is handled correctly if it does happen.

The problem with warning the user is that it requires the user to be monitoring the system.  While it is always a good idea to keep an eye on your system, we want to provide a platform that supports fully automated trading.  So we have to assume that in a situation like this, the user won't be there to fix the problem.

As far as who has to cancel/resize the orders, this will be automatically handled by the position manager for the profit target, stop loss, etc orders.  We will be providing the capability to submit other orders (ie to resize a position perhaps) for a position, and it may be up to the user to resize or cancel these orders.  When the position size reaches 0 however, all pending orders for that position will be canceled (although we may add the option to override this).

Siasb, since you think that it is a bad idea to submit a market order to close out the position, I guess the best thing to do by default is to stop the system with an error.  I think we will also provide a way to add an event handler in your system for this that will correct the problem and allow the system to continue running.

Daniel

Posted Monday January 22 2007
I am not sure how are you exactly implementing it; However an event/exception handling mechanism in this situation probably will work cleanly [that is tied to the order status events]. On any new order call to position manager, it could determine if theoretically this new order would in conjunction with open orders, current positions, and account capabilities [margin, ...], could possibly put it over the set limit of the user; It would throw an exception (special informational class) or an event message, and the strategy would presumably handle it from there. On another note, you also have to make extra sure that threads in these processes are properly synced.

 



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems