Skip to content

Instantly share code, notes, and snippets.

@isomorphisms
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isomorphisms/4b2cfc75bc95c55b228a to your computer and use it in GitHub Desktop.
Save isomorphisms/4b2cfc75bc95c55b228a to your computer and use it in GitHub Desktop.
cov.xts
#####TO DO: write a more reasonable S3 `cov.xts` and `cor.xts`
require(quantmod)
getSymbols(c('WOOD','CUT')) #timber ETF's
> cor(merge.xts(WOOD,CUT, join='inner'))
WOOD.Open WOOD.High WOOD.Low WOOD.Close WOOD.Volume WOOD.Adjusted
WOOD.Open 1.00 1.00 1.00 1.00 0.1 0.99
WOOD.High 1.00 1.00 1.00 1.00 0.1 0.99
WOOD.Low 1.00 1.00 1.00 1.00 0.1 0.99
WOOD.Close 1.00 1.00 1.00 1.00 0.1 0.99
WOOD.Volume 0.13 0.13 0.12 0.12 1.0 0.12
WOOD.Adjusted 0.99 0.99 0.99 0.99 0.1 1.00
CUT.Open 0.97 0.97 0.97 0.97 0.1 0.98
CUT.High 0.97 0.97 0.97 0.98 0.1 0.98
CUT.Low 0.97 0.97 0.97 0.97 0.1 0.98
CUT.Close 0.97 0.97 0.97 0.97 0.1 0.98
CUT.Volume 0.02 0.02 0.01 0.01 0.2 -0.01
CUT.Adjusted 0.96 0.96 0.96 0.96 0.1 0.98
CUT.Open CUT.High CUT.Low CUT.Close CUT.Volume CUT.Adjusted
WOOD.Open 0.97 0.97 0.97 0.97 0.015 0.955
WOOD.High 0.97 0.97 0.97 0.97 0.016 0.955
WOOD.Low 0.97 0.97 0.97 0.97 0.010 0.960
WOOD.Close 0.97 0.98 0.97 0.97 0.013 0.960
WOOD.Volume 0.14 0.14 0.13 0.13 0.198 0.127
WOOD.Adjusted 0.98 0.98 0.98 0.98 -0.010 0.980
CUT.Open 1.00 1.00 1.00 1.00 0.026 0.992
CUT.High 1.00 1.00 1.00 1.00 0.026 0.992
CUT.Low 1.00 1.00 1.00 1.00 0.020 0.992
CUT.Close 1.00 1.00 1.00 1.00 0.024 0.994
CUT.Volume 0.03 0.03 0.02 0.02 1.000 0.004
CUT.Adjusted 0.99 0.99 0.99 0.99 0.004 1.000
The current output is comparing too many things. I don't need the correlation of `CUT.Volume` to `WOOD.Open`. I don't even likely need to compare `Op(WOOD)` to `Cl(CUT)`. A nicer default `print` would be less busy. Print only `cov(CUT.Low, WOOD.Low)`, `cov(CUT.Volume, WOOD.Volume)`, etc.
@isomorphisms
Copy link
Author

Now should this be in xts or quantmod? Hmm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment