mbeta

Syntax

mbeta(Y, X, window, [minPeriods], [intercept=true])

Please see mFunctions for the parameters and windowing logic.

Details

Calculate the coefficient estimate of an ordinary-least-squares regression of Y on X in a sliding window.

Parameters

intercept (optional) is a BOOL scalar, default true. It specifies whether the linear regression includes an intercept term. If set to false, the intercept is fixed at 0, resulting in a regression through the origin.

Returns

The result is of type DOUBLE, with the same form as the input parameters.

Examples

x=0.011 0.006 -0.008 0.012 -0.016 -0.023 0.018
y=0.016 0.009 -0.012 0.022 0.003 -0.056 0.002
mbeta(y, x, 5);
// output: [,,,,0.818182,1.692379,1.188532]

mbeta(y, x, 5, 3);
// output: [,,1.479381,1.594701,0.818182,1.692379,1.188532]

x=0.011 0.006 -0.008 0.012 -0.016 -0.023 0.018
y=0.016 0.009 -0.012 0.022 0.003 -0.056 0.002
mbeta(Y=y, X=x, window=5);
// output: [,,,,0.818182,1.692379,1.188532]

mbeta(Y=y, X=x, window=5, minPeriods=3);
// output: [,,1.479381,1.594701,0.818182,1.692379,1.188532]

mbeta(Y=y, X=x, window=5, minPeriods=3, intercept=true);
// output: [,,1.479381,1.594701,0.818182,1.692379,1.188532]

mbeta(Y=y, X=x, window=5, minPeriods=3, intercept=false);
// output: [,,1.475113,1.616438,0.872786,1.607386,1.242217]
x1 = indexedSeries(date(2020.06.05)+1..7, x)
y1 = indexedSeries(date(2020.06.05)+1..7, y)
mbeta(y1, x1, 5d);
label col1
2020.06.06
2020.06.07 1.4
2020.06.08 1.4794
2020.06.09 1.5947
2020.06.10 0.8182
2020.06.11 1.6924
2020.06.12 1.1885
mbeta(y1, x1, 1w);
label col1
2020.06.06
2020.06.07 1.4
2020.06.08 1.4794
2020.06.09 1.5947
2020.06.10 0.8182
2020.06.11 1.6924
2020.06.12 1.2659

Related function: beta