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

Develop #11

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)