Skip to content

Commit

Permalink
ignore warning for pct_change
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Sep 3, 2023
1 parent c982417 commit e16240b
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions tinycta/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Portfolio"""
from __future__ import annotations

import warnings
from dataclasses import dataclass

import numpy as np
Expand Down Expand Up @@ -134,7 +135,9 @@ def profit(self):
Daily profits, has to be cashposition yesterday times
return in % between (yesterday, today)
"""
price_changes = self.prices.ffill().pct_change()
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=FutureWarning)
price_changes = self.prices.ffill().pct_change()
previous_position = self.cashposition.shift(1)
return (previous_position * price_changes).sum(axis=1)

Expand Down Expand Up @@ -165,19 +168,6 @@ def metrics(self, days=252):
"Annualized Return (%)": 100 * days * self.returns.mean(),
}

# def metrics2(self, days=252):
# return {
# "Sharpe": np.sqrt(days) * self.profit.mean() / self.profit.std(),
# "Kurtosis": self.profit.kurtosis(),
# "Skewness": self.profit.skew(),
# "Annualized Volatility (%)": 100
# * np.sqrt(days)
# * self.profit.std()
# / self.aum,
# "Annualized Return (%)": 100 * days * self.profit.mean() / self.aum,
# }
# # return self.returns().resample("M").sum()

def plot(self, com=100, **kwargs):
def scatter(ts, name):
return go.Scatter(
Expand All @@ -191,23 +181,11 @@ def scatter(ts, name):

fig.add_trace(
scatter(self.nav_accum, "NAV accumulated"),
# go.Scatter(
# x=self.nav_accum.index,
# y=self.nav_accum,
# name="NAV accumulated",
# fill="tozeroy"
# ),
row=1,
col=1,
)
fig.add_trace(
scatter(self.returns.ewm(com=com).std(), "Volatility"),
# go.Scatter(
# x=self.nav_accum.index,
# y=self.returns.ewm(com=com).std(),
# name="Volatility",
# fill="tozeroy"
# ),
row=2,
col=1,
)
Expand All @@ -216,10 +194,6 @@ def scatter(ts, name):

fig.add_trace(
scatter(dd, "Drawdown"),
# go.Scatter(x=dd.index,
# y=dd,
# name="Drawdown",
# fill="tozeroy"),
row=3,
col=1,
)
Expand Down

0 comments on commit e16240b

Please sign in to comment.