mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-25 01:38:12 -07:00
global: adding support for safe lengths
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Bitcoin, Indexes, StoredF64};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Bitcoin, StoredF64};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
@@ -8,17 +9,18 @@ use crate::distribution;
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
indexer: &Indexer,
|
||||
distribution: &distribution::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let starting_height = indexer.safe_lengths().height;
|
||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||
let circulating_supply = &all_metrics.supply.total.sats.height;
|
||||
|
||||
self.coinblocks_created
|
||||
.compute(starting_indexes.height, exit, |vec| {
|
||||
.compute(starting_height, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
circulating_supply,
|
||||
|(i, v, ..)| (i, StoredF64::from(Bitcoin::from(v))),
|
||||
exit,
|
||||
@@ -27,9 +29,9 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.coinblocks_stored
|
||||
.compute(starting_indexes.height, exit, |vec| {
|
||||
.compute(starting_height, exit, |vec| {
|
||||
vec.compute_subtract(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&self.coinblocks_created.block,
|
||||
&distribution.coinblocks_destroyed.block,
|
||||
exit,
|
||||
@@ -38,14 +40,14 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.liveliness.height.compute_divide(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&distribution.coinblocks_destroyed.cumulative.height,
|
||||
&self.coinblocks_created.cumulative.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.ratio.height.compute_divide(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&self.liveliness.height,
|
||||
&self.vaultedness.height,
|
||||
exit,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{BasisPointsSigned32, Indexes};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::BasisPointsSigned32;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::activity;
|
||||
@@ -9,13 +10,15 @@ use crate::supply;
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
indexer: &Indexer,
|
||||
supply: &supply::Vecs,
|
||||
activity: &activity::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let starting_height = indexer.safe_lengths().height;
|
||||
|
||||
self.inflation_rate.bps.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&activity.ratio.height,
|
||||
&supply.inflation_rate.bps.height,
|
||||
|(h, a2vr, inflation, ..)| {
|
||||
@@ -28,14 +31,14 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
self.tx_velocity_native.height.compute_multiply(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&activity.ratio.height,
|
||||
&supply.velocity.native.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.tx_velocity_fiat.height.compute_multiply(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&activity.ratio.height,
|
||||
&supply.velocity.fiat.height,
|
||||
exit,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Dollars, Indexes};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::Dollars;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::{activity, value};
|
||||
@@ -10,40 +11,41 @@ impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
indexer: &Indexer,
|
||||
mining: &mining::Vecs,
|
||||
distribution: &distribution::Vecs,
|
||||
activity: &activity::Vecs,
|
||||
value: &value::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let starting_lengths = indexer.safe_lengths();
|
||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||
let realized_cap_cents = &all_metrics.realized.cap.cents.height;
|
||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||
|
||||
self.thermo.cents.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
&mining.rewards.subsidy.cumulative.cents.height,
|
||||
|(i, v, ..)| (i, v),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.investor.cents.height.compute_subtract(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
realized_cap_cents,
|
||||
&self.thermo.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.vaulted.cents.height.compute_multiply(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
realized_cap_cents,
|
||||
&activity.vaultedness.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.active.cents.height.compute_multiply(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
realized_cap_cents,
|
||||
&activity.liveliness.height,
|
||||
exit,
|
||||
@@ -51,7 +53,7 @@ impl Vecs {
|
||||
|
||||
// cointime_cap = (cointime_value_destroyed_cumulative * circulating_supply) / coinblocks_stored_cumulative
|
||||
self.cointime.cents.height.compute_transform3(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
&value.destroyed.cumulative.height,
|
||||
circulating_supply,
|
||||
&activity.coinblocks_stored.cumulative.height,
|
||||
@@ -67,7 +69,7 @@ impl Vecs {
|
||||
|
||||
// AVIV = active_cap / investor_cap
|
||||
self.aviv.compute_ratio(
|
||||
starting_indexes,
|
||||
&starting_lengths,
|
||||
&self.active.cents.height,
|
||||
&self.investor.cents.height,
|
||||
exit,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::Indexes;
|
||||
use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
@@ -9,7 +9,7 @@ impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
indexer: &Indexer,
|
||||
prices: &prices::Vecs,
|
||||
blocks: &blocks::Vecs,
|
||||
mining: &mining::Vecs,
|
||||
@@ -20,29 +20,23 @@ impl Vecs {
|
||||
self.db.sync_bg_tasks()?;
|
||||
|
||||
// Activity computes first (liveliness, vaultedness, etc.)
|
||||
self.activity
|
||||
.compute(starting_indexes, distribution, exit)?;
|
||||
self.activity.compute(indexer, distribution, exit)?;
|
||||
|
||||
// Phase 2: supply, adjusted, value are independent (all depend only on activity)
|
||||
let (r1, r2) = rayon::join(
|
||||
|| {
|
||||
self.supply
|
||||
.compute(starting_indexes, prices, distribution, &self.activity, exit)
|
||||
.compute(indexer, prices, distribution, &self.activity, exit)
|
||||
},
|
||||
|| {
|
||||
rayon::join(
|
||||
|| {
|
||||
self.adjusted
|
||||
.compute(starting_indexes, supply_vecs, &self.activity, exit)
|
||||
.compute(indexer, supply_vecs, &self.activity, exit)
|
||||
},
|
||||
|| {
|
||||
self.value.compute(
|
||||
starting_indexes,
|
||||
prices,
|
||||
distribution,
|
||||
&self.activity,
|
||||
exit,
|
||||
)
|
||||
self.value
|
||||
.compute(indexer, prices, distribution, &self.activity, exit)
|
||||
},
|
||||
)
|
||||
},
|
||||
@@ -53,7 +47,7 @@ impl Vecs {
|
||||
|
||||
// Cap depends on activity + value
|
||||
self.cap.compute(
|
||||
starting_indexes,
|
||||
indexer,
|
||||
mining,
|
||||
distribution,
|
||||
&self.activity,
|
||||
@@ -65,7 +59,7 @@ impl Vecs {
|
||||
let (r3, r4) = rayon::join(
|
||||
|| {
|
||||
self.prices.compute(
|
||||
starting_indexes,
|
||||
indexer,
|
||||
prices,
|
||||
distribution,
|
||||
&self.activity,
|
||||
@@ -76,7 +70,7 @@ impl Vecs {
|
||||
},
|
||||
|| {
|
||||
self.reserve_risk
|
||||
.compute(starting_indexes, blocks, prices, &self.value, exit)
|
||||
.compute(indexer, blocks, prices, &self.value, exit)
|
||||
},
|
||||
);
|
||||
r3?;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Cents, Indexes};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::Cents;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::{activity, cap, supply};
|
||||
@@ -10,7 +11,7 @@ impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
indexer: &Indexer,
|
||||
prices: &prices::Vecs,
|
||||
distribution: &distribution::Vecs,
|
||||
activity: &activity::Vecs,
|
||||
@@ -18,14 +19,15 @@ impl Vecs {
|
||||
cap: &cap::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let starting_lengths = indexer.safe_lengths();
|
||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||
let realized_price = &all_metrics.realized.price.cents.height;
|
||||
|
||||
self.vaulted
|
||||
.compute_all(prices, starting_indexes, exit, |v| {
|
||||
.compute_all(prices, &starting_lengths, exit, |v| {
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
realized_price,
|
||||
&activity.vaultedness.height,
|
||||
|(i, price, vaultedness, ..)| {
|
||||
@@ -36,9 +38,9 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.active
|
||||
.compute_all(prices, starting_indexes, exit, |v| {
|
||||
.compute_all(prices, &starting_lengths, exit, |v| {
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
realized_price,
|
||||
&activity.liveliness.height,
|
||||
|(i, price, liveliness, ..)| {
|
||||
@@ -49,9 +51,9 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.true_market_mean
|
||||
.compute_all(prices, starting_indexes, exit, |v| {
|
||||
.compute_all(prices, &starting_lengths, exit, |v| {
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
&cap.investor.cents.height,
|
||||
&supply.active.btc.height,
|
||||
|(i, cap_cents, supply_btc, ..)| {
|
||||
@@ -62,9 +64,9 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.cointime
|
||||
.compute_all(prices, starting_indexes, exit, |v| {
|
||||
.compute_all(prices, &starting_lengths, exit, |v| {
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
starting_lengths.height,
|
||||
&cap.cointime.cents.height,
|
||||
circulating_supply,
|
||||
|(i, cap_cents, supply_btc, ..)| {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Indexes, StoredF64};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::StoredF64;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::{super::value, Vecs};
|
||||
@@ -8,21 +9,23 @@ use crate::{blocks, internal::algo::ComputeRollingMedianFromStarts, prices};
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
indexer: &Indexer,
|
||||
blocks: &blocks::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
value: &value::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let starting_height = indexer.safe_lengths().height;
|
||||
|
||||
self.vocdd_median_1y.compute_rolling_median_from_starts(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&blocks.lookback._1y,
|
||||
&value.vocdd.block,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.hodl_bank.compute_cumulative_transformed_binary(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&prices.spot.usd.height,
|
||||
&self.vocdd_median_1y,
|
||||
|price, median| StoredF64::from(f64::from(price) - f64::from(median)),
|
||||
@@ -30,7 +33,7 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
self.value.height.compute_divide(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&prices.spot.usd.height,
|
||||
&self.hodl_bank,
|
||||
exit,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::Indexes;
|
||||
use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::activity;
|
||||
@@ -9,12 +9,13 @@ use crate::{distribution, prices};
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
indexer: &Indexer,
|
||||
prices: &prices::Vecs,
|
||||
distribution: &distribution::Vecs,
|
||||
activity: &activity::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let starting_height = indexer.safe_lengths().height;
|
||||
let circulating_supply = &distribution
|
||||
.utxo_cohorts
|
||||
.all
|
||||
@@ -25,22 +26,21 @@ impl Vecs {
|
||||
.height;
|
||||
|
||||
self.vaulted.sats.height.compute_multiply(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
circulating_supply,
|
||||
&activity.vaultedness.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.active.sats.height.compute_multiply(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
circulating_supply,
|
||||
&activity.liveliness.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.vaulted
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
self.active.compute(prices, starting_indexes.height, exit)?;
|
||||
self.vaulted.compute(prices, starting_height, exit)?;
|
||||
self.active.compute(prices, starting_height, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Bitcoin, Dollars, Indexes, StoredF64};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Bitcoin, Dollars, StoredF64};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::activity;
|
||||
@@ -9,31 +10,31 @@ use crate::{distribution, prices};
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
starting_indexes: &Indexes,
|
||||
indexer: &Indexer,
|
||||
prices: &prices::Vecs,
|
||||
distribution: &distribution::Vecs,
|
||||
activity: &activity::Vecs,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let starting_height = indexer.safe_lengths().height;
|
||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||
let coinblocks_destroyed = &distribution.coinblocks_destroyed;
|
||||
let coindays_destroyed = &all_metrics.activity.coindays_destroyed;
|
||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||
|
||||
self.destroyed
|
||||
.compute(starting_indexes.height, exit, |vec| {
|
||||
vec.compute_multiply(
|
||||
starting_indexes.height,
|
||||
&prices.spot.usd.height,
|
||||
&coinblocks_destroyed.block,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.created.compute(starting_indexes.height, exit, |vec| {
|
||||
self.destroyed.compute(starting_height, exit, |vec| {
|
||||
vec.compute_multiply(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&prices.spot.usd.height,
|
||||
&coinblocks_destroyed.block,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.created.compute(starting_height, exit, |vec| {
|
||||
vec.compute_multiply(
|
||||
starting_height,
|
||||
&prices.spot.usd.height,
|
||||
&activity.coinblocks_created.block,
|
||||
exit,
|
||||
@@ -41,9 +42,9 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.stored.compute(starting_indexes.height, exit, |vec| {
|
||||
self.stored.compute(starting_height, exit, |vec| {
|
||||
vec.compute_multiply(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&prices.spot.usd.height,
|
||||
&activity.coinblocks_stored.block,
|
||||
exit,
|
||||
@@ -54,9 +55,9 @@ impl Vecs {
|
||||
// VOCDD: Value of Coin Days Destroyed = price × (CDD / circulating_supply)
|
||||
// Supply-adjusted to account for growing supply over time
|
||||
// This is a key input for Reserve Risk / HODL Bank calculation
|
||||
self.vocdd.compute(starting_indexes.height, exit, |vec| {
|
||||
self.vocdd.compute(starting_height, exit, |vec| {
|
||||
vec.compute_transform3(
|
||||
starting_indexes.height,
|
||||
starting_height,
|
||||
&prices.spot.usd.height,
|
||||
&coindays_destroyed.block,
|
||||
circulating_supply,
|
||||
|
||||
Reference in New Issue
Block a user