Skip to main content

Library for testing factor strategies

Project description

pqr

pqr is a Python library for portfolio quantitative research.

Provides:

  1. Library for testing factor strategies
  2. A lot of different statistical metrics for portfolios
  3. Fancy visualization of results

Installation

Use the package manager pip to install pqr.

pip install pqr

Documentation

You can find it on rtd.

Quickstart

import pandas as pd
import numpy as np

import pqr

# read data
prices = pd.read_csv('prices.csv', parse_dates=True)
pe = pd.read_csv('pe.csv', parse_dates=True)
volume = pd.read_csv('volume.csv', parse_dates=True)

# preprocess the data
prices = prices.replace(0, np.nan)
pe = pe.replace(0, np.nan)
volume = volume.replace(0, np.nan)

# go to factors
value = pqr.Factor(pe).look_back(3, 'static').lag(0).hold(3)

liquidity = pqr.Factor(volume).look_back()
liquidity_filter = liquidity >= 10_000_000

value.filter(liquidity_filter)

# create custom benchmark from liquid stocks with equal weights
benchmark = pqr.Benchmark().from_stock_universe(prices, liquidity_filter)

# fitting the factor model on value factor (3-0-3)
# after fit we will get 3 quantile portfolios
portfolios = pqr.fit_quantile_factor_model(prices, value)
# fetch the table with summary statistics and plot cumulative returns
pqr.summary_tear_sheet(portfolios, benchmark)

You can also see this example on real data with output in examples/quickstart.ipynb.

Communication

If you find a bug or want to add some features, you are welcome to telegram @atomtosov or @eura71.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project status

Now the project is in beta-version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pqr-0.2.7-py3-none-any.whl (24.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page