diff --git a/quantstats_lumi/_plotting/core.py b/quantstats_lumi/_plotting/core.py index 1dee056..5f52a14 100644 --- a/quantstats_lumi/_plotting/core.py +++ b/quantstats_lumi/_plotting/core.py @@ -354,6 +354,14 @@ def plot_timeseries( _plt.yscale("symlog" if log_scale else "linear") + # Set y-axis limits to avoid blank space at the bottom and top + min_val = returns.min() + max_val = returns.max() + if benchmark is not None: + min_val = min(min_val, benchmark.min()) + max_val = max(max_val, benchmark.max()) + ax.set_ylim(bottom=min_val, top=max_val) + if percent: ax.yaxis.set_major_formatter(_FuncFormatter(format_pct_axis)) # ax.yaxis.set_major_formatter(_plt.FuncFormatter( @@ -940,6 +948,10 @@ def plot_longest_drawdowns( ax.axhline(0, ls="--", lw=1, color="#000000", zorder=2) _plt.yscale("symlog" if log_scale else "linear") + + # Set y-axis limits to avoid blank space at the bottom and top + ax.set_ylim(bottom=series.min(), top=series.max()) + if ylabel: ax.set_ylabel( "Cumulative Returns", @@ -994,6 +1006,7 @@ def plot_distribution( title=None, savefig=None, show=True, + log_scale=False, ): colors = _FLATUI_COLORS if grayscale: @@ -1057,6 +1070,7 @@ def plot_distribution( }, ) + _plt.yscale("symlog" if log_scale else "linear") ax.yaxis.set_major_formatter( _plt.FuncFormatter(lambda x, loc: "{:,}%".format(int(x * 100))) ) diff --git a/quantstats_lumi/_plotting/wrappers.py b/quantstats_lumi/_plotting/wrappers.py index 3f85f7d..c8108b2 100644 --- a/quantstats_lumi/_plotting/wrappers.py +++ b/quantstats_lumi/_plotting/wrappers.py @@ -589,6 +589,7 @@ def distribution( show=True, title=None, prepare_returns=True, + log_scale=True, ): if prepare_returns: returns = _utils._prepare_returns(returns) @@ -604,6 +605,7 @@ def distribution( compounded=compounded, savefig=savefig, show=show, + log_scale=log_scale, ) if not show: return fig diff --git a/quantstats_lumi/reports.py b/quantstats_lumi/reports.py index ce072c6..93bca3b 100644 --- a/quantstats_lumi/reports.py +++ b/quantstats_lumi/reports.py @@ -190,7 +190,7 @@ def html( tpl = tpl.replace("{{metrics}}", _html_table(mtrx)) # Add all of the summary metrics - + # CAGR # # Get the value of the "Strategy" column where the "Metric" column is "CAGR% (Annual Return)" cagr = mtrx.loc["CAGR% (Annual Return)", strategy_title] @@ -209,7 +209,7 @@ def html( max_drawdown = mtrx.loc["Max Drawdown", strategy_title] # Add the max drawdown to the template tpl = tpl.replace("{{max_drawdown}}", max_drawdown) - + # RoMaD # # Get the value of the "Strategy" column where the "Mteric" column is "RoMaD" romad = mtrx.loc["RoMaD", strategy_title] @@ -331,7 +331,7 @@ def html( if benchmark is not None: figfile = _utils._file_stream() - _plots.returns( + _plots.log_returns( returns, benchmark, match_volatility=True, @@ -464,6 +464,7 @@ def html( ylabel=False, compounded=compounded, prepare_returns=False, + log_scale=True, ) tpl = tpl.replace("{{dd_periods}}", _embed_figure(figfile, figfmt)) elif isinstance(returns, _pd.DataFrame): @@ -831,7 +832,7 @@ def parameters_section(parameters): # Make sure that the value is something that can be displayed if not isinstance(value, (int, float, str)): value = str(value) - + tpl += f"{key}{value}" tpl += """ @@ -960,7 +961,7 @@ def metrics( metrics["Sharpe"] = _stats.sharpe(df, rf, win_year, True) metrics["RoMaD"] = _stats.romad(df, win_year, True) - + if benchmark is not None: metrics["Corr to Benchmark "] = _stats.benchmark_correlation(df, benchmark, True) metrics["Prob. Sharpe Ratio %"] = ( diff --git a/report.html b/report.html index cbfba46..6a64013 100644 --- a/report.html +++ b/report.html @@ -281,7 +281,7 @@

Strategy Tearsheet
31 Jan, 2022 - 31 May, 2022

-

Generated by QuantStats (v. +

Generated by QuantStats (v. 0.3.0)


@@ -311,100 +311,100 @@

Generated by QuantStats< - - - - - - - + + + @@ -423,37 +423,37 @@

Generated by QuantStats< - - @@ -472,45 +472,45 @@

Generated by QuantStats< - - @@ -529,8 +529,8 @@

Generated by QuantStats< - @@ -551,31 +551,31 @@

Generated by QuantStats< - - @@ -594,8 +594,8 @@

Generated by QuantStats< - @@ -616,8 +616,8 @@

Generated by QuantStats< - @@ -638,8 +638,8 @@

Generated by QuantStats< - @@ -660,45 +660,45 @@

Generated by QuantStats< - - @@ -719,59 +719,59 @@

Generated by QuantStats< - - @@ -782,8 +782,8 @@

Generated by QuantStats< - @@ -796,8 +796,8 @@

Generated by QuantStats< - @@ -810,8 +810,8 @@

Generated by QuantStats< - @@ -824,8 +824,8 @@

Generated by QuantStats< - @@ -838,8 +838,8 @@

Generated by QuantStats< - @@ -852,8 +852,8 @@

Generated by QuantStats< - @@ -866,8 +866,8 @@

Generated by QuantStats< - @@ -880,8 +880,8 @@

Generated by QuantStats< - @@ -894,21 +894,21 @@

Generated by QuantStats< - - - @@ -916,300 +916,300 @@

Generated by QuantStats< - - - - - - - - - + + + + + + + + - - - - + + + @@ -1266,100 +1266,100 @@

Generated by QuantStats< - - - - - - - + + + @@ -1378,37 +1378,37 @@

Generated by QuantStats< - - @@ -1427,45 +1427,45 @@

Generated by QuantStats< - - @@ -1484,8 +1484,8 @@

Generated by QuantStats< - @@ -1506,31 +1506,31 @@

Generated by QuantStats< - - @@ -1549,8 +1549,8 @@

Generated by QuantStats< - @@ -1571,8 +1571,8 @@

Generated by QuantStats< - @@ -1593,8 +1593,8 @@

Generated by QuantStats< - @@ -1615,45 +1615,45 @@

Generated by QuantStats< - - @@ -1674,59 +1674,59 @@

Generated by QuantStats< - - @@ -1738,8 +1738,8 @@

Generated by QuantStats< - @@ -1752,8 +1752,8 @@

Generated by QuantStats< - @@ -1766,21 +1766,21 @@

Generated by QuantStats< - - - @@ -1788,476 +1788,476 @@

Generated by QuantStats< - - - - - - - - - + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + @@ -2326,81 +2326,81 @@

Generated by QuantStats< - - - - - + @@ -2415,59 +2415,59 @@

Generated by QuantStats< - - @@ -2478,24 +2478,24 @@

Generated by QuantStats< - - @@ -2506,8 +2506,8 @@

Generated by QuantStats< - @@ -2520,45 +2520,45 @@

Generated by QuantStats< - - @@ -2569,31 +2569,31 @@

Generated by QuantStats< - - @@ -2604,21 +2604,21 @@

Generated by QuantStats< - - - @@ -2626,224 +2626,224 @@

Generated by QuantStats< - - - + + - - - - - - - + + + + + + @@ -2891,118 +2891,118 @@

Generated by QuantStats< - - - - - - + + @@ -3014,31 +3014,31 @@

Generated by QuantStats< - - @@ -3050,37 +3050,37 @@

Generated by QuantStats< - - @@ -3092,37 +3092,37 @@

Generated by QuantStats< - - @@ -3133,8 +3133,8 @@

Generated by QuantStats< - @@ -3147,45 +3147,45 @@

Generated by QuantStats< - - @@ -3196,8 +3196,8 @@

Generated by QuantStats< - @@ -3210,52 +3210,52 @@

Generated by QuantStats< - - @@ -3268,8 +3268,8 @@

Generated by QuantStats< - @@ -3281,37 +3281,37 @@

Generated by QuantStats< - - @@ -3322,8 +3322,8 @@

Generated by QuantStats< - @@ -3336,26 +3336,26 @@

Generated by QuantStats< - - @@ -3366,24 +3366,24 @@

Generated by QuantStats< - - @@ -3395,8 +3395,8 @@

Generated by QuantStats< - @@ -3410,8 +3410,8 @@

Generated by QuantStats< - @@ -3427,161 +3427,161 @@

Generated by QuantStats< - - - - - - - + + + + + + @@ -3600,212 +3600,212 @@

Generated by QuantStats< - - - - - - - - - - - - - - - - - - - - - - @@ -3813,235 +3813,235 @@

Generated by QuantStats< - - - - - + + + + - - - - - - + + + + + @@ -4109,100 +4109,100 @@

Generated by QuantStats< - - - - - - - + + + @@ -4221,37 +4221,37 @@

Generated by QuantStats< - - @@ -4270,45 +4270,45 @@

Generated by QuantStats< - - @@ -4327,8 +4327,8 @@

Generated by QuantStats< - @@ -4349,31 +4349,31 @@

Generated by QuantStats< - - @@ -4392,8 +4392,8 @@

Generated by QuantStats< - @@ -4414,8 +4414,8 @@

Generated by QuantStats< - @@ -4436,8 +4436,8 @@

Generated by QuantStats< - @@ -4458,45 +4458,45 @@

Generated by QuantStats< - - @@ -4517,59 +4517,59 @@

Generated by QuantStats< - - @@ -4581,8 +4581,8 @@

Generated by QuantStats< - @@ -4595,8 +4595,8 @@

Generated by QuantStats< - @@ -4609,137 +4609,137 @@

Generated by QuantStats< - - - @@ -4747,279 +4747,279 @@

Generated by QuantStats< - - - - - + + + + - - - - - - - + + + + + + @@ -5070,81 +5070,81 @@

Generated by QuantStats< - - - - - + @@ -5157,24 +5157,24 @@

Generated by QuantStats< - - @@ -5187,8 +5187,8 @@

Generated by QuantStats< - @@ -5203,45 +5203,45 @@

Generated by QuantStats< - - @@ -5254,31 +5254,31 @@

Generated by QuantStats< - - @@ -5291,37 +5291,37 @@

Generated by QuantStats< - - @@ -5334,45 +5334,45 @@

Generated by QuantStats< - - @@ -5385,26 +5385,26 @@

Generated by QuantStats< - - @@ -5417,52 +5417,52 @@

Generated by QuantStats< - - @@ -5475,47 +5475,47 @@

Generated by QuantStats< - - @@ -5528,8 +5528,8 @@

Generated by QuantStats< - @@ -5546,26 +5546,26 @@

Generated by QuantStats< - - - @@ -5579,8 +5579,8 @@

Generated by QuantStats< - @@ -5596,8 +5596,8 @@

Generated by QuantStats< - @@ -5612,8 +5612,8 @@

Generated by QuantStats< - @@ -5628,8 +5628,8 @@

Generated by QuantStats< - @@ -5648,8 +5648,8 @@

Generated by QuantStats< - @@ -5657,362 +5657,362 @@

Generated by QuantStats< - - - - - - + + + + + - - - - - - - - - - - + + + + + + + + + + @@ -6078,81 +6078,81 @@

Generated by QuantStats< - - - - - + @@ -6165,24 +6165,24 @@

Generated by QuantStats< - - @@ -6195,8 +6195,8 @@

Generated by QuantStats< - @@ -6211,45 +6211,45 @@

Generated by QuantStats< - - @@ -6262,31 +6262,31 @@

Generated by QuantStats< - - @@ -6299,37 +6299,37 @@

Generated by QuantStats< - - @@ -6342,45 +6342,45 @@

Generated by QuantStats< - - @@ -6393,26 +6393,26 @@

Generated by QuantStats< - - @@ -6425,52 +6425,52 @@

Generated by QuantStats< - - @@ -6483,47 +6483,47 @@

Generated by QuantStats< - - @@ -6536,8 +6536,8 @@

Generated by QuantStats< - @@ -6554,26 +6554,26 @@

Generated by QuantStats< - - - @@ -6587,8 +6587,8 @@

Generated by QuantStats< - @@ -6604,8 +6604,8 @@

Generated by QuantStats< - @@ -6620,8 +6620,8 @@

Generated by QuantStats< - @@ -6636,8 +6636,8 @@

Generated by QuantStats< - @@ -6656,8 +6656,8 @@

Generated by QuantStats< - @@ -6665,432 +6665,432 @@

Generated by QuantStats< - - - - - - + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + @@ -7152,81 +7152,81 @@

Generated by QuantStats< - - - - - + @@ -7239,24 +7239,24 @@

Generated by QuantStats< - - @@ -7269,8 +7269,8 @@

Generated by QuantStats< - @@ -7285,45 +7285,45 @@

Generated by QuantStats< - - @@ -7336,31 +7336,31 @@

Generated by QuantStats< - - @@ -7373,37 +7373,37 @@

Generated by QuantStats< - - @@ -7416,45 +7416,45 @@

Generated by QuantStats< - - @@ -7467,26 +7467,26 @@

Generated by QuantStats< - - @@ -7499,52 +7499,52 @@

Generated by QuantStats< - - @@ -7557,47 +7557,47 @@

Generated by QuantStats< - - @@ -7610,8 +7610,8 @@

Generated by QuantStats< - @@ -7628,26 +7628,26 @@

Generated by QuantStats< - - - @@ -7661,8 +7661,8 @@

Generated by QuantStats< - @@ -7678,8 +7678,8 @@

Generated by QuantStats< - @@ -7694,8 +7694,8 @@

Generated by QuantStats< - @@ -7710,8 +7710,8 @@

Generated by QuantStats< - @@ -7730,8 +7730,8 @@

Generated by QuantStats< - @@ -7739,343 +7739,343 @@

Generated by QuantStats< - - - - - - + + + + + - - - - - - - - - - + + + + + + + + + @@ -8138,100 +8138,100 @@

Generated by QuantStats< - - - - - - - + + + @@ -8250,37 +8250,37 @@

Generated by QuantStats< - - @@ -8299,45 +8299,45 @@

Generated by QuantStats< - - @@ -8356,8 +8356,8 @@

Generated by QuantStats< - @@ -8378,31 +8378,31 @@

Generated by QuantStats< - - @@ -8421,8 +8421,8 @@

Generated by QuantStats< - @@ -8443,8 +8443,8 @@

Generated by QuantStats< - @@ -8465,8 +8465,8 @@

Generated by QuantStats< - @@ -8487,45 +8487,45 @@

Generated by QuantStats< - - @@ -8546,59 +8546,59 @@

Generated by QuantStats< - - @@ -8609,8 +8609,8 @@

Generated by QuantStats< - @@ -8623,8 +8623,8 @@

Generated by QuantStats< - @@ -8637,8 +8637,8 @@

Generated by QuantStats< - @@ -8651,8 +8651,8 @@

Generated by QuantStats< - @@ -8665,30 +8665,30 @@

Generated by QuantStats< - - - - @@ -8696,424 +8696,424 @@

Generated by QuantStats< - - - - - - - + + + + + + - - - - - - - - - - - + + + + + + + + + + @@ -9185,100 +9185,100 @@

Generated by QuantStats< - - - - - - - + + + @@ -9297,37 +9297,37 @@

Generated by QuantStats< - - @@ -9346,45 +9346,45 @@

Generated by QuantStats< - - @@ -9403,8 +9403,8 @@

Generated by QuantStats< - @@ -9425,31 +9425,31 @@

Generated by QuantStats< - - @@ -9468,8 +9468,8 @@

Generated by QuantStats< - @@ -9490,8 +9490,8 @@

Generated by QuantStats< - @@ -9512,8 +9512,8 @@

Generated by QuantStats< - @@ -9534,45 +9534,45 @@

Generated by QuantStats< - - @@ -9593,59 +9593,59 @@

Generated by QuantStats< - - @@ -9657,8 +9657,8 @@

Generated by QuantStats< - @@ -9672,8 +9672,8 @@

Generated by QuantStats< - @@ -9687,18 +9687,18 @@

Generated by QuantStats< - @@ -9707,26 +9707,26 @@

Generated by QuantStats< - - - - @@ -9734,250 +9734,250 @@

Generated by QuantStats< - - - - - - - - + + + + + + + - - - + + @@ -10029,79 +10029,79 @@

Generated by QuantStats< - - - - - - + + @@ -10113,80 +10113,80 @@

Generated by QuantStats< - - - - + + @@ -10198,62 +10198,62 @@

Generated by QuantStats< - - - + @@ -10265,36 +10265,36 @@

Generated by QuantStats< - - @@ -10306,26 +10306,26 @@

Generated by QuantStats< - - @@ -10337,32 +10337,32 @@

Generated by QuantStats< - - @@ -10374,21 +10374,21 @@

Generated by QuantStats< - - @@ -10400,44 +10400,44 @@

Generated by QuantStats< - - @@ -10449,50 +10449,50 @@

Generated by QuantStats< - - @@ -10504,73 +10504,73 @@

Generated by QuantStats< - - - - + + @@ -10582,24 +10582,24 @@

Generated by QuantStats< - - @@ -10611,39 +10611,39 @@

Generated by QuantStats< - - @@ -10657,62 +10657,62 @@

Generated by QuantStats< - - - + @@ -10725,88 +10725,88 @@

Generated by QuantStats< - - - - - - - - - - - - - @@ -10820,11 +10820,11 @@

Generated by QuantStats< - @@ -10839,37 +10839,37 @@

Generated by QuantStats< - @@ -10883,16 +10883,16 @@

Generated by QuantStats< - @@ -10979,452 +10979,452 @@

Generated by QuantStats< - - - - - - - + + + + + + - - - - - - - - - - - - + + + + + + + + + + + @@ -11494,19 +11494,19 @@

Generated by QuantStats< - - @@ -11516,114 +11516,114 @@

Generated by QuantStats< - - - - - + + + + @@ -11640,66 +11640,66 @@

Generated by QuantStats< - - - + + @@ -11717,108 +11717,108 @@

Generated by QuantStats< - - - - - + + + + @@ -11837,74 +11837,74 @@

Generated by QuantStats< - - - + + @@ -11925,18 +11925,18 @@

Generated by QuantStats< - @@ -11953,78 +11953,78 @@

Generated by QuantStats< - - - - + + @@ -12036,37 +12036,37 @@

Generated by QuantStats< - - @@ -12077,8 +12077,8 @@

Generated by QuantStats< - @@ -12091,8 +12091,8 @@

Generated by QuantStats< - @@ -12105,37 +12105,37 @@

Generated by QuantStats< - - @@ -12146,45 +12146,45 @@

Generated by QuantStats< - - @@ -12195,75 +12195,75 @@

Generated by QuantStats< - - - - - - - - - - - @@ -12272,83 +12272,83 @@

Generated by QuantStats< - - - - - - - - - - - - - - @@ -12356,358 +12356,358 @@

Generated by QuantStats< - - - - - - - + + + + + + - - - - - - - - + + + + + + + @@ -12766,7 +12766,7 @@

Generated by QuantStats<
Annual Return

12.56%

- +
Total Return
@@ -12787,14 +12787,14 @@

1

- +

Parameters Used

ParameterValue
symbolSPY
idle_holding_symbolQQQ
idle_holding_pct0.25
days_to_expiry0
strike_step_size1
min_wing_size2
time_to_start10:30
max_loss0.25
first_adjustment_loss0.1
take_profit0.15
pct_to_trade0.35
time_to_close15:30
days_of_week_to_trade01234
wing_size_adjustment0
max_adx40
min_gamma_risk0
expected_iv_collapse2.5
adx_length14
take_profit_trailing_stop0.02
- +

Key Performance Metrics

@@ -12896,4 +12896,4 @@

Worst 10 Drawdowns

- \ No newline at end of file +