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

68 drawdown #71

Merged
merged 12 commits into from
Aug 27, 2023
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
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,30 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.275'
hooks:
- id: ruff

args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.35.0
hooks:
- id: markdownlint-fix
args: [ "--ignore", "book/**/*.md" ]

# enforcing the use of new python syntax with pyupgrade
- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.26.1
hooks:
- id: pyupgrade
- id: check-dependabot
- id: check-github-workflows

- repo: 'https://github.com/pre-commit/mirrors-mypy'
rev: v1.4.1
- repo: https://github.com/python-poetry/poetry
rev: '1.6.1' # add version here
hooks:
- id: mypy
files: tinycta
args: [ --ignore-missing-imports, --explicit-package-bases ]
- id: poetry-check
- id: poetry-lock
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ install: ## Install a virtual environment
.PHONY: fmt
fmt: ## Run autoformatting and linting
@poetry run pip install pre-commit
@poetry run pre-commit install
@poetry run pre-commit run --all-files

.PHONY: test
Expand Down
13 changes: 2 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tinycta/drawdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pandas as pd


def drawdown(nav: pd.Series) -> pd.Series:
# compute high water mark
hwm = nav.cummax()

# compute drawdown
return (nav - hwm) / hwm
13 changes: 10 additions & 3 deletions tinycta/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from plotly.subplots import make_subplots
import plotly.graph_objects as go

from tinycta.drawdown import drawdown
from tinycta.month import monthlytable, Aggregate

pd.options.plotting.backend = "plotly"
Expand Down Expand Up @@ -165,9 +166,8 @@ def metrics(self, days=252):
# # return self.returns().resample("M").sum()

def plot(self, com=100, **kwargs):
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.02)
fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02)

# fig.append_trace(
fig.add_trace(
go.Scatter(
x=self.nav_accum.index, y=self.nav_accum, name="NAV accumulated"
Expand All @@ -184,13 +184,20 @@ def plot(self, com=100, **kwargs):
row=2,
col=1,
)

dd = drawdown(self.nav_accum)

fig.add_trace(
go.Scatter(x=dd.index, y=dd, name="Drawdown", fill="tozeroy"),
row=3,
col=1,
)
# portfolio.nav_accum.plot(), row=1, col=1)

fig.update_layout(
{
"title": "NAV Accumulated",
"xaxis": {"title": "Time"},
"yaxis": {"title": "NAV"},
"showlegend": True,
}
)
Expand Down
Loading