Hi All
I have a table t.
q)t
sym minute ri rm
IBM 09:30:00 0.10 0.05
IBM 09:31:00 0.05 0.03
IBM 09:32:00 0.11 0.05
IBM 09:33:00 0.13 0.02
IBM 09:34:00 0.11 0.04
How to calculate the rolling covariance?cov1? and mobile covariance?cov2??
cov1?
0.10 cov 0.05
0.10 0.05 cov 0.05 0.03
0.10 0.05 0.11 cov 0.05 0.03 0.05
…
cov2?
0.1 cov 0.05
0.10 0.05 cov 0.05 0.03
0.05 0.11 cov 0.03 0.05
0.11 0.13 cov 0.05 0.02
…
Thanks,
Sky
update cov1: raze (cov).’ flip (ri;rm)@:{x,y} scan til count t from t
update cov2:(cov) .’ flip flip each {(til x)xprev:y}[2;] each (ri;rm) from t
HTH,
Sean
Hi Sky,
The formula for moving covariance is mcov:{mavg[x;y*z] - mavg[x;y] * mavg[x;z]}
So for your second example the 2-step moving covariance is
q)update m:mcov[2;ri;rm] from t
sym minute ri rm m
IBM 09:30:00 0.1 0.05 0
IBM 09:31:00 0.05 0.03 0.00025
IBM 09:32:00 0.11 0.05 0.0003
IBM 09:33:00 0.13 0.02 -0.00015
IBM 09:34:00 0.11 0.04 -0.0001
And for your first example you could use:
q)update m:mcov[count t;ri;rm] from t
sym minute ri rm m
IBM 09:30:00 0.1 0.05 0
IBM 09:31:00 0.05 0.03 0.00025
IBM 09:32:00 0.11 0.05 0.0002444444
IBM 09:33:00 0.13 0.02 -6.25e-006
IBM 09:34:00 0.11 0.04 0
Which ties in with your examples above
Thanks,
Kevin
Hi Kevin, Thank you very much!
? 2015?3?19??? UTC+8??11:00:26?Kevin Smyth???
Hi Sky,
The formula for moving covariance is mcov:{mavg[x;y*z] - mavg[x;y] * mavg[x;z]}
So for your second example the 2-step moving covariance is
q)update m:mcov[2;ri;rm] from t
sym minute ri rm m
-------------------------------
IBM 09:30:00 0.1 0.05 0
IBM 09:31:00 0.05 0.03 0.00025
IBM 09:32:00 0.11 0.05 0.0003
IBM 09:33:00 0.13 0.02 -0.00015
IBM 09:34:00 0.11 0.04 -0.0001
And for your first example you could use:
q)update m:mcov[count t;ri;rm] from t
sym minute ri rm m
-----------------------------------
IBM 09:30:00 0.1 0.05 0
IBM 09:31:00 0.05 0.03 0.00025
IBM 09:32:00 0.11 0.05 0.0002444444
IBM 09:33:00 0.13 0.02 -6.25e-006
IBM 09:34:00 0.11 0.04 0
Which ties in with your examples above
Thanks,
Kevin
On 19 March 2015 at 03:20, <huangyu…@gmail.com> wrote:
Hi All
I have a table t.
q)t
sym minute ri rm
------------------------------–
IBM 09:30:00 0.10 0.05
IBM 09:31:00 0.05 0.03
IBM 09:32:00 0.11 0.05
IBM 09:33:00 0.13 0.02
IBM 09:34:00 0.11 0.04
How to calculate the rolling covariance?cov1? and mobile covariance?cov2??
cov1?
0.10 cov 0.05
0.10 0.05 cov 0.05 0.03
0.10 0.05 0.11 cov 0.05 0.03 0.05
…
cov2?
0.1 cov 0.05
0.10 0.05 cov 0.05 0.03
0.05 0.11 cov 0.03 0.05
0.11 0.13 cov 0.05 0.02
…
Thanks,
Sky
–
Submitted via Google Groups
Hi sean,Thank you very much!
? 2015?3?19??? UTC+8??8:50:30?Sean O’Hagan???
update cov1: raze (cov).’ flip (ri;rm)@:{x,y} scan til count t from t
update cov2:(cov) .’ flip flip each {(til x)xprev:y}[2;] each (ri;rm) from t
HTH,
Sean
On Thursday, March 19, 2015 at 3:20:17 AM UTC, huangyu...@gmail.com wrote:
Hi All
I have a table t.
q)t
sym minute ri rm
------------------------------–
IBM 09:30:00 0.10 0.05
IBM 09:31:00 0.05 0.03
IBM 09:32:00 0.11 0.05
IBM 09:33:00 0.13 0.02
IBM 09:34:00 0.11 0.04
How to calculate the rolling covariance?cov1? and mobile covariance?cov2??
cov1?
0.10 cov 0.05
0.10 0.05 cov 0.05 0.03
0.10 0.05 0.11 cov 0.05 0.03 0.05
…
cov2?
0.1 cov 0.05
0.10 0.05 cov 0.05 0.03
0.05 0.11 cov 0.03 0.05
0.11 0.13 cov 0.05 0.02
…
Thanks,
Sky