braverock / quantstrat

289 stars 114 forks source link

signals.R -- post.signal.returns function returns only difference in levels, not returns #144

Open clairdelaluna opened 3 years ago

clairdelaluna commented 3 years ago

Description

As in title -- when using the apply.paramset.signal.analysis function, which calls on the post.signal.returns function, we're seeing the changes in the level, rather than returns.

Expected behavior

Be able to switch to analysing the behaviour post-signal in returns space.

Minimal, reproducible example

add a parameter called cum.return (default false so the function retains previous behaviour), but if true hits the following code block:


for(j in 1:length(idx)){
      signal.ret[j,] = tryCatch({
      na.omit(diff( log(getPrice(mktdata[idx[j] + (days.increment * days.in.period)  ,])) ))
    }, error = function(e){
      cat('')
      stop('Not enough forward data to evaluate post signal returns.')
    })}
    signal.ret=t(apply(signal.ret+1,1,cumprod))-1
braverock commented 3 years ago

thanks for the suggestion

at first glance, this looks doable. We'll review.

clairdelaluna commented 3 years ago

I've made the changes myself on my local version, so happy to open a PR on the matter.

braverock commented 3 years ago

yes, please open a PR tied to this issue. It will make it easier to review.