brk_cohort 0.11.0

Cohort definitions used throughout BRK
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
use brk_traversable::Traversable;
use brk_types::Cents;
use rayon::prelude::*;
use serde::Serialize;

use super::CohortName;

/// Number of profitability range boundaries (24 boundaries → 25 buckets).
pub const PROFITABILITY_BOUNDARY_COUNT: usize = 24;

/// Compute 24 boundary prices from spot price for profitability bucketing.
///
/// Boundaries are returned in ascending price order (most profitable first → least profitable last).
/// Bucket assignment: prices ascending in k-way merge means we start at the most-profitable bucket
/// (lowest cost basis = highest profit) and advance the cursor as price crosses each boundary.
///
/// For P% profit: boundary = spot × 100 / (100 + P)
/// For L% loss:   boundary = spot × 100 / (100 - L)
///
/// Returns boundaries in ascending order:
/// [spot/11, spot/6, spot/4, spot/3, spot/2, spot×100/190, spot×100/180, ..., spot×100/10]
pub fn compute_profitability_boundaries(spot: Cents) -> [Cents; PROFITABILITY_BOUNDARY_COUNT] {
    let s = spot.as_u128();
    // Divisors in ascending boundary order (ascending price):
    // over_1000pct_in_profit: price < spot/11          → boundary at spot*100/1100 = spot/11
    // 500pct_to_1000pct_in_profit: spot/11 ≤ p < spot/6   → boundary at spot*100/600  = spot/6
    // 300pct_to_500pct_in_profit: spot/6 ≤ p < spot/4     → boundary at spot*100/400  = spot/4
    // 200pct_to_300pct_in_profit: spot/4 ≤ p < spot/3     → boundary at spot*100/300  = spot/3
    // 100pct_to_200pct_in_profit: spot/3 ≤ p < spot/2     → boundary at spot*100/200  = spot/2
    // 90pct_to_100pct_in_profit: spot/2 ≤ p < spot*100/190 → boundary at spot*100/190
    // 80pct_to_90pct_in_profit:                            → boundary at spot*100/180
    // 70pct_to_80pct_in_profit:                            → boundary at spot*100/170
    // 60pct_to_70pct_in_profit:                            → boundary at spot*100/160
    // 50pct_to_60pct_in_profit:                            → boundary at spot*100/150
    // 40pct_to_50pct_in_profit:                            → boundary at spot*100/140
    // 30pct_to_40pct_in_profit:                            → boundary at spot*100/130
    // 20pct_to_30pct_in_profit:                            → boundary at spot*100/120
    // 10pct_to_20pct_in_profit:                            → boundary at spot*100/110
    // 0pct_to_10pct_in_profit:                             → boundary at spot (= spot*100/100)
    // 0pct_to_10pct_in_loss: spot ≤ p < spot*100/90    → boundary at spot*100/90
    // 10pct_to_20pct_in_loss:                          → boundary at spot*100/80
    // 20pct_to_30pct_in_loss:                          → boundary at spot*100/70
    // 30pct_to_40pct_in_loss:                          → boundary at spot*100/60
    // 40pct_to_50pct_in_loss:                          → boundary at spot*100/50 = spot*2
    // 50pct_to_60pct_in_loss:                          → boundary at spot*100/40 = spot*5/2
    // 60pct_to_70pct_in_loss:                          → boundary at spot*100/30 = spot*10/3
    // 70pct_to_80pct_in_loss:                          → boundary at spot*100/20 = spot*5
    // 80pct_to_90pct_in_loss:                          → boundary at spot*100/10 = spot*10
    // 90pct_to_100pct_in_loss: spot*10 ≤ p              (no upper boundary)
    let divisors: [u128; PROFITABILITY_BOUNDARY_COUNT] = [
        1100, // >1000% profit upper bound (spot/11)
        600,  // 500-1000% profit upper bound (spot/6)
        400,  // 300-500% profit upper bound (spot/4)
        300,  // 200-300% profit upper bound (spot/3)
        200,  // 100-200% profit upper bound (spot/2)
        190,  // 90-100% profit upper bound
        180,  // 80-90% profit upper bound
        170,  // 70-80% profit upper bound
        160,  // 60-70% profit upper bound
        150,  // 50-60% profit upper bound
        140,  // 40-50% profit upper bound
        130,  // 30-40% profit upper bound
        120,  // 20-30% profit upper bound
        110,  // 10-20% profit upper bound
        100,  // 0-10% profit upper bound (= spot)
        90,   // 0-10% loss upper bound
        80,   // 10-20% loss upper bound
        70,   // 20-30% loss upper bound
        60,   // 30-40% loss upper bound
        50,   // 40-50% loss upper bound
        40,   // 50-60% loss upper bound
        30,   // 60-70% loss upper bound
        20,   // 70-80% loss upper bound
        10,   // 80-90% loss upper bound
    ];

    let mut boundaries = [Cents::ZERO; PROFITABILITY_BOUNDARY_COUNT];
    for (i, &d) in divisors.iter().enumerate() {
        boundaries[i] = Cents::from(s * 100 / d);
    }
    boundaries
}

/// Profitability range names (25 ranges, from most profitable to most in loss)
pub const PROFITABILITY_RANGE_NAMES: ProfitabilityRange<CohortName> = ProfitabilityRange {
    over_1000pct_in_profit: CohortName::new(
        "utxos_over_1000pct_in_profit",
        "+>1000%",
        "Over 1000% in Profit",
    ),
    _500pct_to_1000pct_in_profit: CohortName::new(
        "utxos_500pct_to_1000pct_in_profit",
        "+500-1000%",
        "500-1000% in Profit",
    ),
    _300pct_to_500pct_in_profit: CohortName::new(
        "utxos_300pct_to_500pct_in_profit",
        "+300-500%",
        "300-500% in Profit",
    ),
    _200pct_to_300pct_in_profit: CohortName::new(
        "utxos_200pct_to_300pct_in_profit",
        "+200-300%",
        "200-300% in Profit",
    ),
    _100pct_to_200pct_in_profit: CohortName::new(
        "utxos_100pct_to_200pct_in_profit",
        "+100-200%",
        "100-200% in Profit",
    ),
    _90pct_to_100pct_in_profit: CohortName::new(
        "utxos_90pct_to_100pct_in_profit",
        "+90-100%",
        "90-100% in Profit",
    ),
    _80pct_to_90pct_in_profit: CohortName::new(
        "utxos_80pct_to_90pct_in_profit",
        "+80-90%",
        "80-90% in Profit",
    ),
    _70pct_to_80pct_in_profit: CohortName::new(
        "utxos_70pct_to_80pct_in_profit",
        "+70-80%",
        "70-80% in Profit",
    ),
    _60pct_to_70pct_in_profit: CohortName::new(
        "utxos_60pct_to_70pct_in_profit",
        "+60-70%",
        "60-70% in Profit",
    ),
    _50pct_to_60pct_in_profit: CohortName::new(
        "utxos_50pct_to_60pct_in_profit",
        "+50-60%",
        "50-60% in Profit",
    ),
    _40pct_to_50pct_in_profit: CohortName::new(
        "utxos_40pct_to_50pct_in_profit",
        "+40-50%",
        "40-50% in Profit",
    ),
    _30pct_to_40pct_in_profit: CohortName::new(
        "utxos_30pct_to_40pct_in_profit",
        "+30-40%",
        "30-40% in Profit",
    ),
    _20pct_to_30pct_in_profit: CohortName::new(
        "utxos_20pct_to_30pct_in_profit",
        "+20-30%",
        "20-30% in Profit",
    ),
    _10pct_to_20pct_in_profit: CohortName::new(
        "utxos_10pct_to_20pct_in_profit",
        "+10-20%",
        "10-20% in Profit",
    ),
    _0pct_to_10pct_in_profit: CohortName::new(
        "utxos_0pct_to_10pct_in_profit",
        "+0-10%",
        "0-10% in Profit",
    ),
    _0pct_to_10pct_in_loss: CohortName::new(
        "utxos_0pct_to_10pct_in_loss",
        "-0-10%",
        "0-10% in Loss",
    ),
    _10pct_to_20pct_in_loss: CohortName::new(
        "utxos_10pct_to_20pct_in_loss",
        "-10-20%",
        "10-20% in Loss",
    ),
    _20pct_to_30pct_in_loss: CohortName::new(
        "utxos_20pct_to_30pct_in_loss",
        "-20-30%",
        "20-30% in Loss",
    ),
    _30pct_to_40pct_in_loss: CohortName::new(
        "utxos_30pct_to_40pct_in_loss",
        "-30-40%",
        "30-40% in Loss",
    ),
    _40pct_to_50pct_in_loss: CohortName::new(
        "utxos_40pct_to_50pct_in_loss",
        "-40-50%",
        "40-50% in Loss",
    ),
    _50pct_to_60pct_in_loss: CohortName::new(
        "utxos_50pct_to_60pct_in_loss",
        "-50-60%",
        "50-60% in Loss",
    ),
    _60pct_to_70pct_in_loss: CohortName::new(
        "utxos_60pct_to_70pct_in_loss",
        "-60-70%",
        "60-70% in Loss",
    ),
    _70pct_to_80pct_in_loss: CohortName::new(
        "utxos_70pct_to_80pct_in_loss",
        "-70-80%",
        "70-80% in Loss",
    ),
    _80pct_to_90pct_in_loss: CohortName::new(
        "utxos_80pct_to_90pct_in_loss",
        "-80-90%",
        "80-90% in Loss",
    ),
    _90pct_to_100pct_in_loss: CohortName::new(
        "utxos_90pct_to_100pct_in_loss",
        "-90-100%",
        "90-100% in Loss",
    ),
};

