Re: [Quickfix-developers] Calculating the profit/lost for an operation
Brought to you by:
orenmnero
|
From: Oren M. <or...@qu...> - 2006-08-07 17:53:50
|
Lidia, Matching a specific sell order to a specific buy order doesn't make a =20= whole lot of sense, especially when the orders are of varying sizes. =20= (You actually shouldn't even be concerned with orders, executions and =20= positions are all you really need to look at). You instead need to =20 look at the number of shares executed, and calculate your realized =20 PnL for what you have matched, then calculate your unrealized PnL for =20= what is unmatched. Adding these up will get you the total PnL. So =20 in your scenario (prices added for to clarify the example) Buy 1000 @ 10 =3D Cost Basis 10,000 Buy 2000 @ 11 =3D Cost Basis 22,000 Sell 1500 @ 10.5 =3D Cost Basis 15,750 Market @ 10.75 Now, for your realized PnL, it is reasonable to take the stance that =20 the earliest shares get 'matched' first. So we get this: (1000 @ 10 =3D 10000) + (500 @ 11 =3D 5500 ) =3D Cost Basis 15,500 The Cost Basis is the amount of currency (we'll use dollars here) you =20= spent in order to accumulate the first 1500 shares of your position. =20= This is what we will used to calculate the realized PnL. The cost =20 basis for the second 1500 shares is 1500 @ 11 =3D 16,500. So we see we =20= payed $1000 more for the second hundred shares, and this is what we =20 will use to calculate the unrealized PnL. So now we need to take the cost basis of the first 1500 shares, and =20 subtract them from the cost basis of our sold shares. Or 1500 @ 10.5 =20= =3D Cost Basis 15,750. So (15,750 - 15,500) means we made $250 on our =20= first 1500 shares, and this is our realized PnL. For the rest of it, we can use the market price to estimate what our =20 PnL might be if we liquidated the position (this is simplistic, much =20 more complicated models can be used to estimate a more realistic =20 price, but it's usually not too important to be accurate here). So =20 the market is trading at 10.75, this means that our cost basis =20 estimate is 1500 @ 10.75 =3D 16,125. So we have 16,125 - 16,500, =20 giving us an unrealized PnL of -375. Now just add the two up, and =20 your total PnL is 250 - 375 =3D -125. I didn't go over them too carefully, but I hope my calculations are =20 correct. I hope the explanation helps. --oren On Aug 7, 2006, at 12:09 PM, Lidia L=F3pez Cuesta wrote: > QuickFIX Documentation: http://www.quickfixengine.org/quickfix/doc/=20 > html/index.html > QuickFIX Support: http://www.quickfixengine.org/services.html > > Hi all, > > If I have sent 2 buy orders to the market. When both has been executed > (firtst at 1000 and the second one at 2000), I send a sell order. =20 > When the > sell order is executed (at 1500), how do I know which the buys =20 > orders is the > couple to close the operation? > > I need to calculate the partial profit/lost, so I need to know =20 > which buy > order corresponds to this sell order. > > Are there any message or field in the execution report to know =20 > which order > is matched with the sell order? > > If the sell order is matched with the first one I have earned 500, =20 > but if it > is the second one I have lost 500 > > Lidia > > > > ----------------------------------------------------------------------=20= > --- > Using Tomcat but need to do more? Need to support web services, =20 > security? > Get stuff done quickly with pre-integrated technology to make your =20 > job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache =20 > Geronimo > http://sel.as-us.falkag.net/sel?=20 > cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=3D121642 > _______________________________________________ > Quickfix-developers mailing list > Qui...@li... > https://lists.sourceforge.net/lists/listinfo/quickfix-developers > |