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
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.1.post2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 69.4 MB
Release files / pydecisiongraph-0.3.1.post2-cp315-cp315t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.1.post2-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 |
dfb7207d7b3789d7070267cdda1c0d59c1bf54d367eaf1a7a60090d5a4814c81
|
|
BLAKE2b-256 checksum How to use checksums |
3f5c599a0aeaa7407e6d2290a6e23be48afa6caa060815f202194d74a1bceb7c
|
| 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.1.post2-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.1.post2-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 |
1e989f51d5694d21f2660222d8d61707ce26f708754db1664dcefe610694f602
|
|
BLAKE2b-256 checksum How to use checksums |
153416db55d9ee2e180cdbbdf4202938fbbef76fa99b7d09b26a8d15138c8e65
|
| 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.1.post2-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.1.post2-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 |
e07abb6a369f1d792316fd86f87035bd887f4f81ce3ec8d765c5560bcc13fcbb
|
|
BLAKE2b-256 checksum How to use checksums |
0f233beef74cfb7e508b0831ddce0c0954654872f519e8805fd8827540883e06
|
| 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.1.post2-cp314-cp314-win_amd64.whl
| Download URL | pydecisiongraph-0.3.1.post2-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6df2b2b0fcb6767de98c16c928870dd371c627da6b3375d59321b06c9cee3bae
|
|
BLAKE2b-256 checksum How to use checksums |
19b4522ab5adb49cd38025c23f7bc87d3a2d936c003f050283834e3597eddae8
|
| 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.1.post2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.1.post2-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 |
871096b844db7c0de4b7ee3729b9420ad5add308b93ce2a4b54c0ba5f4bd9827
|
|
BLAKE2b-256 checksum How to use checksums |
b474e1b612edce2ee95af7415257506e129c37f8b4ee656342eb1f698350ab03
|
| 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.1.post2-cp313-cp313-win_amd64.whl
| Download URL | pydecisiongraph-0.3.1.post2-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
bad9368bafb6d82da614c97bbb3b1b45f03215068094ae19f147cd9824855f02
|
|
BLAKE2b-256 checksum How to use checksums |
0abaf1fc48a213657b48ba00088b2d2e9be92b72e4937ef83c246158713b66e3
|
| 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.1.post2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.1.post2-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 |
5b9491c0489c9e2b70ce72ca9063be3655ac2644651ad22876e8953326465f57
|
|
BLAKE2b-256 checksum How to use checksums |
16717a3f36a617c7b7914637b1f3d63f578b87ca658a52da1e43f617977c736c
|
| 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.1.post2-cp312-cp312-win_amd64.whl
| Download URL | pydecisiongraph-0.3.1.post2-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
20e1e8815c9e1ffe109418d10362c9d6110eabfb04c447779273cf4cd9455eec
|
|
BLAKE2b-256 checksum How to use checksums |
5f835efe86a55e6aaa8d8beb52fe3c7aa64d199e0d9e520ca3832930760dfbb4
|
| 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.1.post2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.1.post2-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 |
7f9b907674a1188a70641fe73c57e1ca98c5839e2ce47f3ef125d1bc76185478
|
|
BLAKE2b-256 checksum How to use checksums |
79e95198dc0887415c28e95c2a24cb48a79f79151e3f7aaf755bbcc340847072
|
| 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.1.post2
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.