Hello!
could you please show a simple example of code that creates this kind of strategy and back-test it ?
for example a strategy on the benchmark with macro data
Thanks!
Hello!
could you please show a simple example of code that creates this kind of strategy and back-test it ?
for example a strategy on the benchmark with macro data
Thanks!
Hi,
You can select macro series and compute indicators. In the example below, I have chosen the V2X (implied volatility on Eurostoxx 50) and EURUSD exchange rate. I first reduce the noise in the two series by using an exponentially weighted moving average, then I compute the 2-month (~40 working days) change in the series. My simple rule is that when volatility increase over 2-month and at the same time, the EURUSD exchange rate is depreciating over the same period, I cut positions (0), otherwise, I am long (1).
Please note that the series I use in my payout to generate the signals are independent from the building block on which I invest (in my algoEngine).
Please see the code below:
#create macro payout
macroPayout = function(volatilitySeries, exchangeRate, fxReturnPeriod=60, volChange=60, smoothing=10){
# get rid of short term noise with exponential moving average and compute discrete rate of change
# Volatility
vol = ROC(EMA(volatilitySeries, smoothing), volChange, type=‘discrete’)
# FX
eurChg = ROC(EMA(exchangeRate, smoothing), fxReturnPeriod , type=‘discrete’)
# Compute simple indicator: if vol increases over the period and FX depreciates, flat out of positions.
indicator = na.omit(ifelse(volatilitySeries>0&eurChg<0.0, 0,1))
return(indicator)
}
#Create algoEngine / strategy: BB is MEUDa but signals are generated from macro series
algoEngine(‘MEUDa’) %>%
payout(macroPayout,
volatilitySeries = getTickersLyxorMacro(‘V2X’, asPrice=T),
exchangeRate = getTickersLyxorMacro(‘EURUSD’, asPrice=T),
fxReturnPeriod = 40,
volChange=40,
smoothing = 10) %>%
evaluate() -> strat
#backtest
backtest(strat)