How to save on commissions by using PositionCloseBy - page 3

 
nicholish en:

I'm sorry but this is both incorrect and ignorant. First, there is an implied misunderstanding of what CloseBy is and how it works. CloseBy is not a trade operation, it is an accounting operation. The CloseBy operation has absolutely no bearing on position's profit because its obly job is to instruct the trade serve to reconcile offsetting deals to be used as one order closing another. It does not matter what order you close them in, and time has absolutely no effect either. The most important thing you have missed with your code (You need to do one cycle) is because you scanning tickets first you will miss and skip deals still in the pool. You will miss them because when you use a larger one to close a smaller one that deal is modified and issued as a new position. That is not good. In order to account for the mutating order pool you need to either restart the entire loop (ugly and error prone) or use recursion so the function can call itself and restart the iteration over your freshly mutated position pool. David's code didn't work because he didn't use my code. He removed the most important abstractions and turned it into something else. 


In summary:

  1. CloseBy is not a trade operation. It doesn't do anything to P&L. All it does is allow one to treat a hedging account in the same way an opposite order will close another in a netting account. That's all.
  2. The order in which you call closeby does not matter. Sorting by size does not make any difference. Your P&L are locked the second you place the opposite position. CloseBy is only an accounting function. 
  3. Nested loops are not dangerous, but it only works correctly if you know how to make recursive functions, like I did.  
  4. If you don't use recursion you will miss position reconciliations due to the mutating position pool. 

Nicholish, you are precisely correct on your explanation!

Thanks for the recursion function, just found it here while look for another thing, but i got interested on it, and it works perfectly!

 
Hi,
M'y Toussaint I interesting thé fonction PositionCloseBy and I want any body to help me pls thé problèm, I want to add in m'y expert if you help me I'm very happy pls help me 
Merci 
Reason: