mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-27 18:58:10 -07:00
bindgen: snapshot
This commit is contained in:
@@ -10,7 +10,7 @@ use brk_types::{Cents, Dollars, SatsFract, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use super::{PerBlock, LazyPerBlock};
|
||||
use super::{LazyPerBlock, PerBlock};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue},
|
||||
@@ -32,8 +32,7 @@ impl Price<PerBlock<Cents>> {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents =
|
||||
PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let cents = PerBlock::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyPerBlock::from_computed::<CentsUnsignedToDollars>(
|
||||
name,
|
||||
version,
|
||||
@@ -65,11 +64,7 @@ where
|
||||
source.height.read_only_boxed_clone(),
|
||||
source,
|
||||
);
|
||||
let usd = LazyPerBlock::from_lazy::<CentsUnsignedToDollars, ST>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
¢s,
|
||||
);
|
||||
let usd = LazyPerBlock::from_lazy::<CentsUnsignedToDollars, ST>(name, version, ¢s);
|
||||
let sats = LazyPerBlock::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
&format!("{name}_sats"),
|
||||
version,
|
||||
|
||||
@@ -27,10 +27,10 @@ impl RatioPerBlockStdDevBands {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! import_sd {
|
||||
($suffix:expr, $period:expr, $days:expr) => {
|
||||
($period:expr, $days:expr) => {
|
||||
StdDevPerBlockExtended::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}", $suffix),
|
||||
name,
|
||||
$period,
|
||||
$days,
|
||||
v,
|
||||
@@ -40,10 +40,10 @@ impl RatioPerBlockStdDevBands {
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
all: import_sd!("ratio", "", usize::MAX),
|
||||
_1y: import_sd!("ratio", "1y", 365),
|
||||
_2y: import_sd!("ratio", "2y", 2 * 365),
|
||||
_4y: import_sd!("ratio", "4y", 4 * 365),
|
||||
all: import_sd!("", usize::MAX),
|
||||
_1y: import_sd!("1y", 365),
|
||||
_2y: import_sd!("2y", 2 * 365),
|
||||
_4y: import_sd!("4y", 4 * 365),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ use vecdb::{
|
||||
|
||||
use crate::{
|
||||
blocks, indexes,
|
||||
internal::{PerBlock, Price, PriceTimesRatioCents},
|
||||
internal::{PerBlock, Price, PriceTimesRatioCents, per_block::stddev::period_suffix},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct StdDevBand<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub value: PerBlock<StoredF32, M>,
|
||||
pub ratio: PerBlock<StoredF32, M>,
|
||||
pub price: Price<PerBlock<Cents, M>>,
|
||||
}
|
||||
|
||||
@@ -49,16 +49,11 @@ impl StdDevPerBlockExtended {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let version = parent_version + Version::TWO;
|
||||
let p = super::period_suffix(period);
|
||||
let p = period_suffix(period);
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
PerBlock::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}{p}", $suffix),
|
||||
version,
|
||||
indexes,
|
||||
)?
|
||||
PerBlock::forced_import(db, &format!("{name}_{}{p}", $suffix), version, indexes)?
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,18 +64,18 @@ impl StdDevPerBlockExtended {
|
||||
}
|
||||
|
||||
macro_rules! import_band {
|
||||
($suffix:expr) => {
|
||||
($suffix:expr) => {{
|
||||
StdDevBand {
|
||||
value: import!(concat!("ratio_", $suffix)),
|
||||
ratio: import!(concat!("ratio_", $suffix)),
|
||||
price: import_price!($suffix),
|
||||
}
|
||||
};
|
||||
}};
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
days,
|
||||
sd: import!("sd"),
|
||||
zscore: import!("zscore"),
|
||||
sd: import!("ratio_sd"),
|
||||
zscore: import!("ratio_zscore"),
|
||||
_0sd: import_price!("0sd"),
|
||||
p0_5sd: import_band!("p0_5sd"),
|
||||
p1sd: import_band!("p1sd"),
|
||||
@@ -106,12 +101,9 @@ impl StdDevPerBlockExtended {
|
||||
sma: &impl ReadableVec<Height, StoredF32>,
|
||||
) -> Result<()> {
|
||||
if self.days == usize::MAX {
|
||||
self.sd.height.compute_expanding_sd(
|
||||
starting_indexes.height,
|
||||
source,
|
||||
sma,
|
||||
exit,
|
||||
)?;
|
||||
self.sd
|
||||
.height
|
||||
.compute_expanding_sd(starting_indexes.height, source, sma, exit)?;
|
||||
} else {
|
||||
let window_starts = blocks.lookback.start_vec(self.days);
|
||||
self.sd.height.compute_rolling_sd(
|
||||
@@ -154,10 +146,7 @@ impl StdDevPerBlockExtended {
|
||||
let source_data = source.collect_range_at(start, source_len);
|
||||
|
||||
let sma_data = sma.collect_range_at(start, sma.len());
|
||||
let sd_data = self
|
||||
.sd
|
||||
.height
|
||||
.collect_range_at(start, self.sd.height.len());
|
||||
let sd_data = self.sd.height.collect_range_at(start, self.sd.height.len());
|
||||
|
||||
const MULTIPLIERS: [f32; 12] = [
|
||||
0.5, 1.0, 1.5, 2.0, 2.5, 3.0, -0.5, -1.0, -1.5, -2.0, -2.5, -3.0,
|
||||
@@ -208,18 +197,18 @@ impl StdDevPerBlockExtended {
|
||||
}
|
||||
|
||||
compute_band_price!(&mut self._0sd, sma);
|
||||
compute_band_price!(&mut self.p0_5sd.price, &self.p0_5sd.value.height);
|
||||
compute_band_price!(&mut self.p1sd.price, &self.p1sd.value.height);
|
||||
compute_band_price!(&mut self.p1_5sd.price, &self.p1_5sd.value.height);
|
||||
compute_band_price!(&mut self.p2sd.price, &self.p2sd.value.height);
|
||||
compute_band_price!(&mut self.p2_5sd.price, &self.p2_5sd.value.height);
|
||||
compute_band_price!(&mut self.p3sd.price, &self.p3sd.value.height);
|
||||
compute_band_price!(&mut self.m0_5sd.price, &self.m0_5sd.value.height);
|
||||
compute_band_price!(&mut self.m1sd.price, &self.m1sd.value.height);
|
||||
compute_band_price!(&mut self.m1_5sd.price, &self.m1_5sd.value.height);
|
||||
compute_band_price!(&mut self.m2sd.price, &self.m2sd.value.height);
|
||||
compute_band_price!(&mut self.m2_5sd.price, &self.m2_5sd.value.height);
|
||||
compute_band_price!(&mut self.m3sd.price, &self.m3sd.value.height);
|
||||
compute_band_price!(&mut self.p0_5sd.price, &self.p0_5sd.ratio.height);
|
||||
compute_band_price!(&mut self.p1sd.price, &self.p1sd.ratio.height);
|
||||
compute_band_price!(&mut self.p1_5sd.price, &self.p1_5sd.ratio.height);
|
||||
compute_band_price!(&mut self.p2sd.price, &self.p2sd.ratio.height);
|
||||
compute_band_price!(&mut self.p2_5sd.price, &self.p2_5sd.ratio.height);
|
||||
compute_band_price!(&mut self.p3sd.price, &self.p3sd.ratio.height);
|
||||
compute_band_price!(&mut self.m0_5sd.price, &self.m0_5sd.ratio.height);
|
||||
compute_band_price!(&mut self.m1sd.price, &self.m1sd.ratio.height);
|
||||
compute_band_price!(&mut self.m1_5sd.price, &self.m1_5sd.ratio.height);
|
||||
compute_band_price!(&mut self.m2sd.price, &self.m2sd.ratio.height);
|
||||
compute_band_price!(&mut self.m2_5sd.price, &self.m2_5sd.ratio.height);
|
||||
compute_band_price!(&mut self.m3sd.price, &self.m3sd.ratio.height);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -228,18 +217,18 @@ impl StdDevPerBlockExtended {
|
||||
&mut self,
|
||||
) -> impl Iterator<Item = &mut EagerVec<PcoVec<Height, StoredF32>>> {
|
||||
[
|
||||
&mut self.p0_5sd.value.height,
|
||||
&mut self.p1sd.value.height,
|
||||
&mut self.p1_5sd.value.height,
|
||||
&mut self.p2sd.value.height,
|
||||
&mut self.p2_5sd.value.height,
|
||||
&mut self.p3sd.value.height,
|
||||
&mut self.m0_5sd.value.height,
|
||||
&mut self.m1sd.value.height,
|
||||
&mut self.m1_5sd.value.height,
|
||||
&mut self.m2sd.value.height,
|
||||
&mut self.m2_5sd.value.height,
|
||||
&mut self.m3sd.value.height,
|
||||
&mut self.p0_5sd.ratio.height,
|
||||
&mut self.p1sd.ratio.height,
|
||||
&mut self.p1_5sd.ratio.height,
|
||||
&mut self.p2sd.ratio.height,
|
||||
&mut self.p2_5sd.ratio.height,
|
||||
&mut self.p3sd.ratio.height,
|
||||
&mut self.m0_5sd.ratio.height,
|
||||
&mut self.m1sd.ratio.height,
|
||||
&mut self.m1_5sd.ratio.height,
|
||||
&mut self.m2sd.ratio.height,
|
||||
&mut self.m2_5sd.ratio.height,
|
||||
&mut self.m3sd.ratio.height,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user