# Systemic Risk Indicator



## sinner (14 June 2013)

Hi guys,

During this week I have written a crude but seemingly effective systemic risk indicator in R. I decided to share the code for anyone who might be interested.

require(quantmod)
startdate='2007-06-01'
getSymbols('IWB',from=startdate)
getSymbols('VWO',from=startdate)
getSymbols('EFA',from=startdate)
getSymbols('GSG',from=startdate)

a=runCov(ROC(Cl(IWB)),ROC(Cl(VWO)),7)
b=runCov(ROC(Cl(IWB)),ROC(Cl(EFA)),7)
c=runCov(ROC(Cl(EFA)),ROC(Cl(VWO)),7)
d=runCov(ROC(Cl(EFA)),ROC(Cl(GSG)),7)
e=runCov(ROC(Cl(IWB)),ROC(Cl(GSG)),7)
f=runCov(ROC(Cl(VWO)),ROC(Cl(GSG)),7)

z=(a+b+c+d+e+f)/6
backtest=Cl(IWB)
backtest[z > 0.00015] = 0

plot(backtest)

Basically the idea is to get the avg pairwise covariance of daily returns for a basket of broad risk assets, and while the value is below a threshold trade a momentum system or similar, and then hedge out or short when the value is above the threshold. 

Here is a picture of a crappy plot which I attempted, since I'm not very good at plotting equity curves in R yet (i.e. the below is not an equity curve). Values of 0 indicate hedged (i.e. systemic risk is occurring) and all other values are invested in IWB (Russell 1000 ETF).


----------



## sinner (25 June 2013)

Dunno if anyone has been following this or not. It went active as of NY Close 20th June indicating to close any mom style positions with a Market-On-Close or at the next open. I generate trading tables the day before so I know what I need to do in advance based on a range of inputs (e.g. "At what price must the market close to be a 10-20-30-40-50-60 day closing low?").


```
> tail(z,4)
                   [,1]
2013-06-19 0.0001136557
[COLOR="#FF0000"]2013-06-20 0.0002629768
2013-06-21 0.0002632056
2013-06-24 0.0002030679[/COLOR]
```


----------

