mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-28 11:18:17 -07:00
global: snapshot
This commit is contained in:
@@ -113,39 +113,39 @@ impl ActivityCountVecs {
|
||||
|
||||
pub(crate) fn min_stateful_len(&self) -> usize {
|
||||
self.reactivated
|
||||
.height
|
||||
.base
|
||||
.len()
|
||||
.min(self.sending.height.len())
|
||||
.min(self.receiving.height.len())
|
||||
.min(self.both.height.len())
|
||||
.min(self.sending.base.len())
|
||||
.min(self.receiving.base.len())
|
||||
.min(self.both.base.len())
|
||||
}
|
||||
|
||||
pub(crate) fn par_iter_height_mut(
|
||||
&mut self,
|
||||
) -> impl ParallelIterator<Item = &mut dyn AnyStoredVec> {
|
||||
[
|
||||
&mut self.reactivated.height as &mut dyn AnyStoredVec,
|
||||
&mut self.sending.height as &mut dyn AnyStoredVec,
|
||||
&mut self.receiving.height as &mut dyn AnyStoredVec,
|
||||
&mut self.both.height as &mut dyn AnyStoredVec,
|
||||
&mut self.reactivated.base as &mut dyn AnyStoredVec,
|
||||
&mut self.sending.base as &mut dyn AnyStoredVec,
|
||||
&mut self.receiving.base as &mut dyn AnyStoredVec,
|
||||
&mut self.both.base as &mut dyn AnyStoredVec,
|
||||
]
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
pub(crate) fn reset_height(&mut self) -> Result<()> {
|
||||
self.reactivated.height.reset()?;
|
||||
self.sending.height.reset()?;
|
||||
self.receiving.height.reset()?;
|
||||
self.both.height.reset()?;
|
||||
self.reactivated.base.reset()?;
|
||||
self.sending.base.reset()?;
|
||||
self.receiving.base.reset()?;
|
||||
self.both.base.reset()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn push_height(&mut self, counts: &BlockActivityCounts) {
|
||||
self.reactivated.height.push(counts.reactivated.into());
|
||||
self.sending.height.push(counts.sending.into());
|
||||
self.receiving.height.push(counts.receiving.into());
|
||||
self.both.height.push(counts.both.into());
|
||||
self.reactivated.base.push(counts.reactivated.into());
|
||||
self.sending.base.push(counts.sending.into());
|
||||
self.receiving.base.push(counts.receiving.into());
|
||||
self.both.base.push(counts.both.into());
|
||||
}
|
||||
|
||||
pub(crate) fn compute_rest(
|
||||
@@ -206,10 +206,10 @@ impl AddressTypeToActivityCountVecs {
|
||||
) -> impl ParallelIterator<Item = &mut dyn AnyStoredVec> {
|
||||
let mut vecs: Vec<&mut dyn AnyStoredVec> = Vec::new();
|
||||
for type_vecs in self.0.values_mut() {
|
||||
vecs.push(&mut type_vecs.reactivated.height);
|
||||
vecs.push(&mut type_vecs.sending.height);
|
||||
vecs.push(&mut type_vecs.receiving.height);
|
||||
vecs.push(&mut type_vecs.both.height);
|
||||
vecs.push(&mut type_vecs.reactivated.base);
|
||||
vecs.push(&mut type_vecs.sending.base);
|
||||
vecs.push(&mut type_vecs.receiving.base);
|
||||
vecs.push(&mut type_vecs.both.base);
|
||||
}
|
||||
vecs.into_par_iter()
|
||||
}
|
||||
|
||||
@@ -11,33 +11,33 @@ use crate::{
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ActivityCore<M: StorageMode = Rw> {
|
||||
pub sent: PerBlockCumulativeWithSums<Sats, Sats, M>,
|
||||
pub transfer_volume: PerBlockCumulativeWithSums<Sats, Sats, M>,
|
||||
pub coindays_destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
#[traversable(wrap = "sent", rename = "in_profit")]
|
||||
pub sent_in_profit: AmountPerBlockCumulativeWithSums<M>,
|
||||
#[traversable(wrap = "sent", rename = "in_loss")]
|
||||
pub sent_in_loss: AmountPerBlockCumulativeWithSums<M>,
|
||||
#[traversable(wrap = "transfer_volume", rename = "in_profit")]
|
||||
pub transfer_volume_in_profit: AmountPerBlockCumulativeWithSums<M>,
|
||||
#[traversable(wrap = "transfer_volume", rename = "in_loss")]
|
||||
pub transfer_volume_in_loss: AmountPerBlockCumulativeWithSums<M>,
|
||||
}
|
||||
|
||||
impl ActivityCore {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let v1 = Version::ONE;
|
||||
Ok(Self {
|
||||
sent: cfg.import("sent", v1)?,
|
||||
transfer_volume: cfg.import("transfer_volume", 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)?,
|
||||
transfer_volume_in_profit: cfg.import("transfer_volume_in_profit", v1)?,
|
||||
transfer_volume_in_loss: cfg.import("transfer_volume_in_loss", v1)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn min_len(&self) -> usize {
|
||||
self.sent
|
||||
self.transfer_volume
|
||||
.base
|
||||
.height
|
||||
.len()
|
||||
.min(self.coindays_destroyed.base.height.len())
|
||||
.min(self.sent_in_profit.base.sats.height.len())
|
||||
.min(self.sent_in_loss.base.sats.height.len())
|
||||
.min(self.transfer_volume_in_profit.base.sats.height.len())
|
||||
.min(self.transfer_volume_in_loss.base.sats.height.len())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -45,16 +45,16 @@ impl ActivityCore {
|
||||
&mut self,
|
||||
state: &CohortState<impl RealizedOps, impl CostBasisOps>,
|
||||
) {
|
||||
self.sent.base.height.push(state.sent);
|
||||
self.transfer_volume.base.height.push(state.sent);
|
||||
self.coindays_destroyed.base.height.push(
|
||||
StoredF64::from(Bitcoin::from(state.satdays_destroyed)),
|
||||
);
|
||||
self.sent_in_profit
|
||||
self.transfer_volume_in_profit
|
||||
.base
|
||||
.sats
|
||||
.height
|
||||
.push(state.realized.sent_in_profit());
|
||||
self.sent_in_loss
|
||||
self.transfer_volume_in_loss
|
||||
.base
|
||||
.sats
|
||||
.height
|
||||
@@ -63,12 +63,12 @@ impl ActivityCore {
|
||||
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
vec![
|
||||
&mut self.sent.base.height as &mut dyn AnyStoredVec,
|
||||
&mut self.transfer_volume.base.height as &mut dyn AnyStoredVec,
|
||||
&mut self.coindays_destroyed.base.height,
|
||||
&mut self.sent_in_profit.base.sats.height,
|
||||
&mut self.sent_in_profit.base.cents.height,
|
||||
&mut self.sent_in_loss.base.sats.height,
|
||||
&mut self.sent_in_loss.base.cents.height,
|
||||
&mut self.transfer_volume_in_profit.base.sats.height,
|
||||
&mut self.transfer_volume_in_profit.base.cents.height,
|
||||
&mut self.transfer_volume_in_loss.base.sats.height,
|
||||
&mut self.transfer_volume_in_loss.base.cents.height,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -82,18 +82,18 @@ impl ActivityCore {
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sent.base.height.compute_sum_of_others(
|
||||
self.transfer_volume.base.height.compute_sum_of_others(
|
||||
starting_indexes.height,
|
||||
&others
|
||||
.iter()
|
||||
.map(|v| &v.sent.base.height)
|
||||
.map(|v| &v.transfer_volume.base.height)
|
||||
.collect::<Vec<_>>(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.base.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent_in_profit.base.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sent_in_loss.base.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; transfer_volume_in_profit.base.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; transfer_volume_in_loss.base.sats.height);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -103,7 +103,7 @@ impl ActivityCore {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sent
|
||||
self.transfer_volume
|
||||
.compute_rest(starting_indexes.height, exit)?;
|
||||
self.coindays_destroyed
|
||||
.compute_rest(starting_indexes.height, exit)?;
|
||||
@@ -116,9 +116,9 @@ impl ActivityCore {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sent_in_profit
|
||||
self.transfer_volume_in_profit
|
||||
.compute_rest(starting_indexes.height, prices, exit)?;
|
||||
self.sent_in_loss
|
||||
self.transfer_volume_in_loss
|
||||
.compute_rest(starting_indexes.height, prices, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ impl ActivityFull {
|
||||
self.dormancy.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.inner.coindays_destroyed.base.height,
|
||||
&self.inner.sent.base.height,
|
||||
&self.inner.transfer_volume.base.height,
|
||||
|(i, cdd, sent_sats, ..)| {
|
||||
let sent_btc = f64::from(Bitcoin::from(sent_sats));
|
||||
if sent_btc == 0.0 {
|
||||
|
||||
@@ -31,7 +31,7 @@ use super::RealizedCore;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedProfit<M: StorageMode = Rw> {
|
||||
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||
pub to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||
pub distribution_flow: LazyPerBlock<Dollars, Cents>,
|
||||
@@ -39,7 +39,7 @@ pub struct RealizedProfit<M: StorageMode = Rw> {
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedLoss<M: StorageMode = Rw> {
|
||||
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||
pub to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||
pub value_created: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||
pub value_destroyed: PerBlockCumulativeWithSums<Cents, Cents, M>,
|
||||
pub capitulation_flow: LazyPerBlock<Dollars, Cents>,
|
||||
@@ -47,11 +47,11 @@ pub struct RealizedLoss<M: StorageMode = Rw> {
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedNetPnl<M: StorageMode = Rw> {
|
||||
pub rel_to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
#[traversable(wrap = "change_1m", rename = "rel_to_rcap")]
|
||||
pub change_1m_rel_to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
#[traversable(wrap = "change_1m", rename = "rel_to_mcap")]
|
||||
pub change_1m_rel_to_mcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
pub to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
#[traversable(wrap = "change_1m", rename = "to_rcap")]
|
||||
pub change_1m_to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
#[traversable(wrap = "change_1m", rename = "to_mcap")]
|
||||
pub change_1m_to_mcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -64,14 +64,14 @@ pub struct RealizedSopr<M: StorageMode = Rw> {
|
||||
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub value: PerBlockCumulative<Cents, M>,
|
||||
pub rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||
pub to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedInvestor<M: StorageMode = Rw> {
|
||||
pub price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub lower_price_band: Price<PerBlock<Cents, M>>,
|
||||
pub upper_price_band: Price<PerBlock<Cents, M>>,
|
||||
pub investor_lower_band: Price<PerBlock<Cents, M>>,
|
||||
pub investor_upper_band: Price<PerBlock<Cents, M>>,
|
||||
#[traversable(hidden)]
|
||||
pub cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
|
||||
}
|
||||
@@ -96,8 +96,8 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
||||
|
||||
#[traversable(hidden)]
|
||||
pub cap_raw: M::Stored<BytesVec<Height, CentsSats>>,
|
||||
#[traversable(wrap = "cap", rename = "rel_to_own_mcap")]
|
||||
pub cap_rel_to_own_mcap: PercentPerBlock<BasisPoints32, M>,
|
||||
#[traversable(wrap = "cap", rename = "to_own_mcap")]
|
||||
pub cap_to_own_mcap: PercentPerBlock<BasisPoints32, M>,
|
||||
|
||||
#[traversable(wrap = "price", rename = "percentiles")]
|
||||
pub price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
||||
@@ -124,7 +124,7 @@ impl RealizedFull {
|
||||
&profit_value_destroyed.base,
|
||||
);
|
||||
let profit = RealizedProfit {
|
||||
rel_to_rcap: cfg.import("realized_profit_rel_to_rcap", Version::new(2))?,
|
||||
to_rcap: cfg.import("realized_profit_to_rcap", Version::new(2))?,
|
||||
value_created: cfg.import("profit_value_created", v1)?,
|
||||
value_destroyed: profit_value_destroyed,
|
||||
distribution_flow: profit_flow,
|
||||
@@ -140,7 +140,7 @@ impl RealizedFull {
|
||||
&loss_value_destroyed.base,
|
||||
);
|
||||
let loss = RealizedLoss {
|
||||
rel_to_rcap: cfg.import("realized_loss_rel_to_rcap", Version::new(2))?,
|
||||
to_rcap: cfg.import("realized_loss_to_rcap", Version::new(2))?,
|
||||
value_created: cfg.import("loss_value_created", v1)?,
|
||||
value_destroyed: loss_value_destroyed,
|
||||
capitulation_flow,
|
||||
@@ -153,12 +153,12 @@ impl RealizedFull {
|
||||
|
||||
// Net PnL
|
||||
let net_pnl = RealizedNetPnl {
|
||||
rel_to_rcap: cfg
|
||||
.import("net_realized_pnl_rel_to_rcap", Version::new(2))?,
|
||||
change_1m_rel_to_rcap: cfg
|
||||
.import("net_pnl_change_1m_rel_to_rcap", Version::new(4))?,
|
||||
change_1m_rel_to_mcap: cfg
|
||||
.import("net_pnl_change_1m_rel_to_mcap", Version::new(4))?,
|
||||
to_rcap: cfg
|
||||
.import("net_realized_pnl_to_rcap", Version::new(2))?,
|
||||
change_1m_to_rcap: cfg
|
||||
.import("net_pnl_change_1m_to_rcap", Version::new(4))?,
|
||||
change_1m_to_mcap: cfg
|
||||
.import("net_pnl_change_1m_to_mcap", Version::new(4))?,
|
||||
};
|
||||
|
||||
// SOPR
|
||||
@@ -169,15 +169,15 @@ impl RealizedFull {
|
||||
// Peak regret
|
||||
let peak_regret = RealizedPeakRegret {
|
||||
value: cfg.import("realized_peak_regret", Version::new(2))?,
|
||||
rel_to_rcap: cfg
|
||||
.import("realized_peak_regret_rel_to_rcap", Version::new(2))?,
|
||||
to_rcap: cfg
|
||||
.import("realized_peak_regret_to_rcap", Version::new(2))?,
|
||||
};
|
||||
|
||||
// Investor
|
||||
let investor = RealizedInvestor {
|
||||
price: cfg.import("investor_price", v0)?,
|
||||
lower_price_band: cfg.import("lower_price_band", v0)?,
|
||||
upper_price_band: cfg.import("upper_price_band", v0)?,
|
||||
investor_lower_band: cfg.import("investor_lower_band", v0)?,
|
||||
investor_upper_band: cfg.import("investor_upper_band", v0)?,
|
||||
cap_raw: cfg.import("investor_cap_raw", v0)?,
|
||||
};
|
||||
|
||||
@@ -197,7 +197,7 @@ impl RealizedFull {
|
||||
investor,
|
||||
profit_to_loss_ratio: cfg.import("realized_profit_to_loss_ratio", v1)?,
|
||||
cap_raw: cfg.import("cap_raw", v0)?,
|
||||
cap_rel_to_own_mcap: cfg.import("realized_cap_rel_to_own_mcap", v1)?,
|
||||
cap_to_own_mcap: cfg.import("realized_cap_to_own_mcap", v1)?,
|
||||
price_ratio_percentiles: RatioPerBlockPercentiles::forced_import(
|
||||
cfg.db,
|
||||
&realized_price_name,
|
||||
@@ -403,7 +403,7 @@ impl RealizedFull {
|
||||
|
||||
// Profit/loss/net_pnl rel to realized cap
|
||||
self.profit
|
||||
.rel_to_rcap
|
||||
.to_rcap
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||
starting_indexes.height,
|
||||
&self.core.minimal.profit.base.cents.height,
|
||||
@@ -411,7 +411,7 @@ impl RealizedFull {
|
||||
exit,
|
||||
)?;
|
||||
self.loss
|
||||
.rel_to_rcap
|
||||
.to_rcap
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||
starting_indexes.height,
|
||||
&self.core.minimal.loss.base.cents.height,
|
||||
@@ -419,7 +419,7 @@ impl RealizedFull {
|
||||
exit,
|
||||
)?;
|
||||
self.net_pnl
|
||||
.rel_to_rcap
|
||||
.to_rcap
|
||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
||||
starting_indexes.height,
|
||||
&self.core.net_pnl.base.cents.height,
|
||||
@@ -453,7 +453,7 @@ impl RealizedFull {
|
||||
|
||||
// Net PnL 1m change relative to rcap and mcap
|
||||
self.net_pnl
|
||||
.change_1m_rel_to_rcap
|
||||
.change_1m_to_rcap
|
||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
||||
starting_indexes.height,
|
||||
&self.core.net_pnl.delta.absolute._1m.cents.height,
|
||||
@@ -461,7 +461,7 @@ impl RealizedFull {
|
||||
exit,
|
||||
)?;
|
||||
self.net_pnl
|
||||
.change_1m_rel_to_mcap
|
||||
.change_1m_to_mcap
|
||||
.compute_binary::<CentsSigned, Dollars, RatioCentsSignedDollarsBps32>(
|
||||
starting_indexes.height,
|
||||
&self.core.net_pnl.delta.absolute._1m.cents.height,
|
||||
@@ -471,7 +471,7 @@ impl RealizedFull {
|
||||
|
||||
// Peak regret rel to rcap
|
||||
self.peak_regret
|
||||
.rel_to_rcap
|
||||
.to_rcap
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||
starting_indexes.height,
|
||||
&self.peak_regret.value.base.height,
|
||||
@@ -487,7 +487,7 @@ impl RealizedFull {
|
||||
)?;
|
||||
|
||||
self.investor
|
||||
.lower_price_band
|
||||
.investor_lower_band
|
||||
.cents
|
||||
.height
|
||||
.compute_transform2(
|
||||
@@ -507,7 +507,7 @@ impl RealizedFull {
|
||||
)?;
|
||||
|
||||
self.investor
|
||||
.upper_price_band
|
||||
.investor_upper_band
|
||||
.cents
|
||||
.height
|
||||
.compute_transform2(
|
||||
@@ -542,7 +542,7 @@ impl RealizedFull {
|
||||
}
|
||||
|
||||
// Realized cap relative to own market cap
|
||||
self.cap_rel_to_own_mcap
|
||||
self.cap_to_own_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||
starting_indexes.height,
|
||||
&self.core.minimal.cap.usd.height,
|
||||
|
||||
@@ -10,12 +10,12 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedCore};
|
||||
/// Extended relative metrics for own market cap (extended && rel_to_all).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeExtendedOwnMarketCap<M: StorageMode = Rw> {
|
||||
#[traversable(wrap = "unrealized/profit", rename = "rel_to_own_mcap")]
|
||||
pub unrealized_profit_rel_to_own_mcap: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/loss", rename = "rel_to_own_mcap")]
|
||||
pub unrealized_loss_rel_to_own_mcap: PercentPerBlock<BasisPoints32, M>,
|
||||
#[traversable(wrap = "unrealized/net_pnl", rename = "rel_to_own_mcap")]
|
||||
pub net_unrealized_pnl_rel_to_own_mcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
#[traversable(wrap = "unrealized/profit", rename = "to_own_mcap")]
|
||||
pub unrealized_profit_to_own_mcap: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/loss", rename = "to_own_mcap")]
|
||||
pub unrealized_loss_to_own_mcap: PercentPerBlock<BasisPoints32, M>,
|
||||
#[traversable(wrap = "unrealized/net_pnl", rename = "to_own_mcap")]
|
||||
pub net_unrealized_pnl_to_own_mcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
}
|
||||
|
||||
impl RelativeExtendedOwnMarketCap {
|
||||
@@ -23,12 +23,12 @@ impl RelativeExtendedOwnMarketCap {
|
||||
let v2 = Version::new(2);
|
||||
|
||||
Ok(Self {
|
||||
unrealized_profit_rel_to_own_mcap: cfg
|
||||
.import("unrealized_profit_rel_to_own_mcap", v2)?,
|
||||
unrealized_loss_rel_to_own_mcap: cfg
|
||||
.import("unrealized_loss_rel_to_own_mcap", Version::new(3))?,
|
||||
net_unrealized_pnl_rel_to_own_mcap: cfg
|
||||
.import("net_unrealized_pnl_rel_to_own_mcap", Version::new(3))?,
|
||||
unrealized_profit_to_own_mcap: cfg
|
||||
.import("unrealized_profit_to_own_mcap", v2)?,
|
||||
unrealized_loss_to_own_mcap: cfg
|
||||
.import("unrealized_loss_to_own_mcap", Version::new(3))?,
|
||||
net_unrealized_pnl_to_own_mcap: cfg
|
||||
.import("net_unrealized_pnl_to_own_mcap", Version::new(3))?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -39,21 +39,21 @@ impl RelativeExtendedOwnMarketCap {
|
||||
own_market_cap: &impl ReadableVec<Height, Dollars>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.unrealized_profit_rel_to_own_mcap
|
||||
self.unrealized_profit_to_own_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.profit.base.usd.height,
|
||||
own_market_cap,
|
||||
exit,
|
||||
)?;
|
||||
self.unrealized_loss_rel_to_own_mcap
|
||||
self.unrealized_loss_to_own_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||
max_from,
|
||||
&unrealized.loss.base.usd.height,
|
||||
own_market_cap,
|
||||
exit,
|
||||
)?;
|
||||
self.net_unrealized_pnl_rel_to_own_mcap
|
||||
self.net_unrealized_pnl_to_own_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBps32>(
|
||||
max_from,
|
||||
&unrealized.net_pnl.usd.height,
|
||||
|
||||
@@ -10,12 +10,12 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedCore};
|
||||
/// Extended relative metrics for own total unrealized PnL (extended only).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeExtendedOwnPnl<M: StorageMode = Rw> {
|
||||
#[traversable(wrap = "unrealized/profit", rename = "rel_to_own_gross")]
|
||||
pub unrealized_profit_rel_to_own_gross_pnl: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/loss", rename = "rel_to_own_gross")]
|
||||
pub unrealized_loss_rel_to_own_gross_pnl: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/net_pnl", rename = "rel_to_own_gross")]
|
||||
pub net_unrealized_pnl_rel_to_own_gross_pnl: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
#[traversable(wrap = "unrealized/profit", rename = "to_own_gross_pnl")]
|
||||
pub unrealized_profit_to_own_gross_pnl: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/loss", rename = "to_own_gross_pnl")]
|
||||
pub unrealized_loss_to_own_gross_pnl: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/net_pnl", rename = "to_own_gross_pnl")]
|
||||
pub net_unrealized_pnl_to_own_gross_pnl: PercentPerBlock<BasisPointsSigned32, M>,
|
||||
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ impl RelativeExtendedOwnPnl {
|
||||
let v1 = Version::ONE;
|
||||
|
||||
Ok(Self {
|
||||
unrealized_profit_rel_to_own_gross_pnl: cfg
|
||||
.import("unrealized_profit_rel_to_own_gross_pnl", v1)?,
|
||||
unrealized_loss_rel_to_own_gross_pnl: cfg
|
||||
.import("unrealized_loss_rel_to_own_gross_pnl", v1)?,
|
||||
net_unrealized_pnl_rel_to_own_gross_pnl: cfg
|
||||
.import("net_unrealized_pnl_rel_to_own_gross_pnl", Version::new(3))?,
|
||||
unrealized_profit_to_own_gross_pnl: cfg
|
||||
.import("unrealized_profit_to_own_gross_pnl", v1)?,
|
||||
unrealized_loss_to_own_gross_pnl: cfg
|
||||
.import("unrealized_loss_to_own_gross_pnl", v1)?,
|
||||
net_unrealized_pnl_to_own_gross_pnl: cfg
|
||||
.import("net_unrealized_pnl_to_own_gross_pnl", Version::new(3))?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,21 +40,21 @@ impl RelativeExtendedOwnPnl {
|
||||
gross_pnl_usd: &impl ReadableVec<Height, Dollars>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.unrealized_profit_rel_to_own_gross_pnl
|
||||
self.unrealized_profit_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.profit.base.usd.height,
|
||||
gross_pnl_usd,
|
||||
exit,
|
||||
)?;
|
||||
self.unrealized_loss_rel_to_own_gross_pnl
|
||||
self.unrealized_loss_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.loss.base.usd.height,
|
||||
gross_pnl_usd,
|
||||
exit,
|
||||
)?;
|
||||
self.net_unrealized_pnl_rel_to_own_gross_pnl
|
||||
self.net_unrealized_pnl_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBps32>(
|
||||
max_from,
|
||||
&unrealized.net_pnl.usd.height,
|
||||
|
||||
@@ -11,15 +11,15 @@ use crate::{
|
||||
/// Full relative metrics (sth/lth/all tier).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeFull<M: StorageMode = Rw> {
|
||||
#[traversable(wrap = "supply/in_profit", rename = "rel_to_own")]
|
||||
pub supply_in_profit_rel_to_own: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "supply/in_loss", rename = "rel_to_own")]
|
||||
pub supply_in_loss_rel_to_own: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "supply/in_profit", rename = "to_own")]
|
||||
pub supply_in_profit_to_own: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "supply/in_loss", rename = "to_own")]
|
||||
pub supply_in_loss_to_own: PercentPerBlock<BasisPoints16, M>,
|
||||
|
||||
#[traversable(wrap = "unrealized/profit", rename = "rel_to_mcap")]
|
||||
pub unrealized_profit_rel_to_mcap: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/loss", rename = "rel_to_mcap")]
|
||||
pub unrealized_loss_rel_to_mcap: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/profit", rename = "to_mcap")]
|
||||
pub unrealized_profit_to_mcap: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "unrealized/loss", rename = "to_mcap")]
|
||||
pub unrealized_loss_to_mcap: PercentPerBlock<BasisPoints16, M>,
|
||||
}
|
||||
|
||||
impl RelativeFull {
|
||||
@@ -28,13 +28,13 @@ impl RelativeFull {
|
||||
let v2 = Version::new(2);
|
||||
|
||||
Ok(Self {
|
||||
supply_in_profit_rel_to_own: cfg
|
||||
.import("supply_in_profit_rel_to_own", v1)?,
|
||||
supply_in_loss_rel_to_own: cfg.import("supply_in_loss_rel_to_own", v1)?,
|
||||
unrealized_profit_rel_to_mcap: cfg
|
||||
.import("unrealized_profit_rel_to_mcap", v2)?,
|
||||
unrealized_loss_rel_to_mcap: cfg
|
||||
.import("unrealized_loss_rel_to_mcap", v2)?,
|
||||
supply_in_profit_to_own: cfg
|
||||
.import("supply_in_profit_to_own", v1)?,
|
||||
supply_in_loss_to_own: cfg.import("supply_in_loss_to_own", v1)?,
|
||||
unrealized_profit_to_mcap: cfg
|
||||
.import("unrealized_profit_to_mcap", v2)?,
|
||||
unrealized_loss_to_mcap: cfg
|
||||
.import("unrealized_loss_to_mcap", v2)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,14 +46,14 @@ impl RelativeFull {
|
||||
market_cap: &impl ReadableVec<Height, Dollars>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.supply_in_profit_rel_to_own
|
||||
self.supply_in_profit_to_own
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from,
|
||||
&supply.in_profit.sats.height,
|
||||
&supply.total.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
self.supply_in_loss_rel_to_own
|
||||
self.supply_in_loss_to_own
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from,
|
||||
&supply.in_loss.sats.height,
|
||||
@@ -61,14 +61,14 @@ impl RelativeFull {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.unrealized_profit_rel_to_mcap
|
||||
self.unrealized_profit_to_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.profit.base.usd.height,
|
||||
market_cap,
|
||||
exit,
|
||||
)?;
|
||||
self.unrealized_loss_rel_to_mcap
|
||||
self.unrealized_loss_to_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.loss.base.usd.height,
|
||||
|
||||
@@ -10,23 +10,23 @@ use crate::distribution::metrics::{ImportConfig, SupplyCore};
|
||||
/// Relative-to-all metrics (not present for the "all" cohort itself).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeToAll<M: StorageMode = Rw> {
|
||||
#[traversable(wrap = "supply", rename = "rel_to_circulating")]
|
||||
pub supply_rel_to_circulating: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "supply/in_profit", rename = "rel_to_circulating")]
|
||||
pub supply_in_profit_rel_to_circulating: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "supply/in_loss", rename = "rel_to_circulating")]
|
||||
pub supply_in_loss_rel_to_circulating: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "supply", rename = "to_circulating")]
|
||||
pub supply_to_circulating: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "supply/in_profit", rename = "to_circulating")]
|
||||
pub supply_in_profit_to_circulating: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "supply/in_loss", rename = "to_circulating")]
|
||||
pub supply_in_loss_to_circulating: PercentPerBlock<BasisPoints16, M>,
|
||||
}
|
||||
|
||||
impl RelativeToAll {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
Ok(Self {
|
||||
supply_rel_to_circulating: cfg
|
||||
.import("supply_rel_to_circulating", Version::ONE)?,
|
||||
supply_in_profit_rel_to_circulating: cfg
|
||||
.import("supply_in_profit_rel_to_circulating", Version::ONE)?,
|
||||
supply_in_loss_rel_to_circulating: cfg
|
||||
.import("supply_in_loss_rel_to_circulating", Version::ONE)?,
|
||||
supply_to_circulating: cfg
|
||||
.import("supply_to_circulating", Version::ONE)?,
|
||||
supply_in_profit_to_circulating: cfg
|
||||
.import("supply_in_profit_to_circulating", Version::ONE)?,
|
||||
supply_in_loss_to_circulating: cfg
|
||||
.import("supply_in_loss_to_circulating", Version::ONE)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,21 +37,21 @@ impl RelativeToAll {
|
||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.supply_rel_to_circulating
|
||||
self.supply_to_circulating
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from,
|
||||
&supply.total.sats.height,
|
||||
all_supply_sats,
|
||||
exit,
|
||||
)?;
|
||||
self.supply_in_profit_rel_to_circulating
|
||||
self.supply_in_profit_to_circulating
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from,
|
||||
&supply.in_profit.sats.height,
|
||||
all_supply_sats,
|
||||
exit,
|
||||
)?;
|
||||
self.supply_in_loss_rel_to_circulating
|
||||
self.supply_in_loss_to_circulating
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from,
|
||||
&supply.in_loss.sats.height,
|
||||
|
||||
@@ -69,7 +69,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub utxo_cohorts: UTXOCohorts<M>,
|
||||
#[traversable(wrap = "cohorts", rename = "address")]
|
||||
pub address_cohorts: AddressCohorts<M>,
|
||||
#[traversable(wrap = "cointime")]
|
||||
#[traversable(wrap = "cointime/activity")]
|
||||
pub coinblocks_destroyed: PerBlockCumulativeWithSums<StoredF64, StoredF64, M>,
|
||||
pub addresses: AddressMetricsVecs<M>,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user