rxtszooperformanceanalytics

How to divide every value with the maximum value in each element in list object


I have data in xts format. Data consists of 360 monthly observations of 650 stocks. I spilt the data into years which results in a large list object with 30 elements (1 for each year) in it. Now for each stock value in every element in the list, I want to divide the value by the maximum value in the year, i.e. I have a stock in tata motor I want to divide its each 2005 year value by the maximum value in the 2005. I am replicating this the following code. I have divide the data into years. But not able to do further.

library(xts)
library(zoo)
library(PerformanceAnalytics)
## splitting the data into years
managers_years<-split(managers,f="years")

Solution

  • The problem can also be solved with out converting into data frame. With help of apply family functions, one can solve this. Try following code

    test<-lapply(managers_years,apply,2,function(x)x/max(x))