This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# * Sat May 19 2012 21:04:56 Steven E. Pav <[email protected]> | |
# from https://github.com/milktrader/rfinance2012/blob/94e6dd0452b16697ad10f9bc7e0e7431c95d9020/xts/.Rhistory | |
require(quantmod) | |
getSymbols('^GSPC', from='1950-01-01') | |
G <- monthlyReturn(Cl(GSPC)) | |
G$monnum <- .indexmon(G) | |
# try ANOVA on the monthly returns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to get the R<->python magic | |
%load_ext rmagic | |
# now you can code in R: | |
%%R | |
library(survival) | |
amod <- coxph(Surv(lung$time,lung$status) ~ lung$sex + lung$ph.karno) | |
print(summary(amod)) | |
# done |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# * Fri Feb 24 2012 09:09:10 PM Steven E. Pav <[email protected]> | |
# | |
# computation of moments and moment-based statistics | |
# | |
# see also: | |
# * http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/ | |
# * http://www.johndcook.com/standard_deviation.html | |
# * J. Bennett, et. al., 'Numerically Stable, Single-Pass, | |
# Parallel Statistics Algorithms,' Proceedings of IEEE | |
# International Conference on Cluster Computing, 2009. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(quantmod) | |
getSymbols(c("SPY","TLT","GLD","AAPL")) | |
allofem <- merge(SPY[,"SPY.Adjusted"],TLT[,"TLT.Adjusted"],GLD[,"GLD.Adjusted"],AAPL[,"AAPL.Adjusted"]) | |
mo.pry <- to.monthly(allofem,OHLC=FALSE) | |
mo.ret <- diff(log(mo.pry)) | |
sub.ret <- mo.ret[(dim(mo.ret)[1]-59):dim(mo.ret)[1],] | |
mu <- apply(sub.ret,2,mean,na.rm=TRUE) | |
Sg <- cov(sub.ret,use="complete.obs") | |
w <- solve(Sg,mu) | |
n <- dim(sub.ret)[1] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer