Hi everyone,
I need to calculate cost of capital based on the model looks like below:
All the variables in this model are known, except the discount rate .
I’m entering a dead end to find useful code to solve the equation above, where only is the unknown.
If you know a solution to this problem, please comment, it is very much appreciated.
Thank you very much.
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).
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).
Do you have SAS/IML? Calling @Rick_SAS
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.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.