Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# R code re: CapitalSpecator.com post on designing a simple probit model:
# "A (Partial) Solution For Narrative Risk: Probit Modeling"
# http://www.capitalspectator.com/a-partial-solution-for-narrative-risk-probit-modeling/
# 15 Dec 2015
# By James Picerno
# http://www.capitalspectator.com/
# (c) 2015 by Beta Publishing LLC
# load packages
library(TTR)
library(quantmod)
library(TTR)
library(zoo)
library(tseries)
# download data
sp500 <-get.hist.quote(instrument="^GSPC",
start="1950-12-31",
quote="AdjClose")
vix <-get.hist.quote(instrument="^VIX",quote="Close")
# generate rolling 1yr S&P returns
sp.252 <-na.omit(ROC(sp500,252,"discrete"))
# merge S&P and VIX data
vix.sp252 <-as.xts(na.omit(cbind(vix,sp.252)))
colnames(vix.sp252) <-c("vix","sp.252")
# generate signal data
sp.sig <-ifelse(vix.sp252[,2] <0,1,0)
# add VIX to signal data file
sp.sig$sp252 <-vix.sp252[,1]
colnames(sp.sig) <-c("sp.sig","vix")
# generate probit model
probit.model <-glm(sp.sig~vix,family=binomial(link="probit"),data=sp.sig)
probit.model.f <-predict(probit.model ,type="response")
# END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.