quantlab-factor-agent 0.1.0__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.
- factor_agent/KUNQUANT_LICENSE +201 -0
- factor_agent/__init__.py +8 -0
- factor_agent/_acceptance_model.py +93 -0
- factor_agent/_admission.py +168 -0
- factor_agent/_expression_fold.py +48 -0
- factor_agent/_feedback.py +399 -0
- factor_agent/_max_drawdown.py +51 -0
- factor_agent/_model_cache.py +100 -0
- factor_agent/_scheduler.py +35 -0
- factor_agent/acceptance.py +808 -0
- factor_agent/accepted/__init__.py +1 -0
- factor_agent/aggregations.py +122 -0
- factor_agent/campaign.py +797 -0
- factor_agent/candidate.py +51 -0
- factor_agent/config.py +651 -0
- factor_agent/derived.py +98 -0
- factor_agent/evaluator.py +1096 -0
- factor_agent/events.py +343 -0
- factor_agent/exported.py +177 -0
- factor_agent/gate/__init__.py +359 -0
- factor_agent/gate/_canonical.py +331 -0
- factor_agent/gate/_checks.py +85 -0
- factor_agent/gate/_constraints.py +85 -0
- factor_agent/gate/_dimension.py +177 -0
- factor_agent/gate/_originality.py +146 -0
- factor_agent/gate/_sandbox.py +105 -0
- factor_agent/gate/graph.py +223 -0
- factor_agent/gate/stages.py +383 -0
- factor_agent/gate/vocabulary.py +1097 -0
- factor_agent/ledger.py +85 -0
- factor_agent/llm/__init__.py +0 -0
- factor_agent/llm/_common.py +18 -0
- factor_agent/llm/_raw.py +78 -0
- factor_agent/llm/anthropic.py +100 -0
- factor_agent/llm/base.py +124 -0
- factor_agent/llm/claude_code.py +101 -0
- factor_agent/llm/log.py +74 -0
- factor_agent/llm/openai_compatible.py +113 -0
- factor_agent/llm/replay.py +59 -0
- factor_agent/llm/scripted.py +39 -0
- factor_agent/period_lag.py +91 -0
- factor_agent/prompts.py +557 -0
- factor_agent/researcher.py +615 -0
- factor_agent/scoring.py +143 -0
- factor_agent/segments.py +184 -0
- factor_agent/session.py +500 -0
- factor_agent/snapshot.py +219 -0
- factor_agent/web/__init__.py +7 -0
- factor_agent/web/_acceptance.py +145 -0
- factor_agent/web/_config.py +51 -0
- factor_agent/web/_diagnosis.py +110 -0
- factor_agent/web/_files.py +78 -0
- factor_agent/web/_health.py +207 -0
- factor_agent/web/_ic.py +27 -0
- factor_agent/web/_ledger.py +293 -0
- factor_agent/web/_memory.py +42 -0
- factor_agent/web/_results.py +77 -0
- factor_agent/web/_round.py +219 -0
- factor_agent/web/_trials.py +112 -0
- factor_agent/web/app.py +118 -0
- factor_agent/web/run_view.py +329 -0
- factor_agent/web/static/assets/index-9QjjJgl3.css +1 -0
- factor_agent/web/static/assets/index-iOE9ei_S.js +74 -0
- factor_agent/web/static/index.html +13 -0
- factor_agent/zoo.py +136 -0
- quantlab_factor_agent-0.1.0.dist-info/METADATA +172 -0
- quantlab_factor_agent-0.1.0.dist-info/RECORD +72 -0
- quantlab_factor_agent-0.1.0.dist-info/WHEEL +5 -0
- quantlab_factor_agent-0.1.0.dist-info/entry_points.txt +2 -0
- quantlab_factor_agent-0.1.0.dist-info/licenses/LICENSE +21 -0
- quantlab_factor_agent-0.1.0.dist-info/licenses/factor_agent/KUNQUANT_LICENSE +201 -0
- quantlab_factor_agent-0.1.0.dist-info/top_level.txt +1 -0
factor_agent/derived.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Derived columns: columns a daily factor's graph reads that its dataset does not hold.
|
|
2
|
+
|
|
3
|
+
A ``DerivedColumnsFactor`` is a KunQuant factor on the daily dataset whose
|
|
4
|
+
graph may read derived columns, filled before the graph runs by its
|
|
5
|
+
providers (``Provider``): period lags (``factor_agent.period_lag``), from
|
|
6
|
+
the daily panel. Each provider says which columns it fills, the dataset
|
|
7
|
+
columns it reads and the warm-up it needs, and fills the arrays; the factor
|
|
8
|
+
reads the longest warm-up any of them needs.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from collections.abc import Iterable, Sequence
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
import xarray as xr
|
|
15
|
+
from quantlab.dataset.base import BaseDataset
|
|
16
|
+
from quantlab.factor.kunquant import FactorKunQuant
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Provider:
|
|
20
|
+
"""Fills derived columns of a ``DerivedColumnsFactor``.
|
|
21
|
+
|
|
22
|
+
``columns`` are the derived columns it fills; ``data_columns`` the
|
|
23
|
+
dataset columns it reads, ``panel_columns`` those of them it reads from
|
|
24
|
+
the panel only, never handed to the graph as arrays (a date key);
|
|
25
|
+
``warmup_bars`` the bars before the first computed bar it reads.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
#: The derived columns the provider fills.
|
|
29
|
+
columns: tuple[str, ...] = ()
|
|
30
|
+
#: The dataset columns it reads.
|
|
31
|
+
data_columns: tuple[str, ...] = ()
|
|
32
|
+
#: The dataset columns it reads from the panel only.
|
|
33
|
+
panel_columns: tuple[str, ...] = ()
|
|
34
|
+
#: The bars before the first computed bar it reads.
|
|
35
|
+
warmup_bars: int = 0
|
|
36
|
+
|
|
37
|
+
def fill(
|
|
38
|
+
self, dataset: BaseDataset, panel: xr.Dataset, arrays: dict[str, np.ndarray],
|
|
39
|
+
symbols: np.ndarray, timestamps: np.ndarray,
|
|
40
|
+
) -> dict[str, np.ndarray]:
|
|
41
|
+
"""The arrays of ``columns``, on the axes of ``arrays`` (``timestamps`` by ``symbols``).
|
|
42
|
+
|
|
43
|
+
``panel`` is the dataset's panel under its shared names
|
|
44
|
+
(``to_shared_names``), warm-up included; ``arrays`` its columns as the
|
|
45
|
+
graph reads them.
|
|
46
|
+
"""
|
|
47
|
+
raise NotImplementedError
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def data_columns(inputs: Iterable[str], providers: Iterable[Provider]) -> tuple[str, ...]:
|
|
51
|
+
"""The dataset columns to read for graph ``inputs``: each derived column becomes its provider's, sorted."""
|
|
52
|
+
inputs, providers = set(inputs), list(providers)
|
|
53
|
+
columns = inputs.difference(*(provider.columns for provider in providers))
|
|
54
|
+
for provider in providers:
|
|
55
|
+
if inputs.intersection(provider.columns):
|
|
56
|
+
columns |= set(provider.data_columns)
|
|
57
|
+
return tuple(sorted(columns))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class DerivedColumnsFactor(FactorKunQuant):
|
|
61
|
+
"""A KunQuant factor whose graph may read derived columns; see the module docstring.
|
|
62
|
+
|
|
63
|
+
A subclass says which providers fill the derived columns its graph reads
|
|
64
|
+
(``_providers``) and holds their dataset columns in ``config.data_columns``
|
|
65
|
+
(``data_columns``). The factor reads at least the warm-up its providers need.
|
|
66
|
+
A graph reading derived columns only (session columns, say) reads one
|
|
67
|
+
column of the dataset still, for the panel's dates and symbols.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
def _providers(self) -> Sequence[Provider]:
|
|
71
|
+
"""The providers of the derived columns the graph reads; none by default."""
|
|
72
|
+
return ()
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def warmup_bars(self) -> int:
|
|
76
|
+
"""``config.warmup_bars``, or the longest warm-up a provider needs when that is longer."""
|
|
77
|
+
return max([self.config.warmup_bars, *(provider.warmup_bars for provider in self._providers())])
|
|
78
|
+
|
|
79
|
+
def _input_variables(self) -> list[str]:
|
|
80
|
+
read = super()._input_variables()
|
|
81
|
+
if read:
|
|
82
|
+
return read
|
|
83
|
+
names = [n for n in self.config.dataset.head(0).collect_schema().names() if n not in ("timestamp", "symbol")]
|
|
84
|
+
return self.config.dataset.own_names(names[:1])
|
|
85
|
+
|
|
86
|
+
def _kunquant_inputs(self, inputs: xr.Dataset) -> tuple[dict[str, np.ndarray], np.ndarray, np.ndarray]:
|
|
87
|
+
providers = self._providers()
|
|
88
|
+
if not providers:
|
|
89
|
+
return super()._kunquant_inputs(inputs)
|
|
90
|
+
hidden = {column for provider in providers for column in provider.panel_columns}
|
|
91
|
+
values = tuple(c for c in self.config.data_columns if c not in hidden)
|
|
92
|
+
dataset = self.config.dataset
|
|
93
|
+
arrays, symbols, timestamps = dataset.to_kunquant(data_columns=values, panel=inputs)
|
|
94
|
+
panel = dataset.to_shared_names(inputs)
|
|
95
|
+
filled = {}
|
|
96
|
+
for provider in providers:
|
|
97
|
+
filled |= provider.fill(dataset, panel, arrays, symbols, timestamps)
|
|
98
|
+
return {**arrays, **filled}, symbols, timestamps
|