Skip to main content

PyDecisionGraph

PyDecisionGraph is an easy-to-use library to create custom decision trees, primarily designed for trading and financial decision-making. This package helps you build rule-based decision processes and visualize them effectively.

Installation

To install the package, run:

pip install PyDecisionGraph

Cython headers

When Cython is installed in the same environment, the build links decision_graph into Cython/Includes through cbase.cython_injection, so downstream projects can cimport decision_graph.

Requirements

  • Python 3.12 or higher

Documentation

For detailed documentation, visit https://pydecisiongraph.readthedocs.io/.

Quick Start

Here is a quick demo on how to use PyDecisionGraph for building a decision tree based on various conditions:

from decision_graph.decision_tree import LOGGER, LongAction, ShortAction, NoAction, RootLogicNode, LogicMapping

# Mapping of attribute names to their values
state = {
    "exposure": 0,  # Current exposure
    "working_order": 0,  # Current working order
    "up_prob": 0.8,  # Probability of price going up
    "down_prob": 0.2,  # Probability of price going down
    "volatility": 0.26,  # Current market volatility
    "ttl": 15.3  # Time to live (TTL) of the decision tree
}

# The store the conditions read from, entered for the scope the tree is built in
with LogicMapping(name='Root', data=state) as lg:
    # Root of the logic tree
    with RootLogicNode() as root:
        # Condition for zero exposure
        with lg.exposure == 0:
            with lg.volatility > 0.25:  # Check if volatility is high
                with lg.down_prob > 0.1:  # Action for down probability
                    LongAction()

                with lg.up_prob < -0.1:  # Action for up probability
                    ShortAction()

            # No action if there's a working order
            with lg.working_order != 0:
                NoAction()

# Visualize the decision tree
root.to_html('tree.html')

# Log the evaluation result
LOGGER.info(root())

Explanation of the Script:

  • LogicNode & LogicMapping:

    • LogicNode: Represents a node in the decision tree where conditions are evaluated. A node evaluates its condition and takes one of its two arms.
    • LogicMapping: The named store the conditions read from, holding the state used in decision-making. Feed it a new value and the next walk moves.
  • State:

    • A dictionary containing the variables used for decision-making, such as exposure, working_order, up_prob, etc.
  • RootLogicNode:

    • The entry point for the decision tree; its single child is the top of the tree.
  • Decision Conditions:

    • Inside each with block, logical conditions are evaluated (e.g., lg.volatility > 0.25, lg.up_prob < -0.1) to determine which action to take.
    • Each with block nests one level deeper; the first block under a node is its true arm, the second its false arm.
    • Actions like LongAction() or ShortAction() are taken based on the conditions.
  • Action Handling:

    • LongAction(), ShortAction(), and NoAction() represent different actions you can trigger in the decision tree based on the conditions.
    • An arm left empty is filled with a NoAction when the tree is evaluated.
  • Logging:

    • The result of the tree evaluation is logged using the LOGGER object, which outputs to the console.
  • Visualization:

    • root.to_html('tree.html') generates a standalone HTML page visualizing the decision tree. Drop the file name and the page is named after the root.

Features

  • Easily define custom decision rules.
  • Actionable outcomes like LongAction, ShortAction, and NoAction.
  • Log outputs for debugging and tracking.
  • Visualize decision paths through HTML export.
  • Bake a finished tree once (root.bake()) and let it decide in a hot loop.

Contributing

Feel free to fork, submit issues, and create pull requests. Contributions are always welcome!

License

This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.

Metadata

Release files for PyDecisionGraph 0.3.2.post1

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

Built distributions (wheels)

Table of built distributions (wheels) for PyDecisionGraph 0.3.2.post1
File
pydecisiongraph-0.3.2.post1-cp315-cp315t-win_amd64.whl CPython 3.15 CPython 3.15 free-threading Windows x86-64 Details
pydecisiongraph-0.3.2.post1-cp315-cp315t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
pydecisiongraph-0.3.2.post1-cp315-cp315-win_amd64.whl CPython 3.15 CPython 3.15 Windows x86-64 Details
pydecisiongraph-0.3.2.post1-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
pydecisiongraph-0.3.2.post1-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
pydecisiongraph-0.3.2.post1-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
pydecisiongraph-0.3.2.post1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pydecisiongraph-0.3.2.post1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
pydecisiongraph-0.3.2.post1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pydecisiongraph-0.3.2.post1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
pydecisiongraph-0.3.2.post1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pydecisiongraph-0.3.2.post1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details

Total release size: 80.8 MB

Release files / pydecisiongraph-0.3.2.post1-cp315-cp315t-win_amd64.whl

