Post Reply 
help: divide a list into other two
05-19-2015, 09:23 PM
Post: #1
help: divide a list into other two
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

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
05-19-2015, 10:01 PM (This post was last modified: 05-19-2015 10:04 PM by Didier Lachieze.)
Post: #2
RE: help: divide a list into other two
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.
Find all posts by this user
Quote this message in a reply
05-19-2015, 10:06 PM
Post: #3
RE: help: divide a list into other two
(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

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
05-19-2015, 10:14 PM
Post: #4
RE: help: divide a list into other two
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?
Find all posts by this user
Quote this message in a reply
05-19-2015, 10:18 PM (This post was last modified: 05-19-2015 10:34 PM by salvomic.)
Post: #5
RE: help: divide a list into other two
(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...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
05-19-2015, 11:08 PM
Post: #6
RE: help: divide a list into other two
Try this:
Code:
flneg:=remove("x->x>=0,L1");
flpos:=CONCAT(0,remove("x->x<0,L1"));
Find all posts by this user
Quote this message in a reply
05-20-2015, 06:57 AM
Post: #7
RE: help: divide a list into other two
(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.

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)