impl ProfitabilityRange<CohortName> {
    pub const fn names() -> &'static Self {
        &PROFITABILITY_RANGE_NAMES
    }
}

/// 25 profitability range buckets ordered from most profitable to most in loss.
///
/// During the k-way merge (ascending price order), the cursor starts at bucket 0
/// (over_1000pct_in_profit, lowest cost basis) and advances as price crosses each boundary.
#[derive(Default, Clone, Traversable, Serialize)]
pub struct ProfitabilityRange<T> {
    pub over_1000pct_in_profit: T,
    pub _500pct_to_1000pct_in_profit: T,
    pub _300pct_to_500pct_in_profit: T,
    pub _200pct_to_300pct_in_profit: T,
    pub _100pct_to_200pct_in_profit: T,
    pub _90pct_to_100pct_in_profit: T,
    pub _80pct_to_90pct_in_profit: T,
    pub _70pct_to_80pct_in_profit: T,
    pub _60pct_to_70pct_in_profit: T,
    pub _50pct_to_60pct_in_profit: T,
    pub _40pct_to_50pct_in_profit: T,
    pub _30pct_to_40pct_in_profit: T,
    pub _20pct_to_30pct_in_profit: T,
    pub _10pct_to_20pct_in_profit: T,
    pub _0pct_to_10pct_in_profit: T,
    pub _0pct_to_10pct_in_loss: T,
    pub _10pct_to_20pct_in_loss: T,
    pub _20pct_to_30pct_in_loss: T,
    pub _30pct_to_40pct_in_loss: T,
    pub _40pct_to_50pct_in_loss: T,
    pub _50pct_to_60pct_in_loss: T,
    pub _60pct_to_70pct_in_loss: T,
    pub _70pct_to_80pct_in_loss: T,
    pub _80pct_to_90pct_in_loss: T,
    pub _90pct_to_100pct_in_loss: T,
}

/// Number of profitability range buckets.
pub const PROFITABILITY_RANGE_COUNT: usize = 25;

