MCPcopy
hub / github.com/ranaroussi/quantstats / html

Function html

quantstats/reports.py:54–489  ·  view source on GitHub ↗
(
    returns,
    benchmark=None,
    rf=0.0,
    grayscale=False,
    title="Strategy Tearsheet",
    output=None,
    compounded=True,
    periods_per_year=252,
    download_filename="quantstats-tearsheet.html",
    figfmt="svg",
    template_path=None,
    match_dates=True,
    **kwargs,
)

Source from the content-addressed store, hash-verified

52
53
54def html(
55 returns,
56 benchmark=None,
57 rf=0.0,
58 grayscale=False,
59 title="Strategy Tearsheet",
60 output=None,
61 compounded=True,
62 periods_per_year=252,
63 download_filename="quantstats-tearsheet.html",
64 figfmt="svg",
65 template_path=None,
66 match_dates=True,
67 **kwargs,
68):
69
70 if output is None and not _utils._in_notebook():
71 raise ValueError("`output` must be specified")
72
73 if match_dates:
74 returns = returns.dropna()
75
76 win_year, win_half_year = _get_trading_periods(periods_per_year)
77
78 tpl = ""
79 with open(template_path or __file__[:-4] + ".html") as f:
80 tpl = f.read()
81 f.close()
82
83 # prepare timeseries
84 if match_dates:
85 returns = returns.dropna()
86 returns = _utils._prepare_returns(returns)
87
88 strategy_title = kwargs.get("strategy_title", "Strategy")
89 if isinstance(returns, _pd.DataFrame):
90 if len(returns.columns) > 1 and isinstance(strategy_title, str):
91 strategy_title = list(returns.columns)
92
93 if benchmark is not None:
94 benchmark_title = kwargs.get("benchmark_title", "Benchmark")
95 if kwargs.get("benchmark_title") is None:
96 if isinstance(benchmark, str):
97 benchmark_title = benchmark
98 elif isinstance(benchmark, _pd.Series):
99 benchmark_title = benchmark.name
100 elif isinstance(benchmark, _pd.DataFrame):
101 benchmark_title = benchmark[benchmark.columns[0]].name
102
103 tpl = tpl.replace(
104 "{{benchmark_title}}", f"Benchmark is {benchmark_title.upper()} | "
105 )
106 benchmark = _utils._prepare_benchmark(benchmark, returns.index, rf)
107 if match_dates is True:
108 returns, benchmark = _match_dates(returns, benchmark)
109 else:
110 benchmark_title = None
111

Callers

nothing calls this directly

Calls 6

_get_trading_periodsFunction · 0.85
_match_datesFunction · 0.85
metricsFunction · 0.85
_html_tableFunction · 0.85
_embed_figureFunction · 0.85
_download_htmlFunction · 0.85

Tested by

no test coverage detected