mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: snapshot
This commit is contained in:
@@ -66,7 +66,6 @@ impl Vecs {
|
||||
self.pricing.compute(
|
||||
starting_indexes,
|
||||
prices,
|
||||
blocks,
|
||||
distribution,
|
||||
&self.activity,
|
||||
&self.supply,
|
||||
|
||||
@@ -4,7 +4,7 @@ use vecdb::{Exit, VecIndex};
|
||||
|
||||
use super::super::{activity, cap, supply};
|
||||
use super::Vecs;
|
||||
use crate::{blocks, distribution, prices};
|
||||
use crate::{distribution, prices};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -12,7 +12,6 @@ impl Vecs {
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
prices: &prices::Vecs,
|
||||
blocks: &blocks::Vecs,
|
||||
distribution: &distribution::Vecs,
|
||||
activity: &activity::Vecs,
|
||||
supply: &supply::Vecs,
|
||||
@@ -24,74 +23,70 @@ impl Vecs {
|
||||
let realized_price = &all_metrics.realized.price.cents.height;
|
||||
let realized_cap = &all_metrics.realized.cap.cents.height;
|
||||
|
||||
self.vaulted_price.cents.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
realized_price,
|
||||
&activity.vaultedness.height,
|
||||
|(i, price, vaultedness, ..)| {
|
||||
(i, Cents::from(f64::from(price) / f64::from(vaultedness)))
|
||||
self.vaulted_price.compute_all(
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
realized_price,
|
||||
&activity.vaultedness.height,
|
||||
|(i, price, vaultedness, ..)| {
|
||||
(i, Cents::from(f64::from(price) / f64::from(vaultedness)))
|
||||
},
|
||||
exit,
|
||||
)?)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.vaulted_price_ratio.compute_rest(
|
||||
blocks,
|
||||
self.active_price.compute_all(
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.vaulted_price.cents.height,
|
||||
)?;
|
||||
|
||||
self.active_price.cents.height.compute_multiply(
|
||||
starting_indexes.height,
|
||||
realized_price,
|
||||
&activity.liveliness.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.active_price_ratio.compute_rest(
|
||||
blocks,
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.active_price.cents.height,
|
||||
)?;
|
||||
|
||||
self.true_market_mean.cents.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&cap.investor_cap.cents.height,
|
||||
&supply.active_supply.btc.height,
|
||||
|(i, cap_cents, supply_btc, ..)| {
|
||||
(i, Cents::from(f64::from(cap_cents) / f64::from(supply_btc)))
|
||||
|v| {
|
||||
Ok(v.compute_multiply(
|
||||
starting_indexes.height,
|
||||
realized_price,
|
||||
&activity.liveliness.height,
|
||||
exit,
|
||||
)?)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.true_market_mean_ratio.compute_rest(
|
||||
blocks,
|
||||
self.true_market_mean.compute_all(
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.true_market_mean.cents.height,
|
||||
|v| {
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&cap.investor_cap.cents.height,
|
||||
&supply.active_supply.btc.height,
|
||||
|(i, cap_cents, supply_btc, ..)| {
|
||||
(i, Cents::from(f64::from(cap_cents) / f64::from(supply_btc)))
|
||||
},
|
||||
exit,
|
||||
)?)
|
||||
},
|
||||
)?;
|
||||
|
||||
// cointime_price = cointime_cap / circulating_supply
|
||||
self.cointime_price.cents.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&cap.cointime_cap.cents.height,
|
||||
circulating_supply,
|
||||
|(i, cap_cents, supply_btc, ..)| {
|
||||
(i, Cents::from(f64::from(cap_cents) / f64::from(supply_btc)))
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.cointime_price_ratio.compute_rest(
|
||||
blocks,
|
||||
self.cointime_price.compute_all(
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.cointime_price.cents.height,
|
||||
|v| {
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&cap.cointime_cap.cents.height,
|
||||
circulating_supply,
|
||||
|(i, cap_cents, supply_btc, ..)| {
|
||||
(i, Cents::from(f64::from(cap_cents) / f64::from(supply_btc)))
|
||||
},
|
||||
exit,
|
||||
)?)
|
||||
},
|
||||
)?;
|
||||
|
||||
// transfer_price = cointime_price - vaulted_price
|
||||
@@ -99,38 +94,20 @@ impl Vecs {
|
||||
starting_indexes.height,
|
||||
&self.cointime_price.cents.height,
|
||||
&self.vaulted_price.cents.height,
|
||||
|(i, cointime, vaulted, ..)| {
|
||||
(i, cointime.saturating_sub(vaulted))
|
||||
},
|
||||
|(i, cointime, vaulted, ..)| (i, cointime.saturating_sub(vaulted)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.transfer_price_ratio.compute_rest(
|
||||
blocks,
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.transfer_price.cents.height,
|
||||
)?;
|
||||
self.transfer_price.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
// balanced_price = (realized_price + transfer_price) / 2
|
||||
self.balanced_price.cents.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
realized_price,
|
||||
&self.transfer_price.cents.height,
|
||||
|(i, realized, transfer, ..)| {
|
||||
(i, (realized + transfer) / 2u64)
|
||||
},
|
||||
|(i, realized, transfer, ..)| (i, (realized + transfer) / 2u64),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.balanced_price_ratio.compute_rest(
|
||||
blocks,
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.balanced_price.cents.height,
|
||||
)?;
|
||||
self.balanced_price.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
// terminal_price = 21M × transfer_price / circulating_supply_btc
|
||||
self.terminal_price.cents.height.compute_transform2(
|
||||
@@ -147,14 +124,7 @@ impl Vecs {
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.terminal_price_ratio.compute_rest(
|
||||
blocks,
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.terminal_price.cents.height,
|
||||
)?;
|
||||
self.terminal_price.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
// cumulative_market_cap = Σ(market_cap) in dollars
|
||||
self.cumulative_market_cap
|
||||
@@ -183,14 +153,7 @@ impl Vecs {
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.delta_price_ratio.compute_rest(
|
||||
blocks,
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.delta_price.cents.height,
|
||||
)?;
|
||||
self.delta_price.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedPerBlock, RatioPerBlockExtended, Price},
|
||||
internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -14,63 +14,27 @@ impl Vecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let vaulted_price = Price::forced_import(db, "vaulted_price", version, indexes)?;
|
||||
let vaulted_price_ratio =
|
||||
RatioPerBlockExtended::forced_import(db, "vaulted_price", version, indexes)?;
|
||||
|
||||
let active_price = Price::forced_import(db, "active_price", version, indexes)?;
|
||||
let active_price_ratio =
|
||||
RatioPerBlockExtended::forced_import(db, "active_price", version, indexes)?;
|
||||
|
||||
let true_market_mean = Price::forced_import(db, "true_market_mean", version, indexes)?;
|
||||
let true_market_mean_ratio = RatioPerBlockExtended::forced_import(
|
||||
db,
|
||||
"true_market_mean",
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let cointime_price = Price::forced_import(db, "cointime_price", version, indexes)?;
|
||||
let cointime_price_ratio =
|
||||
RatioPerBlockExtended::forced_import(db, "cointime_price", version, indexes)?;
|
||||
|
||||
let transfer_price = Price::forced_import(db, "transfer_price", version, indexes)?;
|
||||
let transfer_price_ratio =
|
||||
RatioPerBlockExtended::forced_import(db, "transfer_price", version, indexes)?;
|
||||
|
||||
let balanced_price = Price::forced_import(db, "balanced_price", version, indexes)?;
|
||||
let balanced_price_ratio =
|
||||
RatioPerBlockExtended::forced_import(db, "balanced_price", version, indexes)?;
|
||||
|
||||
let terminal_price = Price::forced_import(db, "terminal_price", version, indexes)?;
|
||||
let terminal_price_ratio =
|
||||
RatioPerBlockExtended::forced_import(db, "terminal_price", version, indexes)?;
|
||||
|
||||
let delta_price = Price::forced_import(db, "delta_price", version, indexes)?;
|
||||
let delta_price_ratio =
|
||||
RatioPerBlockExtended::forced_import(db, "delta_price", version, indexes)?;
|
||||
|
||||
let cumulative_market_cap =
|
||||
ComputedPerBlock::forced_import(db, "cumulative_market_cap", version, indexes)?;
|
||||
macro_rules! import {
|
||||
($name:expr) => {
|
||||
PriceWithRatioExtendedPerBlock::forced_import(db, $name, version, indexes)?
|
||||
};
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
vaulted_price,
|
||||
vaulted_price_ratio,
|
||||
active_price,
|
||||
active_price_ratio,
|
||||
true_market_mean,
|
||||
true_market_mean_ratio,
|
||||
cointime_price,
|
||||
cointime_price_ratio,
|
||||
transfer_price,
|
||||
transfer_price_ratio,
|
||||
balanced_price,
|
||||
balanced_price_ratio,
|
||||
terminal_price,
|
||||
terminal_price_ratio,
|
||||
delta_price,
|
||||
delta_price_ratio,
|
||||
cumulative_market_cap,
|
||||
vaulted_price: import!("vaulted_price"),
|
||||
active_price: import!("active_price"),
|
||||
true_market_mean: import!("true_market_mean"),
|
||||
cointime_price: import!("cointime_price"),
|
||||
transfer_price: import!("transfer_price"),
|
||||
balanced_price: import!("balanced_price"),
|
||||
terminal_price: import!("terminal_price"),
|
||||
delta_price: import!("delta_price"),
|
||||
cumulative_market_cap: ComputedPerBlock::forced_import(
|
||||
db,
|
||||
"cumulative_market_cap",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,19 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Dollars};
|
||||
use brk_types::Dollars;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedPerBlock, RatioPerBlockExtended, Price};
|
||||
use crate::internal::{ComputedPerBlock, PriceWithRatioExtendedPerBlock};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vaulted_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub vaulted_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub active_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub active_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub true_market_mean: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub true_market_mean_ratio: RatioPerBlockExtended<M>,
|
||||
pub cointime_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub cointime_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub transfer_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub transfer_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub balanced_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub balanced_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub terminal_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub terminal_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub delta_price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub delta_price_ratio: RatioPerBlockExtended<M>,
|
||||
pub vaulted_price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub active_price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub true_market_mean: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub cointime_price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub transfer_price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub balanced_price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub terminal_price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub delta_price: PriceWithRatioExtendedPerBlock<M>,
|
||||
|
||||
pub cumulative_market_cap: ComputedPerBlock<Dollars, M>,
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ pub struct AddressCohortVecs<M: StorageMode = Rw> {
|
||||
pub metrics: MinimalCohortMetrics<M>,
|
||||
|
||||
pub addr_count: ComputedPerBlock<StoredU64, M>,
|
||||
#[traversable(wrap = "addr_count", rename = "delta")]
|
||||
pub addr_count_delta: RollingDelta1m<StoredU64, StoredI64, M>,
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,18 @@ pub(super) struct CostBasisNode {
|
||||
sth_usd: i128,
|
||||
}
|
||||
|
||||
impl CostBasisNode {
|
||||
#[inline]
|
||||
fn new(sats: i64, usd: i128, is_sth: bool) -> Self {
|
||||
Self {
|
||||
all_sats: sats,
|
||||
sth_sats: if is_sth { sats } else { 0 },
|
||||
all_usd: usd,
|
||||
sth_usd: if is_sth { usd } else { 0 },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FenwickNode for CostBasisNode {
|
||||
#[inline(always)]
|
||||
fn add_assign(&mut self, other: &Self) {
|
||||
@@ -87,15 +99,13 @@ fn bucket_to_cents(bucket: usize) -> Cents {
|
||||
/// Map a CentsCompact price to a bucket index.
|
||||
#[inline]
|
||||
fn price_to_bucket(price: CentsCompact) -> usize {
|
||||
let rounded = Cents::from(price).round_to_dollar(COST_BASIS_PRICE_DIGITS);
|
||||
dollars_to_bucket(u64::from(rounded) / 100)
|
||||
cents_to_bucket(price.into())
|
||||
}
|
||||
|
||||
/// Map a Cents price to a bucket index.
|
||||
#[inline]
|
||||
fn cents_to_bucket(price: Cents) -> usize {
|
||||
let rounded = price.round_to_dollar(COST_BASIS_PRICE_DIGITS);
|
||||
dollars_to_bucket(u64::from(rounded) / 100)
|
||||
dollars_to_bucket(u64::from(price.round_to_dollar(COST_BASIS_PRICE_DIGITS)) / 100)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -143,13 +153,7 @@ impl CostBasisFenwick {
|
||||
return;
|
||||
}
|
||||
let bucket = price_to_bucket(price);
|
||||
let net_usd = price.as_u128() as i128 * net_sats as i128;
|
||||
let delta = CostBasisNode {
|
||||
all_sats: net_sats,
|
||||
sth_sats: if is_sth { net_sats } else { 0 },
|
||||
all_usd: net_usd,
|
||||
sth_usd: if is_sth { net_usd } else { 0 },
|
||||
};
|
||||
let delta = CostBasisNode::new(net_sats, price.as_u128() as i128 * net_sats as i128, is_sth);
|
||||
self.tree.add(bucket, &delta);
|
||||
self.totals.add_assign(&delta);
|
||||
}
|
||||
@@ -167,13 +171,7 @@ impl CostBasisFenwick {
|
||||
for (&price, &sats) in map.iter() {
|
||||
let bucket = price_to_bucket(price);
|
||||
let s = u64::from(sats) as i64;
|
||||
let usd = price.as_u128() as i128 * s as i128;
|
||||
let node = CostBasisNode {
|
||||
all_sats: s,
|
||||
sth_sats: if is_sth { s } else { 0 },
|
||||
all_usd: usd,
|
||||
sth_usd: if is_sth { usd } else { 0 },
|
||||
};
|
||||
let node = CostBasisNode::new(s, price.as_u128() as i128 * s as i128, is_sth);
|
||||
self.tree.add_raw(bucket, &node);
|
||||
self.totals.add_assign(&node);
|
||||
}
|
||||
@@ -242,9 +240,9 @@ impl CostBasisFenwick {
|
||||
.batch_kth(&sat_targets, &sat_field, &mut sat_buckets);
|
||||
|
||||
result.min_price = bucket_to_cents(sat_buckets[0]);
|
||||
for i in 0..PERCENTILES_LEN {
|
||||
(0..PERCENTILES_LEN).for_each(|i| {
|
||||
result.sat_prices[i] = bucket_to_cents(sat_buckets[i + 1]);
|
||||
}
|
||||
});
|
||||
result.max_price = bucket_to_cents(sat_buckets[PERCENTILES_LEN + 1]);
|
||||
|
||||
// USD-weighted percentiles (batch)
|
||||
@@ -266,6 +264,51 @@ impl CostBasisFenwick {
|
||||
result
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Supply density queries (±5% of spot price)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/// Compute supply density: % of supply with cost basis within ±5% of spot.
|
||||
/// Returns (all_bps, sth_bps, lth_bps) as basis points (0-10000).
|
||||
pub(super) fn density(&self, spot_price: Cents) -> (u16, u16, u16) {
|
||||
if self.totals.all_sats <= 0 {
|
||||
return (0, 0, 0);
|
||||
}
|
||||
|
||||
let spot_f64 = u64::from(spot_price) as f64;
|
||||
let low = Cents::from((spot_f64 * 0.95) as u64);
|
||||
let high = Cents::from((spot_f64 * 1.05) as u64);
|
||||
|
||||
let low_bucket = cents_to_bucket(low);
|
||||
let high_bucket = cents_to_bucket(high);
|
||||
|
||||
let cum_high = self.tree.prefix_sum(high_bucket);
|
||||
let cum_low = if low_bucket > 0 {
|
||||
self.tree.prefix_sum(low_bucket - 1)
|
||||
} else {
|
||||
CostBasisNode::default()
|
||||
};
|
||||
|
||||
let all_range = (cum_high.all_sats - cum_low.all_sats).max(0);
|
||||
let sth_range = (cum_high.sth_sats - cum_low.sth_sats).max(0);
|
||||
let lth_range = all_range - sth_range;
|
||||
|
||||
let to_bps = |range: i64, total: i64| -> u16 {
|
||||
if total <= 0 {
|
||||
0
|
||||
} else {
|
||||
(range as f64 / total as f64 * 10000.0) as u16
|
||||
}
|
||||
};
|
||||
|
||||
let lth_total = self.totals.all_sats - self.totals.sth_sats;
|
||||
(
|
||||
to_bps(all_range, self.totals.all_sats),
|
||||
to_bps(sth_range, self.totals.sth_sats),
|
||||
to_bps(lth_range, lth_total),
|
||||
)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Profitability queries (all cohort only)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::{cmp::Reverse, collections::BinaryHeap, fs, path::Path};
|
||||
|
||||
use brk_cohort::{Filtered, PROFITABILITY_RANGE_COUNT, PROFIT_COUNT, TERM_NAMES};
|
||||
use brk_error::Result;
|
||||
use brk_types::{Cents, CentsCompact, CostBasisDistribution, Date, Dollars, Height, Sats};
|
||||
use brk_types::{BasisPoints16, Cents, CentsCompact, CostBasisDistribution, Date, Dollars, Height, Sats};
|
||||
|
||||
use crate::distribution::metrics::{CostBasis, ProfitabilityMetrics};
|
||||
|
||||
@@ -24,12 +24,7 @@ impl UTXOCohorts {
|
||||
states_path: &Path,
|
||||
) -> Result<()> {
|
||||
if self.fenwick.is_initialized() {
|
||||
// Per-block accurate percentiles from Fenwick tree
|
||||
self.push_percentiles_from_fenwick(height)?;
|
||||
|
||||
// Per-block accurate profitability from Fenwick tree with current spot_price
|
||||
let prof = self.fenwick.profitability(spot_price);
|
||||
push_profitability(height, &prof, &mut self.profitability)?;
|
||||
self.push_fenwick_results(height, spot_price)?;
|
||||
}
|
||||
|
||||
// Disk distributions only at day boundaries
|
||||
@@ -40,18 +35,21 @@ impl UTXOCohorts {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Push Fenwick-computed percentiles for all/sth/lth to vecs.
|
||||
fn push_percentiles_from_fenwick(&mut self, height: Height) -> Result<()> {
|
||||
/// Push all Fenwick-derived per-block results: percentiles, density, profitability.
|
||||
fn push_fenwick_results(&mut self, height: Height, spot_price: Cents) -> Result<()> {
|
||||
let (all_d, sth_d, lth_d) = self.fenwick.density(spot_price);
|
||||
|
||||
let all = self.fenwick.percentiles_all();
|
||||
push_percentile_result(height, &all, &mut self.all.metrics.cost_basis)?;
|
||||
push_cost_basis(height, &all, all_d, &mut self.all.metrics.cost_basis)?;
|
||||
|
||||
let sth = self.fenwick.percentiles_sth();
|
||||
push_percentile_result(height, &sth, &mut self.sth.metrics.cost_basis)?;
|
||||
push_cost_basis(height, &sth, sth_d, &mut self.sth.metrics.cost_basis)?;
|
||||
|
||||
let lth = self.fenwick.percentiles_lth();
|
||||
push_percentile_result(height, <h, &mut self.lth.metrics.cost_basis)?;
|
||||
push_cost_basis(height, <h, lth_d, &mut self.lth.metrics.cost_basis)?;
|
||||
|
||||
Ok(())
|
||||
let prof = self.fenwick.profitability(spot_price);
|
||||
push_profitability(height, &prof, &mut self.profitability)
|
||||
}
|
||||
|
||||
/// K-way merge only for writing daily cost basis distributions to disk.
|
||||
@@ -93,14 +91,16 @@ impl UTXOCohorts {
|
||||
}
|
||||
}
|
||||
|
||||
/// Push a PercentileResult to cost basis vecs.
|
||||
fn push_percentile_result(
|
||||
/// Push percentiles + density to cost basis vecs.
|
||||
fn push_cost_basis(
|
||||
height: Height,
|
||||
result: &PercentileResult,
|
||||
percentiles: &PercentileResult,
|
||||
density_bps: u16,
|
||||
cost_basis: &mut CostBasis,
|
||||
) -> Result<()> {
|
||||
cost_basis.truncate_push_minmax(height, result.min_price, result.max_price)?;
|
||||
cost_basis.truncate_push_percentiles(height, &result.sat_prices, &result.usd_prices)
|
||||
cost_basis.truncate_push_minmax(height, percentiles.min_price, percentiles.max_price)?;
|
||||
cost_basis.truncate_push_percentiles(height, &percentiles.sat_prices, &percentiles.usd_prices)?;
|
||||
cost_basis.truncate_push_density(height, BasisPoints16::from(density_bps))
|
||||
}
|
||||
|
||||
/// Convert raw (cents × sats) accumulator to Dollars (÷ 100 for cents→dollars, ÷ 1e8 for sats).
|
||||
|
||||
@@ -6,13 +6,18 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
use crate::{
|
||||
blocks,
|
||||
distribution::{metrics::ImportConfig, state::{CohortState, CostBasisOps, RealizedOps}},
|
||||
internal::PerBlockWithSum24h,
|
||||
internal::{AmountPerBlockWithSum24h, PerBlockWithSum24h},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ActivityCore<M: StorageMode = Rw> {
|
||||
pub sent: PerBlockWithSum24h<Sats, M>,
|
||||
pub coindays_destroyed: PerBlockWithSum24h<StoredF64, M>,
|
||||
#[traversable(wrap = "sent", rename = "in_profit")]
|
||||
pub sent_in_profit: AmountPerBlockWithSum24h<M>,
|
||||
#[traversable(wrap = "sent", rename = "in_loss")]
|
||||
pub sent_in_loss: AmountPerBlockWithSum24h<M>,
|
||||
}
|
||||
|
||||
impl ActivityCore {
|
||||
@@ -21,6 +26,8 @@ impl ActivityCore {
|
||||
Ok(Self {
|
||||
sent: cfg.import("sent", v1)?,
|
||||
coindays_destroyed: cfg.import("coindays_destroyed", v1)?,
|
||||
sent_in_profit: cfg.import("sent_in_profit", v1)?,
|
||||
sent_in_loss: cfg.import("sent_in_loss", v1)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,6 +37,8 @@ impl ActivityCore {
|
||||
.height
|
||||
.len()
|
||||
.min(self.coindays_destroyed.raw.height.len())
|
||||
.min(self.sent_in_profit.raw.sats.height.len())
|
||||
.min(self.sent_in_loss.raw.sats.height.len())
|
||||
}
|
||||
|
||||
pub(crate) fn truncate_push(
|
||||
@@ -42,6 +51,16 @@ impl ActivityCore {
|
||||
height,
|
||||
StoredF64::from(Bitcoin::from(state.satdays_destroyed)),
|
||||
)?;
|
||||
self.sent_in_profit
|
||||
.raw
|
||||
.sats
|
||||
.height
|
||||
.truncate_push(height, state.realized.sent_in_profit())?;
|
||||
self.sent_in_loss
|
||||
.raw
|
||||
.sats
|
||||
.height
|
||||
.truncate_push(height, state.realized.sent_in_loss())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -49,6 +68,10 @@ impl ActivityCore {
|
||||
vec![
|
||||
&mut self.sent.raw.height as &mut dyn AnyStoredVec,
|
||||
&mut self.coindays_destroyed.raw.height,
|
||||
&mut self.sent_in_profit.raw.sats.height,
|
||||
&mut self.sent_in_profit.raw.cents.height,
|
||||
&mut self.sent_in_loss.raw.sats.height,
|
||||
&mut self.sent_in_loss.raw.cents.height,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -72,6 +95,10 @@ impl ActivityCore {
|
||||
)?;
|
||||
|
||||
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.raw.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent_in_profit.raw.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent_in_profit.raw.cents.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent_in_loss.raw.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent_in_loss.raw.cents.height);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -96,4 +123,36 @@ impl ActivityCore {
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn compute_sent_profitability(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sent_in_profit
|
||||
.raw
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
self.sent_in_loss
|
||||
.raw
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
|
||||
self.sent_in_profit.sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback.height_24h_ago,
|
||||
&self.sent_in_profit.raw.sats.height,
|
||||
&self.sent_in_profit.raw.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
self.sent_in_loss.sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback.height_24h_ago,
|
||||
&self.sent_in_loss.raw.sats.height,
|
||||
&self.sent_in_loss.raw.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ pub struct ActivityFull<M: StorageMode = Rw> {
|
||||
|
||||
#[traversable(wrap = "sent", rename = "sum")]
|
||||
pub sent_sum_extended: RollingWindowsFrom1w<Sats, M>,
|
||||
#[traversable(wrap = "sent/in_profit", rename = "sum")]
|
||||
pub sent_in_profit_sum_extended: RollingWindowsFrom1w<Sats, M>,
|
||||
#[traversable(wrap = "sent/in_loss", rename = "sum")]
|
||||
pub sent_in_loss_sum_extended: RollingWindowsFrom1w<Sats, M>,
|
||||
|
||||
pub coinyears_destroyed: LazyPerBlock<StoredF64, StoredF64>,
|
||||
|
||||
@@ -49,6 +53,8 @@ impl ActivityFull {
|
||||
coindays_destroyed_cumulative: cfg.import("coindays_destroyed_cumulative", v1)?,
|
||||
coindays_destroyed_sum,
|
||||
sent_sum_extended: cfg.import("sent", v1)?,
|
||||
sent_in_profit_sum_extended: cfg.import("sent_in_profit", v1)?,
|
||||
sent_in_loss_sum_extended: cfg.import("sent_in_loss", v1)?,
|
||||
coinyears_destroyed,
|
||||
dormancy: cfg.import("dormancy", v1)?,
|
||||
velocity: cfg.import("velocity", v1)?,
|
||||
@@ -116,6 +122,19 @@ impl ActivityFull {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.sent_in_profit_sum_extended.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.inner.sent_in_profit.raw.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
self.sent_in_loss_sum_extended.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.inner.sent_in_loss.raw.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ pub struct AllCohortMetrics<M: StorageMode = Rw> {
|
||||
|
||||
#[traversable(wrap = "supply", rename = "delta")]
|
||||
pub supply_delta_extended: RollingDeltaExcept1m<Sats, SatsSigned, M>,
|
||||
#[traversable(wrap = "outputs", rename = "utxo_count_delta")]
|
||||
#[traversable(wrap = "outputs/utxo_count", rename = "delta")]
|
||||
pub utxo_count_delta_extended: RollingDeltaExcept1m<StoredU64, StoredI64, M>,
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +114,8 @@ impl CoreCohortMetrics {
|
||||
|
||||
self.activity
|
||||
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
self.activity
|
||||
.compute_sent_profitability(blocks, prices, starting_indexes, exit)?;
|
||||
|
||||
self.realized
|
||||
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
|
||||
@@ -33,7 +33,7 @@ pub struct ExtendedCohortMetrics<M: StorageMode = Rw> {
|
||||
|
||||
#[traversable(wrap = "supply", rename = "delta")]
|
||||
pub supply_delta_extended: RollingDeltaExcept1m<Sats, SatsSigned, M>,
|
||||
#[traversable(wrap = "outputs", rename = "utxo_count_delta")]
|
||||
#[traversable(wrap = "outputs/utxo_count", rename = "delta")]
|
||||
pub utxo_count_delta_extended: RollingDeltaExcept1m<StoredU64, StoredI64, M>,
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::{
|
||||
internal::{
|
||||
AmountPerBlock, AmountPerBlockCumulative, AmountPerBlockWithSum24h, CentsType, ComputedPerBlock,
|
||||
ComputedPerBlockCumulative, ComputedPerBlockCumulativeSum, FiatPerBlockWithSum24h,
|
||||
PerBlockWithSum24h, RatioPerBlock, RollingWindow24hAmountPerBlock,
|
||||
PerBlockWithSum24h, PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock, RollingWindow24hAmountPerBlock,
|
||||
RollingWindow24hFiatPerBlock, RollingWindow24hPerBlock,
|
||||
FiatPerBlock, FiatRollingDelta1m, FiatRollingDeltaExcept1m, NumericValue,
|
||||
PercentPerBlock, PercentRollingWindows, Price, RollingDelta1m, RollingDeltaExcept1m,
|
||||
@@ -40,6 +40,8 @@ impl_config_import!(
|
||||
AmountPerBlock,
|
||||
AmountPerBlockCumulative,
|
||||
RollingWindow24hAmountPerBlock,
|
||||
PriceWithRatioPerBlock,
|
||||
PriceWithRatioExtendedPerBlock,
|
||||
RatioPerBlock<BasisPoints32>,
|
||||
RatioPerBlock<BasisPointsSigned32>,
|
||||
PercentPerBlock<BasisPoints16>,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Height, Version};
|
||||
use brk_types::{BasisPoints16, Cents, Height, Version};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::{ComputedPerBlock, PercentilesVecs, Price, PERCENTILES_LEN};
|
||||
use crate::internal::{ComputedPerBlock, PercentPerBlock, PercentilesVecs, Price, PERCENTILES_LEN};
|
||||
|
||||
use super::ImportConfig;
|
||||
|
||||
/// Cost basis metrics: min/max + percentiles.
|
||||
/// Cost basis metrics: min/max + percentiles + supply density.
|
||||
/// Used by all/sth/lth cohorts only.
|
||||
#[derive(Traversable)]
|
||||
pub struct CostBasis<M: StorageMode = Rw> {
|
||||
@@ -15,6 +15,7 @@ pub struct CostBasis<M: StorageMode = Rw> {
|
||||
pub max: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub percentiles: PercentilesVecs<M>,
|
||||
pub invested_capital: PercentilesVecs<M>,
|
||||
pub supply_density: PercentPerBlock<BasisPoints16, M>,
|
||||
}
|
||||
|
||||
impl CostBasis {
|
||||
@@ -34,11 +35,22 @@ impl CostBasis {
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
supply_density: PercentPerBlock::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("supply_density"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn min_stateful_height_len(&self) -> usize {
|
||||
self.min.cents.height.len().min(self.max.cents.height.len())
|
||||
self.min
|
||||
.cents
|
||||
.height
|
||||
.len()
|
||||
.min(self.max.cents.height.len())
|
||||
.min(self.supply_density.bps.height.len())
|
||||
}
|
||||
|
||||
pub(crate) fn truncate_push_minmax(
|
||||
@@ -63,6 +75,14 @@ impl CostBasis {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn truncate_push_density(
|
||||
&mut self,
|
||||
height: Height,
|
||||
density_bps: BasisPoints16,
|
||||
) -> Result<()> {
|
||||
Ok(self.supply_density.bps.height.truncate_push(height, density_bps)?)
|
||||
}
|
||||
|
||||
pub(crate) fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
self.percentiles
|
||||
.validate_computed_version_or_reset(base_version)?;
|
||||
@@ -75,6 +95,7 @@ impl CostBasis {
|
||||
let mut vecs: Vec<&mut dyn AnyStoredVec> = vec![
|
||||
&mut self.min.cents.height,
|
||||
&mut self.max.cents.height,
|
||||
&mut self.supply_density.bps.height,
|
||||
];
|
||||
vecs.extend(
|
||||
self.percentiles
|
||||
|
||||
@@ -188,6 +188,8 @@ pub trait CohortMetricsBase: CohortMetricsState<Realized = RealizedState, CostBa
|
||||
.compute_rest(blocks, starting_indexes, exit)?;
|
||||
self.activity_mut()
|
||||
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
self.activity_core_mut()
|
||||
.compute_sent_profitability(blocks, prices, starting_indexes, exit)?;
|
||||
|
||||
self.realized_mut()
|
||||
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
|
||||
@@ -18,6 +18,7 @@ pub struct OutputsFull<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub base: OutputsBase<M>,
|
||||
|
||||
#[traversable(wrap = "utxo_count", rename = "delta")]
|
||||
pub utxo_count_delta: RollingDelta1m<StoredU64, StoredI64, M>,
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, CentsSigned, Dollars, Height, Indexes, StoredF64, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{
|
||||
AnyStoredVec, AnyVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode, WritableVec,
|
||||
AnyStoredVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
blocks,
|
||||
distribution::state::{CohortState, CostBasisOps, RealizedOps},
|
||||
internal::{
|
||||
AmountPerBlockWithSum24h, ComputedPerBlock, FiatRollingDelta1m, LazyPerBlock,
|
||||
ComputedPerBlock, FiatRollingDelta1m, LazyPerBlock,
|
||||
NegCentsUnsignedToDollars, PerBlockWithSum24h, RatioCents64,
|
||||
RollingWindow24hPerBlock,
|
||||
},
|
||||
@@ -26,12 +26,6 @@ pub struct RealizedSoprCore<M: StorageMode = Rw> {
|
||||
pub ratio: RollingWindow24hPerBlock<StoredF64, M>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedSentCore<M: StorageMode = Rw> {
|
||||
pub in_profit: AmountPerBlockWithSum24h<M>,
|
||||
pub in_loss: AmountPerBlockWithSum24h<M>,
|
||||
}
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct RealizedCore<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
@@ -51,7 +45,6 @@ pub struct RealizedCore<M: StorageMode = Rw> {
|
||||
pub neg_loss: LazyPerBlock<Dollars, Cents>,
|
||||
pub net_pnl: PerBlockWithSum24h<CentsSigned, M>,
|
||||
pub sopr: RealizedSoprCore<M>,
|
||||
pub sent: RealizedSentCore<M>,
|
||||
}
|
||||
|
||||
impl RealizedCore {
|
||||
@@ -78,44 +71,20 @@ impl RealizedCore {
|
||||
sopr: RealizedSoprCore {
|
||||
ratio: cfg.import("sopr", v1)?,
|
||||
},
|
||||
sent: RealizedSentCore {
|
||||
in_profit: cfg.import("sent_in_profit", v1)?,
|
||||
in_loss: cfg.import("sent_in_loss", v1)?,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn min_stateful_height_len(&self) -> usize {
|
||||
self.minimal
|
||||
.min_stateful_height_len()
|
||||
.min(self.sent.in_profit.raw.sats.height.len())
|
||||
.min(self.sent.in_loss.raw.sats.height.len())
|
||||
self.minimal.min_stateful_height_len()
|
||||
}
|
||||
|
||||
pub(crate) fn truncate_push(&mut self, height: Height, state: &CohortState<impl RealizedOps, impl CostBasisOps>) -> Result<()> {
|
||||
self.minimal.truncate_push(height, state)?;
|
||||
self.sent
|
||||
.in_profit
|
||||
.raw
|
||||
.sats
|
||||
.height
|
||||
.truncate_push(height, state.realized.sent_in_profit())?;
|
||||
self.sent
|
||||
.in_loss
|
||||
.raw
|
||||
.sats
|
||||
.height
|
||||
.truncate_push(height, state.realized.sent_in_loss())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs = self.minimal.collect_vecs_mut();
|
||||
vecs.push(&mut self.sent.in_profit.raw.sats.height as &mut dyn AnyStoredVec);
|
||||
vecs.push(&mut self.sent.in_profit.raw.cents.height);
|
||||
vecs.push(&mut self.sent.in_loss.raw.sats.height);
|
||||
vecs.push(&mut self.sent.in_loss.raw.cents.height);
|
||||
vecs
|
||||
self.minimal.collect_vecs_mut()
|
||||
}
|
||||
|
||||
pub(crate) fn compute_from_stateful(
|
||||
@@ -128,11 +97,6 @@ impl RealizedCore {
|
||||
self.minimal
|
||||
.compute_from_stateful(starting_indexes, &minimal_refs, exit)?;
|
||||
|
||||
sum_others!(self, starting_indexes, others, exit; sent.in_profit.raw.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent.in_profit.raw.cents.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent.in_loss.raw.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent.in_loss.raw.cents.height);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -207,30 +171,6 @@ impl RealizedCore {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.sent
|
||||
.in_profit
|
||||
.raw
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
self.sent
|
||||
.in_loss
|
||||
.raw
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
|
||||
self.sent.in_profit.sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback.height_24h_ago,
|
||||
&self.sent.in_profit.raw.sats.height,
|
||||
&self.sent.in_profit.raw.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
self.sent.in_loss.sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback.height_24h_ago,
|
||||
&self.sent.in_loss.raw.sats.height,
|
||||
&self.sent.in_loss.raw.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
BasisPoints32, BasisPointsSigned32, Bitcoin, Cents, CentsSats, CentsSigned, CentsSquaredSats,
|
||||
Dollars, Height, Indexes, Sats, StoredF64, Version,
|
||||
Dollars, Height, Indexes, StoredF64, Version,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{
|
||||
@@ -16,9 +16,10 @@ use crate::{
|
||||
internal::{
|
||||
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative, FiatPerBlock,
|
||||
FiatRollingDelta1m, FiatRollingDeltaExcept1m, LazyPerBlock, PercentPerBlock,
|
||||
PercentRollingWindows, Price, RatioCents64, RatioCentsBp32, RatioCentsSignedCentsBps32,
|
||||
RatioCentsSignedDollarsBps32, RatioDollarsBp32, RatioPerBlock, RatioPerBlockPercentiles,
|
||||
RatioPerBlockStdDevBands, RollingWindows, RollingWindowsFrom1w,
|
||||
PercentRollingWindows, Price, PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
|
||||
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
|
||||
RatioPerBlockPercentiles, RatioPerBlockStdDevBands, RatioSma, RollingWindows,
|
||||
RollingWindowsFrom1w,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -87,14 +88,6 @@ pub struct RealizedSopr<M: StorageMode = Rw> {
|
||||
pub ratio_extended: RollingWindowsFrom1w<StoredF64, M>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedSentFull<M: StorageMode = Rw> {
|
||||
#[traversable(wrap = "in_profit", rename = "sum")]
|
||||
pub in_profit_sum_extended: RollingWindowsFrom1w<Sats, M>,
|
||||
#[traversable(wrap = "in_loss", rename = "sum")]
|
||||
pub in_loss_sum_extended: RollingWindowsFrom1w<Sats, M>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
@@ -104,13 +97,11 @@ pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedInvestor<M: StorageMode = Rw> {
|
||||
pub price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub price_ratio: RatioPerBlock<BasisPoints32, M>,
|
||||
pub price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub lower_price_band: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub upper_price_band: Price<ComputedPerBlock<Cents, M>>,
|
||||
#[traversable(wrap = "cap", rename = "raw")]
|
||||
pub cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
|
||||
pub price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
||||
}
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
@@ -125,7 +116,6 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
||||
pub gross_pnl: RealizedGrossPnl<M>,
|
||||
pub net_pnl: RealizedNetPnl<M>,
|
||||
pub sopr: RealizedSopr<M>,
|
||||
pub sent: RealizedSentFull<M>,
|
||||
pub peak_regret: RealizedPeakRegret<M>,
|
||||
pub investor: RealizedInvestor<M>,
|
||||
|
||||
@@ -139,9 +129,11 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
||||
#[traversable(wrap = "cap", rename = "rel_to_own_mcap")]
|
||||
pub cap_rel_to_own_mcap: PercentPerBlock<BasisPoints32, M>,
|
||||
|
||||
#[traversable(wrap = "price_ratio", rename = "percentiles")]
|
||||
#[traversable(wrap = "price", rename = "percentiles")]
|
||||
pub price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
||||
#[traversable(wrap = "price_ratio", rename = "std_dev")]
|
||||
#[traversable(wrap = "price", rename = "sma")]
|
||||
pub price_ratio_sma: RatioSma<M>,
|
||||
#[traversable(wrap = "price", rename = "std_dev")]
|
||||
pub price_ratio_std_dev: RatioPerBlockStdDevBands<M>,
|
||||
}
|
||||
|
||||
@@ -218,12 +210,6 @@ impl RealizedFull {
|
||||
ratio_extended: cfg.import("sopr", v1)?,
|
||||
};
|
||||
|
||||
// Sent
|
||||
let sent = RealizedSentFull {
|
||||
in_profit_sum_extended: cfg.import("sent_in_profit", v1)?,
|
||||
in_loss_sum_extended: cfg.import("sent_in_loss", v1)?,
|
||||
};
|
||||
|
||||
// Peak regret
|
||||
let peak_regret = RealizedPeakRegret {
|
||||
value: cfg.import("realized_peak_regret", Version::new(2))?,
|
||||
@@ -234,16 +220,9 @@ impl RealizedFull {
|
||||
// Investor
|
||||
let investor = RealizedInvestor {
|
||||
price: cfg.import("investor_price", v0)?,
|
||||
price_ratio: cfg.import("investor_price", v0)?,
|
||||
lower_price_band: cfg.import("lower_price_band", v0)?,
|
||||
upper_price_band: cfg.import("upper_price_band", v0)?,
|
||||
cap_raw: cfg.import("investor_cap_raw", v0)?,
|
||||
price_ratio_percentiles: RatioPerBlockPercentiles::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("investor_price"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
};
|
||||
|
||||
// Price ratio stats
|
||||
@@ -257,7 +236,6 @@ impl RealizedFull {
|
||||
gross_pnl,
|
||||
net_pnl,
|
||||
sopr,
|
||||
sent,
|
||||
peak_regret,
|
||||
investor,
|
||||
profit_to_loss_ratio: cfg.import("realized_profit_to_loss_ratio", v1)?,
|
||||
@@ -270,6 +248,12 @@ impl RealizedFull {
|
||||
realized_price_version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
price_ratio_sma: RatioSma::forced_import(
|
||||
cfg.db,
|
||||
&realized_price_name,
|
||||
realized_price_version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
price_ratio_std_dev: RatioPerBlockStdDevBands::forced_import(
|
||||
cfg.db,
|
||||
&realized_price_name,
|
||||
@@ -513,20 +497,6 @@ impl RealizedFull {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Sent rolling sums (1w, 1m, 1y)
|
||||
self.sent.in_profit_sum_extended.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.core.sent.in_profit.raw.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
self.sent.in_loss_sum_extended.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.core.sent.in_loss.raw.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Profit/loss value created/destroyed rolling sums
|
||||
self.profit.value_created_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
@@ -616,11 +586,10 @@ impl RealizedFull {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Investor price ratio and bands
|
||||
self.investor.price_ratio.compute_ratio(
|
||||
// Investor price ratio, percentiles and bands
|
||||
self.investor.price.compute_rest(
|
||||
prices,
|
||||
starting_indexes,
|
||||
&prices.price.cents.height,
|
||||
&self.investor.price.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -727,31 +696,28 @@ impl RealizedFull {
|
||||
)?;
|
||||
}
|
||||
|
||||
// Price ratio: percentiles and std dev bands
|
||||
// Price ratio: percentiles, sma and std dev bands
|
||||
self.price_ratio_percentiles.compute(
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.core.minimal.price.ratio.height,
|
||||
&self.core.minimal.price.cents.height,
|
||||
)?;
|
||||
|
||||
self.price_ratio_sma.compute(
|
||||
blocks,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.core.minimal.price_ratio.ratio.height,
|
||||
&self.core.minimal.price.cents.height,
|
||||
&self.core.minimal.price.ratio.height,
|
||||
)?;
|
||||
|
||||
self.price_ratio_std_dev.compute(
|
||||
blocks,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.core.minimal.price_ratio.ratio.height,
|
||||
&self.core.minimal.price.ratio.height,
|
||||
&self.core.minimal.price.cents.height,
|
||||
)?;
|
||||
|
||||
// Investor price ratio: percentiles
|
||||
let investor_price = &self.investor.price.cents.height;
|
||||
self.investor.price_ratio_percentiles.compute(
|
||||
blocks,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.investor.price_ratio.ratio.height,
|
||||
investor_price,
|
||||
&self.price_ratio_sma,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -12,8 +12,8 @@ use crate::{
|
||||
blocks,
|
||||
distribution::state::{CohortState, CostBasisOps, RealizedOps},
|
||||
internal::{
|
||||
ComputedPerBlock, FiatPerBlock, FiatPerBlockWithSum24h, Identity, LazyPerBlock,
|
||||
PerBlockWithSum24h, Price, RatioPerBlock,
|
||||
FiatPerBlock, FiatPerBlockWithSum24h, Identity, LazyPerBlock,
|
||||
PerBlockWithSum24h, PriceWithRatioPerBlock, RatioPerBlock,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -33,8 +33,7 @@ pub struct RealizedMinimal<M: StorageMode = Rw> {
|
||||
pub cap: FiatPerBlock<Cents, M>,
|
||||
pub profit: FiatPerBlockWithSum24h<Cents, M>,
|
||||
pub loss: FiatPerBlockWithSum24h<Cents, M>,
|
||||
pub price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub price_ratio: RatioPerBlock<BasisPoints32, M>,
|
||||
pub price: PriceWithRatioPerBlock<M>,
|
||||
pub mvrv: LazyPerBlock<StoredF32>,
|
||||
pub nupl: RatioPerBlock<BasisPointsSigned32, M>,
|
||||
|
||||
@@ -47,12 +46,11 @@ impl RealizedMinimal {
|
||||
|
||||
let cap: FiatPerBlock<Cents> = cfg.import("realized_cap", Version::ZERO)?;
|
||||
|
||||
let realized_price = cfg.import("realized_price", v1)?;
|
||||
let realized_price_ratio: RatioPerBlock = cfg.import("realized_price", v1)?;
|
||||
let price: PriceWithRatioPerBlock = cfg.import("realized_price", v1)?;
|
||||
let mvrv = LazyPerBlock::from_lazy::<Identity<StoredF32>, BasisPoints32>(
|
||||
&cfg.name("mvrv"),
|
||||
cfg.version,
|
||||
&realized_price_ratio.ratio,
|
||||
&price.ratio,
|
||||
);
|
||||
|
||||
let nupl = cfg.import("nupl", v1)?;
|
||||
@@ -61,8 +59,7 @@ impl RealizedMinimal {
|
||||
cap,
|
||||
profit: cfg.import("realized_profit", v1)?,
|
||||
loss: cfg.import("realized_loss", v1)?,
|
||||
price: realized_price,
|
||||
price_ratio: realized_price_ratio,
|
||||
price,
|
||||
mvrv,
|
||||
nupl,
|
||||
sopr: RealizedSoprMinimal {
|
||||
@@ -164,28 +161,24 @@ impl RealizedMinimal {
|
||||
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.price.cents.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.cap.cents.height,
|
||||
height_to_supply,
|
||||
|(i, cap_cents, supply, ..)| {
|
||||
let cap = cap_cents.as_u128();
|
||||
let supply_sats = Sats::from(supply).as_u128();
|
||||
if supply_sats == 0 {
|
||||
(i, Cents::ZERO)
|
||||
} else {
|
||||
(i, Cents::from(cap * Sats::ONE_BTC_U128 / supply_sats))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.price_ratio.compute_ratio(
|
||||
starting_indexes,
|
||||
&prices.price.cents.height,
|
||||
&self.price.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
let cap = &self.cap.cents.height;
|
||||
self.price.compute_all(prices, starting_indexes, exit, |v| {
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
cap,
|
||||
height_to_supply,
|
||||
|(i, cap_cents, supply, ..)| {
|
||||
let cap = cap_cents.as_u128();
|
||||
let supply_sats = Sats::from(supply).as_u128();
|
||||
if supply_sats == 0 {
|
||||
(i, Cents::ZERO)
|
||||
} else {
|
||||
(i, Cents::from(cap * Sats::ONE_BTC_U128 / supply_sats))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.nupl.bps.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Bitcoin, Dollars, Indexes, StoredF32};
|
||||
use vecdb::Exit;
|
||||
use brk_types::{Bitcoin, Dollars, Indexes, Sats, StoredF32};
|
||||
use vecdb::{Exit, ReadableVec};
|
||||
|
||||
use super::{gini, Vecs};
|
||||
use crate::{distribution, internal::RatioDollarsBp32, mining, transactions};
|
||||
use crate::{distribution, internal::RatioDollarsBp32, market, mining, transactions};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
mining: &mining::Vecs,
|
||||
distribution: &distribution::Vecs,
|
||||
transactions: &transactions::Vecs,
|
||||
market: &market::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -72,7 +74,6 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
// Thermocap Multiple: market_cap / thermo_cap
|
||||
// thermo_cap = cumulative subsidy in USD
|
||||
self.thermocap_multiple
|
||||
.bps
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||
@@ -82,15 +83,9 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let all_activity = &distribution.utxo_cohorts.all.metrics.activity;
|
||||
let supply_total_sats = &distribution
|
||||
.utxo_cohorts
|
||||
.all
|
||||
.metrics
|
||||
.supply
|
||||
.total
|
||||
.sats
|
||||
.height;
|
||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||
let all_activity = &all_metrics.activity;
|
||||
let supply_total_sats = &all_metrics.supply.total.sats.height;
|
||||
|
||||
// Supply-Adjusted CDD = sum_24h(CDD) / circulating_supply_btc
|
||||
self.coindays_destroyed_supply_adjusted
|
||||
@@ -110,7 +105,7 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Supply-Adjusted CYD = CYD / circulating_supply_btc (CYD = 1y rolling sum of CDD)
|
||||
// Supply-Adjusted CYD = CYD / circulating_supply_btc
|
||||
self.coinyears_destroyed_supply_adjusted
|
||||
.height
|
||||
.compute_transform2(
|
||||
@@ -146,6 +141,66 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Stock-to-Flow: supply / annual_issuance
|
||||
// annual_issuance ≈ subsidy_per_block × 52560 (blocks/year)
|
||||
self.stock_to_flow.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
supply_total_sats,
|
||||
&mining.rewards.subsidy.base.sats.height,
|
||||
|(i, supply_sats, subsidy_sats, ..)| {
|
||||
let annual_flow = subsidy_sats.as_u128() as f64 * 52560.0;
|
||||
if annual_flow == 0.0 {
|
||||
(i, StoredF32::from(0.0f32))
|
||||
} else {
|
||||
(i, StoredF32::from(
|
||||
(supply_sats.as_u128() as f64 / annual_flow) as f32,
|
||||
))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Dormancy Flow: supply_btc / dormancy
|
||||
self.dormancy_flow.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
supply_total_sats,
|
||||
&all_activity.dormancy.height,
|
||||
|(i, supply_sats, dormancy, ..)| {
|
||||
let d = f64::from(dormancy);
|
||||
if d == 0.0 {
|
||||
(i, StoredF32::from(0.0f32))
|
||||
} else {
|
||||
let supply = f64::from(Bitcoin::from(supply_sats));
|
||||
(i, StoredF32::from((supply / d) as f32))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Seller Exhaustion Constant: % supply_in_profit × 30d_volatility
|
||||
self.seller_exhaustion_constant
|
||||
.height
|
||||
.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&all_metrics.supply.in_profit.sats.height,
|
||||
&market.volatility._1m.height,
|
||||
|(i, profit_sats, volatility, ..)| {
|
||||
let total_sats: Sats = supply_total_sats
|
||||
.collect_one(i)
|
||||
.unwrap_or_default();
|
||||
let total = total_sats.as_u128() as f64;
|
||||
if total == 0.0 {
|
||||
(i, StoredF32::from(0.0f32))
|
||||
} else {
|
||||
let pct_in_profit = profit_sats.as_u128() as f64 / total;
|
||||
(i, StoredF32::from(
|
||||
(pct_in_profit * f64::from(volatility)) as f32,
|
||||
))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let _lock = exit.lock();
|
||||
self.db.compact()?;
|
||||
Ok(())
|
||||
|
||||
@@ -32,6 +32,10 @@ impl Vecs {
|
||||
ComputedPerBlock::forced_import(&db, "coinyears_destroyed_supply_adjusted", v, indexes)?;
|
||||
let dormancy_supply_adjusted =
|
||||
ComputedPerBlock::forced_import(&db, "dormancy_supply_adjusted", v, indexes)?;
|
||||
let stock_to_flow = ComputedPerBlock::forced_import(&db, "stock_to_flow", v, indexes)?;
|
||||
let dormancy_flow = ComputedPerBlock::forced_import(&db, "dormancy_flow", v, indexes)?;
|
||||
let seller_exhaustion_constant =
|
||||
ComputedPerBlock::forced_import(&db, "seller_exhaustion_constant", v, indexes)?;
|
||||
|
||||
let this = Self {
|
||||
db,
|
||||
@@ -43,6 +47,9 @@ impl Vecs {
|
||||
coindays_destroyed_supply_adjusted,
|
||||
coinyears_destroyed_supply_adjusted,
|
||||
dormancy_supply_adjusted,
|
||||
stock_to_flow,
|
||||
dormancy_flow,
|
||||
seller_exhaustion_constant,
|
||||
};
|
||||
finalize_db(&this.db, &this)?;
|
||||
Ok(this)
|
||||
|
||||
@@ -16,4 +16,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub coindays_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
||||
pub coinyears_destroyed_supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
||||
pub dormancy_supply_adjusted: ComputedPerBlock<StoredF32, M>,
|
||||
pub stock_to_flow: ComputedPerBlock<StoredF32, M>,
|
||||
pub dormancy_flow: ComputedPerBlock<StoredF32, M>,
|
||||
pub seller_exhaustion_constant: ComputedPerBlock<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints32, Cents, Height, Indexes, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, indexes, prices};
|
||||
|
||||
use super::{RatioPerBlock, RatioPerBlockPercentiles};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct RatioPerBlockExtended<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub base: RatioPerBlock<BasisPoints32, M>,
|
||||
#[traversable(flatten)]
|
||||
pub percentiles: RatioPerBlockPercentiles<M>,
|
||||
}
|
||||
|
||||
impl RatioPerBlockExtended {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
base: RatioPerBlock::forced_import(db, name, version, indexes)?,
|
||||
percentiles: RatioPerBlockPercentiles::forced_import(
|
||||
db, name, version, indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute ratio and all percentile metrics from an externally-provided metric price (in cents).
|
||||
pub(crate) fn compute_rest(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
metric_price: &impl ReadableVec<Height, Cents>,
|
||||
) -> Result<()> {
|
||||
let close_price = &prices.price.cents.height;
|
||||
self.base
|
||||
.compute_ratio(starting_indexes, close_price, metric_price, exit)?;
|
||||
self.percentiles
|
||||
.compute(blocks, starting_indexes, exit, &self.base.ratio.height, metric_price)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
mod base;
|
||||
mod extended;
|
||||
mod percentiles;
|
||||
mod price_extended;
|
||||
mod sma;
|
||||
mod std_dev_bands;
|
||||
mod windows;
|
||||
|
||||
pub use base::*;
|
||||
pub use extended::*;
|
||||
pub use percentiles::*;
|
||||
pub use price_extended::*;
|
||||
pub use sma::*;
|
||||
pub use std_dev_bands::*;
|
||||
pub use windows::*;
|
||||
|
||||
@@ -7,7 +7,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
blocks, indexes,
|
||||
indexes,
|
||||
internal::{ExpandingPercentiles, Price, PriceTimesRatioBp32Cents},
|
||||
};
|
||||
|
||||
@@ -22,8 +22,6 @@ pub struct RatioBand<M: StorageMode = Rw> {
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RatioPerBlockPercentiles<M: StorageMode = Rw> {
|
||||
pub sma_1w: RatioPerBlock<BasisPoints32, M>,
|
||||
pub sma_1m: RatioPerBlock<BasisPoints32, M>,
|
||||
pub pct99: RatioBand<M>,
|
||||
pub pct98: RatioBand<M>,
|
||||
pub pct95: RatioBand<M>,
|
||||
@@ -73,8 +71,6 @@ impl RatioPerBlockPercentiles {
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
sma_1w: import_ratio!("ratio_sma_1w"),
|
||||
sma_1m: import_ratio!("ratio_sma_1m"),
|
||||
pct99: import_band!("ratio_pct99"),
|
||||
pct98: import_band!("ratio_pct98"),
|
||||
pct95: import_band!("ratio_pct95"),
|
||||
@@ -87,26 +83,11 @@ impl RatioPerBlockPercentiles {
|
||||
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
||||
metric_price: &impl ReadableVec<Height, Cents>,
|
||||
) -> Result<()> {
|
||||
self.sma_1w.bps.height.compute_rolling_average(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback.height_1w_ago,
|
||||
ratio_source,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.sma_1m.bps.height.compute_rolling_average(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback.height_1m_ago,
|
||||
ratio_source,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let ratio_version = ratio_source.version();
|
||||
self.mut_pct_vecs().try_for_each(|v| -> Result<()> {
|
||||
v.validate_computed_version_or_reset(ratio_version)?;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints32, Cents, Height, Indexes, Version};
|
||||
use brk_types::{BasisPoints32, Cents, Dollars, Height, Indexes, SatsFract, StoredF32, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedPerBlock, Price};
|
||||
use crate::internal::{ComputedPerBlock, LazyPerBlock, Price};
|
||||
use crate::{indexes, prices};
|
||||
|
||||
use super::RatioPerBlock;
|
||||
use super::{RatioPerBlock, RatioPerBlockPercentiles};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[derive(Traversable)]
|
||||
pub struct PriceWithRatioPerBlock<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub inner: RatioPerBlock<BasisPoints32, M>,
|
||||
pub price: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub cents: ComputedPerBlock<Cents, M>,
|
||||
pub usd: LazyPerBlock<Dollars, Cents>,
|
||||
pub sats: LazyPerBlock<SatsFract, Dollars>,
|
||||
pub bps: ComputedPerBlock<BasisPoints32, M>,
|
||||
pub ratio: LazyPerBlock<StoredF32, BasisPoints32>,
|
||||
}
|
||||
|
||||
impl PriceWithRatioPerBlock {
|
||||
@@ -25,13 +25,40 @@ impl PriceWithRatioPerBlock {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + Version::TWO;
|
||||
let price = Price::forced_import(db, name, version, indexes)?;
|
||||
let ratio = RatioPerBlock::forced_import(db, name, version, indexes)?;
|
||||
Ok(Self {
|
||||
inner: RatioPerBlock::forced_import(db, name, version, indexes)?,
|
||||
price: Price::forced_import(db, name, v, indexes)?,
|
||||
cents: price.cents,
|
||||
usd: price.usd,
|
||||
sats: price.sats,
|
||||
bps: ratio.bps,
|
||||
ratio: ratio.ratio,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute ratio from close price and this metric's price.
|
||||
pub(crate) fn compute_ratio(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
close_price: &impl ReadableVec<Height, Cents>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.bps.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
close_price,
|
||||
&self.cents.height,
|
||||
|(i, close, price, ..)| {
|
||||
if price == Cents::ZERO {
|
||||
(i, BasisPoints32::from(1.0))
|
||||
} else {
|
||||
(i, BasisPoints32::from(f64::from(close) / f64::from(price)))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute price via closure (in cents), then compute ratio.
|
||||
pub(crate) fn compute_all<F>(
|
||||
&mut self,
|
||||
@@ -43,10 +70,63 @@ impl PriceWithRatioPerBlock {
|
||||
where
|
||||
F: FnMut(&mut EagerVec<PcoVec<Height, Cents>>) -> Result<()>,
|
||||
{
|
||||
compute_price(&mut self.price.cents.height)?;
|
||||
let close_price = &prices.price.cents.height;
|
||||
self.inner
|
||||
.compute_ratio(starting_indexes, close_price, &self.price.cents.height, exit)?;
|
||||
Ok(())
|
||||
compute_price(&mut self.cents.height)?;
|
||||
self.compute_ratio(starting_indexes, &prices.price.cents.height, exit)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct PriceWithRatioExtendedPerBlock<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub base: PriceWithRatioPerBlock<M>,
|
||||
pub percentiles: RatioPerBlockPercentiles<M>,
|
||||
}
|
||||
|
||||
impl PriceWithRatioExtendedPerBlock {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
base: PriceWithRatioPerBlock::forced_import(db, name, version, indexes)?,
|
||||
percentiles: RatioPerBlockPercentiles::forced_import(db, name, version, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute ratio and percentiles from already-computed price cents.
|
||||
pub(crate) fn compute_rest(
|
||||
&mut self,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let close_price = &prices.price.cents.height;
|
||||
self.base.compute_ratio(starting_indexes, close_price, exit)?;
|
||||
self.percentiles.compute(
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self.base.ratio.height,
|
||||
&self.base.cents.height,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute price via closure (in cents), then compute ratio and percentiles.
|
||||
pub(crate) fn compute_all<F>(
|
||||
&mut self,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
mut compute_price: F,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnMut(&mut EagerVec<PcoVec<Height, Cents>>) -> Result<()>,
|
||||
{
|
||||
compute_price(&mut self.base.cents.height)?;
|
||||
self.compute_rest(prices, starting_indexes, exit)
|
||||
}
|
||||
}
|
||||
|
||||
86
crates/brk_computer/src/internal/per_block/ratio/sma.rs
Normal file
86
crates/brk_computer/src/internal/per_block/ratio/sma.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints32, Height, Indexes, StoredF32, Version};
|
||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, indexes};
|
||||
|
||||
use super::RatioPerBlock;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RatioSma<M: StorageMode = Rw> {
|
||||
pub all: RatioPerBlock<BasisPoints32, M>,
|
||||
pub _1w: RatioPerBlock<BasisPoints32, M>,
|
||||
pub _1m: RatioPerBlock<BasisPoints32, M>,
|
||||
pub _1y: RatioPerBlock<BasisPoints32, M>,
|
||||
pub _2y: RatioPerBlock<BasisPoints32, M>,
|
||||
pub _4y: RatioPerBlock<BasisPoints32, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::new(4);
|
||||
|
||||
impl RatioSma {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
RatioPerBlock::forced_import_raw(
|
||||
db,
|
||||
&format!("{name}_ratio_sma_{}", $suffix),
|
||||
v,
|
||||
indexes,
|
||||
)?
|
||||
};
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
all: import!("all"),
|
||||
_1w: import!("1w"),
|
||||
_1m: import!("1m"),
|
||||
_1y: import!("1y"),
|
||||
_2y: import!("2y"),
|
||||
_4y: import!("4y"),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
||||
) -> Result<()> {
|
||||
// Expanding SMA (all history)
|
||||
self.all.bps.height.compute_sma_(
|
||||
starting_indexes.height,
|
||||
ratio_source,
|
||||
usize::MAX,
|
||||
exit,
|
||||
None,
|
||||
)?;
|
||||
|
||||
// Rolling SMAs
|
||||
for (sma, lookback) in [
|
||||
(&mut self._1w, &blocks.lookback.height_1w_ago),
|
||||
(&mut self._1m, &blocks.lookback.height_1m_ago),
|
||||
(&mut self._1y, &blocks.lookback.height_1y_ago),
|
||||
(&mut self._2y, &blocks.lookback.height_2y_ago),
|
||||
(&mut self._4y, &blocks.lookback.height_4y_ago),
|
||||
] {
|
||||
sma.bps.height.compute_rolling_average(
|
||||
starting_indexes.height,
|
||||
lookback,
|
||||
ratio_source,
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{blocks, indexes, internal::StdDevPerBlockExtended};
|
||||
|
||||
use super::RatioSma;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RatioPerBlockStdDevBands<M: StorageMode = Rw> {
|
||||
pub all: StdDevPerBlockExtended<M>,
|
||||
@@ -52,15 +54,16 @@ impl RatioPerBlockStdDevBands {
|
||||
exit: &Exit,
|
||||
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
||||
metric_price: &impl ReadableVec<Height, Cents>,
|
||||
sma: &RatioSma,
|
||||
) -> Result<()> {
|
||||
for sd in [
|
||||
&mut self.all,
|
||||
&mut self._4y,
|
||||
&mut self._2y,
|
||||
&mut self._1y,
|
||||
for (sd, sma_ratio) in [
|
||||
(&mut self.all, &sma.all.ratio.height),
|
||||
(&mut self._4y, &sma._4y.ratio.height),
|
||||
(&mut self._2y, &sma._2y.ratio.height),
|
||||
(&mut self._1y, &sma._1y.ratio.height),
|
||||
] {
|
||||
sd.compute_all(blocks, starting_indexes, exit, ratio_source)?;
|
||||
sd.compute_cents_bands(starting_indexes, metric_price, exit)?;
|
||||
sd.compute_all(blocks, starting_indexes, exit, ratio_source, sma_ratio)?;
|
||||
sd.compute_cents_bands(starting_indexes, metric_price, sma_ratio, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -2,17 +2,15 @@ use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Height, Indexes, StoredF32, Version};
|
||||
use vecdb::{
|
||||
AnyStoredVec, AnyVec, Database, EagerVec, Exit, Ident, PcoVec, ReadableCloneableVec,
|
||||
ReadableVec, Rw, StorageMode, VecIndex, WritableVec,
|
||||
AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode, VecIndex,
|
||||
WritableVec,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
blocks, indexes,
|
||||
internal::{ComputedPerBlock, LazyPerBlock, Price, PriceTimesRatioCents},
|
||||
internal::{ComputedPerBlock, Price, PriceTimesRatioCents},
|
||||
};
|
||||
|
||||
use super::StdDevPerBlock;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct StdDevBand<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
@@ -20,21 +18,13 @@ pub struct StdDevBand<M: StorageMode = Rw> {
|
||||
pub price: Price<ComputedPerBlock<Cents, M>>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct LazyStdDevBand<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub value: LazyPerBlock<StoredF32>,
|
||||
pub price: Price<ComputedPerBlock<Cents, M>>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct StdDevPerBlockExtended<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub base: StdDevPerBlock<M>,
|
||||
|
||||
days: usize,
|
||||
pub sd: ComputedPerBlock<StoredF32, M>,
|
||||
pub zscore: ComputedPerBlock<StoredF32, M>,
|
||||
|
||||
pub _0sd: LazyStdDevBand<M>,
|
||||
pub _0sd: Price<ComputedPerBlock<Cents, M>>,
|
||||
pub p0_5sd: StdDevBand<M>,
|
||||
pub p1sd: StdDevBand<M>,
|
||||
pub p1_5sd: StdDevBand<M>,
|
||||
@@ -87,29 +77,11 @@ impl StdDevPerBlockExtended {
|
||||
};
|
||||
}
|
||||
|
||||
let base = StdDevPerBlock::forced_import(
|
||||
db,
|
||||
name,
|
||||
period,
|
||||
days,
|
||||
parent_version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let _0sd = LazyStdDevBand {
|
||||
value: LazyPerBlock::from_computed::<Ident>(
|
||||
&format!("{name}_0sd{p}"),
|
||||
version,
|
||||
base.sma.height.read_only_boxed_clone(),
|
||||
&base.sma,
|
||||
),
|
||||
price: import_price!("0sd"),
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
base,
|
||||
days,
|
||||
sd: import!("sd"),
|
||||
zscore: import!("zscore"),
|
||||
_0sd,
|
||||
_0sd: import_price!("0sd"),
|
||||
p0_5sd: import_band!("p0_5sd"),
|
||||
p1sd: import_band!("p1sd"),
|
||||
p1_5sd: import_band!("p1_5sd"),
|
||||
@@ -131,19 +103,34 @@ impl StdDevPerBlockExtended {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
source: &impl ReadableVec<Height, StoredF32>,
|
||||
sma: &impl ReadableVec<Height, StoredF32>,
|
||||
) -> Result<()> {
|
||||
self.base
|
||||
.compute_all(blocks, starting_indexes, exit, source)?;
|
||||
if self.days == usize::MAX {
|
||||
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(
|
||||
starting_indexes.height,
|
||||
window_starts,
|
||||
source,
|
||||
sma,
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
let sma_opt: Option<&EagerVec<PcoVec<Height, StoredF32>>> = None;
|
||||
self.compute_bands(starting_indexes, exit, sma_opt, source)
|
||||
self.compute_bands(starting_indexes, exit, sma, source)
|
||||
}
|
||||
|
||||
pub(crate) fn compute_bands(
|
||||
fn compute_bands(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
sma_opt: Option<&impl ReadableVec<Height, StoredF32>>,
|
||||
sma: &impl ReadableVec<Height, StoredF32>,
|
||||
source: &impl ReadableVec<Height, StoredF32>,
|
||||
) -> Result<()> {
|
||||
let source_version = source.version();
|
||||
@@ -166,19 +153,11 @@ impl StdDevPerBlockExtended {
|
||||
let source_len = source.len();
|
||||
let source_data = source.collect_range_at(start, source_len);
|
||||
|
||||
let sma_len = sma_opt
|
||||
.map(|s| s.len())
|
||||
.unwrap_or(self.base.sma.height.len());
|
||||
let sma_data: Vec<StoredF32> = if let Some(sma) = sma_opt {
|
||||
sma.collect_range_at(start, sma_len)
|
||||
} else {
|
||||
self.base.sma.height.collect_range_at(start, sma_len)
|
||||
};
|
||||
let sma_data = sma.collect_range_at(start, sma.len());
|
||||
let sd_data = self
|
||||
.base
|
||||
.sd
|
||||
.height
|
||||
.collect_range_at(start, self.base.sd.height.len());
|
||||
.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,
|
||||
@@ -197,23 +176,13 @@ impl StdDevPerBlockExtended {
|
||||
self.mut_band_height_vecs().try_for_each(|v| v.flush())?;
|
||||
}
|
||||
|
||||
if let Some(sma) = sma_opt {
|
||||
self.zscore.height.compute_zscore(
|
||||
starting_indexes.height,
|
||||
source,
|
||||
sma,
|
||||
&self.base.sd.height,
|
||||
exit,
|
||||
)?;
|
||||
} else {
|
||||
self.zscore.height.compute_zscore(
|
||||
starting_indexes.height,
|
||||
source,
|
||||
&self.base.sma.height,
|
||||
&self.base.sd.height,
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
self.zscore.height.compute_zscore(
|
||||
starting_indexes.height,
|
||||
source,
|
||||
sma,
|
||||
&self.sd.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -222,6 +191,7 @@ impl StdDevPerBlockExtended {
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
metric_price: &impl ReadableVec<Height, Cents>,
|
||||
sma: &impl ReadableVec<Height, StoredF32>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
macro_rules! compute_band_price {
|
||||
@@ -237,7 +207,7 @@ impl StdDevPerBlockExtended {
|
||||
};
|
||||
}
|
||||
|
||||
compute_band_price!(&mut self._0sd.price, &self.base.sma.height);
|
||||
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);
|
||||
|
||||
@@ -429,18 +429,6 @@ impl Computer {
|
||||
})
|
||||
});
|
||||
|
||||
let indicators = scope.spawn(|| {
|
||||
timed("Computed indicators", || {
|
||||
self.indicators.compute(
|
||||
&self.mining,
|
||||
&self.distribution,
|
||||
&self.transactions,
|
||||
&starting_indexes,
|
||||
exit,
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
timed("Computed supply", || {
|
||||
self.supply.compute(
|
||||
&self.scripts,
|
||||
@@ -455,20 +443,37 @@ impl Computer {
|
||||
})?;
|
||||
|
||||
market.join().unwrap()?;
|
||||
indicators.join().unwrap()?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
timed("Computed cointime", || {
|
||||
self.cointime.compute(
|
||||
&starting_indexes,
|
||||
&self.prices,
|
||||
&self.blocks,
|
||||
&self.mining,
|
||||
&self.supply,
|
||||
&self.distribution,
|
||||
exit,
|
||||
)
|
||||
thread::scope(|scope| -> Result<()> {
|
||||
let indicators = scope.spawn(|| {
|
||||
timed("Computed indicators", || {
|
||||
self.indicators.compute(
|
||||
&self.mining,
|
||||
&self.distribution,
|
||||
&self.transactions,
|
||||
&self.market,
|
||||
&starting_indexes,
|
||||
exit,
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
timed("Computed cointime", || {
|
||||
self.cointime.compute(
|
||||
&starting_indexes,
|
||||
&self.prices,
|
||||
&self.blocks,
|
||||
&self.mining,
|
||||
&self.supply,
|
||||
&self.distribution,
|
||||
exit,
|
||||
)
|
||||
})?;
|
||||
|
||||
indicators.join().unwrap()?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
info!("Total compute time: {:?}", compute_start.elapsed());
|
||||
|
||||
@@ -26,7 +26,7 @@ impl Vecs {
|
||||
let sma_200d = import!("price_sma_200d");
|
||||
let sma_350d = import!("price_sma_350d");
|
||||
|
||||
let price_sma_200d_source = &sma_200d.price.cents;
|
||||
let price_sma_200d_source = &sma_200d.cents;
|
||||
let _200d_x2_4 = Price::from_cents_source::<CentsTimesTenths<24>>(
|
||||
"price_sma_200d_x2_4",
|
||||
version,
|
||||
@@ -38,7 +38,7 @@ impl Vecs {
|
||||
price_sma_200d_source,
|
||||
);
|
||||
|
||||
let price_sma_350d_source = &sma_350d.price.cents;
|
||||
let price_sma_350d_source = &sma_350d.cents;
|
||||
let _350d_x2 = Price::from_cents_source::<CentsTimesTenths<20>>(
|
||||
"price_sma_350d_x2",
|
||||
version,
|
||||
|
||||
@@ -94,7 +94,7 @@ impl Vecs {
|
||||
.bps
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||
starting_indexes.height,
|
||||
&moving_average.sma._111d.price.usd.height,
|
||||
&moving_average.sma._111d.usd.height,
|
||||
&moving_average.sma._350d_x2.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -17,6 +17,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub inflation_rate: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub velocity: velocity::Vecs<M>,
|
||||
pub market_cap: LazyFiatPerBlock<Cents>,
|
||||
#[traversable(wrap = "market_cap", rename = "delta")]
|
||||
pub market_cap_delta: FiatRollingDelta<Cents, CentsSigned, M>,
|
||||
pub market_minus_realized_cap_growth_rate: RollingWindows<BasisPointsSigned32, M>,
|
||||
pub hodled_or_lost_coins: LazyAmountPerBlock,
|
||||
|
||||
Reference in New Issue
Block a user