hg-systematic 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
File without changes
@@ -0,0 +1,72 @@
1
+ import math
2
+ from datetime import timedelta, datetime
3
+ from zoneinfo import ZoneInfo
4
+
5
+ import numpy as np
6
+ from hg_oap.dates.dt_utils import date_tz_to_utc
7
+ from hgraph import generator, TS, EvaluationEngineApi, graph, lag, delayed_binding, feedback, compute_node, \
8
+ RECORDABLE_STATE, TimeSeriesSchema, STATE, SIGNAL
9
+
10
+ __all__ = ["white_noise_generator", "auto_regressive_generator"]
11
+
12
+ @compute_node
13
+ def white_noise_generator(
14
+ signal: SIGNAL,
15
+ loc: float = 0.0,
16
+ scale: float = 1.0,
17
+ size: int = 1000,
18
+ _state: STATE = None
19
+ ) -> TS[float]:
20
+ """
21
+ Generates a stream of white noise at each tick of the ``signal`` input.
22
+ The buffer will be initialised at start, and will be re-initialised if the number of ticks exceeds the buffer
23
+ ``size``.
24
+ The noise stream can now be generated based on any input signal, for example, a calendar ticking out business days.
25
+ """
26
+ out = _state.buffer[_state.ndx]
27
+ _state.ndx += 1
28
+ if size == _state.ndx:
29
+ _state.buffer = np.random.normal(loc, scale, size=size)
30
+ _state.ndx = 0
31
+ return out
32
+
33
+ @white_noise_generator.start
34
+ def white_noise_generator_start(
35
+ loc: float = 0.0,
36
+ scale: float = 1.0,
37
+ size: int = 1000,
38
+ _state: STATE = None
39
+ ):
40
+ _state.buffer = np.random.normal(loc, scale, size=size)
41
+ _state.ndx = 0
42
+
43
+
44
+
45
+ class ARState(TimeSeriesSchema):
46
+ previous_terms: TS[tuple[float,...]]
47
+
48
+ @compute_node(
49
+ requires=lambda m, s: len(s["initial_values"]) == (order:=s["order"]) and len(s["coefficients"]) == order+1
50
+ )
51
+ def auto_regressive_generator(
52
+ white_noise: TS[float],
53
+ order: int = 1,
54
+ initial_values: tuple[float, ...] = (1.0,),
55
+ coefficients: tuple[float, ...] = (1.0, 0.5),
56
+ _state: RECORDABLE_STATE[ARState] = None
57
+ ) -> TS[float]:
58
+ """
59
+ An autoregressive generator.
60
+ The order defines how many terms to use.
61
+ The size of the initial values is ``order`` and coefficients must be the size of ``order+1``.
62
+ """
63
+ result = white_noise.value + coefficients[0]
64
+ prev = _state.previous_terms.value
65
+ result += sum(coefficients[i+1] * prev[i] for i in range(order))
66
+ _state.previous_terms.apply_result((result,) + prev[1:])
67
+ return result
68
+
69
+ @auto_regressive_generator.start
70
+ def autoregressive_generator_start(initial_values: tuple[float, ...], _state: RECORDABLE_STATE[ARState] = None):
71
+ _state.previous_terms.apply_result(initial_values)
72
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Howard Henson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.1
2
+ Name: hg_systematic
3
+ Version: 0.0.1
4
+ Summary: A library and examples to show how HGraph can be used for systematic trading.
5
+ License: MIT
6
+ Keywords: reactive,graph,fpg,forward propogating graph,time series,functional reactive programming,frp,functional,time-series,systematic,trading,strategy
7
+ Author: Howard Henson
8
+ Author-email: howard@henson.me.uk
9
+ Requires-Python: >=3.12
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Requires-Dist: frozendict (>=2.3.10)
19
+ Requires-Dist: hg_oap (>=0.1.9)
20
+ Requires-Dist: hgraph (>=0.3.26)
21
+ Requires-Dist: matplotlib
22
+ Requires-Dist: numpy (>=1.23)
23
+ Requires-Dist: ordered-set (>=4.1.0)
24
+ Requires-Dist: polars (>=1.0)
25
+ Requires-Dist: sortedcontainers (>=2.4.0)
26
+ Requires-Dist: sphinx (>=7.4)
27
+ Requires-Dist: sphinx-autodoc-typehints (>=2.3.0)
28
+ Requires-Dist: sphinx_rtd_theme (>=2.0.0)
29
+ Requires-Dist: sphinxcontrib-plantuml (>=0.30)
30
+ Project-URL: Changelog, https://github.com/hhenson/hg_systematic/blob/main/CHANGELOG.md
31
+ Project-URL: Documentation, https://github.com/hhenson/hg_systematic/blob/main/README.md
32
+ Project-URL: Homepage, https://github.com/hhenson/hg_systematic
33
+ Project-URL: Issues, https://github.com/hhenson/hg_systematic/blob/main/ISSUES.md
34
+ Project-URL: Repository, https://github.com/hhenson/hg_systematic.git
35
+ Description-Content-Type: text/markdown
36
+
37
+ # HG Systematic
38
+
39
+ This is a library of utilities and examples to highlight how HGraph can be used to implement
40
+ systematic trading strategies.
41
+
42
+
43
+ See [this](https://hgraph.readthedocs.io/en/latest/) for more information.
44
+
45
+ ## Development
46
+
47
+ The project is currently configured to make use of [Poetry](https://python-poetry.org) for dependency management.
48
+ Take a look at the website to see how best to install the tool.
49
+
50
+ Here are some useful commands:
51
+
52
+ First, this will cause the virtual environment to be installed in the same folder as the project (in .venv folder)
53
+
54
+ ```bash
55
+ poetry config virtualenvs.in-project true
56
+ ```
57
+
58
+ Use this command to set the version of Python to make use of if you want a specific version of Python.
59
+
60
+ ```bash
61
+ poetry env use 3.12
62
+ ```
63
+
64
+ Then use the following command to install the project and its dependencies. Note that the ``--with docs`` installs
65
+ the dependencies to build the documentation set which is not required otherwise, also the ``--all-extras`` is only
66
+ required for the adaptors.
67
+
68
+ ```bash
69
+ poetry install --with docs --all-extras
70
+ ```
71
+
72
+ If you did not use the first command, you can find the location of the installation using:
73
+
74
+ ```bash
75
+ poetry env info
76
+ ```
77
+
78
+ PyCharm can make use of poetry to ``setup`` the project.
79
+
80
+ ### Run Tests
81
+
82
+ ```bash
83
+ # No Coverage
84
+ poetry run pytest
85
+ ```
86
+
87
+ ```bash
88
+ # Generate Coverage Report
89
+ poetry run pytest --cov=your_package_name --cov-report=xml
90
+ ```
91
+
@@ -0,0 +1,8 @@
1
+ hg_systematic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ hg_systematic/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ hg_systematic/data/generators.py,sha256=L8xpEfjbo1hUfQrwkbuYhDwDpBbe3gGL00SkHIzazkY,2448
4
+ hg_systematic-0.0.1.dist-info/LICENSE,sha256=XknxcS0Tg4ZyGciZAoM3SXoMnAyPZC00HclKokINUNk,1070
5
+ hg_systematic-0.0.1.dist-info/METADATA,sha256=U3YbjBOKWL95QwILfthpfAThdxkx7AKQNMDCZBMzOsI,3078
6
+ hg_systematic-0.0.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
7
+ hg_systematic-0.0.1.dist-info/entry_points.txt,sha256=8N5SofWe8lQrhmJFPd5add1Efz_jF_JoqB1zcR9z8XM,52
8
+ hg_systematic-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ build-docs=sphinx.cmd.build:main
3
+