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

Enrico Schumann es at enricoschumann.net
Tue May 19 07:54:22 CEST 2015

```On Tue, 12 May 2015, Nils Tobias Kramer <ntobiaskramer at gmail.com> writes:

> 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
>> 0^0
>  1
>> 1^0
>  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
>            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
>            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

I am not sure I understand your question, or your questions. Since no
one else answered, let me venture two remarks.

First, on partial moments. The standard way to compute a partial moment
from a sample is this:

(i) sum over all returns below tau and raise them to zeroth power (in
your case). Any number below tau will map to one, and any number
above tau will map to zero.

(ii) divide this sum by the total number of observations. So, for
instance, with 10 observations and 5 of them below tau, you will
get 5/10 = 0.5, which is the empirical frequency of returns below
tau in your sample. Hence the interpretation of probability.

Second, on raising negative numbers to the zeroth power: you need to
consider operator precendence. The "^" binds more tightly than "-",
hence

-1^0

is -1. But

(-1)^0

will give 1.

--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

```