Skip to content

Instantly share code, notes, and snippets.

View raffdoc's full-sized avatar

Rafik Margaryan raffdoc

View GitHub Profile
@timelyportfolio
timelyportfolio / garch in plot.xts panel.r
Created August 17, 2012 21:43
plot.xts and rugarch
#install.packages("xtsExtra", repos="http://R-Forge.R-project.org")
require(quantmod)
require(rugarch)
require(xtsExtra) #if you get an error, see first line and install from r-forge
getSymbols("DEXJPUS",src="FRED")
DEXJPUS<-1/to.weekly(DEXJPUS)
ugarch.panel <- function(index,x,type,cex,col,pch,...){
@timelyportfolio
timelyportfolio / horizonplot from plot-xts.r
Created August 17, 2012 14:10
plot.xts can create horizon charts
#plot.xts with horizons
#install.packages("xtsExtra", repos="http://R-Forge.R-project.org")
require(PerformanceAnalytics)
require(quantmod)
require(xtsExtra) #if you get error, install xtsExtra from r-forge
horizon.panel <- function(index,x,...) {
#get some decent colors from RColorBrewer
#we will use colors on the edges so 2:4 for red and 7:9 for blue
@timelyportfolio
timelyportfolio / chartTimeSeries and chartsPerformanceSummary.r
Last active August 23, 2018 00:43
plot.xts replacements of PerformanceAnalytics chart.TimeSeries and charts.PerformanceSummary
#install.packages("xtsExtra", repos="http://R-Forge.R-project.org")
require(PerformanceAnalytics)
require(xtsExtra) #if you get error, please install xtsExtra from r-forge as shown in the top line
require(RColorBrewer)
#function add alpha or transparency to colors
addalpha <- function(cols,alpha=180) {
rgbcomp <- col2rgb(cols)
rgbcomp[4] <- alpha
@cjbayesian
cjbayesian / bayes_update.R
Created August 16, 2012 20:23
generate a video demonstrating Bayesian updating
## Corey Chivers, 2012 ##
sim_bayes<-function(p=0.5,N=100,y_lim=20,a_a=2,a_b=10,b_a=8,b_b=3)
{
## Simulate outcomes in advance
outcomes<-sample(1:0,N,prob=c(p,1-p),replace=TRUE)
success<-cumsum(outcomes)
for(frame in 1:N)
{
png(paste("plots/",1000+frame,".png",sep=""))
@timelyportfolio
timelyportfolio / horizon plot of 48 industries with dendrogram order.r
Created August 9, 2012 21:43
horizon plot of 48 industries with dendrogram order
require(fAssets)
require(latticeExtra)
require(quantmod)
require(PerformanceAnalytics)
#my.url will be the location of the zip file with the data
my.url="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/48_Industry_Portfolios_daily.zip"
#this will be the temp file set up for the zip file
my.tempfile<-paste(tempdir(),"\\frenchindustry.zip",sep="")
#my.usefile is the name of the txt file with the data
@timelyportfolio
timelyportfolio / horizon in base.r
Created August 3, 2012 13:17
horizon in base graphics
require(RColorBrewer)
require(quantmod)
require(PerformanceAnalytics)
data(managers)
#let's do managers from 2002 to 2004 to get positive and negative
x <- cumprod(1+managers["2002::2004"])[,1] - 1
#get some decent colors from RColorBrewer
@timelyportfolio
timelyportfolio / construction of horizon plot in r.r
Created August 1, 2012 20:20
construction of horizon plot
#look at steps in constructing a horizon plot version
#of http://www.mebanefaber.com/timing-model/
#do horizon of percent above or below 10 month / 200 day moving average
require(lattice)
require(latticeExtra)
require(quantmod)
#since we are focused on the horizon plot, let's just look at one stock
@bobthecat
bobthecat / tweet_air_pol.r
Last active October 7, 2015 20:18
twitter air pollution
library(twitteR)
library(ggplot2)
library(grid)
# download all that you can
pol <- userTimeline('BeijingAir', n=3200)
length(pol)
# 3200
myGrep <- function(x){
@timelyportfolio
timelyportfolio / horizon plot applied.r
Created July 31, 2012 17:15
horizon plot examples
require(lattice)
require(latticeExtra)
require(directlabels)
require(reshape2)
require(quantmod)
require(PerformanceAnalytics)
data(managers)
managers[which(is.na(managers),arr.ind=TRUE)[,1],
@psychemedia
psychemedia / rchitecture.dot
Created July 15, 2012 21:46
An Rchitecture for Reproducible Data Journalism
digraph G {
subgraph cluster_1 {
Rscript -> localDir;
localDir -> Rscript;
Rscript -> Sweave;
Sweave -> TeX;
TeX -> PDF [ label = "laTeX"]
Rscript -> Rmarkdown;
RCurl -> Rscript;