ClearAll;
S2y=(Y0^2)*T+E2y*(T^2)+2*Y0*Ey*(T^(3/2));
S2x=(X0^2)*T+E2x*(T^2)+2*X0*Ex*(T^(3/2));
Syy=(Y0^2)*T+2*Y0*Ey*(T^(3/2))+Y0*Uy*(T^(1/2))+E2y*(T^2)+EUy*T;
Syx=Y0*X0*T+Y0*Ex*(T^(3/2))+X0*Ey*(T^(3/2))+Eyx*(T^2);
Sytx=Y0*X0*T+X0*Ey*(T^(3/2))+X0*Uy*(T^(1/2))+Y0*Ex*(T^(3/2))+Eyx*(T^2)+ExUy*T;
S2yt=(Y0^2)*T+E2y*(T^2)+U2y*T+2*Y0*Ey*(T^(3/2))+2*Y0*Uy*(T^(1/2))+2*EUy*T;
Syt=Y0*T+Uy*(T^(1/2))+Ey*(T^(3/2));

(* Regresión no restringida *)

Mxx=(({{S2y, Syx}, {Syx, S2x}}));
Vxy=(({{Syy}, {Sytx}}));

iMxx=Inverse[Mxx];
Param1=iMxx.Vxy;

P10=Factor[Expand[Extract[Param1,{1,1}]]];
P20=Factor[Expand[Extract[Param1,{2,1}]]];

P40=Factor[Expand[S2yt+(P10^2)*S2y+(P20^2)*S2x-2*P10*Syy-2*P20*Sytx+2*P10*P20*Syx]];

(*Regresión restringida*)
Mxxr=S2y;
Vxyr=Syy;
iMxxr=Mxxr^(-1);

Param1r=iMxxr*Vxyr;

P10r=Factor[Expand[Param1r]];
P40r=Factor[Expand[S2yt+(P10r^2)*S2y-2*P10r*Syy]];

(* F GRANGER *)
RRSS = P40r;
URSS = P40;
FG=Factor[Expand[(RRSS-URSS)/(URSS/(T-1))]];
FGnum=Numerator[FG];
K7=Exponent[FGnum,T];
Wnum=Factor[Limit[Expand[FGnum/(T^K7)],T->∞]];
FGden=Denominator[FG];
K8=Exponent[FGden,T];
Wden=Factor[Limit[Expand[FGden/(T^K8)],T->∞]];
Wpar=Factor[Expand[(Wnum/Wden)*((T^K7)/(T^K8))]]