BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MAC1430
Pyrite | Level 9

Hi everyone,

I need to calculate cost of capital based on the model looks like below:

cheema_3-1630632232865.png

All the variables in this model are known, except the discount rate cheema_4-1630632251555.png.

I’m entering a dead end to find useful code to solve the equation above, where only cheema_5-1630632251555.png  is the unknown.

If you know a solution to this problem, please comment, it is very much appreciated.

Thank you very much.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @MAC1430,

 

I think you can use the SOLVE function in PROC FCMP:

/* Define function DISCRATE */

proc fcmp outlib=work.funcs.test;
function rhs(t, B[*], a, g, e[*], c);
  s=B[t];
  do tau=1 to 5;
    s = s + a*e[t+tau]/(1+g+c)**tau;
  end;
  s = s + a*e[t+5]*(1+g)/(c*(1+g+c)**5);
  return(s);
endfunc;
function discrate(t, P[*], B[*], a, g, e[*]);
  r=g+solve("RHS", {.}, P[t], t, B, a, g, e, .);
  return(r);
endfunc;
run;

/* Make function available */

options cmplib=work.funcs;

/* Apply function DISCRATE to arbitrary sample data */

data test;
array p[3] (175 180 190);
array b[3] (  2   3   4);
array e[8] (. 1.1 0.8 0.9 1.2 1.0 0.7 0.6);
a=0.5772;
g=0.0123;
do t=1 to 3;
  dr=discrate(t,p,b,a,g,e);
  output;
end;
run;

 

EDIT:  Took the second fraction out of the sum (t=1, ..., 5), as this seems more plausible mathematically (without knowing the background or source of the formula).

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hi @MAC1430,

 

I think you can use the SOLVE function in PROC FCMP:

/* Define function DISCRATE */

proc fcmp outlib=work.funcs.test;
function rhs(t, B[*], a, g, e[*], c);
  s=B[t];
  do tau=1 to 5;
    s = s + a*e[t+tau]/(1+g+c)**tau;
  end;
  s = s + a*e[t+5]*(1+g)/(c*(1+g+c)**5);
  return(s);
endfunc;
function discrate(t, P[*], B[*], a, g, e[*]);
  r=g+solve("RHS", {.}, P[t], t, B, a, g, e, .);
  return(r);
endfunc;
run;

/* Make function available */

options cmplib=work.funcs;

/* Apply function DISCRATE to arbitrary sample data */

data test;
array p[3] (175 180 190);
array b[3] (  2   3   4);
array e[8] (. 1.1 0.8 0.9 1.2 1.0 0.7 0.6);
a=0.5772;
g=0.0123;
do t=1 to 3;
  dr=discrate(t,p,b,a,g,e);
  output;
end;
run;

 

EDIT:  Took the second fraction out of the sum (t=1, ..., 5), as this seems more plausible mathematically (without knowing the background or source of the formula).

Ksharp
Super User

Do you have SAS/IML? Calling @Rick_SAS 

Rick_SAS
SAS Super FREQ

For more information about how to use the SOLVE function and PROC FCMP, see "Find the root of a function by using the SAS DATA step."

 

The same article provides links to other root-finding methods in SAS. As @Ksharp points out, the easiest way to solve this equation is to use the FROOT function in SAS/IML, if you have a license for SAS/IML.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 801 views
  • 9 likes
  • 4 in conversation