We have built an algorithmic trading software and need to calculate the following parameters for each position in our portfolio.
- Average Price
- Realized Profit & Loss
- Unrealized Profit & Loss
These values can be calculated by going through all prior fills for that security. But in a trading system that potentially has thousands of trades for a single security this might take too long, especially if this calculation has to be done every time one needs those values. So I assume that it is much quicker to calculate those values based on prior values and the last fill received for that security.
Any help is appreciated!