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.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: 80.8 MB
Release files / pydecisiongraph-0.3.2.post2-cp315-cp315t-win_amd64.whl
| Download URL | pydecisiongraph-0.3.2.post2-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 |
a61323b886cc3e8e5238439a286a2036d0137f6c607d83ab23c39f6742a580c3
|
|
BLAKE2b-256 checksum How to use checksums |
75ae7caaa308c0bb4e343e9b151ca2ab6c743bf4721ca33660885a2f8c24ae96
|
| 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.post2-cp315-cp315t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.2.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 |
b92754ed2088156edae60342554f3168bcc400bc72b0cb38de55968272fe49da
|
|
BLAKE2b-256 checksum How to use checksums |
9c5393d4783ed24a0c62e3a09d01f633e05238dcf03c59d5d9b65b162d9d0191
|
| 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.post2-cp315-cp315-win_amd64.whl
| Download URL | pydecisiongraph-0.3.2.post2-cp315-cp315-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.15 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
68298ed9dd58881cccb7e4c264881cfac707621a8f60837662375094b755ef3d
|
|
BLAKE2b-256 checksum How to use checksums |
9f738feeb286416db7ebbcb96843c1f49e9e8b96efcf5b44a8c3dfeb4bdc10b3
|
| 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.post2-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.2.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 |
7845e4fde1e251e938c4922c23a50bcfa140582ab47ff7235329ad7f96a52f85
|
|
BLAKE2b-256 checksum How to use checksums |
00abeb0595fecc2c3d515ffad0aaee1624eb516cdcba0f0225d14198fd0edb3e
|
| 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.post2-cp314-cp314t-win_amd64.whl
| Download URL | pydecisiongraph-0.3.2.post2-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 |
24c182f677bc5ac864e222a19c91709a69286a84aa9664be4fd0f5bd54e75387
|
|
BLAKE2b-256 checksum How to use checksums |
45b7a462eb78992ad131306a039ca00fef1b7b74efd83c218d0350d228e59e46
|
| 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.post2-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.2.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 |
d538b97255b6f4def1cbdca428c6899cda12e0c43ff8b760ea5da9254f3faadb
|
|
BLAKE2b-256 checksum How to use checksums |
bdd00356cc1188cbba0dd158763d02484be0e028cb3130a7596d7a9dc7df927b
|
| 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.post2-cp314-cp314-win_amd64.whl
| Download URL | pydecisiongraph-0.3.2.post2-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
74ee5ec950ede27ab6057aa3bc4b795f0d1d09786dd9d428e0c2ce9bdc316725
|
|
BLAKE2b-256 checksum How to use checksums |
fa95243f71968f0fe24d7421dd70f927987cead98974d811ab4f56aef20f0a8a
|
| 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.post2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.2.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 |
e8a32db97e1638b52846bb000e872f520d50580af8f6c708e43bedd23d2b9b5d
|
|
BLAKE2b-256 checksum How to use checksums |
4b8f82756252b261590df264aa973a80773eedc12ef33d88b3a38d56e99b6f99
|
| 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.post2-cp313-cp313-win_amd64.whl
| Download URL | pydecisiongraph-0.3.2.post2-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
4d6c65b9544ca88f55a466bfc26817a485ec3f40dafb3a3fdb92e26fa2151865
|
|
BLAKE2b-256 checksum How to use checksums |
972b9930697337414a3e4aa6e87e13b8780269ae87391f826d76fed63ca0c07f
|
| 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.post2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.2.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 |
872697fd7b9ffaba530dae1b70d63f98aa44ea5e553b48e11dbd8c7df45c10d0
|
|
BLAKE2b-256 checksum How to use checksums |
99e76630adbad53c57e81ba9b92a8439420cc5fe7f02e197bc8c4de39f89b45b
|
| 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.post2-cp312-cp312-win_amd64.whl
| Download URL | pydecisiongraph-0.3.2.post2-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d50816ff92a59d710b0a7534b376617815c3086163e957cba4511a2ea25d79db
|
|
BLAKE2b-256 checksum How to use checksums |
6a1e9f3c802a9d83d2689d5ceb13d6983e6e1900d687891392b076400976044e
|
| 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.post2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pydecisiongraph-0.3.2.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 |
262843ef4563f1b9e3cc33228979437c1ba38097f03a6a408605e2429d6cbb45
|
|
BLAKE2b-256 checksum How to use checksums |
16b9f6ca7d588bd10884f0b58385acdea770e03e43d3bbe7ba11d152539b60c6
|
| 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.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.