Comparing account equity vs maintenance margin on large number of positions
Comparing account equity vs maintenance margin on large number of positions
Loading saved threads...
HubbyDubDub · External communityPost link
External question — Quantitative Finance Stack Exchange
Author: HubbyDubDub
Original post: https://quant.stackexchange.com/questions/40195
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Forex brokers will start liquidating your positions when your account's equity falls below the maintenance margin set by the broker.
account equity = deposits - withdrawals + realized pnl + unrealized pnl
It seems that they have some kind of system that calculates the equity of every account that has open positions, in real-time, on every tick, then compares that to the maintenance margin requirement to decide whether to commence a liquidation.
While this may be feasible for a small number of positions, it doesn't seem like it scales well. As the number of accounts and the securities offered for trading increase, so does the complexity of the method described above.
So there must be some other kind of data structure or algorithm or method to do this. Yet I have not found anything about it online.
How do margin trading brokers track user account equity in real-time to determine when it falls below the maintenance margin, and hence trigger a margin call?
Thanks!
Quote
Report
Attack68 · External communityPost link
External answer — Quantitative Finance Stack Exchange
Author: Attack68
Original post: https://quant.stackexchange.com/a/40199
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I don't actually know the answer to this question but the problem you describe is just a linear algebra problem. Imagine a matrix
X
whose rows represent the ordered positions of each client with respect to
all
instruments, and column vector
P
of realtime prices of
all
instruments. Then the equity of each client is the row value of
E
:
$$E=XP$$
Ignoring deposits and withdrawals, intraday trading which could also be considered as vectors and added to the result.
The key is that
X
might be very large, e.g. 1 million accounts x 10,000 instruments, but the matrix will be very sparse (each account will be expected to own a small subset of instruments), so the sparsity might be 1%, and then with appropriate sparse matrix calculators the calculation time will be that which takes
1mm x 10k x 1% = 100mm
calculations, which might take a second. (
https://stackoverflow.com/questions/36969886/using-a-sparse-matrix-versus-numpy-array
)
Then you scan through the results of 1mm clients and do comparisons of the values relative to the margin and flag those that breach. This would also be fast.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Quantitative Finance Stack Exchange Author: Attack68 Source score (net votes, not local likes): 2 Original post: https://quant.stackexchange.com/a/40199 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I don't actually know the answer to this question but the problem you describe is just a linear algebra problem. Imagine a matrix X whose rows represent the ordered positions of each client with respect to all instruments, and column vector P of realtime prices of all instruments. Then the equity of each client is the row value of E : $$E=XP$$ Ignoring deposits and withdrawals, intraday trading which could also be considered as vectors and added to the result. The key is that X might be very large, e.g. 1 million accounts x 10,000 instruments, but the matrix will be very sparse (each account will be expected to own a small subset of instruments), so the sparsity might be 1%, and then with appropriate sparse matrix calculators the calculation time will be that which takes 1mm x 10k x 1% = 100mm calculations, which might take a second. ( https://stackoverflow.com/questions/36969886/using-a-sparse-matrix-versus-numpy-array ) Then you scan through the results of 1mm clients and do comparisons of the values relative to the margin and flag those that breach. This would also be fast.
Checking account access…