8.3 Portfolio Return
w <- c(0.25, 0.25, 0.20, 0.20, 0.10)
portfolio_returns_xts_rebalanced_monthly <-
Return.portfolio(asset_returns_xts, weights = w, rebalance_on = "months") %>%
`colnames<-`("returns") PerformanceAnalytics::Return.portfolio(R=Return_xts, weights=NULL, rebalance_on, verbose=FALSE) Using a time series of returns and any regular or irregular time series of weights for each asset, this function calculates the returns of a portfolio with the same periodicity of the returns data. Returns a time series of returns weighted by the weights parameter, or a list that includes intermediate calculations
RAn xts, vector, matrix, data frame, timeSeries or zoo object of asset returns.weightsA time series or single-row matrix/vector containing asset weights, as decimal percentages, treated as beginning of period (BOP) weights.If the user does not specify weights, an equal weight portfolio is assumed.
if
weightsis anxtsobject, then any value passed torebalance_onis ignored.This is useful when you have varying assets across time.
The
weightsindex specifies the rebalancing dates, therefore a regular rebalancing frequency provided viarebalance_onis not needed and ignored.Note that
weightsandRshould be matched by period.Irregular rebalancing can be done by specifying a time series of weights. The function uses the date index of the weights for xts-style subsetting of rebalancing periods.
rebalance_onDefault “none”; alternatively “daily” “weekly” “monthly” “annual” to specify calendar-period rebalancing supported byendpoints.- Ignored if
weightsis an xts object that specifies the rebalancing dates.
- Ignored if
verboaseIf verbose is TRUE, return a list of intermediary calculations, such as asset contribution and asset value through time.- The resultant list contains
$returns,$contributions,$BOP.Weight,$EOP.Weight,$BOP.Value, and$EOP.Value.
- The resultant list contains
chartSeries plot an OHLC object.
chartSeries(AMZN, type="candlesticks", subset='2016-05-18::2017-01-30', theme = chartTheme('white', up.col='green', dn.col='red'))type="candlesticks"can beline,bar, default tocandlesticks.A candle has four points of data:
- Open – the first trade during the period specified by the candle
- High – the highest traded price
- Low – the lowest traded price
- Close – the last trade during the period specified by the candle
A candle has three parts: body (open/close prices), upper shadow (high price), and lower shadow (low price).
The color of the body can tell them if the stock price is rising or falling. Usually, red stands for falling and green stands for rising.
theme = chartTheme("black")defaults to black theme.up.colup bar/candle colordn.coldown bar/candle color
charts.RollingPerformance(R, width=12) creates a rolling annualized returns chart, rolling annualized standard deviation chart, and a rolling annualized sharpe ratio chart.
Note that if your portfolio return is on a daily basis, first convert to monthly, then run the rolling function. Otherwise, daily rolling frequency can be too computaionally intensive.
Rolling window
Rolling window estimation