PerformanceAnalytics icon indicating copy to clipboard operation
PerformanceAnalytics copied to clipboard

CAPM.beta

Open ggrothendieck opened this issue 4 years ago • 3 comments

CAPM.beta help file claims it works with vectors and zoo objects but these fail. Also the error message runs off the edge of the screen and is unreadable.

CAPM.beta(1:10, 1:10)
## Error in checkData(Ra) : 
##    The data cannot be converted into a time series.  If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'.  Rownames should have standard date formats, such as '1985-03-

CAPM.beta(zoo(1:10), zoo(1:10))
## Error in checkData(Ra) : 
##   The data cannot be converted into a time series.  If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'.  Rownames should have standard date formats, such as '1985-03-15'. 

ggrothendieck avatar Aug 26 '21 18:08 ggrothendieck

what part of the error message isn't clear?


x<-zoo(1:10,as.Date(1:10))
CAPM.beta(x,x)
# 1
y<-as.vector(x)
names(y) <- index(x)
CAPM.beta(y,y)
# 1

braverock avatar Aug 27 '21 11:08 braverock

All inputs to CAPM.beta need to be able to be aligned by a time index. If checkData can't align Ra and Rb by the index, there is high chance of user error simply lining up two un-named vectors, or integer(or other non-time)-indexed ordered observations. In the example above, using a Date index (for zoo) or Date-formated names (for the vector) allow checkData to use the index directly for alignment in the case of the zoo object, or infer that the names are likely meant to be a Date index for the vector.

Perhaps you could be a little more clear about the use case that you see where using a non-time index makes sense?

braverock avatar Aug 27 '21 11:08 braverock

Also the error message runs off the edge of the screen and is unreadable.

I just checked this as well, and I can't reproduce this symptom,

I tested

CAPM.beta(1:10, 1:10)

in bash, csh, sh, ash terminals, which are all the terminals that I have installed, and also tested over ssh to a remote machine and tested in the RStudio terminal, and the the error message wraps based on the terminal width for me.

Perhaps terminal settings are to blame here? Or can you provide more information?

braverock avatar Aug 27 '21 11:08 braverock