I want to compute the mean, min and max of a series of Managers returns, as follows:
ManagerRet <-data.frame(diff(Managerprices)/lag(Managerprices,k=-1))
I then replace return = 0 with NaN since data are extracted from a database and not all the dates are populated.
ManagerRet = replace(ManagerRet,ManagerRet==0,NaN)
I have the following 3 function
> min(ManagerRet,na.rm = TRUE)
[1] -0.0091716
> max(ManagerRet,na.rm = TRUE)
[1] 0.007565
> mean(ManagerRet,na.rm = TRUE)*252
[1] NaN
Why the mean function returns a NaN value while min and max performe calculation properly?
Below you can find the zoo object MangerRet
> ManagerRet
Manager
2011-10-04 NaN
2011-10-05 NaN
2011-10-06 NaN
2011-10-07 NaN
2011-10-11 NaN
2011-10-12 NaN
2011-10-13 NaN
2011-10-14 NaN
2011-10-17 NaN
2011-10-18 NaN
2011-10-19 NaN
2011-10-20 NaN
2011-10-21 NaN
2011-10-24 NaN
2011-10-25 NaN
2011-10-26 NaN
2011-10-27 NaN
2011-10-28 NaN
2011-10-31 6.3832e-04
2011-11-01 -4.4625e-06
2011-11-02 2.8142e-03
2011-11-03 5.1114e-04
2011-11-04 -1.0105e-03
2011-11-07 7.5650e-03
2011-11-08 2.1002e-03
2011-11-09 -9.1716e-03
2011-11-10 1.1173e-03
2011-11-14 -6.9207e-03
2011-11-15 2.6241e-04
2011-11-16 1.7520e-03
2011-11-17 -2.6443e-05
2011-11-18 -1.4169e-03
2011-11-21 3.7602e-04
2011-11-22 4.3982e-05
2011-11-23 -6.7328e-06
2011-11-25 1.1571e-05
2011-11-28 1.4016e-07
2011-11-29 -2.0426e-07
Additional info as required
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=Italian_Italy.1252 LC_CTYPE=Italian_Italy.1252
[3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C
[5] LC_TIME=Italian_Italy.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] gWidgetsRGtk2_0.0-81 gWidgets_0.0-52
[3] RGtk2_2.20.25 lattice_0.20-15
[5] moments_0.13 data.table_1.8.8
[7] tseries_0.10-30 timeDate_2160.97
[9] PerformanceAnalytics_1.1.0 xts_0.9-3
[11] zoo_1.7-9 RODBC_1.3-6
loaded via a namespace (and not attached):
[1] grid_2.15.2 quadprog_1.5-4