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 (for now documentation is outdated).

Quickstart

import pandas as pd
import pqr

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)
prices, pe, volume = pqr.utils.replace_with_nan(prices, pe, volume, to_replace=0)

universe = pqr.Universe(prices)
universe.filter(volume >= 10_000_000)

preprocessor = [
    pqr.Filter(universe.mask),
    pqr.LookBackMedian(3),
    pqr.Hold(3),
]
value = pqr.Factor(pe, "less", preprocessor)

benchmark = pqr.Benchmark.from_universe(universe)

fm = pqr.fm.FactorModel(
    picking_strategies=pqr.fm.split_quantiles(3),
    allocation_strategy=pqr.EqualWeights(),
    add_wml=True
)
portfolios = fm(value, universe)

summary = pqr.dash.Dashboard(
    pqr.dash.Graph(pqr.metrics.CompoundedReturns(), benchmark=benchmark),
    pqr.dash.Table(
        pqr.metrics.MeanReturn(annualizer=1, statistics=True),
        pqr.metrics.Volatility(annualizer=1),
        pqr.metrics.SharpeRatio(rf=0),
        pqr.metrics.MeanExcessReturn(benchmark),
        pqr.metrics.Alpha(benchmark, statistics=True),
        pqr.metrics.Beta(benchmark),
    )
)
summary(portfolios)

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 Distribution

pqr-0.3.2.tar.gz (16.0 kB view hashes)

Uploaded Source

Built Distribution

pqr-0.3.2-py3-none-any.whl (18.9 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