Skip to content

Commit

Permalink
added tests for CSPercentile and renaming CSQuantile to CSQuantiles
Browse files Browse the repository at this point in the history
  • Loading branch information
wegamekinglc committed Sep 8, 2017
1 parent 6af3064 commit 23dff37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PyFin/api/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def CSMeanAdjusted(dependency):
return CSAverageAdjustedSecurityValueHolder(dependency)


def CSQuantile(dependency):
def CSQuantiles(dependency):
return CSQuantileSecurityValueHolder(dependency)


Expand Down
4 changes: 2 additions & 2 deletions PyFin/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from PyFin.api.Analysis import CSRank
from PyFin.api.Analysis import CSMean
from PyFin.api.Analysis import CSMeanAdjusted
from PyFin.api.Analysis import CSQuantile
from PyFin.api.Analysis import CSQuantiles
from PyFin.api.Analysis import CSPercentile
from PyFin.api.Analysis import CSZScore

Expand Down Expand Up @@ -126,7 +126,7 @@
"CSRank",
"CSMean",
"CSMeanAdjusted",
"CSQuantile",
"CSQuantiles",
"CSZScore",
"CSPercentile",
"pyFinAssert"]
16 changes: 16 additions & 0 deletions PyFin/tests/Analysis/testCrossSectionValueHolders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from PyFin.Analysis.CrossSectionValueHolders import CSAverageAdjustedSecurityValueHolder
from PyFin.Analysis.CrossSectionValueHolders import CSQuantileSecurityValueHolder
from PyFin.Analysis.CrossSectionValueHolders import CSZScoreSecurityValueHolder
from PyFin.Analysis.CrossSectionValueHolders import CSPercentileSecurityValueHolder


class TestCrossSectionValueHolder(unittest.TestCase):
Expand Down Expand Up @@ -69,6 +70,21 @@ def testCSAverageSecurityValueHolder(self):
benchmarkValues = benchmark.value
np.testing.assert_array_almost_equal(benchmarkValues.mean(), meanHolder.value.values)

def testCSPercentileSecurityValueHolder(self):
percent = 50
benchmark = SecurityLatestValueHolder(dependency='close')
perHolder = CSPercentileSecurityValueHolder(percent, benchmark)

for i in range(len(self.datas['aapl']['close'])):
data = {'aapl': {Factors.CLOSE: self.datas['aapl'][Factors.CLOSE][i],
Factors.OPEN: self.datas['aapl'][Factors.OPEN][i]},
'ibm': {Factors.CLOSE: self.datas['ibm'][Factors.CLOSE][i],
Factors.OPEN: self.datas['ibm'][Factors.OPEN][i]}}
benchmark.push(data)
perHolder.push(data)
benchmarkValues = benchmark.value
np.testing.assert_array_almost_equal(np.percentile(benchmarkValues.values, 50), perHolder.value.values)

def testCSAverageAdjustedSecurityValueHolder(self):
benchmark = SecurityLatestValueHolder(dependency='close')
meanAdjustedHolder = CSAverageAdjustedSecurityValueHolder(benchmark)
Expand Down

0 comments on commit 23dff37

Please sign in to comment.