Compute Prices for Portfolio Based on Units
Compute prices for a portfolio based on outstanding shares.
unit_prices(NAV, cashflows, initial.price, initial.shares = 0, cf.included = TRUE)
NAV |
a dataframe of two columns: timestamp and net asset value |
cashflows |
a data.frame of two or three columns: timestamp, cashflow and (optionally) an id |
initial.price |
initial price |
initial.shares |
number of outstanding shares for first NAV |
cf.included |
logical |
This function is experimental, and its interface is not stable.
The function may be used to compute the returns for a portfolio with external cashflows, i.e. what is usually called time-weighted returns.
Valuation (i.e. the computation of the NAV) must take place before external cashflows. Fairness suggests that: what price would you give an external investor if you had not valued the positions? And even if fairness mattered not: suppose we traded on a specific day, had a positive PL, and ended the day in cash. We could then not differentiate any more between a cash increase because of an external inflow and a cash increase because of a profitable trade.
A data.frame
timestamp |
the timestamp |
NAV |
total NAV |
price |
NAV per share |
units |
outstanding units (i.e. shares) after cashflows |
Attached as an attribute is a data.frame
transactions
.
Enrico Schumann
Schumann, E. (2020) Portfolio Management with R. http://enricoschumann.net/PMwR/
NAV <- data.frame(timestamp = seq(as.Date("2017-01-01"), as.Date("2017-01-10"), by = "1 day"), NAV = c(100:104, 205:209)) cf <- data.frame(timestamp = c(as.Date("2017-01-01"), as.Date("2017-01-06")), cashflow = c(100, 100)) unit_prices(NAV, cf, cf.included = TRUE) ## timestamp NAV price units ## 1 2017-01-01 100 100.0000 1.000000 ## 2 2017-01-02 101 101.0000 1.000000 ## 3 2017-01-03 102 102.0000 1.000000 ## 4 2017-01-04 103 103.0000 1.000000 ## 5 2017-01-05 104 104.0000 1.000000 ## 6 2017-01-06 205 105.0000 1.952381 ## 7 2017-01-07 206 105.5122 1.952381 ## 8 2017-01-08 207 106.0244 1.952381 ## 9 2017-01-09 208 106.5366 1.952381 ## 10 2017-01-10 209 107.0488 1.952381 ## behaviour prior to version 0.16-0: PMwR:::.unit_prices(NAV, cf, cf.included = TRUE) up <- unit_prices(NAV, cf, cf.included = TRUE) old.cf <- rep(0, nrow(up)) old.cf[up$timestamp %in% cf$timestamp] <- cf$cashflow old_up <- data.frame(timestamp = up$timestamp, NAV = up$NAV, price = up$price, shares = up$units - diff(c(0, up$units)), cashflow = old.cf, new_shares = diff(c(0, up$units)), total_shares = up$units, NAV_after_cf = up$NAV)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.