mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -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>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user