global: add min max choppiness datasets + fixes

This commit is contained in:
nym21
2025-09-09 17:52:45 +02:00
parent 16abce1f2d
commit a610fd53e2
12 changed files with 606 additions and 205 deletions

View File

@@ -2,7 +2,7 @@ use std::path::Path;
use brk_error::Result;
use brk_indexer::Indexer;
use brk_structs::{StoredI16, StoredU16, Version};
use brk_structs::{StoredF32, StoredI16, StoredU16, Version};
use vecdb::{AnyCollectableVec, AnyVec, Database, Exit};
use crate::grouped::Source;
@@ -24,7 +24,9 @@ pub struct Vecs {
pub constant_2: ComputedVecsFromHeight<StoredU16>,
pub constant_3: ComputedVecsFromHeight<StoredU16>,
pub constant_4: ComputedVecsFromHeight<StoredU16>,
pub constant_38_2: ComputedVecsFromHeight<StoredF32>,
pub constant_50: ComputedVecsFromHeight<StoredU16>,
pub constant_61_8: ComputedVecsFromHeight<StoredF32>,
pub constant_100: ComputedVecsFromHeight<StoredU16>,
pub constant_600: ComputedVecsFromHeight<StoredU16>,
pub constant_minus_1: ComputedVecsFromHeight<StoredI16>,
@@ -78,6 +80,14 @@ impl Vecs {
indexes,
VecBuilderOptions::default().add_last(),
)?,
constant_38_2: ComputedVecsFromHeight::forced_import(
&db,
"constant_38_2",
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
VecBuilderOptions::default().add_last(),
)?,
constant_50: ComputedVecsFromHeight::forced_import(
&db,
"constant_50",
@@ -86,6 +96,14 @@ impl Vecs {
indexes,
VecBuilderOptions::default().add_last(),
)?,
constant_61_8: ComputedVecsFromHeight::forced_import(
&db,
"constant_61_8",
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
VecBuilderOptions::default().add_last(),
)?,
constant_100: ComputedVecsFromHeight::forced_import(
&db,
"constant_100",
@@ -223,6 +241,30 @@ impl Vecs {
)
})?;
[
(&mut self.constant_38_2, 38.2),
(&mut self.constant_61_8, 61.8),
]
.into_iter()
.try_for_each(|(vec, value)| {
vec.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|vec, _, indexes, starting_indexes, exit| {
vec.compute_to(
starting_indexes.height,
indexes.height_to_date.len(),
indexes.height_to_date.version(),
|i| (i, StoredF32::from(value)),
exit,
)?;
Ok(())
},
)
})?;
Ok(())
}
@@ -233,7 +275,9 @@ impl Vecs {
self.constant_2.vecs(),
self.constant_3.vecs(),
self.constant_4.vecs(),
self.constant_38_2.vecs(),
self.constant_50.vecs(),
self.constant_61_8.vecs(),
self.constant_100.vecs(),
self.constant_600.vecs(),
self.constant_minus_1.vecs(),

View File

@@ -20,11 +20,11 @@ where
pub average: Option<Box<EagerVec<I, T>>>,
pub sum: Option<Box<EagerVec<I, T>>>,
pub max: Option<Box<EagerVec<I, T>>>,
pub p90: Option<Box<EagerVec<I, T>>>,
pub p75: Option<Box<EagerVec<I, T>>>,
pub pct90: Option<Box<EagerVec<I, T>>>,
pub pct75: Option<Box<EagerVec<I, T>>>,
pub median: Option<Box<EagerVec<I, T>>>,
pub p25: Option<Box<EagerVec<I, T>>>,
pub p10: Option<Box<EagerVec<I, T>>>,
pub pct25: Option<Box<EagerVec<I, T>>>,
pub pct10: Option<Box<EagerVec<I, T>>>,
pub min: Option<Box<EagerVec<I, T>>>,
pub last: Option<Box<EagerVec<I, T>>>,
pub cumulative: Option<Box<EagerVec<I, T>>>,
@@ -152,44 +152,44 @@ where
.unwrap(),
)
}),
p90: options.p90.then(|| {
pct90: options.pct90.then(|| {
Box::new(
EagerVec::forced_import(
db,
&maybe_suffix("p90"),
&maybe_suffix("pct90"),
version + VERSION + Version::ZERO,
format,
)
.unwrap(),
)
}),
p75: options.p75.then(|| {
pct75: options.pct75.then(|| {
Box::new(
EagerVec::forced_import(
db,
&maybe_suffix("p75"),
&maybe_suffix("pct75"),
version + VERSION + Version::ZERO,
format,
)
.unwrap(),
)
}),
p25: options.p25.then(|| {
pct25: options.pct25.then(|| {
Box::new(
EagerVec::forced_import(
db,
&maybe_suffix("p25"),
&maybe_suffix("pct25"),
version + VERSION + Version::ZERO,
format,
)
.unwrap(),
)
}),
p10: options.p10.then(|| {
pct10: options.pct10.then(|| {
Box::new(
EagerVec::forced_import(
db,
&maybe_suffix("p10"),
&maybe_suffix("pct10"),
version + VERSION + Version::ZERO,
format,
)
@@ -293,11 +293,11 @@ where
let needs_average_sum_or_cumulative =
needs_sum_or_cumulative || self.average.is_some();
let needs_sorted = self.max.is_some()
|| self.p90.is_some()
|| self.p75.is_some()
|| self.pct90.is_some()
|| self.pct75.is_some()
|| self.median.is_some()
|| self.p25.is_some()
|| self.p10.is_some()
|| self.pct25.is_some()
|| self.pct10.is_some()
|| self.min.is_some();
let needs_values = needs_sorted || needs_average_sum_or_cumulative;
@@ -334,24 +334,24 @@ where
)?;
}
if let Some(p90) = self.p90.as_mut() {
p90.forced_push_at(index, get_percentile(&values, 0.90), exit)?;
if let Some(pct90) = self.pct90.as_mut() {
pct90.forced_push_at(index, get_percentile(&values, 0.90), exit)?;
}
if let Some(p75) = self.p75.as_mut() {
p75.forced_push_at(index, get_percentile(&values, 0.75), exit)?;
if let Some(pct75) = self.pct75.as_mut() {
pct75.forced_push_at(index, get_percentile(&values, 0.75), exit)?;
}
if let Some(median) = self.median.as_mut() {
median.forced_push_at(index, get_percentile(&values, 0.50), exit)?;
}
if let Some(p25) = self.p25.as_mut() {
p25.forced_push_at(index, get_percentile(&values, 0.25), exit)?;
if let Some(pct25) = self.pct25.as_mut() {
pct25.forced_push_at(index, get_percentile(&values, 0.25), exit)?;
}
if let Some(p10) = self.p10.as_mut() {
p10.forced_push_at(index, get_percentile(&values, 0.10), exit)?;
if let Some(pct10) = self.pct10.as_mut() {
pct10.forced_push_at(index, get_percentile(&values, 0.10), exit)?;
}
if let Some(min) = self.min.as_mut() {
@@ -402,11 +402,11 @@ where
where
I2: StoredIndex + StoredRaw + CheckedSub<I2>,
{
if self.p90.is_some()
|| self.p75.is_some()
if self.pct90.is_some()
|| self.pct75.is_some()
|| self.median.is_some()
|| self.p25.is_some()
|| self.p10.is_some()
|| self.pct25.is_some()
|| self.pct10.is_some()
{
panic!("unsupported");
}
@@ -559,24 +559,24 @@ where
self.max.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_p90(&self) -> &EagerVec<I, T> {
self.p90.as_ref().unwrap()
pub fn unwrap_pct90(&self) -> &EagerVec<I, T> {
self.pct90.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_p75(&self) -> &EagerVec<I, T> {
self.p75.as_ref().unwrap()
pub fn unwrap_pct75(&self) -> &EagerVec<I, T> {
self.pct75.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_median(&self) -> &EagerVec<I, T> {
self.median.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_p25(&self) -> &EagerVec<I, T> {
self.p25.as_ref().unwrap()
pub fn unwrap_pct25(&self) -> &EagerVec<I, T> {
self.pct25.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_p10(&self) -> &EagerVec<I, T> {
self.p10.as_ref().unwrap()
pub fn unwrap_pct10(&self) -> &EagerVec<I, T> {
self.pct10.as_ref().unwrap()
}
pub fn unwrap_min(&self) -> &EagerVec<I, T> {
self.min.as_ref().unwrap()
@@ -616,17 +616,17 @@ where
if let Some(cumulative) = self.cumulative.as_ref() {
v.push(cumulative.as_ref());
}
if let Some(p90) = self.p90.as_ref() {
v.push(p90.as_ref());
if let Some(pct90) = self.pct90.as_ref() {
v.push(pct90.as_ref());
}
if let Some(p75) = self.p75.as_ref() {
v.push(p75.as_ref());
if let Some(pct75) = self.pct75.as_ref() {
v.push(pct75.as_ref());
}
if let Some(p25) = self.p25.as_ref() {
v.push(p25.as_ref());
if let Some(pct25) = self.pct25.as_ref() {
v.push(pct25.as_ref());
}
if let Some(p10) = self.p10.as_ref() {
v.push(p10.as_ref());
if let Some(pct10) = self.pct10.as_ref() {
v.push(pct10.as_ref());
}
v
@@ -657,17 +657,17 @@ where
if let Some(cumulative) = self.cumulative.as_mut() {
cumulative.safe_flush(exit)?;
}
if let Some(p90) = self.p90.as_mut() {
p90.safe_flush(exit)?;
if let Some(pct90) = self.pct90.as_mut() {
pct90.safe_flush(exit)?;
}
if let Some(p75) = self.p75.as_mut() {
p75.safe_flush(exit)?;
if let Some(pct75) = self.pct75.as_mut() {
pct75.safe_flush(exit)?;
}
if let Some(p25) = self.p25.as_mut() {
p25.safe_flush(exit)?;
if let Some(pct25) = self.pct25.as_mut() {
pct25.safe_flush(exit)?;
}
if let Some(p10) = self.p10.as_mut() {
p10.safe_flush(exit)?;
if let Some(pct10) = self.pct10.as_mut() {
pct10.safe_flush(exit)?;
}
Ok(())
@@ -698,17 +698,17 @@ where
if let Some(cumulative) = self.cumulative.as_mut() {
cumulative.validate_computed_version_or_reset(Version::ZERO + version)?;
}
if let Some(p90) = self.p90.as_mut() {
p90.validate_computed_version_or_reset(Version::ZERO + version)?;
if let Some(pct90) = self.pct90.as_mut() {
pct90.validate_computed_version_or_reset(Version::ZERO + version)?;
}
if let Some(p75) = self.p75.as_mut() {
p75.validate_computed_version_or_reset(Version::ZERO + version)?;
if let Some(pct75) = self.pct75.as_mut() {
pct75.validate_computed_version_or_reset(Version::ZERO + version)?;
}
if let Some(p25) = self.p25.as_mut() {
p25.validate_computed_version_or_reset(Version::ZERO + version)?;
if let Some(pct25) = self.pct25.as_mut() {
pct25.validate_computed_version_or_reset(Version::ZERO + version)?;
}
if let Some(p10) = self.p10.as_mut() {
p10.validate_computed_version_or_reset(Version::ZERO + version)?;
if let Some(pct10) = self.pct10.as_mut() {
pct10.validate_computed_version_or_reset(Version::ZERO + version)?;
}
Ok(())
@@ -720,11 +720,11 @@ pub struct VecBuilderOptions {
average: bool,
sum: bool,
max: bool,
p90: bool,
p75: bool,
pct90: bool,
pct75: bool,
median: bool,
p25: bool,
p10: bool,
pct25: bool,
pct10: bool,
min: bool,
first: bool,
last: bool,
@@ -744,24 +744,24 @@ impl VecBuilderOptions {
self.max
}
pub fn p90(&self) -> bool {
self.p90
pub fn pct90(&self) -> bool {
self.pct90
}
pub fn p75(&self) -> bool {
self.p75
pub fn pct75(&self) -> bool {
self.pct75
}
pub fn median(&self) -> bool {
self.median
}
pub fn p25(&self) -> bool {
self.p25
pub fn pct25(&self) -> bool {
self.pct25
}
pub fn p10(&self) -> bool {
self.p10
pub fn pct10(&self) -> bool {
self.pct10
}
pub fn min(&self) -> bool {
@@ -817,26 +817,26 @@ impl VecBuilderOptions {
}
#[allow(unused)]
pub fn add_p90(mut self) -> Self {
self.p90 = true;
pub fn add_pct90(mut self) -> Self {
self.pct90 = true;
self
}
#[allow(unused)]
pub fn add_p75(mut self) -> Self {
self.p75 = true;
pub fn add_pct75(mut self) -> Self {
self.pct75 = true;
self
}
#[allow(unused)]
pub fn add_p25(mut self) -> Self {
self.p25 = true;
pub fn add_pct25(mut self) -> Self {
self.pct25 = true;
self
}
#[allow(unused)]
pub fn add_p10(mut self) -> Self {
self.p10 = true;
pub fn add_pct10(mut self) -> Self {
self.pct10 = true;
self
}
@@ -876,26 +876,26 @@ impl VecBuilderOptions {
}
#[allow(unused)]
pub fn rm_p90(mut self) -> Self {
self.p90 = false;
pub fn rm_pct90(mut self) -> Self {
self.pct90 = false;
self
}
#[allow(unused)]
pub fn rm_p75(mut self) -> Self {
self.p75 = false;
pub fn rm_pct75(mut self) -> Self {
self.pct75 = false;
self
}
#[allow(unused)]
pub fn rm_p25(mut self) -> Self {
self.p25 = false;
pub fn rm_pct25(mut self) -> Self {
self.pct25 = false;
self
}
#[allow(unused)]
pub fn rm_p10(mut self) -> Self {
self.p10 = false;
pub fn rm_pct10(mut self) -> Self {
self.pct10 = false;
self
}
@@ -912,20 +912,20 @@ impl VecBuilderOptions {
}
pub fn add_percentiles(mut self) -> Self {
self.p90 = true;
self.p75 = true;
self.pct90 = true;
self.pct75 = true;
self.median = true;
self.p25 = true;
self.p10 = true;
self.pct25 = true;
self.pct10 = true;
self
}
pub fn remove_percentiles(mut self) -> Self {
self.p90 = false;
self.p75 = false;
self.pct90 = false;
self.pct75 = false;
self.median = false;
self.p25 = false;
self.p10 = false;
self.pct25 = false;
self.pct10 = false;
self
}
@@ -934,11 +934,11 @@ impl VecBuilderOptions {
self.average,
self.sum,
self.max,
self.p90,
self.p75,
self.pct90,
self.pct75,
self.median,
self.p25,
self.p10,
self.pct25,
self.pct10,
self.min,
self.first,
self.last,

View File

@@ -320,24 +320,24 @@ impl ComputedVecsFromTxindex<Bitcoin> {
exit,
)?;
}
if let Some(_90p) = self.height.p90.as_mut() {
_90p.forced_push_at(
if let Some(pct90) = self.height.pct90.as_mut() {
pct90.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_p90()
.unwrap_pct90()
.into_iter()
.unwrap_get_inner(height),
),
exit,
)?;
}
if let Some(_75p) = self.height.p75.as_mut() {
_75p.forced_push_at(
if let Some(pct75) = self.height.pct75.as_mut() {
pct75.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_p75()
.unwrap_pct75()
.into_iter()
.unwrap_get_inner(height),
),
@@ -356,24 +356,24 @@ impl ComputedVecsFromTxindex<Bitcoin> {
exit,
)?;
}
if let Some(_25p) = self.height.p25.as_mut() {
_25p.forced_push_at(
if let Some(pct25) = self.height.pct25.as_mut() {
pct25.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_p25()
.unwrap_pct25()
.into_iter()
.unwrap_get_inner(height),
),
exit,
)?;
}
if let Some(_10p) = self.height.p10.as_mut() {
_10p.forced_push_at(
if let Some(pct10) = self.height.pct10.as_mut() {
pct10.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_p10()
.unwrap_pct10()
.into_iter()
.unwrap_get_inner(height),
),
@@ -503,25 +503,25 @@ impl ComputedVecsFromTxindex<Dollars> {
exit,
)?;
}
if let Some(_90p) = self.height.p90.as_mut() {
_90p.forced_push_at(
if let Some(pct90) = self.height.pct90.as_mut() {
pct90.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_p90()
.unwrap_pct90()
.into_iter()
.unwrap_get_inner(height),
exit,
)?;
}
if let Some(_75p) = self.height.p75.as_mut() {
_75p.forced_push_at(
if let Some(pct75) = self.height.pct75.as_mut() {
pct75.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_p75()
.unwrap_pct75()
.into_iter()
.unwrap_get_inner(height),
exit,
@@ -539,25 +539,25 @@ impl ComputedVecsFromTxindex<Dollars> {
exit,
)?;
}
if let Some(_25p) = self.height.p25.as_mut() {
_25p.forced_push_at(
if let Some(pct25) = self.height.pct25.as_mut() {
pct25.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_p25()
.unwrap_pct25()
.into_iter()
.unwrap_get_inner(height),
exit,
)?;
}
if let Some(_10p) = self.height.p10.as_mut() {
_10p.forced_push_at(
if let Some(pct10) = self.height.pct10.as_mut() {
pct10.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_p10()
.unwrap_pct10()
.into_iter()
.unwrap_get_inner(height),
exit,

View File

@@ -35,9 +35,20 @@ pub struct Vecs {
pub indexes_to_price_1w_volatility: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_price_1m_volatility: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_price_1y_volatility: ComputedVecsFromDateIndex<StoredF32>,
// pub indexes_to_price_true_range: ComputedVecsFromDateIndex<StoredF32>,
// pub indexes_to_price_2w_choppiness_index: ComputedVecsFromDateIndex<StoredF32>,
//
pub indexes_to_price_1w_min: ComputedVecsFromDateIndex<Dollars>,
pub indexes_to_price_1w_max: ComputedVecsFromDateIndex<Dollars>,
pub indexes_to_price_2w_min: ComputedVecsFromDateIndex<Dollars>,
pub indexes_to_price_2w_max: ComputedVecsFromDateIndex<Dollars>,
pub indexes_to_price_1m_min: ComputedVecsFromDateIndex<Dollars>,
pub indexes_to_price_1m_max: ComputedVecsFromDateIndex<Dollars>,
pub indexes_to_price_1y_min: ComputedVecsFromDateIndex<Dollars>,
pub indexes_to_price_1y_max: ComputedVecsFromDateIndex<Dollars>,
pub dateindex_to_price_true_range: EagerVec<DateIndex, StoredF32>,
pub dateindex_to_price_true_range_2w_sum: EagerVec<DateIndex, StoredF32>,
pub indexes_to_price_2w_choppiness_index: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_price_1w_sma: ComputedRatioVecsFromDateIndex,
pub indexes_to_price_8d_sma: ComputedRatioVecsFromDateIndex,
pub indexes_to_price_13d_sma: ComputedRatioVecsFromDateIndex,
@@ -1420,22 +1431,88 @@ impl Vecs {
indexes,
VecBuilderOptions::default().add_last(),
)?,
// indexes_to_price_true_range: ComputedVecsFromDateIndex::forced_import(
// &db,
// "price_true_range",
// Source::Compute,
// version + Version::ZERO,
// indexes,
// VecBuilderOptions::default().add_last(),
// )?,
// indexes_to_price_2w_choppiness_index: ComputedVecsFromDateIndex::forced_import(
// &db,
// "price_2w_choppiness_index",
// Source::Compute,
// version + Version::ZERO,
// indexes,
// VecBuilderOptions::default().add_last(),
// )?,
dateindex_to_price_true_range: EagerVec::forced_import_compressed(
&db,
"price_true_range",
version + Version::ZERO,
)?,
dateindex_to_price_true_range_2w_sum: EagerVec::forced_import_compressed(
&db,
"price_true_range_2w_sum",
version + Version::ZERO,
)?,
indexes_to_price_1w_min: ComputedVecsFromDateIndex::forced_import(
&db,
"price_1w_min",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_price_1w_max: ComputedVecsFromDateIndex::forced_import(
&db,
"price_1w_max",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_price_2w_min: ComputedVecsFromDateIndex::forced_import(
&db,
"price_2w_min",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_price_2w_max: ComputedVecsFromDateIndex::forced_import(
&db,
"price_2w_max",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_price_1m_min: ComputedVecsFromDateIndex::forced_import(
&db,
"price_1m_min",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_price_1m_max: ComputedVecsFromDateIndex::forced_import(
&db,
"price_1m_max",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_price_1y_min: ComputedVecsFromDateIndex::forced_import(
&db,
"price_1y_min",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_price_1y_max: ComputedVecsFromDateIndex::forced_import(
&db,
"price_1y_max",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_price_2w_choppiness_index: ComputedVecsFromDateIndex::forced_import(
&db,
"price_2w_choppiness_index",
Source::Compute,
version + Version::ONE,
indexes,
VecBuilderOptions::default().add_last(),
)?,
db,
};
@@ -1470,7 +1547,7 @@ impl Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.height_to_price_ath.compute_max(
self.height_to_price_ath.compute_all_time_high(
starting_indexes.height,
&price.chainindexes_to_price_high.height,
exit,
@@ -1488,7 +1565,7 @@ impl Vecs {
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_max(
v.compute_all_time_high(
starting_indexes.dateindex,
price.timeindexes_to_price_high.dateindex.as_ref().unwrap(),
exit,
@@ -2251,6 +2328,182 @@ impl Vecs {
},
)?;
self.dateindex_to_price_true_range.compute_transform3(
starting_indexes.dateindex,
price.timeindexes_to_price_open.dateindex.as_ref().unwrap(),
price.timeindexes_to_price_high.dateindex.as_ref().unwrap(),
price.timeindexes_to_price_low.dateindex.as_ref().unwrap(),
|(i, open, high, low, ..)| {
let high_min_low = **high - **low;
let high_min_open = (**high - **open).abs();
let low_min_open = (**low - **open).abs();
(i, high_min_low.max(high_min_open).max(low_min_open).into())
},
exit,
)?;
self.dateindex_to_price_true_range_2w_sum.compute_sum(
starting_indexes.dateindex,
&self.dateindex_to_price_true_range,
14,
exit,
)?;
self.indexes_to_price_1w_max.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_max(
starting_indexes.dateindex,
price.timeindexes_to_price_high.dateindex.as_ref().unwrap(),
7,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_price_1w_min.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_min(
starting_indexes.dateindex,
price.timeindexes_to_price_low.dateindex.as_ref().unwrap(),
7,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_price_2w_max.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_max(
starting_indexes.dateindex,
price.timeindexes_to_price_high.dateindex.as_ref().unwrap(),
14,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_price_2w_min.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_min(
starting_indexes.dateindex,
price.timeindexes_to_price_low.dateindex.as_ref().unwrap(),
14,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_price_1m_max.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_max(
starting_indexes.dateindex,
price.timeindexes_to_price_high.dateindex.as_ref().unwrap(),
30,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_price_1m_min.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_min(
starting_indexes.dateindex,
price.timeindexes_to_price_low.dateindex.as_ref().unwrap(),
30,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_price_1y_max.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_max(
starting_indexes.dateindex,
price.timeindexes_to_price_high.dateindex.as_ref().unwrap(),
365,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_price_1y_min.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_min(
starting_indexes.dateindex,
price.timeindexes_to_price_low.dateindex.as_ref().unwrap(),
365,
exit,
)?;
Ok(())
},
)?;
self.indexes_to_price_2w_choppiness_index.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
let n = 14;
let log10n = (n as f32).log10();
v.compute_transform3(
starting_indexes.dateindex,
&self.dateindex_to_price_true_range_2w_sum,
self.indexes_to_price_2w_max.dateindex.as_ref().unwrap(),
self.indexes_to_price_2w_min.dateindex.as_ref().unwrap(),
|(i, tr_sum, max, min, ..)| {
(
i,
StoredF32::from(
100.0 * (*tr_sum / (*max - *min) as f32).log10() / log10n,
),
)
},
exit,
)?;
Ok(())
},
)?;
Ok(())
}
@@ -2406,7 +2659,21 @@ impl Vecs {
self.indexes_to_price_1w_volatility.vecs(),
self.indexes_to_price_1m_volatility.vecs(),
self.indexes_to_price_1y_volatility.vecs(),
vec![&self.height_to_price_ath, &self.height_to_price_drawdown],
self.indexes_to_price_2w_choppiness_index.vecs(),
self.indexes_to_price_1w_min.vecs(),
self.indexes_to_price_1w_max.vecs(),
self.indexes_to_price_2w_min.vecs(),
self.indexes_to_price_2w_max.vecs(),
self.indexes_to_price_1m_min.vecs(),
self.indexes_to_price_1m_max.vecs(),
self.indexes_to_price_1y_min.vecs(),
self.indexes_to_price_1y_max.vecs(),
vec![
&self.height_to_price_ath,
&self.height_to_price_drawdown,
&self.dateindex_to_price_true_range,
&self.dateindex_to_price_true_range_2w_sum,
],
]
.into_iter()
.flatten()