HP Forums

Full Version: help: divide a list into other two
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi,
to calculate MIRR (modified IRR) I need to divide list L1 in this way:
if L1(j) < 0 -> flneg(j), if L1(j) >=0 -> flpos(j)

with
Code:

FOR j FROM 1 TO size(L1) DO
IF L1(j) < 0 THEN flneg(j):= L1(j); ELSE flpos(j):= L1(j); END;
END;

in both lists there is 0 at the correspondent place in the other list (i.e. {-1, 2, 3, -4} -> {-1, 0, 0, -4} and {0, 2, 3, 0}
I need {-1, -4} and {2, 3}

please, help
TIA!

Salvo
This should work:

Code:
flneg:=MIN(L1,0); flpos:=MAX(L1,0);
flneg:=remove(0,flneg);
flpos:=remove(0,flpos);

You need to do it in two steps: flneg:=remove(0,MIN(L1,0)) doesn't work.
(05-19-2015 10:01 PM)Didier Lachieze Wrote: [ -> ]This should work:

Code:
flneg:=MIN(L1,0); flpos:=MAX(L1,0);
flneg:=remove(0,flneg);
flpos:=remove(0,flpos);

You need to do it in two steps: flneg:=remove(0,MIN(L1,0)) doesn't work.


Thank you!
quite ok, but there is a possibility that the original list has zeros among items (i.e {-100, 100, 100, 0, 0, 0, -50, -50, 100})

Any help for this?
TIA

salvo
As in your program example you were testing L1(j)<0 and L1(j)>0 I assumed you wanted to discard the zeros.
So, where do you want the zeros to fall? In both lists?
(05-19-2015 10:14 PM)Didier Lachieze Wrote: [ -> ]As in your program example you were testing L1(j)<0 and L1(j)>0 I assumed you wanted to discard the zeros.
So, where do you want the zeros to fall? In both lists?

I think only in flpos, positive...

precisely, to calc MIRR I must have a list of positive values (and 0) and a list of negative, in the same order of original.
Actually I've this list {-180000, 100000 (5 times), -100000 (5 times), 0 (9 times), 200000}
that's {-180000, 100000, 100000, 100000, 100000, 100000, -100000, -100000, -100000, -100000, -100000, 0,0,0,0,0,0,0,0,0, 200000}
The 9 zeros are period to discount...

EDIT
(see here page 193)
positive list must also have a first element prepend, zero:
{0, 100000, ..., 0, 0, ..., 200000} but this is another 0 (fix, I think) Smile

However, maybe the leading zeros are ok, I'm trying another way...
Try this:
Code:
flneg:=remove("x->x>=0,L1");
flpos:=CONCAT(0,remove("x->x<0,L1"));
(05-19-2015 11:08 PM)Didier Lachieze Wrote: [ -> ]Try this:
Code:
flneg:=remove("x->x>=0,L1");
flpos:=CONCAT(0,remove("x->x<0,L1"));

(05-19-2015 11:15 PM)DrD Wrote: [ -> ]
(05-19-2015 10:01 PM)Didier Lachieze Wrote: [ -> ]This should work:

Code:
flneg:=MIN(L1,0); flpos:=MAX(L1,0);
flneg:=remove(0,flneg);
flpos:=remove(0,flpos);

You need to do it in two steps: flneg:=remove(0,MIN(L1,0)) doesn't work.

or this:

flneg:=remove((x)->x≥0,L1)

thank you both!
this tip is very interesting.
Reference URL's