mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-30 04:08:11 -07:00
global: snapshot
This commit is contained in:
@@ -1073,7 +1073,7 @@ impl _10y1m1w1y2y3m3y4y5y6m6y8yPattern3 {
|
||||
pub struct CapGrossInvestorLossMvrvNetPeakPriceProfitSellSoprPattern {
|
||||
pub cap: CentsDeltaToUsdPattern,
|
||||
pub gross_pnl: BaseCumulativeSumPattern3,
|
||||
pub investor: InvestorPricePattern,
|
||||
pub investor: PricePattern,
|
||||
pub loss: BaseCapitulationCumulativeNegativeSumToValuePattern,
|
||||
pub mvrv: SeriesPattern1<StoredF32>,
|
||||
pub net_pnl: BaseChangeCumulativeDeltaSumToPattern,
|
||||
@@ -2507,24 +2507,6 @@ pub struct GreedNetPainPattern {
|
||||
pub pain_index: CentsUsdPattern2,
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct InvestorPricePattern {
|
||||
pub investor_lower_band: CentsSatsUsdPattern,
|
||||
pub investor_upper_band: CentsSatsUsdPattern,
|
||||
pub price: BpsCentsPercentilesRatioSatsUsdPattern,
|
||||
}
|
||||
|
||||
impl InvestorPricePattern {
|
||||
/// Create a new pattern node with accumulated series name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
|
||||
Self {
|
||||
investor_lower_band: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "lower_band")),
|
||||
investor_upper_band: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "upper_band")),
|
||||
price: BpsCentsPercentilesRatioSatsUsdPattern::new(client.clone(), _m(&acc, "price")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct LossNuplProfitPattern {
|
||||
pub loss: BaseCumulativeNegativeSumPattern,
|
||||
@@ -2896,6 +2878,20 @@ impl NuplPattern {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct PricePattern {
|
||||
pub price: BpsCentsPercentilesRatioSatsUsdPattern,
|
||||
}
|
||||
|
||||
impl PricePattern {
|
||||
/// Create a new pattern node with accumulated series name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
|
||||
Self {
|
||||
price: BpsCentsPercentilesRatioSatsUsdPattern::new(client.clone(), acc.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct UnspentPattern {
|
||||
pub unspent_count: BaseDeltaPattern,
|
||||
@@ -6313,7 +6309,7 @@ pub struct SeriesTree_Cohorts_Utxo_All_Realized {
|
||||
pub gross_pnl: BaseCumulativeSumPattern3,
|
||||
pub sell_side_risk_ratio: _1m1w1y24hPattern6,
|
||||
pub peak_regret: BaseCumulativeToPattern,
|
||||
pub investor: InvestorPricePattern,
|
||||
pub investor: PricePattern,
|
||||
pub profit_to_loss_ratio: _1m1w1y24hPattern<StoredF64>,
|
||||
}
|
||||
|
||||
@@ -6330,7 +6326,7 @@ impl SeriesTree_Cohorts_Utxo_All_Realized {
|
||||
gross_pnl: BaseCumulativeSumPattern3::new(client.clone(), "realized_gross_pnl".to_string()),
|
||||
sell_side_risk_ratio: _1m1w1y24hPattern6::new(client.clone(), "sell_side_risk_ratio".to_string()),
|
||||
peak_regret: BaseCumulativeToPattern::new(client.clone(), "realized_peak_regret".to_string()),
|
||||
investor: InvestorPricePattern::new(client.clone(), "investor".to_string()),
|
||||
investor: PricePattern::new(client.clone(), "investor_price".to_string()),
|
||||
profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), "realized_profit_to_loss_ratio".to_string()),
|
||||
}
|
||||
}
|
||||
@@ -6812,7 +6808,7 @@ pub struct SeriesTree_Cohorts_Utxo_Sth_Realized {
|
||||
pub gross_pnl: BaseCumulativeSumPattern3,
|
||||
pub sell_side_risk_ratio: _1m1w1y24hPattern6,
|
||||
pub peak_regret: BaseCumulativeToPattern,
|
||||
pub investor: InvestorPricePattern,
|
||||
pub investor: PricePattern,
|
||||
pub profit_to_loss_ratio: _1m1w1y24hPattern<StoredF64>,
|
||||
}
|
||||
|
||||
@@ -6829,7 +6825,7 @@ impl SeriesTree_Cohorts_Utxo_Sth_Realized {
|
||||
gross_pnl: BaseCumulativeSumPattern3::new(client.clone(), "sth_realized_gross_pnl".to_string()),
|
||||
sell_side_risk_ratio: _1m1w1y24hPattern6::new(client.clone(), "sth_sell_side_risk_ratio".to_string()),
|
||||
peak_regret: BaseCumulativeToPattern::new(client.clone(), "sth_realized_peak_regret".to_string()),
|
||||
investor: InvestorPricePattern::new(client.clone(), "sth_investor".to_string()),
|
||||
investor: PricePattern::new(client.clone(), "sth_investor_price".to_string()),
|
||||
profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), "sth_realized_profit_to_loss_ratio".to_string()),
|
||||
}
|
||||
}
|
||||
@@ -7250,7 +7246,7 @@ pub struct SeriesTree_Cohorts_Utxo_Lth_Realized {
|
||||
pub gross_pnl: BaseCumulativeSumPattern3,
|
||||
pub sell_side_risk_ratio: _1m1w1y24hPattern6,
|
||||
pub peak_regret: BaseCumulativeToPattern,
|
||||
pub investor: InvestorPricePattern,
|
||||
pub investor: PricePattern,
|
||||
pub profit_to_loss_ratio: _1m1w1y24hPattern<StoredF64>,
|
||||
}
|
||||
|
||||
@@ -7267,7 +7263,7 @@ impl SeriesTree_Cohorts_Utxo_Lth_Realized {
|
||||
gross_pnl: BaseCumulativeSumPattern3::new(client.clone(), "lth_realized_gross_pnl".to_string()),
|
||||
sell_side_risk_ratio: _1m1w1y24hPattern6::new(client.clone(), "lth_sell_side_risk_ratio".to_string()),
|
||||
peak_regret: BaseCumulativeToPattern::new(client.clone(), "lth_realized_peak_regret".to_string()),
|
||||
investor: InvestorPricePattern::new(client.clone(), "lth_investor".to_string()),
|
||||
investor: PricePattern::new(client.clone(), "lth_investor_price".to_string()),
|
||||
profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), "lth_realized_profit_to_loss_ratio".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@ pub struct Date(u32);
|
||||
impl Date {
|
||||
pub const INDEX_ZERO: Self = Self(20090101);
|
||||
pub const INDEX_ZERO_: Date_ = Date_::constant(2009, 1, 1);
|
||||
pub const MIN_RATIO: Self = Self(20120101);
|
||||
|
||||
pub fn new(year: u16, month: u8, day: u8) -> Self {
|
||||
Self(year as u32 * 1_00_00 + month as u32 * 1_00 + day as u32)
|
||||
|
||||
Reference in New Issue
Block a user