Skip to content

Commit d8761d9

Browse files
Experiment with SMA's interface. Provide attr address to update after its called via .mean
1 parent 6dc5e5a commit d8761d9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = rtta
3-
version = 0.1.3
3+
version = 0.1.4
44
description = Low latency incremental technical analysis
55
long_description = file: README.md
66
long_description_content_type = text/markdown

src/rtta.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ cdef class SMA():
331331
cdef int window
332332
cdef bint fillna
333333
cdef double tally
334+
cdef double mean
334335

335336
def __init__(self, int window, bint fillna=False):
336337
self.history = np.zeros(window)
@@ -340,6 +341,7 @@ cdef class SMA():
340341
self.window = window
341342
self.fillna = fillna
342343
self.tally = 0
344+
self.mean = float('nan')
343345

344346
@cython.boundscheck(False) # turn off bounds-checking for entire function
345347
@cython.wraparound(False)
@@ -356,9 +358,12 @@ cdef class SMA():
356358

357359
if self.first_pass:
358360
if not self.fillna:
359-
return np.nan
360-
return self.tally / self.index
361-
return self.tally/self.window
361+
self.mean = np.nan
362+
return self.mean
363+
self.mean = self.tally / self.index
364+
return self.mean
365+
self.mean = self.tally/self.window
366+
return self.mean
362367

363368
cpdef batch(self, input):
364369
cdef long i

0 commit comments

Comments
 (0)