Created
May 16, 2018 13:23
-
-
Save yakneens/85cd50a4f0860ea95e468678e87ca4ef to your computer and use it in GitHub Desktop.
This file contains 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
count_outcomes_by_condition <- function(my_data, cond){ | |
ret = apply.weekly(na.omit(my_data), function(r){sum(eval(parse(text=cond)))}) | |
names(ret)[1] = cond | |
return(ret) | |
} | |
xts2df <- function(x) { | |
res_qqq_df = xts2df(res_qqq) | |
data.frame(date=index(x), coredata(x)) | |
} | |
conds = list("r < -0.01", "r>=-0.01 & r <= -0.002", "r>-0.002 & r < 0.002", "r>=0.002 & r<=0.01", "r>0.01") | |
res_qqq = do.call(cbind,lapply(conds,count_outcomes_by_condition,my_data=qqq_xts$Returns)) | |
names(res_qqq) = c("red", "slightly_red", "flat", "slightly_green", "green") | |
summary(res_qqq) | |
res_qqq_df = xts2df(res_qqq) | |
res_qqq_long = melt(res_qqq_df, measure.vars=names(res_qqq)) | |
ggplot(res_qqq_long, aes(value)) + | |
geom_histogram(bins = 5) + | |
facet_wrap(~variable, scales = 'free_x') | |
sum(apply(res_qqq,1,function(x){all(x > 0)})) / dim(res_qqq)[1] | |
week_types_qqq = table(as.factor(apply(res_qqq, 1, paste0, collapse=""))) | |
barplot(week_types_qqq[week_types_qqq>10],las=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment