aiden-shared-calculations-unified 1.0.83 → 1.0.86
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.
- package/calculations/core/asset-pnl-status.js +122 -104
- package/calculations/core/asset-position-size.js +110 -73
- package/calculations/core/average-daily-pnl-all-users.js +17 -3
- package/calculations/core/average-daily-pnl-per-sector.js +83 -75
- package/calculations/core/average-daily-pnl-per-stock.js +84 -73
- package/calculations/core/average-daily-position-pnl.js +2 -2
- package/calculations/core/holding-duration-per-asset.js +24 -23
- package/calculations/core/instrument-price-change-1d.js +72 -82
- package/calculations/core/instrument-price-momentum-20d.js +66 -100
- package/calculations/core/long-position-per-stock.js +21 -13
- package/calculations/core/overall-holding-duration.js +8 -3
- package/calculations/core/overall-profitability-ratio.js +2 -2
- package/calculations/core/platform-buy-sell-sentiment.js +75 -22
- package/calculations/core/platform-daily-bought-vs-sold-count.js +19 -10
- package/calculations/core/platform-daily-ownership-delta.js +39 -15
- package/calculations/core/platform-ownership-per-sector.js +38 -18
- package/calculations/core/platform-total-positions-held.js +36 -14
- package/calculations/core/pnl-distribution-per-stock.js +39 -36
- package/calculations/core/price-metrics.js +70 -172
- package/calculations/core/profitability-ratio-per-sector.js +23 -29
- package/calculations/core/profitability-ratio-per-stock.js +20 -13
- package/calculations/core/profitability-skew-per-stock.js +20 -13
- package/calculations/core/profitable-and-unprofitable-status.js +34 -10
- package/calculations/core/sentiment-per-stock.js +20 -9
- package/calculations/core/short-position-per-stock.js +23 -37
- package/calculations/core/social-activity-aggregation.js +41 -115
- package/calculations/core/social-asset-posts-trend.js +77 -94
- package/calculations/core/social-event-correlation.js +87 -106
- package/calculations/core/social-sentiment-aggregation.js +56 -138
- package/calculations/core/social-top-mentioned-words.js +74 -106
- package/calculations/core/social-topic-interest-evolution.js +94 -94
- package/calculations/core/social-topic-sentiment-matrix.js +90 -74
- package/calculations/core/social-word-mentions-trend.js +92 -106
- package/calculations/core/speculator-asset-sentiment.js +63 -92
- package/calculations/core/speculator-danger-zone.js +77 -90
- package/calculations/core/speculator-distance-to-stop-loss-per-leverage.js +75 -90
- package/calculations/core/speculator-distance-to-tp-per-leverage.js +75 -88
- package/calculations/core/speculator-entry-distance-to-sl-per-leverage.js +75 -90
- package/calculations/core/speculator-entry-distance-to-tp-per-leverage.js +74 -89
- package/calculations/core/speculator-leverage-per-asset.js +62 -57
- package/calculations/core/speculator-leverage-per-sector.js +53 -65
- package/calculations/core/speculator-risk-reward-ratio-per-asset.js +71 -76
- package/calculations/core/speculator-stop-loss-distance-by-sector-short-long-breakdown.js +60 -81
- package/calculations/core/speculator-stop-loss-distance-by-ticker-short-long-breakdown.js +57 -77
- package/calculations/core/speculator-stop-loss-per-asset.js +43 -80
- package/calculations/core/speculator-take-profit-per-asset.js +45 -69
- package/calculations/core/speculator-tsl-per-asset.js +42 -49
- package/calculations/core/total-long-figures.js +19 -19
- package/calculations/core/total-long-per-sector.js +39 -36
- package/calculations/core/total-short-figures.js +19 -19
- package/calculations/core/total-short-per-sector.js +39 -36
- package/calculations/core/users-processed.js +52 -25
- package/calculations/gauss/cohort-capital-flow.js +38 -29
- package/calculations/gauss/cohort-definer.js +17 -25
- package/calculations/gauss/daily-dna-filter.js +10 -4
- package/calculations/gauss/gauss-divergence-signal.js +28 -6
- package/calculations/gem/cohort-momentum-state.js +113 -92
- package/calculations/gem/cohort-skill-definition.js +23 -53
- package/calculations/gem/platform-conviction-divergence.js +62 -116
- package/calculations/gem/quant-skill-alpha-signal.js +107 -123
- package/calculations/gem/skilled-cohort-flow.js +178 -167
- package/calculations/gem/skilled-unskilled-divergence.js +73 -113
- package/calculations/gem/unskilled-cohort-flow.js +176 -166
- package/calculations/helix/helix-contrarian-signal.js +91 -83
- package/calculations/helix/herd-consensus-score.js +135 -97
- package/calculations/helix/winner-loser-flow.js +14 -16
- package/calculations/pyro/risk-appetite-index.js +121 -123
- package/calculations/pyro/squeeze-potential.js +93 -125
- package/calculations/pyro/volatility-signal.js +109 -97
- package/package.json +5 -5
- package/README.MD +0 -155
package/README.MD
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
|
|
3
|
-
# Quantum Test Harness for Computation System
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The Quantum Test Harness is a **dynamic, dependency-aware testing framework** for running, validating, and profiling the entire computation system.
|
|
8
|
-
|
|
9
|
-
The new architecture is built around a `run-suite.js` orchestrator. It automatically builds a dependency graph of all calculations, ensuring they are tested in the correct order. This "ground-up" approach allows for robust, efficient, and realistic testing that mimics the production environment.
|
|
10
|
-
|
|
11
|
-
The harness still tests calculations **without modifying their source code**. It:
|
|
12
|
-
|
|
13
|
-
* Builds a dependency graph of all calculations.
|
|
14
|
-
* Dynamically generates mock data for a consistent "universe" of users and tickers.
|
|
15
|
-
* Executes calculations in the correct order, passing the results of one test as dependencies to the next.
|
|
16
|
-
* Monitors performance and validates output against each calculation's `getSchema()`.
|
|
17
|
-
* Generates rich, interactive HTML reports for each calculation run.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## Core Concepts
|
|
22
|
-
|
|
23
|
-
The harness is built on **four main components**:
|
|
24
|
-
|
|
25
|
-
### 1. Test Suite Orchestrator (`run-suite.js`)
|
|
26
|
-
|
|
27
|
-
The main CLI entry point for running automated test suites. Responsibilities:
|
|
28
|
-
|
|
29
|
-
* Scans all calculation files and builds a computation graph.
|
|
30
|
-
* Topologically sorts the graph to determine the correct execution order.
|
|
31
|
-
* Parses CLI commands (`--all`, `--target`, `--product`) to decide which tests to run.
|
|
32
|
-
* Manages a results cache to efficiently pass outputs as dependencies.
|
|
33
|
-
|
|
34
|
-
### 2. Test Worker (`test-worker.js`)
|
|
35
|
-
|
|
36
|
-
Executes the test for a single calculation. Responsibilities:
|
|
37
|
-
|
|
38
|
-
* Receives a calculation to test from the orchestrator, along with its pre-computed dependencies.
|
|
39
|
-
* Generates fresh, temporal mock data for the specific test.
|
|
40
|
-
* Instantiates the calculation and wraps it in the Quantum Monitor.
|
|
41
|
-
* Executes `process()` and `getResult()`.
|
|
42
|
-
* Triggers the report generation.
|
|
43
|
-
|
|
44
|
-
### 3. Dynamic Data Generation (`data-generator.js`)
|
|
45
|
-
|
|
46
|
-
Generates **temporal mock data**:
|
|
47
|
-
|
|
48
|
-
1. The orchestrator creates a consistent "universe" (tickers and userIds) for the entire test run.
|
|
49
|
-
2. The test worker generates "today" and optional "yesterday" data snapshots using this universe, ensuring data is consistent and comparable across tests.
|
|
50
|
-
|
|
51
|
-
### 4. Instrumentation & Validation (`test-harness.js`)
|
|
52
|
-
|
|
53
|
-
Provides:
|
|
54
|
-
|
|
55
|
-
* **Instrumentation**: Wraps the calculation instance in a Proxy via `createQuantumRecorder`. Logs performance, memory, and errors without changing the calculation logic.
|
|
56
|
-
* **Validation**:
|
|
57
|
-
* **Schema Check**: Uses Ajv to validate `getResult()` against `getSchema()`.
|
|
58
|
-
* **Sanity Check**: Flags "valid but empty" results like `0`, `null`, `[]`, or `{}` as warnings.
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## Usage: Automated Test Suite
|
|
63
|
-
|
|
64
|
-
To run automated, dependency-aware test suites, use the `run-suite.js` orchestrator. This is the recommended method for all testing.
|
|
65
|
-
|
|
66
|
-
### Prerequisites
|
|
67
|
-
|
|
68
|
-
Graphviz is required to render data-flow diagrams. Ensure `dot` is available in your PATH.
|
|
69
|
-
|
|
70
|
-
| OS | Installation |
|
|
71
|
-
| ------- | ------------------------------- |
|
|
72
|
-
| macOS | `brew install graphviz` |
|
|
73
|
-
| Windows | `choco install graphviz` |
|
|
74
|
-
| Linux | `sudo apt-get install graphviz` |
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
### Commands
|
|
79
|
-
|
|
80
|
-
#### 1. Run ALL Computations
|
|
81
|
-
|
|
82
|
-
Tests every non-legacy computation, ordered by complexity (dependency-free calculations first).
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
node run-suite.js --all
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
#### 2. Run a Specific Target
|
|
89
|
-
|
|
90
|
-
Tests a single computation and all of its dependencies in the correct order.
|
|
91
|
-
|
|
92
|
-
```bash
|
|
93
|
-
# Syntax
|
|
94
|
-
node run-suite.js --target [computation-name]
|
|
95
|
-
|
|
96
|
-
# Example (note: uses the name, not the file path)
|
|
97
|
-
node run-suite.js --target asset-pnl-status
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
#### 3. Run a Full Product Line
|
|
101
|
-
|
|
102
|
-
Tests all computations belonging to a specific product category (defined in `getMetadata`) and all of their dependencies.
|
|
103
|
-
|
|
104
|
-
```bash
|
|
105
|
-
# Syntax
|
|
106
|
-
node run-suite.js --product [product-name]
|
|
107
|
-
|
|
108
|
-
# Example
|
|
109
|
-
node run-suite.js --product gem
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
### Output
|
|
115
|
-
|
|
116
|
-
Running a test produces:
|
|
117
|
-
|
|
118
|
-
* **Console Output**: Live logs of the orchestration and test progress.
|
|
119
|
-
* **Test Reports**: Generated for each executed calculation at `test_reports/[CalculationName]/`:
|
|
120
|
-
* `timeline.html` – Interactive performance report.
|
|
121
|
-
* `dataflow.svg` – Diagram of the calculation's data flow.
|
|
122
|
-
* `computation_result.json` – Raw JSON output from `getResult()`.
|
|
123
|
-
* `report.json` – Full metrics collected by the harness.
|
|
124
|
-
|
|
125
|
-
---
|
|
126
|
-
|
|
127
|
-
## Adding a New Calculation
|
|
128
|
-
|
|
129
|
-
The process remains the same.
|
|
130
|
-
|
|
131
|
-
1. **Create Your File**: `calculations/my_product/my-new-calc.js`
|
|
132
|
-
2. **Implement the Class**: Must include `constructor()`, `process()`, and `getResult()`.
|
|
133
|
-
3. **Add `getDependencies()`**: Define the other calculations this one depends on.
|
|
134
|
-
4. **Add `getMetadata()`**: Defines the contract for the harness.
|
|
135
|
-
5. **Add `getSchema()`**: Enables automatic output validation.
|
|
136
|
-
6. **Run the Test**: Use the `run-suite.js` commands.
|
|
137
|
-
|
|
138
|
-
```bash
|
|
139
|
-
# Test your new calculation and its dependencies
|
|
140
|
-
node run-suite.js --target my-new-calc
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
## Troubleshooting
|
|
146
|
-
|
|
147
|
-
| Issue | Solution |
|
|
148
|
-
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
149
|
-
| Graphviz rendering failed | Ensure Graphviz is installed and `dot` is in your system's PATH. |
|
|
150
|
-
| `SchemaValidation` errors in `report.json` | The calculation's output does not match its `getSchema()`. Check `computation_result.json` to see the actual output and fix the logic. |
|
|
151
|
-
| `SanityCheck` warnings in `report.json` | The output is valid according to the schema but is empty (`null`, `0`, `[]`, `{}`). This may be expected, but it's worth verifying. |
|
|
152
|
-
| `Error: Unknown computation dependency: [name]` | A calculation lists a dependency in `getDependencies()` that doesn't exist or has a typo. Check the name for errors. |
|
|
153
|
-
| `Error: Circular dependency detected!` | Two or more calculations depend on each other, creating an impossible loop. Review the `getDependencies()` lists for the involved calculations. |
|
|
154
|
-
|
|
155
|
-
---
|