mylittleindicators 0.1.8

Multi-stream financial indicators library — 556 bar indicators + 21 event primitives across 35 categories. Consumes 27 stream kinds from digdigdig3 exchange connectors: OHLCV bars, ticks, orderbook (snapshot/delta/L3), funding/predicted funding/funding settlement, mark price, index price, open interest, liquidations, ticker, agg trades, long/short ratio, option greeks, volatility index, historical volatility, basis (derived), composite index, settlement events, block trades, insurance fund, risk limit, market warning, and three kline-family variants. Live-verified on 12 exchanges (89% pass-rate on a 150s BTC slice).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
//! entropy_catalog.rs: Auto-generated indicator catalog for entropy indicators
//!
//! Generated for Universal Indicator System
//! Contains IndicatorSignature definitions for all 13 entropy indicators

use crate::catalog::{
    IndicatorSignature, IndicatorCategory, ParamConstraint, ParamType, ParamValue,
    IndicatorRoleKind,
};
use crate::bar_indicators::indicator_value::IndicatorValueKind;
use super::super::bar_indicator_id::BarIndicatorId;

use once_cell::sync::Lazy;
use std::collections::HashMap;

/// Category for all indicators in this module
pub const CATEGORY: IndicatorCategory = IndicatorCategory::Entropy;

// ============================================================================
// Individual indicator signatures
// ============================================================================

/// Approximate Entropy
pub fn signature_approximate_entropy() -> IndicatorSignature {
    IndicatorSignature::builder("APEN", CATEGORY)
        .name("Approximate Entropy")
        .description("Measures regularity and predictability in price patterns")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("pattern_length", ParamType::USize)
                .with_min(ParamValue::USize(1))
                .with_max(ParamValue::USize(5))
                .with_default(ParamValue::USize(2))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("tolerance", ParamType::F64)
                .with_min(ParamValue::F64(0.01))
                .with_max(ParamValue::F64(1.0))
                .with_default(ParamValue::F64(0.15))
                .required()
        )
        .metadata("range", "0.0-2.0+")
        .metadata("interpretation", "0.0 = maximally regular, higher = less regular")
        .machine_id(BarIndicatorId::Apen)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "APEN" is already the main ID, no need for alias
        .alias("Apen")
        .alias("apen")
        .alias("APPROXIMATEENTROPY")
        .alias("ApproximateEntropy")
        .alias("approximateentropy")
        .alias("approximate_entropy")
        .alias("APPROXIMATE_ENTROPY")
        .alias("Approximate_Entropy")
        .build()
}

/// Conditional Entropy
pub fn signature_conditional_entropy() -> IndicatorSignature {
    IndicatorSignature::builder("CONDEN", CATEGORY)
        .name("Conditional Entropy")
        .description("Measures conditional uncertainty in price movements")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(5))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(10))
                .required()
        )
        .machine_id(BarIndicatorId::Conden)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "CONDEN" is already the main ID, no need for alias
        .alias("Conden")
        .alias("conden")
        .alias("CONDITIONALENTROPY")
        .alias("ConditionalEntropy")
        .alias("conditionalentropy")
        .alias("conditional_entropy")
        .alias("CONDITIONAL_ENTROPY")
        .alias("Conditional_Entropy")
        .build()
}

/// Cross Mutual Information with Lags
pub fn signature_cross_mutual_information_lags() -> IndicatorSignature {
    IndicatorSignature::builder("XMIL", CATEGORY)
        .name("Cross Mutual Information with Lags")
        .description("Measures mutual information between price and lagged values")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("lag", ParamType::USize)
                .with_min(ParamValue::USize(1))
                .with_max(ParamValue::USize(20))
                .with_default(ParamValue::USize(5))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(5))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(10))
                .required()
        )
        .machine_id(BarIndicatorId::Xmil)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "XMIL" is already the main ID, no need for alias
        .alias("Xmil")
        .alias("xmil")
        .alias("CROSSMUTUALINFORMATIONWITHLAGS")
        .alias("CrossMutualInformationwithLags")
        .alias("crossmutualinformationwithlags")
        .alias("cross_mutual_information_with_lags")
        .alias("CROSS_MUTUAL_INFORMATION_WITH_LAGS")
        .alias("Cross_Mutual_Information_With_Lags")
        .build()
}

/// Fisher Information
pub fn signature_fisher_information() -> IndicatorSignature {
    IndicatorSignature::builder("FISHER", CATEGORY)
        .name("Fisher Information")
        .description("Measures information content and parameter sensitivity")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(5))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(10))
                .required()
        )
        .machine_id(BarIndicatorId::Fisher)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "FISHER" is already the main ID, no need for alias
        .alias("Fisher")
        .alias("fisher")
        .alias("FISHERINFORMATION")
        .alias("FisherInformation")
        .alias("fisherinformation")
        .alias("fisher_information")
        .alias("FISHER_INFORMATION")
        .alias("Fisher_Information")
        .build()
}

/// Information Gain
pub fn signature_information_gain() -> IndicatorSignature {
    IndicatorSignature::builder("INFOG", CATEGORY)
        .name("Information Gain")
        .description("Measures reduction in uncertainty from price information")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(5))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(10))
                .required()
        )
        .machine_id(BarIndicatorId::Infog)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "INFOG" is already the main ID, no need for alias
        .alias("Infog")
        .alias("infog")
        .alias("INFORMATIONGAIN")
        .alias("InformationGain")
        .alias("informationgain")
        .alias("information_gain")
        .alias("INFORMATION_GAIN")
        .alias("Information_Gain")
        .build()
}

/// Jensen-Shannon Divergence
pub fn signature_js_divergence() -> IndicatorSignature {
    IndicatorSignature::builder("JSD", CATEGORY)
        .name("Jensen-Shannon Divergence")
        .description("Symmetric measure of distribution difference between periods")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(8))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(10))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("clip_abs", ParamType::F64)
                .with_min(ParamValue::F64(0.001))
                .with_max(ParamValue::F64(1.0))
                .with_default(ParamValue::F64(0.1))
                .required()
        )
        .metadata("range", "0.0-1.0")
        .metadata("interpretation", "0.0 = identical distributions, 1.0 = maximally different")
        .machine_id(BarIndicatorId::Jsd)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        .output_bounds(0.0, 1.0)
        // Note: "JSD" is already the main ID, no need for alias
        .alias("Jsd")
        .alias("jsd")
        .alias("JENSENSHANNONDIVERGENCE")
        .alias("JensenShannonDivergence")
        .alias("jensenshannondivergence")
        .alias("jensen_shannon_divergence")
        .alias("JENSEN_SHANNON_DIVERGENCE")
        .alias("Jensen_Shannon_Divergence")
        .build()
}

/// Kullback-Leibler Divergence
pub fn signature_kl_divergence() -> IndicatorSignature {
    IndicatorSignature::builder("KLD", CATEGORY)
        .name("Kullback-Leibler Divergence")
        .description("Measures distribution difference between adjacent windows")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(8))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(10))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("clip_abs", ParamType::F64)
                .with_min(ParamValue::F64(0.001))
                .with_max(ParamValue::F64(1.0))
                .with_default(ParamValue::F64(0.1))
                .required()
        )
        .metadata("range", "0.0+")
        .metadata("interpretation", "0.0 = identical distributions, higher = more different")
        .machine_id(BarIndicatorId::Kld)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "KLD" is already the main ID, no need for alias
        .alias("Kld")
        .alias("kld")
        .alias("KULLBACKLEIBLERDIVERGENCE")
        .alias("KullbackLeiblerDivergence")
        .alias("kullbackleiblerdivergence")
        .alias("kullback_leibler_divergence")
        .alias("KULLBACK_LEIBLER_DIVERGENCE")
        .alias("Kullback_Leibler_Divergence")
        .build()
}

/// Mutual Information
pub fn signature_mutual_information() -> IndicatorSignature {
    IndicatorSignature::builder("MI", CATEGORY)
        .name("Mutual Information")
        .description("Measures mutual dependence between current and lagged returns")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("lag", ParamType::USize)
                .with_min(ParamValue::USize(1))
                .with_max(ParamValue::USize(20))
                .with_default(ParamValue::USize(1))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(5))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(10))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("clip_abs", ParamType::F64)
                .with_min(ParamValue::F64(0.001))
                .with_max(ParamValue::F64(1.0))
                .with_default(ParamValue::F64(0.1))
                .required()
        )
        .metadata("range", "0.0+")
        .metadata("complexity", "O(1) with rolling histogram")
        .machine_id(BarIndicatorId::Mi)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "MI" is already the main ID, no need for alias
        .alias("Mi")
        .alias("mi")
        .alias("MUTUALINFORMATION")
        .alias("MutualInformation")
        .alias("mutualinformation")
        .alias("mutual_information")
        .alias("MUTUAL_INFORMATION")
        .alias("Mutual_Information")
        .build()
}

/// Permutation Entropy
pub fn signature_permutation_entropy() -> IndicatorSignature {
    IndicatorSignature::builder("PE", CATEGORY)
        .name("Permutation Entropy")
        .description("Measures diversity of ordinal patterns in time series")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("order", ParamType::USize)
                .with_min(ParamValue::USize(3))
                .with_max(ParamValue::USize(7))
                .with_default(ParamValue::USize(3))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("delay", ParamType::USize)
                .with_min(ParamValue::USize(1))
                .with_max(ParamValue::USize(5))
                .with_default(ParamValue::USize(1))
                .required()
        )
        .metadata("range", "0.0-1.0 (normalized)")
        .metadata("interpretation", "0.0 = one pattern, 1.0 = all patterns equally probable")
        .machine_id(BarIndicatorId::Pe)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        .output_bounds(0.0, 1.0)
        // Note: "PE" is already the main ID, no need for alias
        .alias("Pe")
        .alias("pe")
        .alias("PERMUTATIONENTROPY")
        .alias("PermutationEntropy")
        .alias("permutationentropy")
        .alias("permutation_entropy")
        .alias("PERMUTATION_ENTROPY")
        .alias("Permutation_Entropy")
        .build()
}

/// Sample Entropy
pub fn signature_sample_entropy() -> IndicatorSignature {
    IndicatorSignature::builder("SAMPEN", CATEGORY)
        .name("Sample Entropy")
        .description("Improved ApEn without self-matches, measures time series complexity")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("pattern_length", ParamType::USize)
                .with_min(ParamValue::USize(1))
                .with_max(ParamValue::USize(5))
                .with_default(ParamValue::USize(2))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("tolerance", ParamType::F64)
                .with_min(ParamValue::F64(0.01))
                .with_max(ParamValue::F64(1.0))
                .with_default(ParamValue::F64(0.15))
                .required()
        )
        .metadata("range", "0.0-3.0+")
        .metadata("interpretation", "0.0 = maximally predictable, higher = more complex")
        .machine_id(BarIndicatorId::Sampen)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "SAMPEN" is already the main ID, no need for alias
        .alias("Sampen")
        .alias("sampen")
        .alias("SAMPLEENTROPY")
        .alias("SampleEntropy")
        .alias("sampleentropy")
        .alias("sample_entropy")
        .alias("SAMPLE_ENTROPY")
        .alias("Sample_Entropy")
        .build()
}

/// Shannon Entropy
pub fn signature_shannon_entropy() -> IndicatorSignature {
    IndicatorSignature::builder("SHANNON", CATEGORY)
        .name("Shannon Entropy")
        .description("Measures market unpredictability and randomness")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(5))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(20))
                .required()
        )
        .metadata("range", "0.0-1.0 (normalized)")
        .metadata("interpretation", "0.0 = fully predictable, 1.0 = maximally random")
        .machine_id(BarIndicatorId::Shannon)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        .output_bounds(0.0, 1.0)
        // Note: "SHANNON" is already the main ID, no need for alias
        .alias("Shannon")
        .alias("shannon")
        .alias("SHANNONENTROPY")
        .alias("ShannonEntropy")
        .alias("shannonentropy")
        .alias("shannon_entropy")
        .alias("SHANNON_ENTROPY")
        .alias("Shannon_Entropy")
        .build()
}

/// Transfer Entropy
pub fn signature_transfer_entropy() -> IndicatorSignature {
    IndicatorSignature::builder("TE", CATEGORY)
        .name("Transfer Entropy")
        .description("Measures directional information transfer between time series")
        .add_constraint(ParamConstraint::period(10, 200, 20))
        .add_constraint(
            ParamConstraint::new("lag", ParamType::USize)
                .with_min(ParamValue::USize(1))
                .with_max(ParamValue::USize(20))
                .with_default(ParamValue::USize(1))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("bins", ParamType::USize)
                .with_min(ParamValue::USize(5))
                .with_max(ParamValue::USize(50))
                .with_default(ParamValue::USize(10))
                .required()
        )
        .add_constraint(
            ParamConstraint::new("clip_abs", ParamType::F64)
                .with_min(ParamValue::F64(0.001))
                .with_max(ParamValue::F64(1.0))
                .with_default(ParamValue::F64(0.1))
                .required()
        )
        .metadata("range", "0.0+")
        .metadata("interpretation", "Higher values indicate stronger directional causality")
        .machine_id(BarIndicatorId::Te)
        .role_kind(IndicatorRoleKind::Statistical)
        .output_kind(IndicatorValueKind::Single)
        // Note: "TE" is already the main ID, no need for alias
        .alias("Te")
        .alias("te")
        .alias("TRANSFERENTROPY")
        .alias("TransferEntropy")
        .alias("transferentropy")
        .alias("transfer_entropy")
        .alias("TRANSFER_ENTROPY")
        .alias("Transfer_Entropy")
        .build()
}

// ============================================================================
// Catalog HashMap
// ============================================================================

/// Static catalog of all entropy indicators
/// Base catalog with main IDs only (used for initialization)
const BASE_CATALOG: &[(&str, fn() -> IndicatorSignature)] = &[
    ("APEN", signature_approximate_entropy as fn() -> IndicatorSignature),
    ("CONDEN", signature_conditional_entropy as fn() -> IndicatorSignature),
    ("XMIL", signature_cross_mutual_information_lags as fn() -> IndicatorSignature),
    ("FISHER", signature_fisher_information as fn() -> IndicatorSignature),
    ("INFOG", signature_information_gain as fn() -> IndicatorSignature),
    ("JSD", signature_js_divergence as fn() -> IndicatorSignature),
    ("KLD", signature_kl_divergence as fn() -> IndicatorSignature),
    ("MI", signature_mutual_information as fn() -> IndicatorSignature),
    ("PE", signature_permutation_entropy as fn() -> IndicatorSignature),
    ("SAMPEN", signature_sample_entropy as fn() -> IndicatorSignature),
    ("SHANNON", signature_shannon_entropy as fn() -> IndicatorSignature),
    ("TE", signature_transfer_entropy as fn() -> IndicatorSignature),
];

/// Expanded catalog with all aliases auto-generated from signatures
/// This allows O(1) lookup by any alias without manual maintenance
pub static ENTROPY_CATALOG: Lazy<HashMap<String, fn() -> IndicatorSignature>> = Lazy::new(|| {
    let mut m = HashMap::new();

    for &(main_id, func) in BASE_CATALOG {
        // Call function once to get signature with aliases
        let sig = func();

        // Insert main ID
        m.insert(main_id.to_string(), func);

        // Auto-insert all aliases from signature
        for alias in &sig.aliases {
            m.insert(alias.clone(), func);
        }
    }

    m
});

// ============================================================================
// Public API
// ============================================================================

/// Get indicator signature by ID
pub fn get_signature(id: &str) -> Option<IndicatorSignature> {
    ENTROPY_CATALOG.get(id).map(|f| f())
}

/// Get all indicator IDs in this category
pub fn all_indicator_ids() -> Vec<&'static str> {
    BASE_CATALOG.iter().map(|(id, _)| *id).collect()
}

/// Get count of indicators
pub fn count() -> usize {
    BASE_CATALOG.len()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_get_shannon_signature() {
        let sig = get_signature("SHANNON").unwrap();
        assert_eq!(sig.id, "SHANNON");
        assert_eq!(sig.category, CATEGORY);
    }

    #[test]
    fn test_all_signatures_valid() {
        for id in all_indicator_ids() {
            let sig = get_signature(id).unwrap();
            assert_eq!(sig.id, id);
            assert_eq!(sig.category, CATEGORY);
        }
    }

    #[test]
    fn test_count() {
        assert_eq!(count(), 12);
    }
}