Package: qis
Quantitative Investment Strategies: QISqis package implements analytics for visualisation of financial data, performance
reporting, analysis of quantitative strategies.qis package is split into 5 main modules with the
dependecy path increasing sequentially as follows.qis.utilsis module containing low level utilities for operations with pandas, numpy, and datetimes.qis.perfstatsis module for computing performance statistics and performance attribution including returns, volatilities, etc.qis.plotsis module for plotting and visualization apis.qis.modelsis module containing statistical models including filtering and regressions.qis.portfoliois high level module for analysis, simulation, backtesting, and reporting of quant strategies.qis.examplescontains scripts with illustrations of QIS analytics.Table of contentsAnalyticsInstallationExamplesVisualization of price dataMulti assets factsheetStrategy factsheetStrategy benchmark factsheetMulti strategy factsheetNotebooksContributionsUpdatesToDosDisclaimerUpdatesInstallationinstall usingpipinstallqisupgrade usingpipinstall--upgradeqisclose usinggitclonehttps://github.com/ArturSepp/QuantInvestStrats.gitCore dependencies:
python = ">=3.8,<3.11",
numba = ">=0.56.4",
numpy = ">=1.22.4",
scipy = ">=1.10",
statsmodels = ">=0.13.5",
pandas = ">=1.5.2",
matplotlib = ">=3.2.2",
seaborn = ">=0.12.2"Optional dependencies:
yfinance ">=0.1.38" (for getting test price data),
pybloqs ">=1.2.13" (for producing html and pdf factsheets)Examples1. Visualization of price dataThe script is located inqis.examples.performances(https://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/performances.py)importmatplotlib.pyplotaspltimportseabornassnsimportyfinanceasyfimportqis# define tickers and fetch price datatickers=['SPY','QQQ','EEM','TLT','IEF','SHY','LQD','HYG','GLD']prices=yf.download(tickers,start=None,end=None)['Adj Close'][tickers].dropna()# plotting price data with minimum usagewithsns.axes_style("darkgrid"):fig,ax=plt.subplots(1,1,figsize=(10,7))qis.plot_prices(prices=prices,x_date_freq='A',ax=ax)# 2-axis plot with drawdowns using sns styleswithsns.axes_style("darkgrid"):fig,axs=plt.subplots(2,1,figsize=(10,7))qis.plot_prices_with_dd(prices=prices,x_date_freq='A',axs=axs)# plot risk-adjusted performance table with excess Sharpe ratioust_3m_rate=yf.download('^IRX',start=None,end=None)['Adj Close'].dropna()/100.0# set parameters for computing performance stats including returns vols and regressionsperf_params=qis.PerfParams(freq='M',freq_reg='Q',alpha_an_factor=4.0,rates_data=ust_3m_rate)# perf_columns is list to display different perfomance metrics from enumeration PerfStatfig=qis.plot_ra_perf_table(prices=prices,perf_columns=[PerfStat.TOTAL_RETURN,PerfStat.PA_RETURN,PerfStat.PA_EXCESS_RETURN,PerfStat.VOL,PerfStat.SHARPE_RF0,PerfStat.SHARPE_EXCESS,PerfStat.SORTINO_RATIO,PerfStat.CALMAR_RATIO,PerfStat.MAX_DD,PerfStat.MAX_DD_VOL,PerfStat.SKEWNESS,PerfStat.KURTOSIS],title=f"Risk-adjusted performance:{qis.get_time_period_label(prices,date_separator='-')}",perf_params=perf_params)# add benchmark regression using excess returns for linear beta# regression frequency is specified using perf_params.freq_reg# regression alpha is multiplied using perf_params.alpha_an_factorfig=qis.plot_ra_perf_table_benchmark(prices=prices,benchmark='SPY',perf_columns=[PerfStat.TOTAL_RETURN,PerfStat.PA_RETURN,PerfStat.PA_EXCESS_RETURN,PerfStat.VOL,PerfStat.SHARPE_RF0,PerfStat.SHARPE_EXCESS,PerfStat.SORTINO_RATIO,PerfStat.CALMAR_RATIO,PerfStat.MAX_DD,PerfStat.MAX_DD_VOL,PerfStat.SKEWNESS,PerfStat.KURTOSIS,PerfStat.ALPHA_AN,PerfStat.BETA,PerfStat.R2],title=f"Risk-adjusted performance:{qis.get_time_period_label(prices,date_separator='-')}benchmarked with SPY",perf_params=perf_params)2. Multi assets factsheetThis report is adopted for reporting the risk-adjusted performance
of several assets with the goal
of cross-sectional comparisionRun example inqis.examples.factsheets.multi_assets.pyhttps://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/factsheets/multi_assets.py3. Strategy factsheetThis report is adopted for report performance, risk, and trading statistics
for either backtested or actual strategy
with strategy data passed as PortfolioData objectRun example inqis.examples.factsheets.strategy.pyhttps://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/factsheets/strategy.py4. Strategy benchmark factsheetThis report is adopted for report performance and marginal comparison
of strategy vs a benchmark strategy
(data for both are passed using individual PortfolioData object)Run example inqis.examples.factsheets.strategy_benchmark.pyhttps://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/factsheets/strategy_benchmark.py5. Multi strategy factsheetThis report is adopted to examine the sensitivity of
backtested strategy to a parameter or set of parameters:Run example inqis.examples.factsheets.multi_strategy.pyhttps://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/factsheets/multi_strategy.py6. NotebooksRecommended package to work with notebooks:pipinstallnotebookStarting local serverjupyternotebookContributionsIf you are interested in extending and improving QIS analytics,
please consider contributing to the library.I have found it is a good practice to isolate general purpose and low level analytics and visualizations, which can be outsourced and shared, while keeping
the focus on developing high level commercial applications.There are a number of requirements:The code isPep 8 compliantReliance on common Python data types including numpy arrays, pandas, and dataclasses.Transparent naming of functions and data types with enough comments. Type annotations of functions and arguments is a must.Each submodule has a unit test for core functions and a localised entry point to core functions.Avoid "super" pythonic constructions. Readability is the priority.Updates30 December 2022,  Version 1.0.1 released08 July 2023, Version 2.0.1 releasedCore ChangesPortfolio optimization (qis.portfolio.optimisation) layer is removed with core
functionality moved to a stand-alone Python package: Backtesting Optimal Portfolio (bop)This allows to remove the dependency from cvxpy and sklearn packages and
thus to simplify the dependency management for qisAdded factsheet reporting using pybloqs packagehttps://github.com/man-group/PyBloqsPybloqs is a versatile tool to create customised reporting using Matplotlib figures and table
and thus leveraging QIS visualisation analyticsNew factsheets are addedExamples are added for the four type of reports:multi assets: report performance of several assets with goal of cross-sectional comparision:
see qis.examples.factsheets.multi_asset.pystrategy: report performance, risk, and trading statictics for either backtested or actual strategy
with strategy data passed as PortfolioData object: see qis.examples.factsheets.strategy.pystrategy vs benchmark: report performance and marginal comparison
of strategy vs a benchmark strategy (data for both are passed using individual PortfolioData object):
see qis.examples.factsheets.strategy_benchmark.pymulti_strategy: report for a list of strategies with individual PortfolioData. This report is
useful to examine the sensetivity of backtested strategy to a parameter or set of parameters:
see qis.examples.factsheets.multi_strategyToDosEnhanced documentation and readme examples.Docstrings for key functions.Reporting analytics and factsheets generation enhancing to matplotlib.DisclaimerQIS package is distributed FREE & WITHOUT ANY WARRANTY under the GNU GENERAL PUBLIC LICENSE.See theLICENSE.txtin the release for details.Please report any bugs or suggestions by opening anissue.