简体   繁体   中英

How do i combine monthly and daily xts data for use with PerformanceAnalytics?

I have several xts objects, most of which are daily observations. I have one which is monthly. I would like to be able to combine three of them into one xts object, which I can then use in the PerfrormanceAnalytics package (eg - charts.PerformanceSummary). I have the following:

Ret <- merge.xts(dailyReturns[,3], 
       shortBothDaily[,3], 
       shortBothMonthly[,3])

The above code gives me an xts object, with the monthly returns filled in with 'NA'. I can make this fill be equal to zero, which then allows me to plot, but it produces a step wise function:

charts.PerformanceSummary(Ret)

在此处输入图片说明

I would like something similar to this, but with a typical looking cumulative returns series for the monthly data.

I can convert the two daily series into monthly (to.monthly()), but would rather not lose the granularity in the daily returns.

Is there an elegant way to do this? To maybe fill with simulated return data? Or have PerformanceAnalytics recognize the monthly return data and plot it accordingly?

I would like to see something like this (via Bloomberg):

在此处输入图片说明

As you can see, we have a series of daily returns, with another series of monthly returns plotted over the same time period.

This is not a huge deal, but it seems fairly simple and as if it should be a common need. I was hoping there was some sort of PerformanceAnalytics way to plot monthly and daily values together.

The Bloomberg chart is wrong. It is interpolating data where none exists.

I assume that you need cbind.

require(quantmod)
require(PerformanceAnalytics)
data(managers)
getSymbols.yahoo('IBM',from='1996-01-01',to='2006-12-31',env=.GlobalEnv)
IBM.r <- Return.calculate(Ad(IBM))
monthly.r<-cbind(IBM.r,managers[,c(8,10)],fill=0)
charts.PerformanceSummary(monthly.r)

图表输出

If you would like to make up data like the Bloomberg chart does, you may do that via na.approx, but please don't confuse that with real data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM