Calculating P&L for your portfolio
Before we start writing more code, let’s cover a few basic terms and formulas that will come in handy in this chapter:
- Time-Weighted Rate of Return (TWRR): This is the simplest method of projecting potential portfolio returns. This approach ignores any additional cash coming in or out of your portfolio. The formula for TWRR is as follows:
Here:
- R is the return for the period
- EV is the end value for the period
- BV is the beginning value for the period
- C is the added cash flow for the period
If we combine multiple periods, we can calculate TWRR as follows:
Here:
- is the TWRR at period n
- is the return for period 1
- is the return for period n
- Money-Weighted Rate of Return (MWRR): This is a more sophisticated version of TWRR, whereby we factor in cash flows coming in and going out of your investment. With MWRR, the timing...