Skip to content

Commit

Permalink
adding tests to Stochastic Oscillator
Browse files Browse the repository at this point in the history
  • Loading branch information
bukosabino committed Dec 8, 2019
1 parent 88c17ea commit ca81242
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ta/tests/__init__.py
@@ -1,6 +1,6 @@
from ta.tests.momentum import (TestMFIIndicator, TestRateOfChangeIndicator,
TestRSIIndicator,
TestUltimateOscillatorIndicator)
TestRSIIndicator, TestStochasticOscillator,
TestUltimateOscillator)
# from ta.tests.pipeline_wrapper import TestTAFeaturesTransform
from ta.tests.trend import (TestADXIndicator, TestCCIIndicator,
TestMACDIndicator, TestPSARIndicator,
Expand Down
31 changes: 31 additions & 0 deletions ta/tests/data/cs-soo.csv
@@ -0,0 +1,31 @@
Date,High,Low,Highest High (14),Lowest Low (14),Close,SO,SO_SIG
23-Feb-10,127.009000,125.357400,,,,,
24-Feb-10,127.615900,126.163300,,,,,
25-Feb-10,126.591100,124.929600,,,,,
26-Feb-10,127.347200,126.093700,,,,,
1-Mar-10,128.173000,126.819900,,,,,
2-Mar-10,128.431700,126.481700,,,,,
3-Mar-10,127.367100,126.034000,,,,,
4-Mar-10,126.422000,124.830100,,,,,
5-Mar-10,126.899500,126.392100,,,,,
8-Mar-10,126.849800,125.715600,,,,,
9-Mar-10,125.646000,124.561500,,,,,
10-Mar-10,125.715600,124.571500,,,,,
11-Mar-10,127.158200,125.068900,,,,,
12-Mar-10,127.715400,126.859700,128.431700,124.561500,127.287600,70.438220,
15-Mar-10,127.685500,126.630900,128.431700,124.561500,127.178100,67.608909,
16-Mar-10,128.222800,126.800100,128.431700,124.561500,128.013800,89.202108,
17-Mar-10,128.272500,126.710500,128.431700,124.561500,127.108500,65.810552,74.20719
18-Mar-10,128.093400,126.800100,128.431700,124.561500,127.725300,81.747713,78.920124
19-Mar-10,128.272500,126.133500,128.431700,124.561500,127.058700,64.523797,70.694021
22-Mar-10,127.735300,125.924500,128.272500,124.561500,127.327300,74.529776,73.600429
23-Mar-10,128.770000,126.989100,128.770000,124.561500,128.710300,98.581442,79.211672
24-Mar-10,129.287300,127.814800,129.287300,124.561500,127.874500,70.104533,81.071917
25-Mar-10,130.063300,128.471500,130.063300,124.561500,128.580900,73.056091,80.580689
26-Mar-10,129.118200,128.064100,130.063300,124.561500,128.600800,73.417791,72.192805
29-Mar-10,129.287300,127.605900,130.063300,124.571500,127.934200,61.231290,69.235057
30-Mar-10,128.471500,127.596000,130.063300,125.068900,128.113300,60.956271,65.201784
31-Mar-10,128.093400,126.999000,130.063300,125.924500,127.596000,40.386102,54.191221
1-Apr-10,128.650600,126.899500,130.063300,125.924500,127.596000,40.386102,47.242825
5-Apr-10,129.138100,127.486500,130.063300,125.924500,128.690400,66.828549,49.200251
6-Apr-10,128.640600,127.397000,130.063300,125.924500,128.272500,56.731420,54.64869
34 changes: 30 additions & 4 deletions ta/tests/momentum.py
Expand Up @@ -3,7 +3,7 @@
import pandas as pd

from ta.momentum import (MFIIndicator, ROCIndicator, RSIIndicator,
UltimateOscillatorIndicator, roc)
StochasticOscillator, UltimateOscillator, roc)
from ta.tests.utils import TestIndicator


Expand Down Expand Up @@ -68,7 +68,7 @@ def test_mfi(self):
pd.testing.assert_series_equal(self._df[target].tail(), result.tail(), check_names=False)


class TestUltimateOscillatorIndicator(unittest.TestCase):
class TestUltimateOscillator(unittest.TestCase):
"""
https://school.stockcharts.com/doku.php?id=technical_indicators:ultimate_oscillator
"""
Expand All @@ -77,14 +77,40 @@ class TestUltimateOscillatorIndicator(unittest.TestCase):

def setUp(self):
self._df = pd.read_csv(self._filename, sep=',')
self._indicator = UltimateOscillatorIndicator(
self._indicator = UltimateOscillator(
high=self._df['High'], low=self._df['Low'], close=self._df['Close'],
s=7, m=14, len=28, ws=4.0, wm=2.0, wl=1.0, fillna=False)

def tearDown(self):
del(self._df)

def test_mfi(self):
def test_uo(self):
target = 'Ult_Osc'
result = self._indicator.uo()
pd.testing.assert_series_equal(self._df[target].tail(), result.tail(), check_names=False)


class TestStochasticOscillator(unittest.TestCase):
"""
https://school.stockcharts.com/doku.php?id=technical_indicators:stochastic_oscillator_fast_slow_and_full
"""

_filename = 'ta/tests/data/cs-soo.csv'

def setUp(self):
self._df = pd.read_csv(self._filename, sep=',')
self._indicator = StochasticOscillator(
high=self._df['High'], low=self._df['Low'], close=self._df['Close'], n=14, d_n=3, fillna=False)

def tearDown(self):
del(self._df)

def test_so(self):
target = 'SO'
result = self._indicator.stoch()
pd.testing.assert_series_equal(self._df[target].tail(), result.tail(), check_names=False)

def test_so_signal(self):
target = 'SO_SIG'
result = self._indicator.stoch_signal()
pd.testing.assert_series_equal(self._df[target].tail(), result.tail(), check_names=False)

0 comments on commit ca81242

Please sign in to comment.