Skip to main content

Package to build universes for factor pricing model

Project description

Factor Pricing Model Universe

CI Status Documentation Status Test coverage percentage

Poetry black pre-commit

PyPI Version Supported Python versions License

Package to build universes for factor pricing model. For further details, please refer to the documentation

Installation

Install this via pip (or your favourite package manager):

pip install factor-pricing-model-universe

Usage

The library contains the pipelines to build the universe. You can run the pipelines interactively in Jupyter Notebook.

from fpm_universe import pipeline

Alternatively, for scheduled runs, you can create a configuration and run the command line entry point to create the universe.

Configuration

The configuration is in yaml format and contains a few inputs

Name Description
output_filename Output filename
intermediate_directory Intermediate directory to export the pipeline outputs
start_datetime Start datetime of the universe
last_datetime Last datetime of the universe
frequency Frequency of the universe. For further details, please see the "Offset aliases" in pandas documentation
pipeline List of pipelines to filter the universe
data Defines the data used by pipeline, or referred by yaml tag !data

Each pipeline returns a pandas dataframe indicating if the instrument is included into the universe on the specified date / time. For example, the pipeline returns the following dataframe

+------------+--------+-------+
|    date    |  AAPL  | GOOGL |
+------------+--------+-------+
| 2022-11-17 |  True  | False |
+------------+--------+-------+
| 2022-11-18 |  True  |  True |
+------------+--------+-------+

and it indicates AAPL is included in the universe on both 2022-11-17 and 2022-11-18 while GOOGL only on 2022-11-18.

By default, the pipeline functions are imported from module fpm_universe.pipeline.

Each data defines the method to retrieve from the source, or the operator on the source data. The return type of each data is unconstrained. It can be a json-like dict, a list, a pandas series, or even a pandas dataframe.

In the configuration, Each data can be referred by yaml tag !data, and it is loaded in lazy only when it is referred by another data object or a pipeline.

Command

The entry point factor-pricing-model-universe is to generate the universe regarding the given configuration to the destination, with dynamically passing the parameters to format the configuration.

The arguments of the entry point are

Argument Description
-c, --config TEXT Required. Configuration file path.
-p, --parameter TEXT Parameters to be formatted in the configuration.

For example, given the configuration as follows,

output_filename: "{output_directory}/{date}.parquet"
intermediate_directory: "{output_directory}/{date}"
start_datetime: "2015-01-01"
last_datetime: "{date}"
frequency: "B"
pipeline:
  - name: range_validity
    function: range_validity
    parameters:
      values: !data initial_validity
data:
  symbols:
    function: jq_compile
    parameters:
      json_filename: "{data_directory}/index/sp500/default/{date}.json"
      pattern: "[.[] | .tickers[]] | sort | unique | .[]"
  initial_validity:
    function: jq_compile
    parameters:
      json_filename: "{data_directory}/listings/{date}.json"
      pattern: ".[] | {{ symbol: .symbol, valid_start_datetime: .ipoDate, valid_last_datetime: .delistingDate }}"
      includes:
        symbol: !data symbols

and run the following command

factor-pricing-model-universe \
  --config <path> \
  --parameter output_directory=$HOME/output \
  --parameter data_directory=$HOME/data \
  --parameter date=2022-10-20

the universe dataframe is output to $HOME/output/2022-10-20.parquet (formatted with the parameter output_directory and date).

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

factor_pricing_model_universe-2022.1.2.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file factor_pricing_model_universe-2022.1.2.tar.gz.

File metadata

  • Download URL: factor_pricing_model_universe-2022.1.2.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.8

File hashes

Hashes for factor_pricing_model_universe-2022.1.2.tar.gz
Algorithm Hash digest
SHA256 fb08387fa90c0ef07fc9461f0e739a0f5447531818ff32d5a334f97250edc1d8
MD5 8d67128ad8f3775899ce34bbf1fa648f
BLAKE2b-256 6b7c8120b6f18252e0226bf2aedc3daeb0bf59a38faebcd63a3e1c5124a6acf7

See more details on using hashes here.

File details

Details for the file factor_pricing_model_universe-2022.1.2-py3-none-any.whl.

File metadata

  • Download URL: factor_pricing_model_universe-2022.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.8

File hashes

Hashes for factor_pricing_model_universe-2022.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9dfb8537396134784af6fcb7e4c5b9dc37afc0dd3d4b816fc328dc23ffc8ce6a
MD5 c26194d8fa716fe39abc088cdf8aa2b5
BLAKE2b-256 1483054b4da7282aa1d62df756c99e431ac73eb46c54798fc859cea83dc749ab

See more details on using hashes here.

Supported by

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