0

I am trying to calculate the beta for a fund with a customized index in R. The customized index is made from a few different indexes. The index has data from before the fund, so when I am trying to calculate the beta by using

beta <- cov(data$fund,data$index, use =
            "pairwise.complete.obs")/var(data$index, use =
            "pairwise.complete.obs")

I get the variance from the whole period of the index. The covariance gets correct. I assume that I need to make the customized index to fit the data of the fund, but I can not find any answer on how I am doing this. My data is from latest to newest, so I need the start of the customized index to be NA to where the funds data starts. I need a function that gives me a column with the customized index with only data at the dates where the fund also has data.

Example of the data (random numbers):

Date     Fund        Customized Index 
01.01     NA             100
01.02     50             105

I want it the customized index column to be:

Date     Fund        Customized Index
01.01     NA              NA
01.02     50              105

Update: Solution

I used "ifelse" on making the customized index. This works just as the same way as =IF does in Excel.

Granax
  • 1
  • 1
  • Welcome to StackOverflow. Please take a look at these tips on how to produce a [minimum, complete, and verifiable example](http://stackoverflow.com/help/mcve), as well as this post on [creating a great example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – lmo Jan 27 '17 at 12:33
  • UPDATE: Solution: used "ifelse" on making the customized index. This works just as the same way as =IF does in Excel. – Granax Jan 27 '17 at 12:42
  • if you have solved your own problem, please post the solution as an answer ... – Ben Bolker Jan 27 '17 at 14:27

0 Answers0