mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Dollars;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{PerBlock, PriceWithRatioExtendedPerBlock};
|
||||
use crate::internal::PriceWithRatioExtendedPerBlock;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::{
|
||||
blocks,
|
||||
distribution::state::{WithCapital, CohortState, CostBasisData, RealizedState},
|
||||
internal::{
|
||||
CentsUnsignedToDollars, PerBlock, PerBlockCumulative,
|
||||
CentsUnsignedToDollars, PerBlockCumulative,
|
||||
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
|
||||
LazyPerBlock, PercentPerBlock, PercentRollingWindows,
|
||||
PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
|
||||
|
||||
@@ -146,4 +146,5 @@ mod tests {
|
||||
assert_eq!(ep.count(), 0);
|
||||
assert_eq!(quantile(&ep, 0.5), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,11 @@ pub struct RatioPerBlockPercentiles<M: StorageMode = Rw> {
|
||||
expanding_pct: ExpandingPercentiles,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::new(4);
|
||||
const VERSION: Version = Version::new(5);
|
||||
|
||||
/// First height included in ratio percentile computation (first halving).
|
||||
/// Earlier blocks lack meaningful market data and pollute the distribution.
|
||||
const MIN_HEIGHT: usize = 210_000;
|
||||
|
||||
impl RatioPerBlockPercentiles {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -100,11 +104,11 @@ impl RatioPerBlockPercentiles {
|
||||
let ratio_len = ratio_source.len();
|
||||
|
||||
if ratio_len > start {
|
||||
let pct_count = self.expanding_pct.count() as usize;
|
||||
if pct_count != start {
|
||||
let expected_count = start.saturating_sub(MIN_HEIGHT);
|
||||
if self.expanding_pct.count() as usize != expected_count {
|
||||
self.expanding_pct.reset();
|
||||
if start > 0 {
|
||||
let historical = ratio_source.collect_range_at(0, start);
|
||||
if start > MIN_HEIGHT {
|
||||
let historical = ratio_source.collect_range_at(MIN_HEIGHT, start);
|
||||
self.expanding_pct.add_bulk(&historical);
|
||||
}
|
||||
}
|
||||
@@ -125,8 +129,10 @@ impl RatioPerBlockPercentiles {
|
||||
vec.truncate_if_needed_at(start)?;
|
||||
}
|
||||
|
||||
for &ratio in new_ratios.iter() {
|
||||
self.expanding_pct.add(*ratio);
|
||||
for (i, &ratio) in new_ratios.iter().enumerate() {
|
||||
if start + i >= MIN_HEIGHT {
|
||||
self.expanding_pct.add(*ratio);
|
||||
}
|
||||
self.expanding_pct.quantiles(&PCTS, &mut out);
|
||||
for (vec, &val) in pct_vecs.iter_mut().zip(out.iter()) {
|
||||
vec.push(BasisPoints32::from(val));
|
||||
|
||||
@@ -49,7 +49,7 @@ pub struct Computer<M: StorageMode = Rw> {
|
||||
pub outputs: Box<outputs::Vecs<M>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::new(5);
|
||||
const VERSION: Version = Version::new(6);
|
||||
|
||||
impl Computer {
|
||||
pub fn forced_import(outputs_path: &Path, indexer: &Indexer) -> Result<Self> {
|
||||
|
||||
@@ -165,8 +165,9 @@ impl Vecs {
|
||||
let start_days = super::ByDcaClass::<()>::start_days();
|
||||
for (stack, day1) in self.class.stack.iter_mut().zip(start_days) {
|
||||
let mut last_di: Option<Day1> = None;
|
||||
let mut prev_value = if starting_height > 0 {
|
||||
stack.sats.height.collect_one_at(starting_height - 1).unwrap_or_default()
|
||||
let cls_start = stack.sats.height.len().min(starting_height);
|
||||
let mut prev_value = if cls_start > 0 {
|
||||
stack.sats.height.collect_one_at(cls_start - 1).unwrap_or_default()
|
||||
} else {
|
||||
Sats::ZERO
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user