Skip to main content

factor-score

Quantitative factor scoring for equities and ETFs.

from factor_score import FactorEngine

engine = FactorEngine()
scores = engine.score(["DIS", "NVDA", "MSFT", "META"])
for s in scores:
    print(f"{s.ticker:6}  composite={s.composite_score:.2f}  rank=#{s.composite_rank}")

Install

pip install factor-score           # core (bring your own data)
pip install 'factor-score[yfinance]'  # with built-in yfinance provider

Design

  • Input-agnostic: implement the two-method DataProvider protocol to plug in any data source (yfinance, Polygon, IBKR, CSV).
  • Code-driven config: use FactorConfig to override weights and lookback periods — no YAML required.
  • Normalized scores: composite scores are 0–1 within the scored universe; raw factor values are always returned alongside.

Factors

Factor Weight Description
Vol-adjusted momentum 35% 90d return / annualized vol — rewards smooth trends
Momentum (90d) 25% Trailing 90-day return
Momentum (180d) 25% Trailing 180-day return
Relative value 15% Proximity to 52-week low (mean-reversion tilt)

Custom config

from factor_score import FactorEngine, FactorConfig

config = FactorConfig(
    weight_vol_adj_momentum=0.50,
    weight_momentum_short=0.25,
    weight_momentum_long=0.15,
    weight_relative_value=0.10,
    momentum_short_days=60,
)
engine = FactorEngine(config=config)

Custom data provider

import pandas as pd
from factor_score import FactorEngine

class MyProvider:
    def get_history(self, ticker: str, period: str = "1y") -> pd.DataFrame:
        # return a DataFrame with a "Close" column
        ...

engine = FactorEngine(provider=MyProvider())

Contributing

Local development setup

Prerequisites: Python 3.11 or 3.12, and pip.

  1. Clone the repo and create a virtual environment:
git clone https://github.com/brainscanstudios/factor-score.git
cd factor-score
python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
  1. Install the package in editable mode with dev dependencies:
pip install -e '.[dev]'

This installs pytest, pytest-cov, and the yfinance provider so the full test suite can run.

Running tests

pytest

To see coverage:

pytest --cov=factor_score

Project layout

factor_score/      # library source
  engine.py        # FactorEngine — main entry point
  models.py        # FactorConfig, FactorScore dataclasses
  factors/         # individual factor implementations
  providers/       # DataProvider implementations (yfinance, …)
tests/             # pytest suite

Adding a factor

  1. Implement the scoring logic in factor_score/factors/.
  2. Add a weight field to FactorConfig in models.py (default to 0.0 so existing configs stay valid).
  3. Wire it into FactorEngine.score() in engine.py.
  4. Add tests in tests/.

Adding a data provider

Implement the two-method DataProvider protocol (see factor_score/providers/) and pass an instance to FactorEngine(provider=...). No base class required — duck typing is sufficient.

License

MIT

Metadata

Release files for factor-score 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for factor-score 0.2.0
File Size Uploaded Provenance Actions
factor_score-0.2.0.tar.gz 10.1 kB With provenance Details for factor_score-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for factor-score 0.2.0
File Interpreter ABI Platform Actions
factor_score-0.2.0-py3-none-any.whl Python 3 none any Details for factor_score-0.2.0-py3-none-any.whl

Total release size: 20.7 kB

Release files / factor_score-0.2.0.tar.gz

Download URL factor_score-0.2.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c5209aec6748ba077e730bbe4639de3fa28e2d38befbabc5e4b843cb39e96f6e
BLAKE2b-256 checksum
How to use checksums
4ee767369dcf092270e238728446cf1126038ae9f3086eef985d2991b4174a1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 26, 2026.

Transparency log

Release files / factor_score-0.2.0-py3-none-any.whl

Download URL factor_score-0.2.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af8492352942e3c6d3f9de6cc2febe1022857565b288c5098026cc9dc69a8cd6
BLAKE2b-256 checksum
How to use checksums
2c3b39f70d25652dafd70eb45e20466ef1c3e75cc960a8020cb7e3c052ce304d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 26, 2026.

Transparency log

Security for factor-score 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for factor_score-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page