qis examples

August 15, 2026 · View on GitHub

Worked examples organised by qis sub-package. They are repository documentation and are not included in the installed wheel. Run a script from the repository root as a module, for example python -m examples.perfstats.quickstart; each either prints output or shows a matplotlib figure.

Most examples pull data from yfinance. A few use Bloomberg via bbg_fetch and require an open Bloomberg terminal — those are noted below.

Layout

examples/
├── _helpers/                     shared helpers, imported by examples
├── perfstats/                    qis.perfstats — performance metrics on price series
├── models/                       qis.models — EWM, regression, vol estimation, bootstrap
├── regimes/                      qis.perfstats.regime_classifier — regime-conditional analytics
├── portfolios/                   qis.backtest_model_portfolio — scheduled backtests
├── discrete_portfolio/           bar-by-bar orders, fills, and trade ledgers
├── factsheets/                   qis.generate_*_factsheet — full factsheets
├── plots/                        qis.plots — plotting primitives showcase
├── utils/                        qis.utils — date schedules
├── case_studies/                 cross-cutting domain studies (VIX, credit)
└── market_data/                  qis.market_data — FX rates, CIP/carry, FX hedging

perfstats — performance metrics

FileWhat it shows
quickstart.pyMinimal: plot_prices, plot_ra_perf_table, plot_ra_perf_table_benchmark. Same code shown in the package README.
full_performance_report.pyFive-figure summary on a yfinance universe (ETFs, crypto, vol ETFs…). Uses _helpers.reporting_helpers.
sharpe_vs_sortino.pySharpe vs Sortino across return frequencies.
risk_return_frontier.pyBond-ETF risk/return scatter using compute_ra_perf_table.
rolling_performance.pyRolling per-annum returns via compute_rolling_perf_stat. Bloomberg.
cboe_vol_strats_perf.pyCBOE SVRPO vol strat vs SPY — uses a CSV ship in qis.get_resource_path().
miss_best_worst_days_impact.pyPerformance with the best / worst N days per month removed.
infrequent_returns_interpolation.pyinterpolate_infrequent_returns for monthly/quarterly hedge-fund-like series.
unsmoothing_and_delevering.pyEnd-to-end walkthrough of delever_returns, implied_leverage, unsmooth_returns_ar1_ewma and unsmooth_returns_glm on a bundled OCSL/GCF dataset.

models — EWM, regression, vol estimation

FileWhat it shows
ewm_kernels.pyNumba-vs-pandas timing benchmark of ewm_recursion, compute_ewm, and a covariance-tensor cross-check.
ewm_linear_model.pyTime-varying multivariate factor loadings via EwmLinearModel.
ewm_correlation_table.pyEWMA correlation heatmap-table via plot_returns_ewm_corr_table.
multivariate_ols.pyfit_multivariate_ols with intercept / no-intercept.
rolling_correlations.pyRolling 3m/6m/12m correlations between BTC and QQQ.
ohlc_volatility_estimators.pyOHLC realised-vol estimators via estimate_hf_ohlc_vol.
crypto_intraday_vol.pyBTC hourly EWMA vol — handles 24/7 markets without weekend gaps.
overnight_intraday_returns.pyDecomposes close-to-close returns into overnight + intraday components.
bootstrap_analysis.pyBlock bootstrap of price paths via bootstrap_price_data.

regimes — regime-conditional analytics

FileWhat it shows
bull_bear_normal_sharpe.pyBull / bear / normal regime Sharpe via BenchmarkReturnsQuantilesRegime.
boxplot_conditional.pyConditional return boxplots by VIX regime via df_boxplot_by_classification_var.
seasonality.pyReturns conditional on calendar month.
us_election_regimes.pyReturns conditional on divided / unified US government. Bloomberg.

portfolios — backtests

FileWhat it shows
balanced_60_40.py60/40 SPY/IEF with management fee — backtest_model_portfolio.
balanced_60_40_with_btc.pyImpact of adding a 2% BTC sleeve to a 60/40 portfolio.
constant_notional_short.pyConstant-notional vs constant-weight short SPY simulation.
leveraged_etf_strategies.pySSO/IEF leveraged-ETF backtest with rebalancing costs.
long_short.pyLong IEF / short LQD pair (Treasury duration vs IG credit).
ex_anti_tracking_error_and_risk.pyOffline ex-ante TE, benchmark beta, and Euler marginal TE through RiskModel.
ex_post_tracking_error_and_risk.pyOffline realised EWMA TE, whole-sample TE/IR, and EWMA beta/annualised alpha.
vol_target_and_trend.pyVol-target + trend-following sweep via examples.portfolios.strats.qis_delta1.

