currently, I am trying to find the internal rate of return or cost of equity for companies over time. So I have many companies and for each company a time series of data. Hence, I am trying to find the cost of equity for each year for a given company. This requires to solve an equation like: Price = function(cost of equity, earnings0, earnings1, earnings2,.....) . Here the cost of equity is the only unkonwn paramter, while I have 13 input paramters.
In this context I wrote some mata code which loops over all observations and determines the cost of equity (here k). Nevertheles, the command optimize allows only for 9 Input paramters....
Does anyone have an idea how to increase the number of arguments or can recommand any other command that allows for at least 13 arguments?
Thanks a lof for your help and consideration!
Best,
Dominik
HTML Code:
mata: mata clear
mata
P = st_data(.,("me"))
GL = st_data(.,("g_l"))
B0 = st_data(.,("be"))
B1 = st_data(.,("be_1"))
B2 = st_data(.,("be_2"))
B3 = st_data(.,("be_3"))
B4 = st_data(.,("be_4"))
B5 = st_data(.,("be_5"))
E1 = st_data(.,("E_1"))
E2 = st_data(.,("E_2"))
E3 = st_data(.,("E_3"))
E4 = st_data(.,("E_4"))
E5 = st_data(.,("E_5"))
void eval0(todo, k, p, gl, b0, b1, b2, b3, b4, b5, e1, e2, e3, e4, e5, v, g, H) {
v = (p :- b0 :- ((e1 :- k :* b0) :/ (1 :+ k)) :- ((e2 :- k :* b1) :/ (1 :+ k)^2) :- ((e3 :- k :* b2) :/ (1 :+ k)^3) :- ((e4 :- k :* b3) :/ (1 :+ k)^4) :- ((e5 :- k :* b4) :/ (1 :+ k)^5) :- (((e5 :- k :* b4) :* (1+gl)) :/ ((1 :+ k)^5) :* (k-gl)))^2
}
S = optimize_init()
optimize_init_which(S, "min")
optimize_init_conv_ptol(S, 1e-12)
optimize_init_conv_vtol(S, 1e-12)
optimize_init_evaluator(S, &eval0())
optimize_init_params(S, (0))
for(i=1;i<=235313;i++) {
p =P[i..i,1..1]
gl =GL[i..i,1..1]
b0 =B0[i..i,1..1]
b1 =B1[i..i,1..1]
b2 =B2[i..i,1..1]
b3 =B3[i..i,1..1]
b4 =B4[i..i,1..1]
b5 =B5[i..i,1..1]
e1 =E1[i..i,1..1]
e2 =E2[i..i,1..1]
e3 =E3[i..i,1..1]
e4 =E4[i..i,1..1]
e5 =E5[i..i,1..1]
optimize_init_argument(S, 1, p)
optimize_init_argument(S, 2, gl)
optimize_init_argument(S, 3, b0)
optimize_init_argument(S, 4, b1)
optimize_init_argument(S, 5, b2)
optimize_init_argument(S, 6, b3)
optimize_init_argument(S, 7, b4)
optimize_init_argument(S, 8, b5)
optimize_init_argument(S, 9, E1)
optimize_init_argument(S, 10, E2)
optimize_init_argument(S, 11, E3)
optimize_init_argument(S, 12, E4)
optimize_init_argument(S, 13, E5)
k= optimize(S)
k
ri = k
ri
st_matrix("r"+strofreal(i),ri)
if (i == 1) R = st_matrix( "r1")
if (i >= 2) R = R \ ri
}
R
end
0 Response to Limitation of arguments in mata
Post a Comment