hedgequantx 2.9.206 → 2.9.208
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/package.json +1 -1
- package/src/lib/smart-logs-engine.js +78 -55
package/package.json
CHANGED
|
@@ -38,6 +38,11 @@ class SmartLogsEngine {
|
|
|
38
38
|
this.counter = 0;
|
|
39
39
|
this.lastState = null;
|
|
40
40
|
this.lastLogTime = 0;
|
|
41
|
+
// QUANT-specific state tracking for event detection
|
|
42
|
+
this.lastZRegime = null; // 'extreme' | 'high' | 'building' | 'neutral'
|
|
43
|
+
this.lastBias = null; // 'bullish' | 'bearish' | 'neutral'
|
|
44
|
+
this.lastVpinToxic = false; // true if VPIN > 0.6
|
|
45
|
+
this.warmupLogged = false; // Track if we logged warmup milestones
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
setSymbol(s) { this.symbolCode = s; }
|
|
@@ -169,74 +174,87 @@ class SmartLogsEngine {
|
|
|
169
174
|
const events = this._detectEvents(state, this.lastState);
|
|
170
175
|
this.lastState = { ...state };
|
|
171
176
|
|
|
172
|
-
// For QUANT strategy:
|
|
173
|
-
//
|
|
177
|
+
// For QUANT strategy: EVENT-DRIVEN logs based on regime changes
|
|
178
|
+
// Uses the same smart-logs system as HQX-2B for consistency
|
|
174
179
|
if (this.strategyId === 'ultra-scalping') {
|
|
175
|
-
const
|
|
176
|
-
const
|
|
180
|
+
const ticks = state.tickCount || state.bars || 0;
|
|
181
|
+
const absZ = Math.abs(zScore);
|
|
182
|
+
const vpinToxic = vpin > 0.6;
|
|
177
183
|
|
|
178
|
-
//
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
//
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const d = {
|
|
205
|
-
sym, price,
|
|
206
|
-
zScore: zScore.toFixed(1),
|
|
207
|
-
zScoreAbs,
|
|
208
|
-
rawZScore: zScore,
|
|
209
|
-
vpin: vpinPct,
|
|
210
|
-
ofi: ofiPct,
|
|
211
|
-
ticks
|
|
184
|
+
// Determine current regimes
|
|
185
|
+
const zRegime = absZ >= 2.0 ? 'extreme' : absZ >= 1.5 ? 'high' : absZ >= 1.0 ? 'building' : 'neutral';
|
|
186
|
+
const bias = ofi > 0.15 ? 'bullish' : ofi < -0.15 ? 'bearish' : 'neutral';
|
|
187
|
+
|
|
188
|
+
let event = null;
|
|
189
|
+
let logType = 'analysis';
|
|
190
|
+
let message = null;
|
|
191
|
+
|
|
192
|
+
// EVENT 1: Warmup complete (only log once at 250 ticks)
|
|
193
|
+
if (ticks >= 250 && !this.warmupLogged) {
|
|
194
|
+
this.warmupLogged = true;
|
|
195
|
+
event = 'warmup_complete';
|
|
196
|
+
message = `[${sym}] QUANT models ready | ${ticks} ticks processed`;
|
|
197
|
+
logType = 'system';
|
|
198
|
+
}
|
|
199
|
+
// EVENT 2: Z-Score regime change (significant threshold crossing)
|
|
200
|
+
else if (this.lastZRegime !== null && zRegime !== this.lastZRegime) {
|
|
201
|
+
event = 'z_regime_change';
|
|
202
|
+
// Use smartLogs.getLiveAnalysisLog for varied contextual messages
|
|
203
|
+
const liveState = {
|
|
204
|
+
trend: bias,
|
|
205
|
+
bars: ticks,
|
|
206
|
+
swings: absZ >= 1.0 ? 1 : 0,
|
|
207
|
+
zones: absZ >= 1.5 ? 1 : 0,
|
|
208
|
+
nearZone: absZ >= 1.5,
|
|
209
|
+
setupForming: absZ >= 2.0,
|
|
212
210
|
};
|
|
211
|
+
const baseMsg = smartLogs.getLiveAnalysisLog(liveState);
|
|
213
212
|
|
|
214
|
-
|
|
215
|
-
let message;
|
|
216
|
-
|
|
217
|
-
if (absZ >= 2.0) {
|
|
218
|
-
// Strong signal zone - use bull/bear messages
|
|
213
|
+
if (zRegime === 'extreme') {
|
|
219
214
|
logType = 'signal';
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
215
|
+
const dir = zScore < 0 ? 'LONG' : 'SHORT';
|
|
216
|
+
message = `[${sym}] ${price} | Z: ${zScore.toFixed(1)}σ | ${dir} edge | ${baseMsg}`;
|
|
217
|
+
} else if (zRegime === 'high') {
|
|
223
218
|
logType = 'signal';
|
|
224
|
-
message =
|
|
225
|
-
} else if (
|
|
226
|
-
|
|
227
|
-
message = QUANT.zones(d);
|
|
219
|
+
message = `[${sym}] ${price} | Z: ${zScore.toFixed(1)}σ | ${baseMsg}`;
|
|
220
|
+
} else if (zRegime === 'building') {
|
|
221
|
+
message = `[${sym}] ${price} | Z building (${zScore.toFixed(1)}σ) | ${baseMsg}`;
|
|
228
222
|
} else {
|
|
229
|
-
|
|
230
|
-
message = QUANT.neutral(d);
|
|
223
|
+
message = `[${sym}] ${price} | Z normalized | ${baseMsg}`;
|
|
231
224
|
}
|
|
232
|
-
|
|
225
|
+
}
|
|
226
|
+
// EVENT 3: Bias flip (bullish ↔ bearish) - significant directional change
|
|
227
|
+
else if (this.lastBias !== null && bias !== this.lastBias && bias !== 'neutral' && this.lastBias !== 'neutral') {
|
|
228
|
+
event = 'bias_flip';
|
|
229
|
+
const arrow = bias === 'bullish' ? chalk.green('▲') : chalk.red('▼');
|
|
230
|
+
message = `[${sym}] ${arrow} Flow flip: ${this.lastBias} → ${bias} | OFI: ${(ofi * 100).toFixed(0)}%`;
|
|
231
|
+
}
|
|
232
|
+
// EVENT 4: VPIN toxicity threshold crossing
|
|
233
|
+
else if (this.lastVpinToxic !== null && vpinToxic !== this.lastVpinToxic) {
|
|
234
|
+
event = 'vpin_change';
|
|
235
|
+
if (vpinToxic) {
|
|
236
|
+
message = `[${sym}] ${price} | VPIN elevated (${(vpin * 100).toFixed(0)}%) - informed flow`;
|
|
237
|
+
logType = 'risk';
|
|
238
|
+
} else {
|
|
239
|
+
message = `[${sym}] ${price} | VPIN normalized (${(vpin * 100).toFixed(0)}%) - clean flow`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Update state tracking
|
|
244
|
+
this.lastZRegime = zRegime;
|
|
245
|
+
this.lastBias = bias;
|
|
246
|
+
this.lastVpinToxic = vpinToxic;
|
|
247
|
+
|
|
248
|
+
// Only return if we have an event
|
|
249
|
+
if (event && message) {
|
|
233
250
|
return {
|
|
234
251
|
type: logType,
|
|
235
252
|
message,
|
|
236
|
-
logToSession:
|
|
253
|
+
logToSession: event === 'z_regime_change' || event === 'bias_flip'
|
|
237
254
|
};
|
|
238
255
|
}
|
|
239
|
-
|
|
256
|
+
|
|
257
|
+
return null; // No event = silence
|
|
240
258
|
}
|
|
241
259
|
|
|
242
260
|
// HQX-2B strategy: event-based logging
|
|
@@ -257,6 +275,11 @@ class SmartLogsEngine {
|
|
|
257
275
|
this.lastState = null;
|
|
258
276
|
this.counter = 0;
|
|
259
277
|
this.lastLogTime = 0;
|
|
278
|
+
// Reset QUANT tracking
|
|
279
|
+
this.lastZRegime = null;
|
|
280
|
+
this.lastBias = null;
|
|
281
|
+
this.lastVpinToxic = false;
|
|
282
|
+
this.warmupLogged = false;
|
|
260
283
|
}
|
|
261
284
|
}
|
|
262
285
|
|