Download URL pydecisiongraph-0.3.2.post1-cp315-cp315t-win_amd64.whl
Size 3.9 MB
Tags CPython 3.15 CPython 3.15 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
f259686b81ade7c04440aaad55a581e2e6464c1d8c93c46f07625a0c1ab905cc
BLAKE2b-256 checksum
How to use checksums
5a61323407b49db9c74e1e6122ca15566cfbe4beaec2964da2de564a780b3cbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / pydecisiongraph-0.3.2.post1-cp315-cp315t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pydecisiongraph-0.3.2.post1-cp315-cp315t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.8 MB
Tags CPython 3.15 CPython 3.15 free-threading Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
adee9e2bb9d0af364c18c9468e2a93434919b7a13dd32078624df5016d7fbab3
BLAKE2b-256 checksum
How to use checksums
ef8bf9f7d0128196df1dbb8647b075fa19a57ac78bf057ccbf96cfbfd9094e65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / pydecisiongraph-0.3.2.post1-cp315-cp315-win_amd64.whl

Download URL pydecisiongraph-0.3.2.post1-cp315-cp315-win_amd64.whl
Size 3.7 MB
Tags CPython 3.15 Windows x86-64
SHA-256 checksum
How to use checksums
a3ba4eb24a78a350bb2258dc600a8f4c99662eb8724250c3b4a138baa627a381
BLAKE2b-256 checksum
How to use checksums
12822b30b77cf9cd523846852e6b4724a9e4b1e6daad067404d7682106689358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / pydecisiongraph-0.3.2.post1-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pydecisiongraph-0.3.2.post1-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.7 MB
Tags CPython 3.15 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
472add4842a131d7d6c7995e4241594c7f08e3eb1a2d05611e5b9e76162ade4c
BLAKE2b-256 checksum
How to use checksums
c1b23b898def11db02ca18cf5a6e05dd51140283d1d8ebe8ff2d12d5f1312bb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / pydecisiongraph-0.3.2.post1-cp314-cp314t-win_amd64.whl

Download URL pydecisiongraph-0.3.2.post1-cp314-cp314t-win_amd64.whl
Size 3.9 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
7ae953a209972bc878dc4fb2adb5d452eee6f475304ef823fdf593d5b236d38b
BLAKE2b-256 checksum
How to use checksums
4eaf38f69b51cabcd89c836c7596c54b56e60d0d0f8cdd6155da11b49a6a46eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / pydecisiongraph-0.3.2.post1-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pydecisiongraph-0.3.2.post1-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.8 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
608784e5aae8fc40418be73d1c44528a92fe9403826877653bbb9a679f9b2f96
BLAKE2b-256 checksum
How to use checksums
ca61621c3191915875a346855a1c15f096f2960b8e07bc98701866368d5440c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / pydecisiongraph-0.3.2.post1-cp314-cp314-win_amd64.whl

Download URL pydecisiongraph-0.3.2.post1-cp314-cp314-win_amd64.whl
Size 3.7 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
25828c01312c5bfc0c02d85d3ab09063c21d388ec52499cbc2c0ebd80c90c41b
BLAKE2b-256 checksum
How to use checksums
89cb82218b155dfa038986a86ee8741e90b9823092ef07a8abd975d2b063eaf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / pydecisiongraph-0.3.2.post1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pydecisiongraph-0.3.2.post1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.6 MB
Tags CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
3f7052d4d25cc9412d492103383cda872a637f5cc5414684d8b5379c18c1547a
BLAKE2b-256 checksum
How to use checksums
a1d15c1c11fe7c7de71ef5c845060cc8b612819d007ace64ce3834c8c1e32166
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / pydecisiongraph-0.3.2.post1-cp313-cp313-win_amd64.whl

Download URL pydecisiongraph-0.3.2.post1-cp313-cp313-win_amd64.whl
Size 3.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
96742d5c064dbab416c041884afa3dc2467b8b1c82bfe0c5277449fcdafcb98f
BLAKE2b-256 checksum
How to use checksums
4bc3910b9a6758c89d8794e748169fff7b9cebad7ecfe43f8ddbfd1e73d7c1d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / pydecisiongraph-0.3.2.post1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pydecisiongraph-0.3.2.post1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.7 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
380dd9e76c2917b04237f3eadec56ad7320a659e49d1c1f7b46447869138ba28
BLAKE2b-256 checksum
How to use checksums
17048d0107f2f84cba5044975cf67f896c9c6e453c8c1f576fe5e9c4b35fffcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / pydecisiongraph-0.3.2.post1-cp312-cp312-win_amd64.whl

Download URL pydecisiongraph-0.3.2.post1-cp312-cp312-win_amd64.whl
Size 3.7 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
90b3c91321dbce9442ba2c5740f5950f2ad1e346bbbcce1dc6f7241ae3576a34
BLAKE2b-256 checksum
How to use checksums
fda5d1f50ad51b5bedb4b06706c393bf47004fed9539f771f3f62f6b94e1899c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / pydecisiongraph-0.3.2.post1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pydecisiongraph-0.3.2.post1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.7 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
5ea32881b38a6185cad7f21946b94e5e6e9d335b9fdbb659171f080d93fb0f0b
BLAKE2b-256 checksum
How to use checksums
a208fc168716753730bc5e81cb44f444a245e2a76d124d923e35739e9394fed1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for PyDecisionGraph 0.3.2.post1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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