Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX refactor annual_return to return CAGR. Removes returns_style para… #234

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
FIX unittests to support refactored annual_return
Justin Lent committed Dec 8, 2015
commit 2203793d51b1996b7ae8d28dc5efb89beb063a8c
34 changes: 15 additions & 19 deletions pyfolio/tests/test_timeseries.py
Original file line number Diff line number Diff line change
@@ -40,8 +40,8 @@ def test_get_max_drawdown(
# Need to use isnull because the result can be NaN, NaT, etc.
self.assertTrue(
pd.isnull(peak)) if expected_peak is None else self.assertEqual(
peak,
expected_peak)
peak,
expected_peak)
self.assertTrue(
pd.isnull(valley)) if expected_valley is None else \
self.assertEqual(
@@ -235,21 +235,20 @@ class TestStats(TestCase):
[10, -10, 10]) / 100. # Ends in drawdown
dt = pd.date_range('2000-1-3', periods=3, freq='D')

px_list_2 = [1.0, 1.2, 1.0, 0.8, 0.7, 0.8, 0.8, 0.8]
dt_2 = pd.date_range('2000-1-3', periods=8, freq='D')

@parameterized.expand([
(simple_rets, 'calendar', utils.DAILY, 0.10584000000000014),
(simple_rets, 'compound', utils.DAILY, 0.16317653888658334),
(simple_rets, 'calendar', utils.DAILY, 0.10584000000000014),
(simple_rets, 'compound', utils.DAILY, 0.16317653888658334),
(simple_week_rets, 'compound', utils.WEEKLY, 0.031682168889005213),
(simple_week_rets, 'calendar', utils.WEEKLY, 0.021840000000000033),
(simple_month_rets, 'compound', utils.MONTHLY, 0.0072238075842128158),
(simple_month_rets, 'calendar', utils.MONTHLY, 0.0050400000000000071)
(simple_rets, utils.DAILY, 0.15500998835658075),
(simple_week_rets, utils.WEEKLY, 0.030183329386562319),
(simple_month_rets, utils.MONTHLY, 0.006885932704891129)
])
def test_annual_ret(self, returns, style, period, expected):
def test_annual_ret(self, returns, period, expected):
self.assertEqual(
timeseries.annual_return(
returns,
style=style, period=period),
period=period
),
expected)

@parameterized.expand([
@@ -306,16 +305,13 @@ def test_beta(self, returns, benchmark_rets, rolling_window, expected):
expected)

@parameterized.expand([
(pd.Series(px_list,
index=dt), 'calendar', -8.3999999999999559),
(pd.Series(px_list,
index=dt), 'arithmetic', 84.000000000000014)
(pd.Series(px_list_2,
index=dt_2).pct_change().dropna(), -2.3992211554712197)
])
def test_calmar(self, returns, returns_style, expected):
def test_calmar(self, returns, expected):
self.assertEqual(
timeseries.calmar_ratio(
returns,
returns_style=returns_style),
returns),
expected)

@parameterized.expand([