discrete_portfolio — event-based backtests

FileWhat it shows
discrete_trend_backtest.pyLong/flat moving-average momentum events on free SPY 5-minute bars: orders are emitted only when momentum changes sign, then fill on the next observation and aggregate into a trade ledger and PortfolioData. Requires qis[data]; change INTERVAL to "1m" for 1-minute bars.

factsheets — full multi-page reports

FileWhat it shows
strategy.pygenerate_strategy_factsheet on a volparity portfolio.
strategy_benchmark.pygenerate_strategy_benchmark_factsheet_plt — strategy vs benchmark.
multi_assets.pygenerate_multi_asset_factsheet on an asset-class universe.
multi_strategy.pygenerate_multi_portfolio_factsheet over a span sweep.
strategy_reporting_frequencies.pygenerate_strategy_factsheet reproduced across the DAILY/WEEKLY/MONTHLY/QUARTERLY × {long, short} reporting-frequency grid via fetch_default_report_kwargs, on one volparity portfolio.
strategy_benchmark_reporting_frequencies.pygenerate_strategy_benchmark_factsheet_plt across the same reporting-frequency grid — volparity vs equal-weight.
multi_strategy_reporting_frequencies.pygenerate_multi_portfolio_factsheet across the same grid, on a vol-parity span sweep.
multi_assets_reporting_frequencies.pygenerate_multi_asset_factsheet across the same grid, on the asset-class universe (no backtest).
momentum_indices.pyMulti-asset factsheet on momentum index family. Bloomberg.
europe_futures.pyStrategy factsheet on volume-weighted European futures. Bloomberg.
hedge_funds.pyMulti-asset factsheet on HFRX/HFRI/CTA index family. Bloomberg.
bbg_universe.pyMulti-asset factsheet template for any Bloomberg ticker dict. Bloomberg.
pybloqs_factsheets.pyOptional: pybloqs-rendered factsheets (RA-perf / multi-portfolio / strategy-benchmark). Requires pybloqs and a small jinja patch — see file docstring.

plots — plotting primitives

FileWhat it shows
dual_axis_figure.pyBuilding a 2-axis time-series plot via plot_time_series_2ax.
scatter_with_regression.pyScatter + regression diagnostics with synthetic data.

utils — date schedules

FileWhat it shows
option_rolls_schedule.pygenerate_fixed_maturity_rolls for option/futures roll calendars.

case_studies — cross-cutting domain studies

FileWhat it shows
credit_spreads.pyCredit spread vs equity / rates beta, regime regression. Bloomberg.
vix_beta_to_equities_bonds.pyRolling beta of VIX ETF to SPY/TLT.
vix_conditional_returns.pyConditional returns on short-front-month VIX strategy. Bloomberg.
vix_spy_scatter_by_year.pyVIX changes vs SPY returns scattered by year.
vix_term_structure.pyVIX term-structure correlation with SPX returns. Bloomberg.

market_data — FX rates & hedging

FileWhat it shows
fx_rates_data_yahoo_example.pyBuild FxRatesData from free yfinance FX spots; cross rates, CIP forward premia, FX total-return NAVs, cash NAVs, reference-ccy translation. USD rate from ^IRX, others stylised.
fx_rates_data_bloomberg_example.pyThe same, built from Bloomberg via bbg_fetch — real 3M rates, full currency set. Bloomberg.
fx_cip_identity_yahoo_example.pyCovered-interest-parity check: USD excess vs CHF-hedged excess agree to within bp.
fx_hedging_yahoo_example.pySingle/multi-asset FX hedging: optimal/carry/beta ratios, hedged NAVs, EWM FX vol/beta, hedge reports.
fx_hedging_example.pyHedging demo on the CSV-backed production universe (load_fx_rates_data, load_usd_assets).

Output files

Examples write generated PDFs / PNGs to qis.local_path.get_output_path(). Output figures committed to examples/figures/ are gitignored — the path exists for README assets only and is regenerated on demand.