Skip to main content

Quantitative factor scoring for equities and ETFs

Project description

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

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_score-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

factor_score-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file factor_score-0.1.0.tar.gz.

File metadata

  • Download URL: factor_score-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for factor_score-0.1.0.tar.gz
Algorithm Hash digest
SHA256 57022204d261f610ae2d31490b0b4f229cd0bcb991c38bb9a087443c606df14d
MD5 9d8a671ddb916e0ab7c76c49acd0f289
BLAKE2b-256 e7003968e839e9472960d71a9e7c0720ec151d202d0f5b24526ffe50856bff7d

See more details on using hashes here.

File details

Details for the file factor_score-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: factor_score-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for factor_score-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aee41b28525b43b22a0bffab759afdba5a6b3b578a45888cb075c3023d3a87ed
MD5 27c73a5aaede04118c13d97940063467
BLAKE2b-256 442120d5df4720bbd44470dc2272896e53b8714c9aaf99ffc32a499bcfda9d65

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