impl<T> ProfitabilityRange<T> {
    pub fn new<F>(mut create: F) -> Self
    where
        F: FnMut(&'static str) -> T,
    {
        let n = &PROFITABILITY_RANGE_NAMES;
        Self {
            over_1000pct_in_profit: create(n.over_1000pct_in_profit.id),
            _500pct_to_1000pct_in_profit: create(n._500pct_to_1000pct_in_profit.id),
            _300pct_to_500pct_in_profit: create(n._300pct_to_500pct_in_profit.id),
            _200pct_to_300pct_in_profit: create(n._200pct_to_300pct_in_profit.id),
            _100pct_to_200pct_in_profit: create(n._100pct_to_200pct_in_profit.id),
            _90pct_to_100pct_in_profit: create(n._90pct_to_100pct_in_profit.id),
            _80pct_to_90pct_in_profit: create(n._80pct_to_90pct_in_profit.id),
            _70pct_to_80pct_in_profit: create(n._70pct_to_80pct_in_profit.id),
            _60pct_to_70pct_in_profit: create(n._60pct_to_70pct_in_profit.id),
            _50pct_to_60pct_in_profit: create(n._50pct_to_60pct_in_profit.id),
            _40pct_to_50pct_in_profit: create(n._40pct_to_50pct_in_profit.id),
            _30pct_to_40pct_in_profit: create(n._30pct_to_40pct_in_profit.id),
            _20pct_to_30pct_in_profit: create(n._20pct_to_30pct_in_profit.id),
            _10pct_to_20pct_in_profit: create(n._10pct_to_20pct_in_profit.id),
            _0pct_to_10pct_in_profit: create(n._0pct_to_10pct_in_profit.id),
            _0pct_to_10pct_in_loss: create(n._0pct_to_10pct_in_loss.id),
            _10pct_to_20pct_in_loss: create(n._10pct_to_20pct_in_loss.id),
            _20pct_to_30pct_in_loss: create(n._20pct_to_30pct_in_loss.id),
            _30pct_to_40pct_in_loss: create(n._30pct_to_40pct_in_loss.id),
            _40pct_to_50pct_in_loss: create(n._40pct_to_50pct_in_loss.id),
            _50pct_to_60pct_in_loss: create(n._50pct_to_60pct_in_loss.id),
            _60pct_to_70pct_in_loss: create(n._60pct_to_70pct_in_loss.id),
            _70pct_to_80pct_in_loss: create(n._70pct_to_80pct_in_loss.id),
            _80pct_to_90pct_in_loss: create(n._80pct_to_90pct_in_loss.id),
            _90pct_to_100pct_in_loss: create(n._90pct_to_100pct_in_loss.id),
        }
    }

    pub fn try_new<F, E>(mut create: F) -> Result<Self, E>
    where
        F: FnMut(&'static str) -> Result<T, E>,
    {
        let n = &PROFITABILITY_RANGE_NAMES;
        Ok(Self {
            over_1000pct_in_profit: create(n.over_1000pct_in_profit.id)?,
            _500pct_to_1000pct_in_profit: create(n._500pct_to_1000pct_in_profit.id)?,
            _300pct_to_500pct_in_profit: create(n._300pct_to_500pct_in_profit.id)?,
            _200pct_to_300pct_in_profit: create(n._200pct_to_300pct_in_profit.id)?,
            _100pct_to_200pct_in_profit: create(n._100pct_to_200pct_in_profit.id)?,
            _90pct_to_100pct_in_profit: create(n._90pct_to_100pct_in_profit.id)?,
            _80pct_to_90pct_in_profit: create(n._80pct_to_90pct_in_profit.id)?,
            _70pct_to_80pct_in_profit: create(n._70pct_to_80pct_in_profit.id)?,
            _60pct_to_70pct_in_profit: create(n._60pct_to_70pct_in_profit.id)?,
            _50pct_to_60pct_in_profit: create(n._50pct_to_60pct_in_profit.id)?,
            _40pct_to_50pct_in_profit: create(n._40pct_to_50pct_in_profit.id)?,
            _30pct_to_40pct_in_profit: create(n._30pct_to_40pct_in_profit.id)?,
            _20pct_to_30pct_in_profit: create(n._20pct_to_30pct_in_profit.id)?,
            _10pct_to_20pct_in_profit: create(n._10pct_to_20pct_in_profit.id)?,
            _0pct_to_10pct_in_profit: create(n._0pct_to_10pct_in_profit.id)?,
            _0pct_to_10pct_in_loss: create(n._0pct_to_10pct_in_loss.id)?,
            _10pct_to_20pct_in_loss: create(n._10pct_to_20pct_in_loss.id)?,
            _20pct_to_30pct_in_loss: create(n._20pct_to_30pct_in_loss.id)?,
            _30pct_to_40pct_in_loss: create(n._30pct_to_40pct_in_loss.id)?,
            _40pct_to_50pct_in_loss: create(n._40pct_to_50pct_in_loss.id)?,
            _50pct_to_60pct_in_loss: create(n._50pct_to_60pct_in_loss.id)?,
            _60pct_to_70pct_in_loss: create(n._60pct_to_70pct_in_loss.id)?,
            _70pct_to_80pct_in_loss: create(n._70pct_to_80pct_in_loss.id)?,
            _80pct_to_90pct_in_loss: create(n._80pct_to_90pct_in_loss.id)?,
            _90pct_to_100pct_in_loss: create(n._90pct_to_100pct_in_loss.id)?,
        })
    }

    pub fn iter(&self) -> impl Iterator<Item = &T> {
        [
            &self.over_1000pct_in_profit,
            &self._500pct_to_1000pct_in_profit,
            &self._300pct_to_500pct_in_profit,
            &self._200pct_to_300pct_in_profit,
            &self._100pct_to_200pct_in_profit,
            &self._90pct_to_100pct_in_profit,
            &self._80pct_to_90pct_in_profit,
            &self._70pct_to_80pct_in_profit,
            &self._60pct_to_70pct_in_profit,
            &self._50pct_to_60pct_in_profit,
            &self._40pct_to_50pct_in_profit,
            &self._30pct_to_40pct_in_profit,
            &self._20pct_to_30pct_in_profit,
            &self._10pct_to_20pct_in_profit,
            &self._0pct_to_10pct_in_profit,
            &self._0pct_to_10pct_in_loss,
            &self._10pct_to_20pct_in_loss,
            &self._20pct_to_30pct_in_loss,
            &self._30pct_to_40pct_in_loss,
            &self._40pct_to_50pct_in_loss,
            &self._50pct_to_60pct_in_loss,
            &self._60pct_to_70pct_in_loss,
            &self._70pct_to_80pct_in_loss,
            &self._80pct_to_90pct_in_loss,
            &self._90pct_to_100pct_in_loss,
        ]
        .into_iter()
    }

    pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
        self.iter_mut_with_is_profit().map(|(_, v)| v)
    }

    /// Iterate mutably, yielding `(is_profit, &mut T)` for each range.
    pub fn iter_mut_with_is_profit(&mut self) -> impl Iterator<Item = (bool, &mut T)> {
        [
            (true, &mut self.over_1000pct_in_profit),
            (true, &mut self._500pct_to_1000pct_in_profit),
            (true, &mut self._300pct_to_500pct_in_profit),
            (true, &mut self._200pct_to_300pct_in_profit),
            (true, &mut self._100pct_to_200pct_in_profit),
            (true, &mut self._90pct_to_100pct_in_profit),
            (true, &mut self._80pct_to_90pct_in_profit),
            (true, &mut self._70pct_to_80pct_in_profit),
            (true, &mut self._60pct_to_70pct_in_profit),
            (true, &mut self._50pct_to_60pct_in_profit),
            (true, &mut self._40pct_to_50pct_in_profit),
            (true, &mut self._30pct_to_40pct_in_profit),
            (true, &mut self._20pct_to_30pct_in_profit),
            (true, &mut self._10pct_to_20pct_in_profit),
            (true, &mut self._0pct_to_10pct_in_profit),
            (false, &mut self._0pct_to_10pct_in_loss),
            (false, &mut self._10pct_to_20pct_in_loss),
            (false, &mut self._20pct_to_30pct_in_loss),
            (false, &mut self._30pct_to_40pct_in_loss),
            (false, &mut self._40pct_to_50pct_in_loss),
            (false, &mut self._50pct_to_60pct_in_loss),
            (false, &mut self._60pct_to_70pct_in_loss),
            (false, &mut self._70pct_to_80pct_in_loss),
            (false, &mut self._80pct_to_90pct_in_loss),
            (false, &mut self._90pct_to_100pct_in_loss),
        ]
        .into_iter()
    }

    pub fn par_iter_mut(&mut self) -> impl ParallelIterator<Item = &mut T>
    where
        T: Send + Sync,
    {
        [
            &mut self.over_1000pct_in_profit,
            &mut self._500pct_to_1000pct_in_profit,
            &mut self._300pct_to_500pct_in_profit,
            &mut self._200pct_to_300pct_in_profit,
            &mut self._100pct_to_200pct_in_profit,
            &mut self._90pct_to_100pct_in_profit,
            &mut self._80pct_to_90pct_in_profit,
            &mut self._70pct_to_80pct_in_profit,
            &mut self._60pct_to_70pct_in_profit,
            &mut self._50pct_to_60pct_in_profit,
            &mut self._40pct_to_50pct_in_profit,
            &mut self._30pct_to_40pct_in_profit,
            &mut self._20pct_to_30pct_in_profit,
            &mut self._10pct_to_20pct_in_profit,
            &mut self._0pct_to_10pct_in_profit,
            &mut self._0pct_to_10pct_in_loss,
            &mut self._10pct_to_20pct_in_loss,
            &mut self._20pct_to_30pct_in_loss,
            &mut self._30pct_to_40pct_in_loss,
            &mut self._40pct_to_50pct_in_loss,
            &mut self._50pct_to_60pct_in_loss,
            &mut self._60pct_to_70pct_in_loss,
            &mut self._70pct_to_80pct_in_loss,
            &mut self._80pct_to_90pct_in_loss,
            &mut self._90pct_to_100pct_in_loss,
        ]
        .into_par_iter()
    }

    /// Access as a fixed-size array of references (for indexed access during merge).
    pub fn as_array(&self) -> [&T; PROFITABILITY_RANGE_COUNT] {
        [
            &self.over_1000pct_in_profit,
            &self._500pct_to_1000pct_in_profit,
            &self._300pct_to_500pct_in_profit,
            &self._200pct_to_300pct_in_profit,
            &self._100pct_to_200pct_in_profit,
            &self._90pct_to_100pct_in_profit,
            &self._80pct_to_90pct_in_profit,
            &self._70pct_to_80pct_in_profit,
            &self._60pct_to_70pct_in_profit,
            &self._50pct_to_60pct_in_profit,
            &self._40pct_to_50pct_in_profit,
            &self._30pct_to_40pct_in_profit,
            &self._20pct_to_30pct_in_profit,
            &self._10pct_to_20pct_in_profit,
            &self._0pct_to_10pct_in_profit,
            &self._0pct_to_10pct_in_loss,
            &self._10pct_to_20pct_in_loss,
            &self._20pct_to_30pct_in_loss,
            &self._30pct_to_40pct_in_loss,
            &self._40pct_to_50pct_in_loss,
            &self._50pct_to_60pct_in_loss,
            &self._60pct_to_70pct_in_loss,
            &self._70pct_to_80pct_in_loss,
            &self._80pct_to_90pct_in_loss,
            &self._90pct_to_100pct_in_loss,
        ]
    }

    /// Access as a fixed-size array of mutable references (for indexed access during merge).
    pub fn as_array_mut(&mut self) -> [&mut T; PROFITABILITY_RANGE_COUNT] {
        [
            &mut self.over_1000pct_in_profit,
            &mut self._500pct_to_1000pct_in_profit,
            &mut self._300pct_to_500pct_in_profit,
            &mut self._200pct_to_300pct_in_profit,
            &mut self._100pct_to_200pct_in_profit,
            &mut self._90pct_to_100pct_in_profit,
            &mut self._80pct_to_90pct_in_profit,
            &mut self._70pct_to_80pct_in_profit,
            &mut self._60pct_to_70pct_in_profit,
            &mut self._50pct_to_60pct_in_profit,
            &mut self._40pct_to_50pct_in_profit,
            &mut self._30pct_to_40pct_in_profit,
            &mut self._20pct_to_30pct_in_profit,
            &mut self._10pct_to_20pct_in_profit,
            &mut self._0pct_to_10pct_in_profit,
            &mut self._0pct_to_10pct_in_loss,
            &mut self._10pct_to_20pct_in_loss,
            &mut self._20pct_to_30pct_in_loss,
            &mut self._30pct_to_40pct_in_loss,
            &mut self._40pct_to_50pct_in_loss,
            &mut self._50pct_to_60pct_in_loss,
            &mut self._60pct_to_70pct_in_loss,
            &mut self._70pct_to_80pct_in_loss,
            &mut self._80pct_to_90pct_in_loss,
            &mut self._90pct_to_100pct_in_loss,
        ]
    }
}