From 4a961ab55cb94d32ff0c03fc5eb987f5c5083920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E5=AD=90=E7=90=A6?= Date: Fri, 25 Mar 2022 14:12:17 +0800 Subject: [PATCH 1/5] update ir --- rqrisk/risk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rqrisk/risk.py b/rqrisk/risk.py index ddf8689..ab0b90d 100644 --- a/rqrisk/risk.py +++ b/rqrisk/risk.py @@ -119,7 +119,7 @@ def annual_tracking_error(self): return np.nan return self.tracking_error * (self._annual_factor ** 0.5) - @indicator_property(min_period_count=2) + @indicator_property(min_period_count=3) def information_ratio(self): # residual_return / residual_risk residual_returns = self._portfolio - self.beta * self._benchmark From 134a55e6779f75a2f75bb68b59edfc314d4647b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E5=AD=90=E7=90=A6?= Date: Fri, 25 Mar 2022 14:14:45 +0800 Subject: [PATCH 2/5] update ir --- rqrisk/risk.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rqrisk/risk.py b/rqrisk/risk.py index 3b491a5..72b769e 100644 --- a/rqrisk/risk.py +++ b/rqrisk/risk.py @@ -119,11 +119,13 @@ def annual_tracking_error(self): return np.nan return self.tracking_error * (self._annual_factor ** 0.5) - @indicator_property(min_period_count=3) + @indicator_property(min_period_count=2) def information_ratio(self): # residual_return / residual_risk residual_returns = self._portfolio - self.beta * self._benchmark annual_residual_std = residual_returns.std(ddof=1) * np.sqrt(self._annual_factor) + if not annual_residual_std: + return np.nan return (self.annual_return - self.beta * self.benchmark_annual_return) / annual_residual_std @indicator_property(min_period_count=2) From 458eb59dbd71e65d727cef43477886ba47a12d30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=98=89=E4=BF=8A?= <654181984@qq.com> Date: Mon, 27 Jun 2022 18:24:14 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E5=A2=9Eperiod=E9=80=89=E9=A1=B9:?= =?UTF-8?q?NATURAL=5FDAILY(=E8=87=AA=E7=84=B6=E6=97=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rqrisk/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rqrisk/utils.py b/rqrisk/utils.py index aeb8a51..36ab1ec 100644 --- a/rqrisk/utils.py +++ b/rqrisk/utils.py @@ -50,16 +50,19 @@ def __get__(self, instance, owner): MONTHS_PER_YEAR = 12 WEEKS_PER_YEAR = 52 APPROX_BDAYS_PER_YEAR = 252 +DAYS_PER_YEAR = 365 DAILY = 'daily' WEEKLY = 'weekly' MONTHLY = 'monthly' YEARLY = 'yearly' +NATURAL_DAILY = "natural_daily" ANNUALIZATION_FACTORS = { DAILY: APPROX_BDAYS_PER_YEAR, WEEKLY: WEEKS_PER_YEAR, - MONTHLY: MONTHS_PER_YEAR + MONTHLY: MONTHS_PER_YEAR, + NATURAL_DAILY: DAYS_PER_YEAR } From 728e2c5b8130c57a52036baeec3c4db126ceef4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=98=89=E4=BF=8A?= <654181984@qq.com> Date: Tue, 28 Jun 2022 14:58:11 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E7=84=B6?= =?UTF-8?q?=E6=97=A5=E6=B5=8B=E8=AF=95=E6=A1=88=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rqrisk/__init__.py | 5 +++-- test.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/rqrisk/__init__.py b/rqrisk/__init__.py index ab93583..6ab7ae9 100644 --- a/rqrisk/__init__.py +++ b/rqrisk/__init__.py @@ -1,10 +1,11 @@ from .risk import Risk -from .utils import DAILY, WEEKLY, MONTHLY, YEARLY +from .utils import DAILY, WEEKLY, MONTHLY, YEARLY, NATURAL_DAILY __all__ = [ "Risk", "DAILY", "WEEKLY", "MONTHLY", - "YEARLY" + "YEARLY", + "NATURAL_DAILY" ] diff --git a/test.py b/test.py index 5361a96..eaca7ee 100644 --- a/test.py +++ b/test.py @@ -6,7 +6,7 @@ import numpy as np import rqrisk -from rqrisk import DAILY, WEEKLY, MONTHLY +from rqrisk import DAILY, WEEKLY, MONTHLY, NATURAL_DAILY # Simple benchmark, no drawdown @@ -231,3 +231,14 @@ def _assert(returns, benchmark, desired_max_dd, desired_excess_max_dd): _assert(volatile_returns, zero_benchmark, 0.10899999999999994, 0.10899999999999994) _assert(volatile_returns, volatile_benchmark, 0.10899999999999994, 0.20000000000000007) + + +def test_natural_daily(): + """ 测试自然日 """ + r = _r(volatile_returns, volatile_benchmark, 0, NATURAL_DAILY) + assert_almost_equal(r.annual_return, -0.41377394067925255) + assert_almost_equal(r.benchmark_annual_return, 92.86171734511149) + assert_almost_equal(r.alpha, 62.31947511024051) + assert_almost_equal(r.information_ratio, 97.92626812366308) + assert_almost_equal(r.sharpe, -0.23942084288518412) + From c6dbfcb394aae9a684b6bd13c60393097ba01b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=98=89=E4=BF=8A?= <654181984@qq.com> Date: Tue, 5 Jul 2022 16:56:07 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 4662627..10639b9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,7 +5,7 @@ [metadata] name = rqrisk -version = 1.0.0 +version = 1.0.1 [versioneer] VCS = git