diff --git a/quantstats/_plotting/core.py b/quantstats/_plotting/core.py index 4a29f499..3dce7f99 100644 --- a/quantstats/_plotting/core.py +++ b/quantstats/_plotting/core.py @@ -245,7 +245,6 @@ def plot_timeseries( benchmark=None, title="Returns", compound=False, - cumulative=True, fill=False, returns_label="Strategy", hline=None, @@ -279,15 +278,14 @@ def plot_timeseries( returns = (returns / returns.std()) * bmark_vol # --------------- - if compound is True: - if cumulative: - returns = _stats.compsum(returns) - if isinstance(benchmark, _pd.Series): - benchmark = _stats.compsum(benchmark) - else: - returns = returns.cumsum() - if isinstance(benchmark, _pd.Series): - benchmark = benchmark.cumsum() + if compound: + returns = _stats.compsum(returns) + if isinstance(benchmark, _pd.Series): + benchmark = _stats.compsum(benchmark) + else: + returns = returns.cumsum() + if isinstance(benchmark, _pd.Series): + benchmark = benchmark.cumsum() if resample: returns = returns.resample(resample) diff --git a/quantstats/_plotting/wrappers.py b/quantstats/_plotting/wrappers.py index c4a06501..48865825 100644 --- a/quantstats/_plotting/wrappers.py +++ b/quantstats/_plotting/wrappers.py @@ -151,17 +151,26 @@ def snapshot( axes[0].set_ylabel( "Cumulative Return", fontname=fontname, fontweight="bold", fontsize=12 ) + if isinstance(returns, _pd.Series): + if mode.lower() in ["cumsum", "sum"]: + cum_ret = returns.cumsum() * 100 + else: + cum_ret = _stats.compsum(returns) * 100 axes[0].plot( - _stats.compsum(returns) * 100, + cum_ret, color=colors[1], lw=1 if grayscale else lw, zorder=1, ) elif isinstance(returns, _pd.DataFrame): for col in returns.columns: + if mode.lower() in ["cumsum", "sum"]: + cum_ret = returns[col].cumsum() * 100 + else: + cum_ret = _stats.compsum(returns[col]) * 100 axes[0].plot( - _stats.compsum(returns[col]) * 100, + cum_ret, label=col, lw=1 if grayscale else lw, zorder=1, @@ -381,7 +390,6 @@ def returns( lw=1.5, match_volatility=False, compound=True, - cumulative=True, resample=None, ylabel="Cumulative Returns", subtitle=True, @@ -413,7 +421,6 @@ def returns( log_scale=False, resample=resample, compound=compound, - cumulative=cumulative, lw=lw, figsize=figsize, fontname=fontname, @@ -435,7 +442,6 @@ def log_returns( lw=1.5, match_volatility=False, compound=True, - cumulative=True, resample=None, ylabel="Cumulative Returns", subtitle=True, @@ -470,7 +476,6 @@ def log_returns( log_scale=True, resample=resample, compound=compound, - cumulative=cumulative, lw=lw, figsize=figsize, fontname=fontname, @@ -564,7 +569,7 @@ def yearly_returns( if compounded: returns = returns.resample("A").apply(_stats.comp) else: - returns = returns.resample("A").apply(_df.sum) + returns = returns.resample("A").sum() returns = returns.resample("A").last() fig = _core.plot_returns_bars( diff --git a/quantstats/reports.py b/quantstats/reports.py index de34b9c3..f51e93b7 100644 --- a/quantstats/reports.py +++ b/quantstats/reports.py @@ -221,7 +221,7 @@ def html( savefig={"fname": figfile, "format": figfmt}, show=False, ylabel=False, - cumulative=compounded, + compound=compounded, prepare_returns=False, ) tpl = tpl.replace("{{returns}}", _embed_figure(figfile, figfmt)) @@ -236,7 +236,7 @@ def html( savefig={"fname": figfile, "format": figfmt}, show=False, ylabel=False, - cumulative=compounded, + compound=compounded, prepare_returns=False, ) tpl = tpl.replace("{{log_returns}}", _embed_figure(figfile, figfmt)) @@ -253,7 +253,7 @@ def html( savefig={"fname": figfile, "format": figfmt}, show=False, ylabel=False, - cumulative=compounded, + compound=compounded, prepare_returns=False, ) tpl = tpl.replace("{{vol_returns}}", _embed_figure(figfile, figfmt)) @@ -631,6 +631,7 @@ def full( grayscale=grayscale, figsize=figsize, mode="full", + compounded=compounded, periods_per_year=periods_per_year, prepare_returns=False, benchmark_title=benchmark_title, @@ -710,6 +711,7 @@ def basic( grayscale=grayscale, figsize=figsize, mode="basic", + compounded=compounded, periods_per_year=periods_per_year, prepare_returns=False, benchmark_title=benchmark_title, @@ -1290,6 +1292,7 @@ def plots( show=True, ylabel=False, prepare_returns=False, + compound=compounded, ) _plots.log_returns( @@ -1300,6 +1303,7 @@ def plots( show=True, ylabel=False, prepare_returns=False, + compound=compounded, ) if benchmark is not None: @@ -1312,6 +1316,7 @@ def plots( show=True, ylabel=False, prepare_returns=False, + compound=compounded, ) _plots.yearly_returns( @@ -1322,6 +1327,7 @@ def plots( show=True, ylabel=False, prepare_returns=False, + compounded=compounded, ) _plots.histogram( @@ -1332,6 +1338,7 @@ def plots( show=True, ylabel=False, prepare_returns=False, + compounded=compounded, ) small_fig_size = (figsize[0], figsize[0] * 0.35) @@ -1401,6 +1408,7 @@ def plots( show=True, ylabel=False, prepare_returns=False, + compounded=compounded, ) elif isinstance(returns, _pd.DataFrame): for col in returns.columns: @@ -1412,6 +1420,7 @@ def plots( ylabel=False, title=col, prepare_returns=False, + compounded=compounded, ) _plots.drawdown( @@ -1420,6 +1429,7 @@ def plots( figsize=(figsize[0], figsize[0] * 0.4), show=True, ylabel=False, + compound=compounded, ) if isinstance(returns, _pd.Series): @@ -1431,6 +1441,7 @@ def plots( returns_label=returns.name, show=True, ylabel=False, + compounded=compounded, active=active, ) elif isinstance(returns, _pd.DataFrame): @@ -1456,6 +1467,7 @@ def plots( title=returns.name, ylabel=False, prepare_returns=False, + compounded=compounded, ) elif isinstance(returns, _pd.DataFrame): for col in returns.columns: @@ -1467,6 +1479,7 @@ def plots( title=col, ylabel=False, prepare_returns=False, + compounded=compounded, )