Help with updating Exit criteria

Reply
Super Contributor
Posts: 371

Help with updating Exit criteria

Good morning,

I have the following dataset:

Time      Value    Critical_level      Exit_level           

1              3              .                 .

2              9              20                30

3              5              3                   8

4              21           .                      .

5              31           .                     .

6              34           .                      .

For Time=2, I get in at its value of 9 and track its performance over time. If future value gets above Exit_level of 30, I will exit.

The tricky part is that, if value reach Critical_level (20), Exit_level should be increased by 10%. So at Time=4, Value is above 20 and therefore Exit_level is now increased by 10% to 33. So I will exit at Time=6 rather than time=5.

Any helps is very much appreciated.

Thank you,

HHC

Respected Advisor
Posts: 3,124

Re: Help with updating Exit criteria

What is the deal of T=3? Is that a downward exit setting?

Super Contributor
Posts: 371

Re: Help with updating Exit criteria

Hi,

Yes, it is downward exit. After Sas finish observation 2, finding its exit, it move to obsetvation 3.

Thank you,

Hhc

Super Contributor
Posts: 371

Re: Help with updating Exit criteria

Hi,

Yes, it is downward exit. After Sas finish observation 2, finding its exit, it move to obsetvation 3.

Thank you,

Hhc

Respected Advisor
Posts: 3,124

Re: Help with updating Exit criteria

Since you haven't lay out downward rules, this is only for the upward scenario:

data have;

input Time Value Critical_level Exit_level ; 

cards;

1 3 . .

2 9 20 30

3 5 3 8

4 21 . .

5 31 . .

6 34 . .

;

data want;

  set have;

  retain up_cr up_ext up_ext1 0;

if _n_=2 then do; up_cr=Critical_level; up_ext=Exit_level; up_ext1=Exit_level*1.1;end;

if value>= up_ext and _n_>3 then flag='sell';

  if value>= up_cr then up_ext=up_ext1;

run;

Haikuo

Super Contributor
Posts: 371

Re: Help with updating Exit criteria

Thank you, Haikuo.

Actually, I should be more clear about the output file which should be the original file and added 2 more column: Time2 that exit (or sell) happen and Actual_Exit_value (or up_ext1 in your code).

Based on your suggestion, I try the below code and it works.

Now, I am thinking to move it 1 step forward, which is: When critical_level is reached, I should change both Exit_level (up_ext 1) and Critical_level itself by 10%. So the whole system will move up by 10%.

Any suggestion is welcome,

Thank you,

HHC

data have;

input Time Value Critical_level Exit_level ;

cards;

1 3 . .

2 9 20 40

3 5 20 28

4 21 . .

5 31 . .

6 50 . .

;run;

data want3;

  set have nobs=totalobs;

  retain up_cr up_ext up_ext1 ;

found=0;

do n=_n_+1 to totalobs until(found=1);

  set have (keep=time value rename=(time=time2 value=value2)) point=n;

  up_cr=Critical_level; up_ext=Exit_level; up_ext1=Exit_level*1.1;

  if value2>up_ext then do;

  found=1;

  end;

  if value>=up_cr then up_ext=up_ext1;

end;

run;

data want3; set want3;

drop found;

if critical_level=. then do;

  time2=.;

  value2=.;

  end;

run;

Ask a Question
Discussion stats
  • 5 replies
  • 189 views
  • 3 likes
  • 2 in conversation