[R-SIG-Finance] assetsLPM from fAssets and 0.moment
Nils Tobias Kramer
ntobiaskramer at gmail.com
Tue May 19 09:22:30 CEST 2015
thanks a lot for your answer. The precedence is key and was causing my confusion.
Because of the precedence the vector X.max raised to the power equals always 1, right? That's why the result for LPM0 is always one using assetsLPM:
> 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)
X.max is a vector (assuming a single time series) where the entries are 0 whenever the return is above tau and a positive return (the absolute return) whenever the return is below the threshold tau.
So now these numbers are taken to the power on 0 and every single entry results in beeing converted to 1 in assestLPM. At least the way I used it and I was expecting (and you confirmed this) that only the returns below tau should be counted.
> On 19.05.2015, at 07:54, Enrico Schumann <es at enricoschumann.net> wrote:
> 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
>> x <- weeklyReturn(IBM)
>> #using fAssets to calculate lpm, 0.order
>> tau <- 0 #to make things easier
>> assetsLPM(x,tau,0) #returns 1
>> [1,] 0
>> 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
>>  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
>> 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:
>> x <- weeklyReturn(IBM)
>> y <- -x
>> 2007-01-05 1
>> 2007-01-12 1
>> 2007-01-19 1
>> 2007-01-26 1
>> 2007-02-02 1
>> 2007-02-09 1
>> 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?
> 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 "-",
> is -1. But
> will give 1.
> Enrico Schumann
> Lucerne, Switzerland
[[alternative HTML version deleted]]
More information about the R-SIG-Finance