Pues esencialmente esto:
Es decir, un grupo numeroso de valores ha bajado de precio mientras que otros dos grupos han tenido una evolución en U y ha recuperado, con creces incluso, el valor que tenían hace un mes.
Y, como siempre, el código:
library(tseries) library(zoo) library(XML) library(reshape) library(ggplot2) foo <- function( simbolo, final = Sys.time(), profundidad = 30 * 24 * 3600 ){ precios <- get.hist.quote(instrument= simbolo, start = final - profundidad, end = final, quote=c("AdjClose"), provider="yahoo", origin="1970-01-01", compression="d", retclass="zoo") colnames(precios) <- simbolo return(precios) } # lista de símbolos del ibex tmp <- readHTMLTable("http://finance.yahoo.com/q/cp?s=%5EIBEX+Components")[[5]] tmp <- as.character(tmp$V1[-(1:6)]) tmp <- gsub("-P", "", tmp) simbolos <- tmp[tmp != "ABG.MC"] ibex <- do.call(merge, sapply(simbolos, foo, simplify = F)) ibex.scaled <- scale(ibex) ibex.df <- data.frame(ibex.scaled, fecha = index(ibex.scaled)) ibex.df <- melt(ibex.df, id.vars = "fecha") ibex.df <- ibex.df[ order(ibex.df$fecha, ibex.df$variable), ] ibex.df$cluster <- kmeans(data.frame(t(ibex.scaled)), 4)$cluster ggplot(ibex.df, aes(x=fecha, y=value, group=variable)) + geom_line() + facet_wrap(~cluster)
Me añadido un campo de actividad a las empresas del IBEX para estudiar si había algún tipo de relación entre las evoluciones de la cotización y su area de actividad económica. A simple vista no se ve ningún tipo claro de asociación.
actividad <- c('Otros','Construccion','Otros','Otros','Construccion','Banco','Banco','Otros','Banco','Retail','Energia','Energia','Construccion','Construccion','Energia','Tecnologia','Otros','Energia','Tecnologia','Retail','Otros','Otros','Construccion','Banco','Energia','Energia','Banco','Banco','Construccion','Otros','Otros','Construccion','Tecnologia')
actividad.empresas <- data.frame(simbolo=simbolos,actividad=actividad)
ibex.df <- merge(ibex.df,actividad.empresas,by.x="variable",by.y="simbolo")
ggplot(ibex.df, aes(x=fecha, y=value, group=variable)) +
geom_line(aes(color=actividad)) + facet_wrap(~cluster) +
opts(legend.text = theme_text(size=8),legend.key.size = unit(0.5,"cm"))