[R-sig-finance] Need help to modify rsiTA function from fSeries
BBands
bbands at gmail.com
Thu Apr 28 17:20:23 CEST 2005
On 4/24/05, Neuro LeSuperHéros <neuro3000 at hotmail.com> wrote:
> Need help to modify rsiTA function from fSeries
<snip>
> Can you help?
Perhaps...
First, the reference is Welles Wilders' "New Concepts in Technical
Trading Systems".
This indicator is often calculated inaccurately. The problems most
often seen are incorrect calculation of the averages.
Here is a Python snippet from Crusher that calcs RSI. I have no idea
whether it coincides with the sources you cite, but it does the job
correctly, or at least as Welles said it should be done.
def rsi(self):
"""RSI"""
# checked 2004-10-15, OK
self.rsi = []
length = config['indconsts.rsi']
up = dn = 0.0
# find the first value
for line in range(0, length):
if self.close[length - line] > self.close[length - line - 1]:
up += self.close[length - line] - self.close[length - line - 1]
if self.close[length - line] < self.close[length - line - 1]:
dn += self.close[length - line - 1] - self.close[length - line]
# pad the runup with 0
if line < (length - 1):
self.rsi.append(0.0)
up = up / length
dn = dn / length
try:
self.rsi.append(100 - 100 / (1 + up / dn))
except ZeroDivisionError:
self.rsi.append(0.0)
# use Wilder's average technique to find the remaining values
for line in range(length, len(self.date)):
if self.close[line] > self.close[line - 1]:
up = ((self.close[line] - self.close[line - 1]) + up *
(length - 1)) / length
else:
up = up / length * (length - 1)
if self.close[line] < self.close[line - 1]:
dn = ((self.close[line - 1] - self.close[line]) + dn *
(length - 1)) / length
else:
dn = dn / length * (length - 1)
try:
self.rsi.append(100 - 100 / (1 + up / dn))
except ZeroDivisionError:
self.rsi.append(0.0)
if config['general.debug'] == 1:
for line in range(len(self.date)):
print '%4d %10s %8.2f %8.2f' % (line, self.date[line],
self.close[line], self.rsi[line])
Sorry, I haven't the time to translate it into R, but it could serve
as a template for you to do so.
Good trading,
jab
--
John Bollinger, CFA, CMT
www.BollingerBands.com
If you advance far enough, you arrive at the beginning.
More information about the R-sig-finance
mailing list