Skip to content

Commit

Permalink
新增excess_win_rate实现超额收益胜率,win_rate改为绝对收益胜率;新增工作流上传版本到pypi;新增测试案例
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-JiaJun committed Sep 22, 2022
1 parent bb23dc7 commit cfc0fa1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on:
release:
types:
- published # upload build tar when publish

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a source tarball
run: >-
python -m
build
--sdist
--outdir dist/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 4 additions & 0 deletions rqrisk/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ def param_var(self, alpha):

@indicator_property(min_period_count=1)
def win_rate(self):
return len(self._portfolio[self._portfolio > 0]) / self.period_count

@indicator_property(min_period_count=1)
def excess_win_rate(self):
return len(self._portfolio[self._portfolio > self._benchmark]) / self.period_count

def all(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[metadata]
name = rqrisk
version = 1.0.2
version = 1.0.3

[versioneer]
VCS = git
Expand Down
20 changes: 20 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,23 @@ def test_natural_daily():
assert_almost_equal(r.information_ratio, 97.92626812366308)
assert_almost_equal(r.sharpe, -0.23942084288518412)


def test_win_rate():
""" 测试胜率 """
def _assert(returns, benchmark, desired_win_rate):
assert_almost_equal(_r(returns, benchmark, 0).win_rate, desired_win_rate)

_assert(volatile_returns, volatile_benchmark, 0.6666666666666666)
_assert(positive_returns, volatile_benchmark, 1)
_assert(negative_returns, volatile_benchmark, 0)


def test_excess_win_rate():
""" 测试超额胜率 """
def _assert(returns, benchmark, desired_win_rate):
assert_almost_equal(_r(returns, benchmark, 0).excess_win_rate, desired_win_rate)

_assert(volatile_returns, volatile_benchmark, 0.4444444444444444)
_assert(positive_returns, zero_benchmark, 1)
_assert(negative_returns, zero_benchmark, 0)

0 comments on commit cfc0fa1

Please sign in to comment.