01-04-2024
MAC1430
Pyrite | Level 9
Member since
07-04-2014
- 95 Posts
- 51 Likes Given
- 0 Solutions
- 0 Likes Received
-
Latest posts by MAC1430
Subject Views Posted 807 09-29-2021 12:55 AM 950 09-28-2021 04:37 AM 2536 09-22-2021 04:17 AM 2573 09-21-2021 01:02 AM 2598 09-20-2021 08:00 AM 2642 09-19-2021 06:42 AM 2691 09-16-2021 09:15 PM 2737 09-16-2021 12:05 AM 2821 09-15-2021 03:03 AM 2853 09-15-2021 02:50 AM -
Activity Feed for MAC1430
- Posted Re: Issues in solving equation on SAS Programming. 09-29-2021 12:55 AM
- Liked Re: Issues in solving equation for FreelanceReinh. 09-29-2021 12:54 AM
- Posted Issues in solving equation on SAS Programming. 09-28-2021 04:37 AM
- Posted Re: FCMP - solving equation on SAS Programming. 09-22-2021 04:17 AM
- Liked Re: FCMP - solving equation for FreelanceReinh. 09-21-2021 08:27 PM
- Posted Re: FCMP - solving equation on SAS Programming. 09-21-2021 01:02 AM
- Posted Re: FCMP - solving equation on SAS Programming. 09-20-2021 08:00 AM
- Liked Re: FCMP - solving equation for FreelanceReinh. 09-20-2021 12:34 AM
- Posted Re: FCMP - solving equation on SAS Programming. 09-19-2021 06:42 AM
- Liked Re: FCMP - solving equation for FreelanceReinh. 09-19-2021 06:39 AM
- Posted Re: FCMP - solving equation on SAS Programming. 09-16-2021 09:15 PM
- Posted Re: FCMP - solving equation on SAS Programming. 09-16-2021 12:05 AM
- Posted Re: FCMP - solving equation on SAS Programming. 09-15-2021 03:03 AM
- Posted FCMP - solving equation on SAS Programming. 09-15-2021 02:50 AM
- Liked Re: PROC IML to solve non-linear equation for Rick_SAS. 09-09-2021 01:20 AM
- Posted Re: PROC IML to solve non-linear equation on SAS/IML Software and Matrix Computations. 09-08-2021 09:03 PM
- Posted Re: PROC IML to solve non-linear equation on SAS/IML Software and Matrix Computations. 09-07-2021 07:32 PM
- Liked Re: PROC IML to solve non-linear equation for Rick_SAS. 09-07-2021 07:30 PM
- Posted Re: PROC IML to solve non-linear equation on SAS/IML Software and Matrix Computations. 09-07-2021 03:47 AM
- Posted PROC IML to solve non-linear equation on SAS/IML Software and Matrix Computations. 09-06-2021 09:35 PM
-
Posts I Liked
Subject Likes Author Latest Post 1 2 1 1 1
09-28-2021
04:37 AM
Hi everyone,
I tried to use the code below to solve r in the bove equation.
Could you please have a look at what is the issue in the attached SAS code?
Thank you very much for your help.
KindRegards,
Mac
... View more
09-21-2021
01:02 AM
Thank you very much Reinhard, I selected some sotcks in the attached.
... View more
09-20-2021
08:00 AM
Thank you very much for the explanation Reinhard.
I applied the procedure on my real dataset, got a mix of positive and negative results in both r1 and r2, some missing values as well. I guess it has something to do with the selection of initial value? Any suggestions how to select an initial value that returns the more robust results? (The unknown r I’m looking for is a rate of return, which should be positive numbers and not exceed 1 or 100%.)
Thank you again for your help, it's really appreciated.
... View more
09-19-2021
06:42 AM
Thank you very much Reinhard,
I will apply the code on other equations, so trying to understand every bit of the procedure here. I got two questions.
First, I understand how c0 (the intercept) is derived. But, having trouble to get C1 to C6. Could you kindly explain it?
Second, in the check procedure, s2 is defined as:
s2 = s2 + (B[t]+F[t]/2)/u**(t+1);
However, the equation has terms of (B[t]+F[t+1]/2)/u**(t+2) rather than (B[t]+F[t]/2)/u**(t+1). Such as,
So, I made an attempt to modify by introducing s3, and separate the above terms into two parts (B[t]/u**(t+2), and (F[t]/2)/u**(t+1)) the code becomes:
proc fcmp outlib=work.funcs.test;
function h(r, p, B[*], F[*], g);
u=1+r;
s1=p-B[1];
do t=1 to 5;
s1 = s1 - F[t]/u**t;
end;
s2=B[1]/u;
do t=1 to 3;
s2 = s2 + B[t]/u**(t+2);
end;
s3 = B[1]/u**2;
do t=1 to 4;
s3 = s3 + (F[t]/2)/u**(t+1);
end;
z = s1 + r*s2 + r*s3 - (F[5]+r*B[4])*(1+g)/((r-g)*u**5);
return(z);
endfunc;
run;
Is my understanding correct? The diff1 and diff2 values become much bigger after this modification.
Thank you.
... View more
09-16-2021
09:15 PM
Thank you very much Reinhard, F was used to calculate F1 to F5, yes, we can ignore F for this equation.
... View more
09-16-2021
12:05 AM
Thank you very much Reinhard, below is my current try (could be silly) by modifying your code.
data test;
input stock$ y P B B1 B2 B3 B4 F F1 F2 F3 F4 F5 g;
datalines;
A 1 80.16 12.1492 14.7642 17.7592 21.1642 24.6292 3.8886 5.23 5.99 6.81 6.93 6.63 0.3038
A 2 63.54 15.3785 18.4785 21.9535 25.8685 29.9185 4.8659 6.2 6.95 7.83 8.1 8.51 0.3769
A 3 41.19 11.5507 15.1507 19.1257 23.5857 28.3907 4.5454 7.2 7.95 8.92 9.61 10.47 0.205
A 4 35.28 15.1777 18.7327 22.7277 27.1727 32.2727 4.3858 7.11 7.99 8.89 10.2 11.14 0.1478
A 5 52 14.9545 18.3545 22.1945 26.4395 31.1195 5.7079 6.8 7.68 8.49 9.36 11.07 0.0644
A 6 50.78 15.8837 19.6137 23.8137 28.4137 33.5537 6.1861 7.46 8.4 9.2 10.28 11.43 -0.0636
A 7 67.64 19.3065 23.2765 27.6065 32.3565 37.6015 6.7226 7.94 8.66 9.5 10.49 12.24 -0.0915
A 8 72.05 21.6415 26.5265 31.9415 37.8015 44.3815 7.7686 9.77 10.83 11.72 13.16 14.59 -0.0553
A 9 74.51 23.6561 30.0461 36.9961 44.5511 52.4911 8.804 12.78 13.9 15.11 15.88 11.32 0.0005
A 10 43.05 27.2373 34.5373 42.7023 51.6873 61.0373 9.0739 14.6 16.33 17.97 18.7 16.621 0.123
B 1 37.8 6.3668 7.6503 9.0298 10.5533 12.2488 2.7893 2.567 2.759 3.047 3.391 3.807 0.3038
B 2 35.4 7.6967 8.9367 10.2797 11.7422 13.3282 3.238 2.48 2.686 2.925 3.172 3.46 0.3769
B 3 29.3 8.6812 10.0817 11.5857 13.2137 14.9497 3.2122 2.801 3.008 3.256 3.472 3.778 0.205
B 4 30.9 8.999 10.3945 11.8675 13.4585 15.18 3.2352 2.791 2.946 3.182 3.443 3.753 0.1478
B 5 29.75 9.5064 10.9409 12.4669 14.1014 15.9644 3.5381 2.869 3.052 3.269 3.726 3.942 0.0644
B 6 39.3 10.1293 11.6418 13.2513 14.9848 16.8748 3.4308 3.025 3.219 3.467 3.78 3.954 -0.0636
B 7 43.3 12.2344 13.8109 15.4949 17.3094 19.3754 3.7561 3.153 3.368 3.629 4.132 4.534 -0.0915
B 8 52 13.2885 14.78 16.4125 18.216 20.2585 4.2523 2.983 3.265 3.607 NA NA -0.0553
B 9 41.6 13.9864 15.6949 17.5539 19.5994 21.7379 4.7464 3.417 3.718 4.091 4.277 4.836 0.0005
B 10 50.2 14.043 16.067 18.2475 20.607 23.178 4.2598 4.048 4.361 4.719 5.142 5.474 0.123
C 1 24.19 1.4639 3.5839 4.8589 6.6539 9.1189 0.3939 4.24 2.55 3.59 4.93 5.63 0.3038
C 2 19.52 2.3384 3.9534 5.7434 7.9884 10.8534 1.3403 3.23 3.58 4.49 5.73 6.51 0.3769
C 3 7.96 2.626 3.711 5.381 7.581 10.846 -1.0251 2.17 3.34 4.4 6.53 5.9 0.205
C 4 15.72 2.7283 4.0083 5.8033 8.0983 11.6433 0.3156 2.56 3.59 4.59 7.09 7.28 0.1478
C 5 11.81 2.3651 3.9451 5.7001 7.9701 10.8651 0.049 3.16 3.51 4.54 5.79 6.39 0.0644
C 6 16.9 2.8771 4.4821 6.5371 9.0671 11.6921 0.964 3.21 4.11 5.06 5.25 7.21 -0.0636
C 7 18.84 3.532 5.792 8.587 12.027 16.417 1.1485 4.52 5.59 6.88 NA NA -0.0915
C 8 21.66 4.5199 7.5199 11.0849 15.4049 20.4099 2.0169 6 7.13 8.64 10.01 11.18 -0.0553
C 9 12.75 4.379 7.449 11.774 16.944 23.244 2.0582 6.14 8.65 10.34 12.6 13.89 0.0005
C 10 24 4.6028 8.4778 13.4228 19.5128 26.4078 0.9412 7.75 9.89 12.18 13.79 16.74 0.123
;
/* Define function XRATE */
proc fcmp outlib=work.funcs.test;
function rs(w, y, B, B1, B2, B3, B4, F1, F2, F3, F4, F5, g, x);
select(w);
when(1) z=-1-exp(-x*1e4); /* for a solution < -1 */
when(2) z=-1+exp(-x*1e4); /* for a solution > -1 */
when(3) z=g+sign((F5-g*B4)*(1+g))*exp(-x*1e4); /* for a solution near g */
end;
p = (F1/(g+z)+F2/(g+z)**2+F3/(g+z)**3+F4/(g+z)**4+F5/(g+z)**5)-(z+g)*(B/(1+g+z)+B1/(1+g+z)**2+B2/(1+g+z)**3+B3/(1+g+z)**4+B4/(1+g+z)**5)+(F5-(g+z)*B4)*(1+g)/(z*(1+g+z)**5);
return(p);
endsub;
function xrate(w, y, p, B, B1, B2, B3, B4, F1, F2, F3, F4, F5, g);
array solvopts[5] initial abconv relconv maxiter status (0.001 0.001 1.0e-6 100);
t=exp(-solve("RS", solvopts, p, w, y, B, B1, B2, B3, B4, F1, F2, F3, F4, F5, g, .)*1e4);
select(w);
when(1) r=-1-t; /* solution < -1 */
when(2) r=-1+t; /* solution > -1 */
when(3) r=g+sign((F5-g*B4)*(1+g))*t; /* solution near g */
end;
return(r);
endfunc;
run;
/* Make function available */
options cmplib=work.funcs;
/* Apply function XRATE to dataset TEST */
data want;
array _B[99] _temporary_;
array _B1[99] _temporary_;
array _B2[99] _temporary_;
array _B3[99] _temporary_;
array _B4[99] _temporary_;
array _P[99] _temporary_;
array _F1[99] _temporary_;
array _F2[99] _temporary_;
array _F3[99] _temporary_;
array _F4[99] _temporary_;
array _F5[99] _temporary_;
do until(last.stock);
set test;
by stock;
r1=xrate(1,y,_P,_B,_B1,_B2,_B3,_B4,_F1,_F2,_F3,_F4,_F5,g);
r2=xrate(2,y,_P,_B,_B1,_B2,_B3,_B4,_F1,_F2,_F3,_F4,_F5,g);
r3=xrate(3,y,_P,_B,_B1,_B2,_B3,_B4,_F1,_F2,_F3,_F4,_F5,g);
output;
end;
... View more
09-15-2021
03:03 AM
yes, I tried and still trying, got error "ERROR 71-185: The xrate function call does not have enough arguments".
... View more
09-15-2021
02:50 AM
Hi everyone,
To solve equation below to calculate the unknown r:
Data looks like:
data test;
input stock$ year P B B1 B2 B3 B4 F F1 F2 F3 F4 F5 g;
datalines;
A 1 80.16 12.1492 14.7642 17.7592 21.1642 24.6292 3.8886 5.23 5.99 6.81 6.93 6.63 0.3038
A 2 63.54 15.3785 18.4785 21.9535 25.8685 29.9185 4.8659 6.2 6.95 7.83 8.1 8.51 0.3769
A 3 41.19 11.5507 15.1507 19.1257 23.5857 28.3907 4.5454 7.2 7.95 8.92 9.61 10.47 0.205
A 4 35.28 15.1777 18.7327 22.7277 27.1727 32.2727 4.3858 7.11 7.99 8.89 10.2 11.14 0.1478
A 5 52 14.9545 18.3545 22.1945 26.4395 31.1195 5.7079 6.8 7.68 8.49 9.36 11.07 0.0644
A 6 50.78 15.8837 19.6137 23.8137 28.4137 33.5537 6.1861 7.46 8.4 9.2 10.28 11.43 -0.0636
A 7 67.64 19.3065 23.2765 27.6065 32.3565 37.6015 6.7226 7.94 8.66 9.5 10.49 12.24 -0.0915
A 8 72.05 21.6415 26.5265 31.9415 37.8015 44.3815 7.7686 9.77 10.83 11.72 13.16 14.59 -0.0553
A 9 74.51 23.6561 30.0461 36.9961 44.5511 52.4911 8.804 12.78 13.9 15.11 15.88 11.32 0.0005
A 10 43.05 27.2373 34.5373 42.7023 51.6873 61.0373 9.0739 14.6 16.33 17.97 18.7 16.621 0.123
B 1 37.8 6.3668 7.6503 9.0298 10.5533 12.2488 2.7893 2.567 2.759 3.047 3.391 3.807 0.3038
B 2 35.4 7.6967 8.9367 10.2797 11.7422 13.3282 3.238 2.48 2.686 2.925 3.172 3.46 0.3769
B 3 29.3 8.6812 10.0817 11.5857 13.2137 14.9497 3.2122 2.801 3.008 3.256 3.472 3.778 0.205
B 4 30.9 8.999 10.3945 11.8675 13.4585 15.18 3.2352 2.791 2.946 3.182 3.443 3.753 0.1478
B 5 29.75 9.5064 10.9409 12.4669 14.1014 15.9644 3.5381 2.869 3.052 3.269 3.726 3.942 0.0644
B 6 39.3 10.1293 11.6418 13.2513 14.9848 16.8748 3.4308 3.025 3.219 3.467 3.78 3.954 -0.0636
B 7 43.3 12.2344 13.8109 15.4949 17.3094 19.3754 3.7561 3.153 3.368 3.629 4.132 4.534 -0.0915
B 8 52 13.2885 14.78 16.4125 18.216 20.2585 4.2523 2.983 3.265 3.607 NA NA -0.0553
B 9 41.6 13.9864 15.6949 17.5539 19.5994 21.7379 4.7464 3.417 3.718 4.091 4.277 4.836 0.0005
B 10 50.2 14.043 16.067 18.2475 20.607 23.178 4.2598 4.048 4.361 4.719 5.142 5.474 0.123
C 1 24.19 1.4639 3.5839 4.8589 6.6539 9.1189 0.3939 4.24 2.55 3.59 4.93 5.63 0.3038
C 2 19.52 2.3384 3.9534 5.7434 7.9884 10.8534 1.3403 3.23 3.58 4.49 5.73 6.51 0.3769
C 3 7.96 2.626 3.711 5.381 7.581 10.846 -1.0251 2.17 3.34 4.4 6.53 5.9 0.205
C 4 15.72 2.7283 4.0083 5.8033 8.0983 11.6433 0.3156 2.56 3.59 4.59 7.09 7.28 0.1478
C 5 11.81 2.3651 3.9451 5.7001 7.9701 10.8651 0.049 3.16 3.51 4.54 5.79 6.39 0.0644
C 6 16.9 2.8771 4.4821 6.5371 9.0671 11.6921 0.964 3.21 4.11 5.06 5.25 7.21 -0.0636
C 7 18.84 3.532 5.792 8.587 12.027 16.417 1.1485 4.52 5.59 6.88 NA NA -0.0915
C 8 21.66 4.5199 7.5199 11.0849 15.4049 20.4099 2.0169 6 7.13 8.64 10.01 11.18 -0.0553
C 9 12.75 4.379 7.449 11.774 16.944 23.244 2.0582 6.14 8.65 10.34 12.6 13.89 0.0005
C 10 24 4.6028 8.4778 13.4228 19.5128 26.4078 0.9412 7.75 9.89 12.18 13.79 16.74 0.123
;
This is a variant of a previous post with a different data layout (https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766280#M242843).
... View more
09-08-2021
09:03 PM
Thank you very much for the comment.
In the equation, p, denote the stock price; r, denote a discount rate; all the vars (p,B,F,g,r) are specific to each stock.
By solving the equation, I want to estimate the values of r, for each stock and year (y).
I want a solution using proc IML because it is advised that it’s most suitable to solve problems like this. I want to learn how to use porc IML for this equation, with the hope to solve other problems like this. It’s a learning process for me, and hope the solution can benefit other SAS users as well.
Please feel free to comment if more info needed, thank you for the help.
... View more
09-07-2021
07:32 PM
Hi Rick,
Thank you very much.
Yes, solution for y<=5 would be great, assuming the first 5 year are known data, last 5 year are forecast data.
Please let me know if you need more information, thank you for the help.
... View more
09-07-2021
03:47 AM
Another member has already helped me finding the solution using Proc fcmp. https://communities.sas.com/t5/SAS-Programming/Solving-Equation/m-p/766280#M242843 I am wondering if someone can help me to find solution using Proc IML. Thank you very much.
... View more
09-06-2021
09:35 PM
Hi everyone,
I need to calculate the unknown discount rate r in the equation below, all the other variables in the model are known.
Anyone knows how to solve the equation below using PROC IML, Froot function please?
A data sample looks like below:
data test;
input stock$ y B P F g;
datalines;
A 1 12.1492 80.16 3.8886 0.3038
A 2 15.3785 63.54 4.8659 0.3769
A 3 11.5507 41.19 4.5454 0.205
A 4 15.1777 35.28 4.3858 0.1478
A 5 14.9545 52 5.7079 0.0644
A 6 15.8837 50.78 6.1861 -0.0636
A 7 19.3065 67.64 6.7226 -0.0915
A 8 21.6415 72.05 7.7686 -0.0553
A 9 23.6561 74.51 8.804 0.0005
A 10 27.2373 43.05 9.0739 0.123
B 1 6.3668 37.8 2.7893 0.3038
B 2 7.6967 35.4 3.238 0.3769
B 3 8.6812 29.3 3.2122 0.205
B 4 8.999 30.9 3.2352 0.1478
B 5 9.5064 29.75 3.5381 0.0644
B 6 10.1293 39.3 3.4308 -0.0636
B 7 12.2344 43.3 3.7561 -0.0915
B 8 13.2885 52 4.2523 -0.0553
B 9 13.9864 41.6 4.7464 0.0005
B 10 14.043 50.2 4.2598 0.123
C 1 1.4639 24.19 0.3939 0.3038
C 2 2.3384 19.52 1.3403 0.3769
C 3 2.626 7.96 -1.0251 0.205
C 4 2.7283 15.72 0.3156 0.1478
C 5 2.3651 11.81 0.049 0.0644
C 6 2.8771 16.9 0.964 -0.0636
C 7 3.532 18.84 1.1485 -0.0915
C 8 4.5199 21.66 2.0169 -0.0553
C 9 4.379 12.75 2.0582 0.0005
C 10 4.6028 24 0.9412 0.123
;
If you know the solution to the problem, please comment, thank you very much.
... View more