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

Function full

quantstats/reports.py:492–639  ·  view source on GitHub ↗
(
    returns,
    benchmark=None,
    rf=0.0,
    grayscale=False,
    figsize=(8, 5),
    display=True,
    compounded=True,
    periods_per_year=252,
    match_dates=True,
    **kwargs,
)

Source from the content-addressed store, hash-verified

490
491
492def full(
493 returns,
494 benchmark=None,
495 rf=0.0,
496 grayscale=False,
497 figsize=(8, 5),
498 display=True,
499 compounded=True,
500 periods_per_year=252,
501 match_dates=True,
502 **kwargs,
503):
504
505 # prepare timeseries
506 if match_dates:
507 returns = returns.dropna()
508 returns = _utils._prepare_returns(returns)
509 if benchmark is not None:
510 benchmark = _utils._prepare_benchmark(benchmark, returns.index, rf)
511 if match_dates is True:
512 returns, benchmark = _match_dates(returns, benchmark)
513
514 benchmark_title = None
515 if benchmark is not None:
516 benchmark_title = kwargs.get("benchmark_title", "Benchmark")
517 strategy_title = kwargs.get("strategy_title", "Strategy")
518 active = kwargs.get("active_returns", "False")
519
520 if isinstance(returns, _pd.DataFrame):
521 if len(returns.columns) > 1 and isinstance(strategy_title, str):
522 strategy_title = list(returns.columns)
523
524 if benchmark is not None:
525 benchmark.name = benchmark_title
526 if isinstance(returns, _pd.Series):
527 returns.name = strategy_title
528 elif isinstance(returns, _pd.DataFrame):
529 returns.columns = strategy_title
530
531 dd = _stats.to_drawdown_series(returns)
532
533 if isinstance(dd, _pd.Series):
534 col = _stats.drawdown_details(dd).columns[4]
535 dd_info = _stats.drawdown_details(dd).sort_values(by=col, ascending=True)[:5]
536 if not dd_info.empty:
537 dd_info.index = range(1, min(6, len(dd_info) + 1))
538 dd_info.columns = map(lambda x: str(x).title(), dd_info.columns)
539 elif isinstance(dd, _pd.DataFrame):
540 col = _stats.drawdown_details(dd).columns.get_level_values(1)[4]
541 dd_info_dict = {}
542 for ptf in dd.columns:
543 dd_info = _stats.drawdown_details(dd[ptf]).sort_values(
544 by=col, ascending=True
545 )[:5]
546 if not dd_info.empty:
547 dd_info.index = range(1, min(6, len(dd_info) + 1))
548 dd_info.columns = map(lambda x: str(x).title(), dd_info.columns)
549 dd_info_dict[ptf] = dd_info

Callers

nothing calls this directly

Calls 3

_match_datesFunction · 0.85
metricsFunction · 0.85
plotsFunction · 0.85

Tested by

no test coverage detected