joshuaulrich / TTR

Technical analysis and other functions to construct technical trading rules with R
GNU General Public License v2.0
330 stars 103 forks source link

It seems initGap has a forward looking bias for the SAR indicator #23

Open ivannp opened 8 years ago

ivannp commented 8 years ago

If I am reading the code correctly, it's sd over the Hi - Lo series. That's forward looking in a way.

joshuaulrich commented 8 years ago

It is forward-looking. But it's better than the prior setting, which was always 0.01. That didn't work well for data that tended to have smaller changes (e.g. foreign exchange). I'm open to alternatives.

ivannp commented 8 years ago

It seems stockcharts.com use something like previous day low. That seems reasonable. One can always throw away a few days and use the computed sd. A third one is to do some magic using HLC from one day to come up with some sd approximation.

I was looking at the code just as a reference while implementing something similar. Otherwise I might have coded one of the above alternatives.

HFDave commented 8 years ago

I was wondering about the same "issue" and dumb enough to overlook the ahead looking in the code.

http://stackoverflow.com/questions/37745430/r-parabolic-sar-and-look-ahead-bias/