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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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