[R-SIG-Finance] assetsLPM from fAssets and 0.moment

Nils Tobias Kramer ntobiaskramer at gmail.com
Tue May 12 12:29:03 CEST 2015


Hi there,

I was wondering how to calculate LPMs in R. My interpretation of the
0.moment is somehow different from what I can see in fAssets:

#using quantmod to get just any data
getSymbols("IBM")
x <- weeklyReturn(IBM)
#using fAssets to calculate lpm, 0.order
tau <- 0 #to make things easier
assetsLPM(x,tau,0) #returns 1
$mu
weekly.returns
             1
$Sigma
     [,1]
[1,]    0
attr(,"control")
  a tau
  0   0

When I think of lpm 0 I think of the probability that my returns are below
tau. This is what I expect let's say from Matlab.

Code of assetsLPM:
TauX <- Tau - x #0-x in my case
X.max <- ((TauX) + abs(TauX))/2 #equals max(0,-returns), so either 0 for
positive returns and for negative returns the absolute value of that return
LPM <- colMeans(X.max^a)

Checking what R does by ^0:
> -1^0
[1] -1
> 0^0
[1] 1
> 1^0
[1] 1

I can see why the sum is expected to be 1 as there are only elements either
0 or positive which are taken to the power of 0 which equals 1 for each
entry.

Somehow I can't get my interpretation (probability) and the output of 1
together. Maybe someone can help me out?

Aside, this here confuses my a little:
getSymbols("IBM")
x <- weeklyReturn(IBM)
y <- -x
head(y^0)
           weekly.returns
2007-01-05              1
2007-01-12              1
2007-01-19              1
2007-01-26              1
2007-02-02              1
2007-02-09              1
> head(y)
           weekly.returns
2007-01-05   -0.002469644
2007-01-12   -0.019708479
2007-01-19    0.031910610
2007-01-26   -0.013309764
2007-02-02   -0.017650077
2007-02-09    0.006251891

Now all entries are 1 when taken to the power of 0 whereas I expected only
the positive numbers to turn to 1 and the negative ones to -1!?

Anyways, the first and second moments of assetsLPM are just what I
expected, so I was wondering why I can't figure out the reason for the
results of the 0. moment.

Any insights?

Thanks
Toby

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list