Skip to content

Commit

Permalink
Merge pull request #20 from kartiksubbarao/patch-9
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesir authored Mar 21, 2024
2 parents 77e1027 + 712d8b8 commit a4e7e0c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions quantstats_lumi/_plotting/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def plot_histogram(

colors, _, _ = _get_colors(grayscale)

apply_fnc = _stats.comp if compounded else _np.sum
apply_fnc = _stats.comp if compounded else 'sum'
if benchmark is not None:
benchmark = (
benchmark.fillna(0)
Expand Down Expand Up @@ -1003,7 +1003,7 @@ def plot_distribution(
port = _pd.DataFrame(returns.fillna(0))
port.columns = ["Daily"]

apply_fnc = _stats.comp if compounded else _np.sum
apply_fnc = _stats.comp if compounded else 'sum'

port["Weekly"] = port["Daily"].resample("W-MON").apply(apply_fnc)
port["Weekly"] = port["Weekly"].ffill()
Expand Down
3 changes: 1 addition & 2 deletions quantstats_lumi/_plotting/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import seaborn as _sns
from matplotlib.ticker import FuncFormatter as _FuncFormatter
from matplotlib.ticker import StrMethodFormatter as _StrMethodFormatter
from pandas import DataFrame as _df

from .. import stats as _stats
from .. import utils as _utils
Expand Down Expand Up @@ -552,7 +551,7 @@ def yearly_returns(
if compounded:
returns = returns.resample("YE").apply(_stats.comp)
else:
returns = returns.resample("YE").apply(_df.sum)
returns = returns.resample("YE").sum()
returns = returns.resample("YE").last()

fig = _core.plot_returns_bars(
Expand Down
2 changes: 1 addition & 1 deletion quantstats_lumi/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ def metrics(

# returns
metrics["~~"] = blank
comp_func = _stats.comp if compounded else _np.sum
comp_func = _stats.comp if compounded else lambda x: _np.sum(x, axis=0)

today = df.index[-1] # _dt.today()
metrics["MTD %"] = comp_func(df[df.index >= _dt(today.year, today.month, 1)]) * pct
Expand Down
4 changes: 2 additions & 2 deletions quantstats_lumi/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_outliers(data):
else:
returns = returns[returns.columns[0]]

apply_fnc = comp if compounded else _np.sum
apply_fnc = comp if compounded else 'sum'
daily = returns.dropna()

if prepare_returns:
Expand Down Expand Up @@ -594,7 +594,7 @@ def cagr(returns, rf=0.0, compounded=True, periods=365):
if compounded:
total = comp(total)
else:
total = _np.sum(total)
total = _np.sum(total, axis=0)

years = (returns.index[-1] - returns.index[0]).days / periods

Expand Down

0 comments on commit a4e7e0c

Please sign in to comment.