performanceanalytics

R code to rename header of an xts object using name(object) <- vector

旧巷老猫 提交于 2021-02-19 05:38:08
问题 I'm new to learning R and I'm having an issue with some of my R code. I placed all the code for your convenience so that you can see the logic in what I am trying to do. My issue is renaming the header of my xts object Monthly_Quotes. I understand that when having an invalid stock symbol, the getsymbols function will not retrieve the quotes for "zzzz", which is why I am running into the issue of renaming the header. I'd like to resolve this such that if I have a much larger list of ticker

Cumulative Returns with NA's in R

左心房为你撑大大i 提交于 2021-02-18 13:47:12
问题 I have the following data frame: df <- data.frame(Return1=c(NA, NA, .03, .04, .05), Return2=c(.25, .33, NA, .045, .90), Return3=c(.04, .073, .08, .04, .01)) Return1 Return2 Return3 1 NA 0.250 0.040 2 NA 0.330 0.073 3 0.03 NA 0.080 4 0.04 0.045 0.040 5 0.05 0.900 0.010 I would like to compute the cumulative returns, but there are missing values in the dataframe. I used: cumprod(df+1)-1 Getting as a result Return1 Return2 Return3 1 NA 0.2500 0.0400000 2 NA 0.6625 0.1159200 3 NA NA 0.2051936 4

Cumulative Returns with NA's in R

£可爱£侵袭症+ 提交于 2021-02-18 13:46:46
问题 I have the following data frame: df <- data.frame(Return1=c(NA, NA, .03, .04, .05), Return2=c(.25, .33, NA, .045, .90), Return3=c(.04, .073, .08, .04, .01)) Return1 Return2 Return3 1 NA 0.250 0.040 2 NA 0.330 0.073 3 0.03 NA 0.080 4 0.04 0.045 0.040 5 0.05 0.900 0.010 I would like to compute the cumulative returns, but there are missing values in the dataframe. I used: cumprod(df+1)-1 Getting as a result Return1 Return2 Return3 1 NA 0.2500 0.0400000 2 NA 0.6625 0.1159200 3 NA NA 0.2051936 4

Faster alternative to function 'rollapply'

霸气de小男生 提交于 2021-02-05 04:50:18
问题 I need to run rolling window function on a xts data which contains about 7,000 rows and 11,000 columns. I did the following: require(PerformanceAnalytics) ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) I waited till 12 hours but the computation did not finish. However, when I tried with small dataset as follows: sample<-wddxts[,1:5] ssd60<-rollapply(sample,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) the computation was done within 60 seconds. I

Faster alternative to function 'rollapply'

房东的猫 提交于 2021-02-05 04:49:54
问题 I need to run rolling window function on a xts data which contains about 7,000 rows and 11,000 columns. I did the following: require(PerformanceAnalytics) ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) I waited till 12 hours but the computation did not finish. However, when I tried with small dataset as follows: sample<-wddxts[,1:5] ssd60<-rollapply(sample,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) the computation was done within 60 seconds. I

Using rollapply function for VaR calculation using R

僤鯓⒐⒋嵵緔 提交于 2019-12-31 02:34:09
问题 I did the following for calculating Value at Risk (VaR) over 20 period rolling window: require(PerformanceAnalytics); require(zoo) data(edhec) class(edhec) # [1] "xts" "zoo" class(edhec$CTAGlobal) # "NULL" var1<-rollapply(edhec,width=20,FUN=function(edhec) VaR(R=edhec,p=.95,method="modified"),by.column=TRUE) It produces the desired output, and then I tried the same on another data: data(managers) class(managers) # [1] "xts" "zoo" class(managers$HAM4) # [1] "xts" "zoo" var2<-rollapply(managers

VaR calculation with complete missing column

我只是一个虾纸丫 提交于 2019-12-24 04:34:03
问题 I need to calculate rolling VaR of stock returns. From this post: Using rollapply function for VaR calculation using R , I understand that columns having complete missing cases will give error. But since the starting date and end date of stock returns for various firms are different, it creates missing values when data is converted from long to wide format. Estimation can be done using only rows with no missing values but this leads to serious loss of data. Thus, is there any way to perform

R Recession Dates Conversion

牧云@^-^@ 提交于 2019-12-18 17:29:54
问题 I am downloading recession band data into R via quantmod . Now this comes as a binary information (in xts format) looking like this (just the first recession period shown) 1857-01-01 0 1857-02-01 0 1857-03-01 0 1857-04-01 0 1857-05-01 0 1857-06-01 0 1857-07-01 1 1857-08-01 1 1857-09-01 1 1857-10-01 1 1857-11-01 1 1857-12-01 1 1858-01-01 1 1858-02-01 1 1858-03-01 1 1858-04-01 1 1858-05-01 1 1858-06-01 1 1858-07-01 1 1858-08-01 1 1858-09-01 1 1858-10-01 1 1858-11-01 1 1858-12-01 1 Now, I have

Drawdowns- Performance Analytics error— Factor and Numeric

自闭症网瘾萝莉.ら 提交于 2019-12-11 06:51:28
问题 Some data in a text file: date,p 2013-11-14,0.001 2013-11-13,-0.005 2013-11-12,0.001 library(PerformanceAnalytics) stuff<-read.csv("C:stuffexample.txt") str(stuff) 'data.frame': 3 obs. of 2 variables: $ date: Factor w/ 3 levels "2013-11-12","2013-11-13",..: 3 2 1 $ p : num 0.001 -0.005 0.001 Want to use Performance Analytics on the data: AverageDrawdown(stuff) Error in checkData(R) : The data cannot be converted into a time series. If you are trying to pass in names from a data object with

No contribution in component VaR using historical method in R

喜欢而已 提交于 2019-12-11 02:56:51
问题 I am new to R. I am using package "PerformanceAnalytics" to calculate Component VaR of portfolio. If I use gaussian method , it returns contribution. > VaR(edhec, p=.95, method="gaussian", portfolio_method="component") no weights passed in, assuming equal weighted portfolio $VaR [,1] [1,] 0.01193358 $contribution Convertible Arbitrage CTA Global Distressed Securities Emerging Markets Equity Market Neutral Event Driven Fixed Income Arbitrage 0.0014400703 0.0003687009 0.0012961865 0.0032090406