global: snapshot

This commit is contained in:
nym21
2026-03-01 12:46:07 +01:00
parent e10013fd2c
commit 7bf0220f25
35 changed files with 1450 additions and 2044 deletions
@@ -3,7 +3,7 @@ use brk_types::StoredU16;
use vecdb::{Exit, ReadableVec, VecIndex};
use super::Vecs;
use crate::{ComputeIndexes, prices};
use crate::{ComputeIndexes, prices, traits::ComputeDrawdown};
impl Vecs {
pub(crate) fn compute(
@@ -63,6 +63,13 @@ impl Vecs {
exit,
)?;
self.price_drawdown.height.compute_drawdown(
starting_indexes.height,
&prices.price.usd.height,
&self.price_ath.usd.height,
exit,
)?;
Ok(())
}
}
@@ -43,7 +43,7 @@ impl Vecs {
|(h, close, low, high, ..)| {
let range = *high - *low;
let stoch = if range == 0.0 {
StoredF32::from(50.0)
StoredF32::NAN
} else {
StoredF32::from(((*close - *low) / range * 100.0) as f32)
};
@@ -72,7 +72,7 @@ pub(super) fn compute(
.map(|((r, mn), mx)| {
let range = mx - mn;
if range == 0.0 {
50.0
f32::NAN
} else {
(r - mn) / range * 100.0
}
@@ -26,11 +26,7 @@ pub(super) fn compute_ema(source: &[f32], period: usize) -> Vec<f32> {
for (i, &val) in source.iter().enumerate() {
if i < period {
sum += val;
if i == period - 1 {
result.push(sum / period as f32);
} else {
result.push(val);
}
result.push(sum / (i + 1) as f32);
} else {
let prev = result[i - 1];
result.push(val * k + prev * (1.0 - k));
@@ -102,18 +102,18 @@ impl Vecs {
exit,
)?;
// Choppiness index: 100 * log10(tr_2w_sum / (price_2w_max - price_2w_min)) / log10(14)
let log10n = 14.0f32.log10();
self.price_2w_choppiness_index.height.compute_transform3(
self.price_2w_choppiness_index.height.compute_transform4(
starting_indexes.height,
&self.price_true_range_2w_sum.height,
&self.price_2w_max.usd.height,
&self.price_2w_min.usd.height,
|(h, tr_sum, max, min, ..)| {
&blocks.count.height_2w_ago,
|(h, tr_sum, max, min, window_start, ..)| {
let range = *max - *min;
let ci = if range > 0.0 {
let n = (h.to_usize() - window_start.to_usize() + 1) as f32;
let ci = if range > 0.0 && n > 1.0 {
StoredF32::from(
100.0 * (*tr_sum / range as f32).log10() / log10n,
100.0 * (*tr_sum / range as f32).log10() / n.log10(),
)
} else {
StoredF32::NAN