Skip to content

Commit

Permalink
added another test
Browse files Browse the repository at this point in the history
  • Loading branch information
bbcho committed Oct 2, 2023
1 parent 5cfe31d commit e420d2f
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand All @@ -24,6 +24,7 @@ jobs:
python -m pip install --upgrade pip
pip install flake8 pytest cython numpy setuptools pandas scikit-learn requests numba
pip install matplotlib plotly quandl arch scipy statsmodels seaborn pandas_datareader
pip install yfinance
python setup.py build_ext --inplace
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
strategy:
matrix:
os: [windows-latest, macos-latest]
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand Down
338 changes: 335 additions & 3 deletions notebooks/scratchpad.ipynb

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pytest/archive/tradeStats.json

This file was deleted.

1 change: 1 addition & 0 deletions pytest/data/tradeStats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"CumReturn":[0.0699],"Ret.Ann":[0.0057],"SD.Ann":[0.2214],"Sharpe":[0.0256],"Omega":[0.0257],"%.Win":[0.5372],"%.InMrkt":[0.9967],"DD.Length":[1657],"DD.Max":[-0.5519]}
70 changes: 36 additions & 34 deletions pytest/test_risktools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import plotly.graph_objects as go
import time
import yfinance as yf

sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../src/")

Expand Down Expand Up @@ -151,41 +152,42 @@ def test_bond():


def test_trade_stats():
pass

# df = data.DataReader(["SPY", "AAPL"], "yahoo", "2000-01-01", "2012-01-01")
# df = df.pct_change()
# df = df.asfreq("B")

# ou = rt.trade_stats(df[("Adj Close", "SPY")])
# ts = _load_json("tradeStats.json")

# assert round(ou["cum_ret"], 4) == round(
# ts["CumReturn"][0], 4
# ), "tradeStats Test cum_ret failed"
# assert round(ou["ret_ann"], 4) == round(
# ts["Ret_Ann"][0], 4
# ), "tradeStats Test ret_ann failed"
# assert round(ou["sd_ann"], 4) == round(
# ts["SD_Ann"][0], 4
# ), "tradeStats Test sd_ann failed"
# assert round(ou["omega"], 4) == round(
# ts["Omega"][0], 4
# ), "tradeStats Test omega failed"
# assert round(ou["sharpe"], 4) == round(
# ts["Sharpe"][0], 4
# ), "tradeStats Test sharpe failed"
# assert round(ou["perc_win"], 4) == round(
# ts["%_Win"][0], 4
# ), "tradeStats Test perc_win failed"
# assert round(ou["perc_in_mkt"], 4) == round(
# ts["%_InMrkt"][0], 4
# ), "tradeStats Test perc_in_mkt failed"
# assert round(ou["dd_length"], 4) == round(
# ts["DD_Length"][0], 4
# ), "tradeStats Test dd_length failed"
# assert round(ou["dd_max"], 4) == round(
# ts["DD_Max"][0], 4
# ), "tradeStats Test dd_max failed"
df = yf.download(["SPY", "AAPL"], start="2000-01-01", end="2012-01-01")
df = df.pct_change()
df = df.asfreq("B")

ou = rt.trade_stats(df[("Adj Close", "SPY")])
ts = _load_json("./data/tradeStats.json")

assert round(ou["cum_ret"], 4) == round(
ts["CumReturn"][0], 4
), "tradeStats Test cum_ret failed"
assert round(ou["ret_ann"], 4) == round(
ts["Ret_Ann"][0], 4
), "tradeStats Test ret_ann failed"
assert round(ou["sd_ann"], 4) == round(
ts["SD_Ann"][0], 4
), "tradeStats Test sd_ann failed"
assert round(ou["omega"], 4) == round(
ts["Omega"][0], 4
), "tradeStats Test omega failed"
assert round(ou["sharpe"], 4) == round(
ts["Sharpe"][0], 4
), "tradeStats Test sharpe failed"
assert round(ou["perc_win"], 4) == round(
ts["%_Win"][0], 4
), "tradeStats Test perc_win failed"
assert round(ou["perc_in_mkt"], 4) == round(
ts["%_InMrkt"][0], 4
), "tradeStats Test perc_in_mkt failed"
assert round(ou["dd_length"], 4) == round(
ts["DD_Length"][0], 4
), "tradeStats Test dd_length failed"
assert round(ou["dd_max"], 4) == round(
ts["DD_Max"][0], 4
), "tradeStats Test dd_max failed"


def test_returns():
Expand Down
2 changes: 1 addition & 1 deletion src/risktools/_main_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def trade_stats(R, Rf=0):
r = _pd.DataFrame({"trade_stats": r})
series_flag = True

for lab, con in r.iteritems():
for lab, con in r.items():
rs[lab] = dict()
y = find_drawdowns(con)
rs[lab]["cum_ret"] = return_cumulative(con, geometric=True)
Expand Down

0 comments on commit e420d2f

Please sign in to comment.