BookmarkSubscribeRSS Feed
ZRick
Obsidian | Level 7

I defined a function in fcmp, use ssum to accumulate previous result, initial value is 0, but it didn't take any effect.

When you run the data step in following code, the unsifted_t is the same as unshifed, but it should be same as unshifted_spot_result.

I really need this function to go through other variables.

data unshifted_t;

input

Years   

Unshifted Unshifted_spot_result;

cards;

0.5    0.06    0.06

1    0.0995    0.099509828

1.5    0.114    0.114015775

2    0.1285    0.128527322

2.5    0.17625    0.17636429

3    0.224    0.224255193

3.5    0.32975    0.330598452

4    0.4355    0.437295432

4.5    0.562    0.565505696

5    0.6885    0.694372675

5.5    0.806875    0.815596351

6    0.92525    0.937551696

6.5    1.043625    1.060324593

7    1.162    1.184005865

7.5    1.242833333    1.268562214

8    1.323666667    1.353681835

8.5    1.4045    1.43941207

9    1.485333333    1.525802656

9.5    1.566166667    1.612905958

10    1.647    1.70077724

10.5    1.7015    1.759653469

11    1.756    1.819015077

11.5    1.8105    1.878885836

12    1.865    1.939291582

12.5    1.900666667    1.978108796

13    1.936333333    2.017278596

13.5    1.972    2.056807704

14    2.007666667    2.096704449

14.5    2.043333333    2.136978638

15    2.079    2.177641474

;

proc fcmp outlib=work.ftn.krd;

function OSSC(in);

ssum= 0;

do i = 1 to 60;

    llatest = 0.5 * (in) / 100;

    spot_llatest1 = (1 - llatest*ssum) / (1 + llatest);

    ssum+spot_llatest1;

    spot_llatest2 = Exp(-Log(spot_llatest1)/i) - 1;

    spot_llatest3=spot_llatest2*100*2;

    return(spot_llatest3);

end;

endsub;

run;

data OSSC;

    set unshifted_t;

    Unshifted_s = OSSC(Unshifted);

    format unshifted_s 10.8;

run;

5 REPLIES 5
FriedEgg
SAS Employee

You are not letting your function loop as you are expecting.  By having the return function inside your do loop you are cuaseing it to prematurely end the computation.

Reeza
Super User

I may have made a mistake but the logic inside the code is set to return 0 for an input of 0 so you may have some logic issues, take a look at your definition of llatest which will always resolve to the same value.

It also looks like a NPV or bi-annual interest accumulation function and there should be a closed form or some other SAS function that might get you there easier.

FriedEgg
SAS Employee

I agree with Reeza that the function itself does not appear to have a purpose.  The return value will always equal the input value because of the mathmatical logic employed.  Since I am unaware of what you are attempting to calculate I chose to just point out the syntactical error in your function, but you should probably consider also checking your calculations logic as well.

ZRick
Obsidian | Level 7

how do I fix it then? retain statement has no effect in the fcmp function.

Reeza, it does look like a NPV issue, but it is acutally bootstrapping the zero curve rate.

FriedEgg
SAS Employee

I believe the zero-coupon yield curve can be calculated using the yieldp function.

YIELDP Function

Returns the yield-to-maturity for a periodic cash flow stream, such as a bond.

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001123050.htm

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1258 views
  • 0 likes
  • 3 in conversation