0
votes

So I am trying to calculate this formula but the results are strange. The elements are extremely large so I am not sure where I went wrong. I have attached a photo of the formula:enter image description here

and here is my code:

*calculating mu_sum and sigma_sum;
T_hat=180;
mu_sum_first_part={0,0,0,0};
mu_sum_second_part={0,0,0,0};
mu_sum={0,0,0,0};

*calculating mu_sum;
do i = 0 to T_hat;
    term=(T_hat - i)*(B0**i)*a;
    mu_sum_first_part = mu_sum_first_part + term;
end;
do i=1 to T_hat; 
    term =B0**i;
    mu_sum_second_part = mu_sum_second_part + term;
end;
mu_sum = mu_sum_first_part + mu_sum_second_part*zt;
print mu_sum;

*calculating sigma_sum;
term=I(4);
sigma_sum=sigma;
do j=1 to T_hat;
    term = term + B0**j;
    sigma_sum = sigma_sum + (term*sigma*(term`));
end;
print sigma_sum;

I know this is long but please help!!

2
What is this calculating, I would like to look it up? Is Bo a scalar, vector, or matrix? I would have thought a vector, but I+Bo doesn't make sense in that way.DomPazz
@DomPazz I am doing a asset allocation task. this is from a paper by Barberis (2000 JF) "Investing for the long run when returns are predictable". Bo is a 4x4 matrix with the first column being zeros. alpha is a 4x1 matrix and sigma is a 4x4 matrix.duckman
I haven't pulled the paper, is the power operator on the matrix a matrix power or element-wise power? IE B^2 = B`*B or B#B where # is an element-wise multiplicationDomPazz
The "double star operator" is repeated matrix multiplication.Rick
@DomPazz the power operator is matrix power, not element-wise powerduckman

2 Answers

0
votes

First thing that jumps out at me is your loop first term in mu has 1 too many:

do i = 0 to T_hat;
    term=(T_hat - i)*(B0**i)*a;
    mu_sum_first_part = mu_sum_first_part + term;
end;

Should be:

do i = 0 to T_hat-1;
    term=(T_hat - i)*(B0**i)*a;
    mu_sum_first_part = mu_sum_first_part + term;
end;
0
votes

There is nothing mathematically wrong with your program. When you are raising a matrix to the 180th power, you should not be surprised to see very large or very small values. For example, if you let B0 = { 0 1 0 0, 0 0 1 0, 0 0 0 1, 0 1 1 1 }; then elements of B0**T are O( 1E47 ). If you divide B0 by 2 and raise the result to the 180th power, then the elements are O( 1E-8 ).

Presumably these formulas are intended for matrices B0 that have a special structure, such as ||B0**n|| --> 0 as n --> infinity. Otherwise the power series won't converge. I suggest you double-check that the B0 you are using satisfies the assumptions of the reference.

You didn't ask about efficiency, but you would be wise to compute the truncated power series by using Horner's method in SAS/IML, rather than explicitly forming powers of B0.