I am trying to test the cointegration between two ETFs.

-----------------------------------------------------------

ewa = FinancialData["NYSE:EWA", {{2006, 4, 4}, {2012, 4, 9}}, "Value"];

ewc = FinancialData["NYSE:EWC", {{2006, 4, 4}, {2012, 4, 9}}, "Value"];

data = Transpose@{ewa, ewc};

johansenProcedure[levels_?MatrixQ, p_Integer] /;

(Dimensions[levels][[ 1]] > (Dimensions[levels][[2]] + p)) :=

With[{N = Dimensions[levels][[1]], T = Dimensions[levels][[2]],

diff = Rest[levels - RotateLeft[levels]], ypt = Drop[levels, -p]},

Module[{x, r0t, rpt, s00, sop, cc, \[Lambda], v\[Lambda], log\[Lambda]},

x = Join @@ (Drop[RotateLeft[diff, #], p - 1] & /@ Range[p]);

With[{q = Inverse[Transpose[x].x], y0t = Drop[diff, p - 1]},

r0t = y0t - x.q.Transpose[x].y0t; rpt = ypt - x.q.Transpose[x].ypt; s00 = (Transpose[r0t].r0t)/T; s0p = (Transpose[r0t].rpt)/T;

cc = Inverse[CholeskyDecomposition[(Transpose[rpt].rpt)/T]];

{\[Lambda], v\[Lambda]} = Eigensystem[(cc.Transpose[s0p].Inverse[s00].s0p.Transpose[cc])];

log\[Lambda] = Log[1 - \[Lambda]];

{Reverse[-T* FoldList[Plus, First[log\[Lambda]], Rest[log\[Lambda]]]],

Reverse[-T log\[Lambda]], Join[Reverse[Transpose[Transpose[cc].v\[Lambda]]], s00, s0p]} ]]];

johansenProcedure[data, 10]

and then it keeps running until I abort

Dot::dotsh: Tensors {<<1>>} and {{0.38,0.42},{-0.21,-0.27},{0.03,0.13},{0.,-0.03},<<44>>,{0.04,0.02},{-0.56,-0.63},<<1455>>} have incompatible shapes. >>