mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-27 08:09:58 -07:00
global: snapshot
This commit is contained in:
@@ -9,14 +9,14 @@ use vecdb::{
|
||||
WritableVec,
|
||||
};
|
||||
|
||||
use crate::{ComputeIndexes, blocks, indexes, internal::ComputedFromHeightLast};
|
||||
use crate::{ComputeIndexes, blocks, indexes, internal::ComputedFromHeight};
|
||||
|
||||
/// Address count with 30d change metric for a single type.
|
||||
#[derive(Traversable)]
|
||||
pub struct AddrCountVecs<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub count: ComputedFromHeightLast<StoredU64, M>,
|
||||
pub _30d_change: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub count: ComputedFromHeight<StoredU64, M>,
|
||||
pub _30d_change: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl AddrCountVecs {
|
||||
@@ -27,8 +27,8 @@ impl AddrCountVecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
count: ComputedFromHeightLast::forced_import(db, name, version, indexes)?,
|
||||
_30d_change: ComputedFromHeightLast::forced_import(
|
||||
count: ComputedFromHeight::forced_import(db, name, version, indexes)?,
|
||||
_30d_change: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_30d_change"),
|
||||
version,
|
||||
|
||||
@@ -6,16 +6,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredU64, Version};
|
||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{indexes, internal::{ComputedFromHeightCumulativeFull, WindowStarts}};
|
||||
use crate::{indexes, internal::{ComputedFromHeightFull, WindowStarts}};
|
||||
|
||||
use super::TotalAddrCountVecs;
|
||||
|
||||
/// New address count per block (global + per-type)
|
||||
#[derive(Traversable)]
|
||||
pub struct NewAddrCountVecs<M: StorageMode = Rw> {
|
||||
pub all: ComputedFromHeightCumulativeFull<StoredU64, M>,
|
||||
pub all: ComputedFromHeightFull<StoredU64, M>,
|
||||
#[traversable(flatten)]
|
||||
pub by_addresstype: ByAddressType<ComputedFromHeightCumulativeFull<StoredU64, M>>,
|
||||
pub by_addresstype: ByAddressType<ComputedFromHeightFull<StoredU64, M>>,
|
||||
}
|
||||
|
||||
impl NewAddrCountVecs {
|
||||
@@ -24,16 +24,16 @@ impl NewAddrCountVecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let all = ComputedFromHeightCumulativeFull::forced_import(
|
||||
let all = ComputedFromHeightFull::forced_import(
|
||||
db,
|
||||
"new_addr_count",
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let by_addresstype: ByAddressType<ComputedFromHeightCumulativeFull<StoredU64>> =
|
||||
let by_addresstype: ByAddressType<ComputedFromHeightFull<StoredU64>> =
|
||||
ByAddressType::new_with_name(|name| {
|
||||
ComputedFromHeightCumulativeFull::forced_import(
|
||||
ComputedFromHeightFull::forced_import(
|
||||
db,
|
||||
&format!("{name}_new_addr_count"),
|
||||
version,
|
||||
|
||||
@@ -6,16 +6,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredU64, Version};
|
||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{indexes, internal::ComputedFromHeightLast};
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
|
||||
use super::AddrCountsVecs;
|
||||
|
||||
/// Total address count (global + per-type) with all derived indexes
|
||||
#[derive(Traversable)]
|
||||
pub struct TotalAddrCountVecs<M: StorageMode = Rw> {
|
||||
pub all: ComputedFromHeightLast<StoredU64, M>,
|
||||
pub all: ComputedFromHeight<StoredU64, M>,
|
||||
#[traversable(flatten)]
|
||||
pub by_addresstype: ByAddressType<ComputedFromHeightLast<StoredU64, M>>,
|
||||
pub by_addresstype: ByAddressType<ComputedFromHeight<StoredU64, M>>,
|
||||
}
|
||||
|
||||
impl TotalAddrCountVecs {
|
||||
@@ -24,16 +24,16 @@ impl TotalAddrCountVecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let all = ComputedFromHeightLast::forced_import(
|
||||
let all = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"total_addr_count",
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let by_addresstype: ByAddressType<ComputedFromHeightLast<StoredU64>> = ByAddressType::new_with_name(
|
||||
let by_addresstype: ByAddressType<ComputedFromHeight<StoredU64>> = ByAddressType::new_with_name(
|
||||
|name| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_total_addr_count"),
|
||||
version,
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
distribution::state::AddressCohortState,
|
||||
indexes,
|
||||
internal::ComputedFromHeightLast,
|
||||
internal::ComputedFromHeight,
|
||||
prices,
|
||||
};
|
||||
|
||||
@@ -35,8 +35,8 @@ pub struct AddressCohortVecs<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub metrics: BasicCohortMetrics<M>,
|
||||
|
||||
pub addr_count: ComputedFromHeightLast<StoredU64, M>,
|
||||
pub addr_count_30d_change: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub addr_count: ComputedFromHeight<StoredU64, M>,
|
||||
pub addr_count_30d_change: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl AddressCohortVecs {
|
||||
@@ -67,13 +67,13 @@ impl AddressCohortVecs {
|
||||
|
||||
metrics: BasicCohortMetrics::forced_import(&cfg)?,
|
||||
|
||||
addr_count: ComputedFromHeightLast::forced_import(
|
||||
addr_count: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&cfg.name("addr_count"),
|
||||
version + VERSION,
|
||||
indexes,
|
||||
)?,
|
||||
addr_count_30d_change: ComputedFromHeightLast::forced_import(
|
||||
addr_count_30d_change: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&cfg.name("addr_count_30d_change"),
|
||||
version + VERSION,
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, AnyVec, EagerVec, Exit, ImportableVec, PcoVec, Rw, Sto
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
internal::{ComputedFromHeightCumulativeSum, ValueFromHeightCumulative, ValueFromHeightLast},
|
||||
internal::{ComputedFromHeightCumulativeSum, ValueFromHeightCumulative, ValueFromHeight},
|
||||
};
|
||||
|
||||
use super::ImportConfig;
|
||||
@@ -18,7 +18,7 @@ pub struct ActivityMetrics<M: StorageMode = Rw> {
|
||||
pub sent: ValueFromHeightCumulative<M>,
|
||||
|
||||
/// 14-day EMA of sent supply (sats, btc, usd)
|
||||
pub sent_14d_ema: ValueFromHeightLast<M>,
|
||||
pub sent_14d_ema: ValueFromHeight<M>,
|
||||
|
||||
/// Satoshi-blocks destroyed (supply * blocks_old when spent)
|
||||
pub satblocks_destroyed: M::Stored<EagerVec<PcoVec<Height, Sats>>>,
|
||||
@@ -44,7 +44,7 @@ impl ActivityMetrics {
|
||||
cfg.indexes,
|
||||
)?,
|
||||
|
||||
sent_14d_ema: ValueFromHeightLast::forced_import(
|
||||
sent_14d_ema: ValueFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("sent_14d_ema"),
|
||||
cfg.version,
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
use crate::{
|
||||
ComputeIndexes,
|
||||
distribution::state::CohortState,
|
||||
internal::{ComputedFromHeightLast, Price},
|
||||
internal::{ComputedFromHeight, Price},
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
@@ -15,10 +15,10 @@ use crate::distribution::metrics::ImportConfig;
|
||||
#[derive(Traversable)]
|
||||
pub struct CostBasisBase<M: StorageMode = Rw> {
|
||||
/// Minimum cost basis for any UTXO at this height
|
||||
pub min: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub min: Price<ComputedFromHeight<Cents, M>>,
|
||||
|
||||
/// Maximum cost basis for any UTXO at this height
|
||||
pub max: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub max: Price<ComputedFromHeight<Cents, M>>,
|
||||
}
|
||||
|
||||
impl CostBasisBase {
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, Rw, StorageMode, WritableVec};
|
||||
use crate::{
|
||||
distribution::state::CohortState,
|
||||
internal::{
|
||||
ComputedFromHeightLast, PERCENTILES_LEN, PercentilesVecs, compute_spot_percentile_rank,
|
||||
ComputedFromHeight, PERCENTILES_LEN, PercentilesVecs, compute_spot_percentile_rank,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -22,10 +22,10 @@ pub struct CostBasisExtended<M: StorageMode = Rw> {
|
||||
pub invested_capital: PercentilesVecs<M>,
|
||||
|
||||
/// What percentile of cost basis is below spot (sat-weighted)
|
||||
pub spot_cost_basis_percentile: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub spot_cost_basis_percentile: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
/// What percentile of invested capital is below spot (USD-weighted)
|
||||
pub spot_invested_capital_percentile: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub spot_invested_capital_percentile: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
impl CostBasisExtended {
|
||||
@@ -43,13 +43,13 @@ impl CostBasisExtended {
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
spot_cost_basis_percentile: ComputedFromHeightLast::forced_import(
|
||||
spot_cost_basis_percentile: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("spot_cost_basis_percentile"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
spot_invested_capital_percentile: ComputedFromHeightLast::forced_import(
|
||||
spot_invested_capital_percentile: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("spot_invested_capital_percentile"),
|
||||
cfg.version,
|
||||
|
||||
@@ -4,28 +4,28 @@ use brk_types::{Height, StoredF64, StoredU64};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::{ComputeIndexes, blocks, internal::ComputedFromHeightLast};
|
||||
use crate::{ComputeIndexes, blocks, internal::ComputedFromHeight};
|
||||
|
||||
use super::ImportConfig;
|
||||
|
||||
/// Output metrics for a cohort.
|
||||
#[derive(Traversable)]
|
||||
pub struct OutputsMetrics<M: StorageMode = Rw> {
|
||||
pub utxo_count: ComputedFromHeightLast<StoredU64, M>,
|
||||
pub utxo_count_30d_change: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub utxo_count: ComputedFromHeight<StoredU64, M>,
|
||||
pub utxo_count_30d_change: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl OutputsMetrics {
|
||||
/// Import output metrics from database.
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
Ok(Self {
|
||||
utxo_count: ComputedFromHeightLast::forced_import(
|
||||
utxo_count: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("utxo_count"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
utxo_count_30d_change: ComputedFromHeightLast::forced_import(
|
||||
utxo_count_30d_change: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("utxo_count_30d_change"),
|
||||
cfg.version,
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Exit, Ident, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
internal::{ComputedFromHeightLast, LazyFromHeightLast, RatioCents64},
|
||||
internal::{ComputedFromHeight, LazyFromHeight, RatioCents64},
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
@@ -14,29 +14,29 @@ use crate::distribution::metrics::ImportConfig;
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedAdjusted<M: StorageMode = Rw> {
|
||||
// === Adjusted Value (computed: cohort - up_to_1h) ===
|
||||
pub adjusted_value_created: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_destroyed: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_created: ComputedFromHeight<Cents, M>,
|
||||
pub adjusted_value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
|
||||
// === Adjusted Value Created/Destroyed Rolling Sums ===
|
||||
pub adjusted_value_created_24h: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_created_7d: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_created_30d: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_created_1y: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_destroyed_24h: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_destroyed_7d: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_destroyed_30d: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_destroyed_1y: ComputedFromHeightLast<Cents, M>,
|
||||
pub adjusted_value_created_24h: ComputedFromHeight<Cents, M>,
|
||||
pub adjusted_value_created_7d: ComputedFromHeight<Cents, M>,
|
||||
pub adjusted_value_created_30d: ComputedFromHeight<Cents, M>,
|
||||
pub adjusted_value_created_1y: ComputedFromHeight<Cents, M>,
|
||||
pub adjusted_value_destroyed_24h: ComputedFromHeight<Cents, M>,
|
||||
pub adjusted_value_destroyed_7d: ComputedFromHeight<Cents, M>,
|
||||
pub adjusted_value_destroyed_30d: ComputedFromHeight<Cents, M>,
|
||||
pub adjusted_value_destroyed_1y: ComputedFromHeight<Cents, M>,
|
||||
|
||||
// === Adjusted SOPR (rolling window ratios) ===
|
||||
pub adjusted_sopr: LazyFromHeightLast<StoredF64>,
|
||||
pub adjusted_sopr_24h: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub adjusted_sopr_7d: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub adjusted_sopr_30d: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub adjusted_sopr_1y: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub adjusted_sopr_24h_7d_ema: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub adjusted_sopr_7d_ema: LazyFromHeightLast<StoredF64>,
|
||||
pub adjusted_sopr_24h_30d_ema: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub adjusted_sopr_30d_ema: LazyFromHeightLast<StoredF64>,
|
||||
pub adjusted_sopr: LazyFromHeight<StoredF64>,
|
||||
pub adjusted_sopr_24h: ComputedFromHeight<StoredF64, M>,
|
||||
pub adjusted_sopr_7d: ComputedFromHeight<StoredF64, M>,
|
||||
pub adjusted_sopr_30d: ComputedFromHeight<StoredF64, M>,
|
||||
pub adjusted_sopr_1y: ComputedFromHeight<StoredF64, M>,
|
||||
pub adjusted_sopr_24h_7d_ema: ComputedFromHeight<StoredF64, M>,
|
||||
pub adjusted_sopr_7d_ema: LazyFromHeight<StoredF64>,
|
||||
pub adjusted_sopr_24h_30d_ema: ComputedFromHeight<StoredF64, M>,
|
||||
pub adjusted_sopr_30d_ema: LazyFromHeight<StoredF64>,
|
||||
}
|
||||
|
||||
impl RealizedAdjusted {
|
||||
@@ -45,7 +45,7 @@ impl RealizedAdjusted {
|
||||
|
||||
macro_rules! import_rolling {
|
||||
($name:expr) => {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name($name),
|
||||
cfg.version + v1,
|
||||
@@ -54,13 +54,13 @@ impl RealizedAdjusted {
|
||||
};
|
||||
}
|
||||
|
||||
let adjusted_value_created = ComputedFromHeightLast::forced_import(
|
||||
let adjusted_value_created = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("adjusted_value_created"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let adjusted_value_destroyed = ComputedFromHeightLast::forced_import(
|
||||
let adjusted_value_destroyed = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("adjusted_value_destroyed"),
|
||||
cfg.version,
|
||||
@@ -76,31 +76,31 @@ impl RealizedAdjusted {
|
||||
let adjusted_value_destroyed_30d = import_rolling!("adjusted_value_destroyed_30d");
|
||||
let adjusted_value_destroyed_1y = import_rolling!("adjusted_value_destroyed_1y");
|
||||
|
||||
let adjusted_sopr_24h = ComputedFromHeightLast::forced_import(
|
||||
let adjusted_sopr_24h = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("adjusted_sopr_24h"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let adjusted_sopr_7d = ComputedFromHeightLast::forced_import(
|
||||
let adjusted_sopr_7d = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("adjusted_sopr_7d"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let adjusted_sopr_30d = ComputedFromHeightLast::forced_import(
|
||||
let adjusted_sopr_30d = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("adjusted_sopr_30d"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let adjusted_sopr_1y = ComputedFromHeightLast::forced_import(
|
||||
let adjusted_sopr_1y = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("adjusted_sopr_1y"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let adjusted_sopr = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let adjusted_sopr = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("adjusted_sopr"),
|
||||
cfg.version + v1,
|
||||
adjusted_sopr_24h.height.read_only_boxed_clone(),
|
||||
@@ -108,14 +108,14 @@ impl RealizedAdjusted {
|
||||
);
|
||||
|
||||
let adjusted_sopr_24h_7d_ema = import_rolling!("adjusted_sopr_24h_7d_ema");
|
||||
let adjusted_sopr_7d_ema = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let adjusted_sopr_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("adjusted_sopr_7d_ema"),
|
||||
cfg.version + v1,
|
||||
adjusted_sopr_24h_7d_ema.height.read_only_boxed_clone(),
|
||||
&adjusted_sopr_24h_7d_ema,
|
||||
);
|
||||
let adjusted_sopr_24h_30d_ema = import_rolling!("adjusted_sopr_24h_30d_ema");
|
||||
let adjusted_sopr_30d_ema = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let adjusted_sopr_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("adjusted_sopr_30d_ema"),
|
||||
cfg.version + v1,
|
||||
adjusted_sopr_24h_30d_ema.height.read_only_boxed_clone(),
|
||||
|
||||
@@ -12,10 +12,10 @@ use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
distribution::state::RealizedState,
|
||||
internal::{
|
||||
CentsPlus, CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeightLast,
|
||||
ComputedFromHeightRatio, NegCentsUnsignedToDollars, ValueFromHeightCumulative, LazyFromHeightLast,
|
||||
CentsPlus, CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeight,
|
||||
ComputedFromHeightRatio, NegCentsUnsignedToDollars, ValueFromHeightCumulative, LazyFromHeight,
|
||||
PercentageCentsF32, PercentageCentsSignedCentsF32, PercentageCentsSignedDollarsF32, Price, RatioCents64,
|
||||
StoredF32Identity, ValueFromHeightLast,
|
||||
StoredF32Identity, ValueFromHeight,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -26,113 +26,113 @@ use crate::distribution::metrics::ImportConfig;
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
// === Realized Cap ===
|
||||
pub realized_cap_cents: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_cap: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub realized_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub realized_cap_cents: ComputedFromHeight<Cents, M>,
|
||||
pub realized_cap: LazyFromHeight<Dollars, Cents>,
|
||||
pub realized_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub realized_price_extra: ComputedFromHeightRatio<M>,
|
||||
pub realized_cap_30d_delta: ComputedFromHeightLast<CentsSigned, M>,
|
||||
pub realized_cap_30d_delta: ComputedFromHeight<CentsSigned, M>,
|
||||
|
||||
// === Investor Price ===
|
||||
pub investor_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub investor_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub investor_price_extra: ComputedFromHeightRatio<M>,
|
||||
|
||||
// === Floor/Ceiling Price Bands ===
|
||||
pub lower_price_band: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub upper_price_band: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub lower_price_band: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub upper_price_band: Price<ComputedFromHeight<Cents, M>>,
|
||||
|
||||
// === Raw values for aggregation ===
|
||||
pub cap_raw: M::Stored<BytesVec<Height, CentsSats>>,
|
||||
pub investor_cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
|
||||
|
||||
// === MVRV ===
|
||||
pub mvrv: LazyFromHeightLast<StoredF32>,
|
||||
pub mvrv: LazyFromHeight<StoredF32>,
|
||||
|
||||
// === Realized Profit/Loss ===
|
||||
pub realized_profit: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub realized_profit_7d_ema: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_profit_7d_ema: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub realized_loss_7d_ema: ComputedFromHeightLast<Cents, M>,
|
||||
pub neg_realized_loss: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub realized_loss_7d_ema: ComputedFromHeight<Cents, M>,
|
||||
pub neg_realized_loss: LazyFromHeight<Dollars, Cents>,
|
||||
pub net_realized_pnl: ComputedFromHeightCumulative<CentsSigned, M>,
|
||||
pub net_realized_pnl_7d_ema: ComputedFromHeightLast<CentsSigned, M>,
|
||||
pub realized_value: ComputedFromHeightLast<Cents, M>,
|
||||
pub net_realized_pnl_7d_ema: ComputedFromHeight<CentsSigned, M>,
|
||||
pub realized_value: ComputedFromHeight<Cents, M>,
|
||||
|
||||
// === Realized vs Realized Cap Ratios ===
|
||||
pub realized_profit_rel_to_realized_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub realized_loss_rel_to_realized_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub net_realized_pnl_rel_to_realized_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub realized_profit_rel_to_realized_cap: ComputedFromHeight<StoredF32, M>,
|
||||
pub realized_loss_rel_to_realized_cap: ComputedFromHeight<StoredF32, M>,
|
||||
pub net_realized_pnl_rel_to_realized_cap: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
// === Total Realized PnL ===
|
||||
pub total_realized_pnl: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub total_realized_pnl: LazyFromHeight<Dollars, Cents>,
|
||||
|
||||
// === Value Created/Destroyed Splits (stored) ===
|
||||
pub profit_value_created: ComputedFromHeightLast<Cents, M>,
|
||||
pub profit_value_destroyed: ComputedFromHeightLast<Cents, M>,
|
||||
pub loss_value_created: ComputedFromHeightLast<Cents, M>,
|
||||
pub loss_value_destroyed: ComputedFromHeightLast<Cents, M>,
|
||||
pub profit_value_created: ComputedFromHeight<Cents, M>,
|
||||
pub profit_value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
pub loss_value_created: ComputedFromHeight<Cents, M>,
|
||||
pub loss_value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
|
||||
// === Value Created/Destroyed Totals ===
|
||||
pub value_created: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_destroyed: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_created: ComputedFromHeight<Cents, M>,
|
||||
pub value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
|
||||
// === Capitulation/Profit Flow (lazy aliases) ===
|
||||
pub capitulation_flow: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub profit_flow: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub capitulation_flow: LazyFromHeight<Dollars, Cents>,
|
||||
pub profit_flow: LazyFromHeight<Dollars, Cents>,
|
||||
|
||||
// === Value Created/Destroyed Rolling Sums ===
|
||||
pub value_created_24h: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_created_7d: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_created_30d: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_created_1y: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_destroyed_24h: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_destroyed_7d: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_destroyed_30d: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_destroyed_1y: ComputedFromHeightLast<Cents, M>,
|
||||
pub value_created_24h: ComputedFromHeight<Cents, M>,
|
||||
pub value_created_7d: ComputedFromHeight<Cents, M>,
|
||||
pub value_created_30d: ComputedFromHeight<Cents, M>,
|
||||
pub value_created_1y: ComputedFromHeight<Cents, M>,
|
||||
pub value_destroyed_24h: ComputedFromHeight<Cents, M>,
|
||||
pub value_destroyed_7d: ComputedFromHeight<Cents, M>,
|
||||
pub value_destroyed_30d: ComputedFromHeight<Cents, M>,
|
||||
pub value_destroyed_1y: ComputedFromHeight<Cents, M>,
|
||||
|
||||
// === SOPR (rolling window ratios) ===
|
||||
pub sopr: LazyFromHeightLast<StoredF64>,
|
||||
pub sopr_24h: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub sopr_7d: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub sopr_30d: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub sopr_1y: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub sopr_24h_7d_ema: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub sopr_7d_ema: LazyFromHeightLast<StoredF64>,
|
||||
pub sopr_24h_30d_ema: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub sopr_30d_ema: LazyFromHeightLast<StoredF64>,
|
||||
pub sopr: LazyFromHeight<StoredF64>,
|
||||
pub sopr_24h: ComputedFromHeight<StoredF64, M>,
|
||||
pub sopr_7d: ComputedFromHeight<StoredF64, M>,
|
||||
pub sopr_30d: ComputedFromHeight<StoredF64, M>,
|
||||
pub sopr_1y: ComputedFromHeight<StoredF64, M>,
|
||||
pub sopr_24h_7d_ema: ComputedFromHeight<StoredF64, M>,
|
||||
pub sopr_7d_ema: LazyFromHeight<StoredF64>,
|
||||
pub sopr_24h_30d_ema: ComputedFromHeight<StoredF64, M>,
|
||||
pub sopr_30d_ema: LazyFromHeight<StoredF64>,
|
||||
|
||||
// === Sell Side Risk Rolling Sum Intermediates ===
|
||||
pub realized_value_24h: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_value_7d: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_value_30d: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_value_1y: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_value_24h: ComputedFromHeight<Cents, M>,
|
||||
pub realized_value_7d: ComputedFromHeight<Cents, M>,
|
||||
pub realized_value_30d: ComputedFromHeight<Cents, M>,
|
||||
pub realized_value_1y: ComputedFromHeight<Cents, M>,
|
||||
|
||||
// === Sell Side Risk (rolling window ratios) ===
|
||||
pub sell_side_risk_ratio: LazyFromHeightLast<StoredF32>,
|
||||
pub sell_side_risk_ratio_24h: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_7d: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_30d: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_1y: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_24h_7d_ema: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_7d_ema: LazyFromHeightLast<StoredF32>,
|
||||
pub sell_side_risk_ratio_24h_30d_ema: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_30d_ema: LazyFromHeightLast<StoredF32>,
|
||||
pub sell_side_risk_ratio: LazyFromHeight<StoredF32>,
|
||||
pub sell_side_risk_ratio_24h: ComputedFromHeight<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_7d: ComputedFromHeight<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_30d: ComputedFromHeight<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_1y: ComputedFromHeight<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_24h_7d_ema: ComputedFromHeight<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_7d_ema: LazyFromHeight<StoredF32>,
|
||||
pub sell_side_risk_ratio_24h_30d_ema: ComputedFromHeight<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_30d_ema: LazyFromHeight<StoredF32>,
|
||||
|
||||
// === Net Realized PnL Deltas ===
|
||||
pub net_realized_pnl_cumulative_30d_delta: ComputedFromHeightLast<CentsSigned, M>,
|
||||
pub net_realized_pnl_cumulative_30d_delta: ComputedFromHeight<CentsSigned, M>,
|
||||
pub net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub net_realized_pnl_cumulative_30d_delta_rel_to_market_cap:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
// === Peak Regret ===
|
||||
pub peak_regret: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub peak_regret_rel_to_realized_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub peak_regret_rel_to_realized_cap: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
// === Sent in Profit/Loss ===
|
||||
pub sent_in_profit: ValueFromHeightCumulative<M>,
|
||||
pub sent_in_profit_14d_ema: ValueFromHeightLast<M>,
|
||||
pub sent_in_profit_14d_ema: ValueFromHeight<M>,
|
||||
pub sent_in_loss: ValueFromHeightCumulative<M>,
|
||||
pub sent_in_loss_14d_ema: ValueFromHeightLast<M>,
|
||||
pub sent_in_loss_14d_ema: ValueFromHeight<M>,
|
||||
}
|
||||
|
||||
impl RealizedBase {
|
||||
@@ -142,14 +142,14 @@ impl RealizedBase {
|
||||
let v2 = Version::new(2);
|
||||
let v3 = Version::new(3);
|
||||
// Import combined types using forced_import which handles height + derived
|
||||
let realized_cap_cents = ComputedFromHeightLast::forced_import(
|
||||
let realized_cap_cents = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_cap_cents"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_cap = LazyFromHeightLast::from_computed::<CentsUnsignedToDollars>(
|
||||
let realized_cap = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
&cfg.name("realized_cap"),
|
||||
cfg.version,
|
||||
realized_cap_cents.height.read_only_boxed_clone(),
|
||||
@@ -163,7 +163,7 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_profit_7d_ema = ComputedFromHeightLast::forced_import(
|
||||
let realized_profit_7d_ema = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_profit_7d_ema"),
|
||||
cfg.version,
|
||||
@@ -177,14 +177,14 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_loss_7d_ema = ComputedFromHeightLast::forced_import(
|
||||
let realized_loss_7d_ema = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_loss_7d_ema"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let neg_realized_loss = LazyFromHeightLast::from_height_source::<NegCentsUnsignedToDollars>(
|
||||
let neg_realized_loss = LazyFromHeight::from_height_source::<NegCentsUnsignedToDollars>(
|
||||
&cfg.name("neg_realized_loss"),
|
||||
cfg.version + v1,
|
||||
realized_loss.height.read_only_boxed_clone(),
|
||||
@@ -198,7 +198,7 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let net_realized_pnl_7d_ema = ComputedFromHeightLast::forced_import(
|
||||
let net_realized_pnl_7d_ema = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_7d_ema"),
|
||||
cfg.version,
|
||||
@@ -212,35 +212,35 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_value = ComputedFromHeightLast::forced_import(
|
||||
let realized_value = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_value"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let total_realized_pnl = LazyFromHeightLast::from_computed::<CentsUnsignedToDollars>(
|
||||
let total_realized_pnl = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
&cfg.name("total_realized_pnl"),
|
||||
cfg.version + v1,
|
||||
realized_value.height.read_only_boxed_clone(),
|
||||
&realized_value,
|
||||
);
|
||||
|
||||
let realized_profit_rel_to_realized_cap = ComputedFromHeightLast::forced_import(
|
||||
let realized_profit_rel_to_realized_cap = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_profit_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_loss_rel_to_realized_cap = ComputedFromHeightLast::forced_import(
|
||||
let realized_loss_rel_to_realized_cap = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_loss_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let net_realized_pnl_rel_to_realized_cap = ComputedFromHeightLast::forced_import(
|
||||
let net_realized_pnl_rel_to_realized_cap = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
@@ -286,51 +286,51 @@ impl RealizedBase {
|
||||
let investor_cap_raw =
|
||||
BytesVec::forced_import(cfg.db, &cfg.name("investor_cap_raw"), cfg.version)?;
|
||||
|
||||
let profit_value_created = ComputedFromHeightLast::forced_import(
|
||||
let profit_value_created = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("profit_value_created"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let profit_value_destroyed = ComputedFromHeightLast::forced_import(
|
||||
let profit_value_destroyed = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("profit_value_destroyed"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let loss_value_created = ComputedFromHeightLast::forced_import(
|
||||
let loss_value_created = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("loss_value_created"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let loss_value_destroyed = ComputedFromHeightLast::forced_import(
|
||||
let loss_value_destroyed = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("loss_value_destroyed"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let value_created = ComputedFromHeightLast::forced_import(
|
||||
let value_created = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("value_created"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let value_destroyed = ComputedFromHeightLast::forced_import(
|
||||
let value_destroyed = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("value_destroyed"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let capitulation_flow = LazyFromHeightLast::from_computed::<CentsUnsignedToDollars>(
|
||||
let capitulation_flow = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
&cfg.name("capitulation_flow"),
|
||||
cfg.version,
|
||||
loss_value_destroyed.height.read_only_boxed_clone(),
|
||||
&loss_value_destroyed,
|
||||
);
|
||||
let profit_flow = LazyFromHeightLast::from_computed::<CentsUnsignedToDollars>(
|
||||
let profit_flow = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
&cfg.name("profit_flow"),
|
||||
cfg.version,
|
||||
profit_value_destroyed.height.read_only_boxed_clone(),
|
||||
@@ -344,7 +344,7 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let mvrv = LazyFromHeightLast::from_computed::<StoredF32Identity>(
|
||||
let mvrv = LazyFromHeight::from_computed::<StoredF32Identity>(
|
||||
&cfg.name("mvrv"),
|
||||
cfg.version,
|
||||
realized_price_extra.ratio.height.read_only_boxed_clone(),
|
||||
@@ -354,7 +354,7 @@ impl RealizedBase {
|
||||
// === Rolling sum intermediates ===
|
||||
macro_rules! import_rolling {
|
||||
($name:expr) => {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name($name),
|
||||
cfg.version + v1,
|
||||
@@ -382,7 +382,7 @@ impl RealizedBase {
|
||||
let sopr_7d = import_rolling!("sopr_7d");
|
||||
let sopr_30d = import_rolling!("sopr_30d");
|
||||
let sopr_1y = import_rolling!("sopr_1y");
|
||||
let sopr = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let sopr = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("sopr"),
|
||||
cfg.version + v1,
|
||||
sopr_24h.height.read_only_boxed_clone(),
|
||||
@@ -393,7 +393,7 @@ impl RealizedBase {
|
||||
let sell_side_risk_ratio_7d = import_rolling!("sell_side_risk_ratio_7d");
|
||||
let sell_side_risk_ratio_30d = import_rolling!("sell_side_risk_ratio_30d");
|
||||
let sell_side_risk_ratio_1y = import_rolling!("sell_side_risk_ratio_1y");
|
||||
let sell_side_risk_ratio = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let sell_side_risk_ratio = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("sell_side_risk_ratio"),
|
||||
cfg.version + v1,
|
||||
sell_side_risk_ratio_24h.height.read_only_boxed_clone(),
|
||||
@@ -402,14 +402,14 @@ impl RealizedBase {
|
||||
|
||||
// === EMA imports + identity aliases ===
|
||||
let sopr_24h_7d_ema = import_rolling!("sopr_24h_7d_ema");
|
||||
let sopr_7d_ema = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let sopr_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("sopr_7d_ema"),
|
||||
cfg.version + v1,
|
||||
sopr_24h_7d_ema.height.read_only_boxed_clone(),
|
||||
&sopr_24h_7d_ema,
|
||||
);
|
||||
let sopr_24h_30d_ema = import_rolling!("sopr_24h_30d_ema");
|
||||
let sopr_30d_ema = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let sopr_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("sopr_30d_ema"),
|
||||
cfg.version + v1,
|
||||
sopr_24h_30d_ema.height.read_only_boxed_clone(),
|
||||
@@ -417,7 +417,7 @@ impl RealizedBase {
|
||||
);
|
||||
|
||||
let sell_side_risk_ratio_24h_7d_ema = import_rolling!("sell_side_risk_ratio_24h_7d_ema");
|
||||
let sell_side_risk_ratio_7d_ema = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let sell_side_risk_ratio_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("sell_side_risk_ratio_7d_ema"),
|
||||
cfg.version + v1,
|
||||
sell_side_risk_ratio_24h_7d_ema
|
||||
@@ -426,7 +426,7 @@ impl RealizedBase {
|
||||
&sell_side_risk_ratio_24h_7d_ema,
|
||||
);
|
||||
let sell_side_risk_ratio_24h_30d_ema = import_rolling!("sell_side_risk_ratio_24h_30d_ema");
|
||||
let sell_side_risk_ratio_30d_ema = LazyFromHeightLast::from_computed::<Ident>(
|
||||
let sell_side_risk_ratio_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||
&cfg.name("sell_side_risk_ratio_30d_ema"),
|
||||
cfg.version + v1,
|
||||
sell_side_risk_ratio_24h_30d_ema
|
||||
@@ -435,7 +435,7 @@ impl RealizedBase {
|
||||
&sell_side_risk_ratio_24h_30d_ema,
|
||||
);
|
||||
|
||||
let peak_regret_rel_to_realized_cap = ComputedFromHeightLast::forced_import(
|
||||
let peak_regret_rel_to_realized_cap = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("peak_regret_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
@@ -447,7 +447,7 @@ impl RealizedBase {
|
||||
realized_cap,
|
||||
realized_price,
|
||||
realized_price_extra,
|
||||
realized_cap_30d_delta: ComputedFromHeightLast::forced_import(
|
||||
realized_cap_30d_delta: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_cap_30d_delta"),
|
||||
cfg.version,
|
||||
@@ -510,21 +510,21 @@ impl RealizedBase {
|
||||
sell_side_risk_ratio_7d_ema,
|
||||
sell_side_risk_ratio_24h_30d_ema,
|
||||
sell_side_risk_ratio_30d_ema,
|
||||
net_realized_pnl_cumulative_30d_delta: ComputedFromHeightLast::forced_import(
|
||||
net_realized_pnl_cumulative_30d_delta: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_cumulative_30d_delta"),
|
||||
cfg.version + v3,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap"),
|
||||
cfg.version + v3,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
net_realized_pnl_cumulative_30d_delta_rel_to_market_cap:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_cumulative_30d_delta_rel_to_market_cap"),
|
||||
cfg.version + v3,
|
||||
@@ -538,7 +538,7 @@ impl RealizedBase {
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
sent_in_profit_14d_ema: ValueFromHeightLast::forced_import(
|
||||
sent_in_profit_14d_ema: ValueFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("sent_in_profit_14d_ema"),
|
||||
cfg.version,
|
||||
@@ -550,7 +550,7 @@ impl RealizedBase {
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
sent_in_loss_14d_ema: ValueFromHeightLast::forced_import(
|
||||
sent_in_loss_14d_ema: ValueFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("sent_in_loss_14d_ema"),
|
||||
cfg.version,
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
internal::{ComputedFromHeightLast, ComputedFromHeightRatioExtension, RatioCents64},
|
||||
internal::{ComputedFromHeight, ComputedFromHeightRatioExtension, RatioCents64},
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
@@ -15,23 +15,23 @@ use super::RealizedBase;
|
||||
/// Extended realized metrics (only for extended cohorts: all, sth, lth, age_range).
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedExtended<M: StorageMode = Rw> {
|
||||
pub realized_cap_rel_to_own_market_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub realized_cap_rel_to_own_market_cap: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
// === Realized Profit/Loss Rolling Sums ===
|
||||
pub realized_profit_24h: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_profit_7d: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_profit_30d: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_profit_1y: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_loss_24h: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_loss_7d: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_loss_30d: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_loss_1y: ComputedFromHeightLast<Cents, M>,
|
||||
pub realized_profit_24h: ComputedFromHeight<Cents, M>,
|
||||
pub realized_profit_7d: ComputedFromHeight<Cents, M>,
|
||||
pub realized_profit_30d: ComputedFromHeight<Cents, M>,
|
||||
pub realized_profit_1y: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss_24h: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss_7d: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss_30d: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss_1y: ComputedFromHeight<Cents, M>,
|
||||
|
||||
// === Realized Profit to Loss Ratio (from rolling sums) ===
|
||||
pub realized_profit_to_loss_ratio_24h: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub realized_profit_to_loss_ratio_7d: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub realized_profit_to_loss_ratio_30d: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub realized_profit_to_loss_ratio_1y: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub realized_profit_to_loss_ratio_24h: ComputedFromHeight<StoredF64, M>,
|
||||
pub realized_profit_to_loss_ratio_7d: ComputedFromHeight<StoredF64, M>,
|
||||
pub realized_profit_to_loss_ratio_30d: ComputedFromHeight<StoredF64, M>,
|
||||
pub realized_profit_to_loss_ratio_1y: ComputedFromHeight<StoredF64, M>,
|
||||
|
||||
// === Extended ratio metrics for realized/investor price ===
|
||||
pub realized_price_ratio_ext: ComputedFromHeightRatioExtension<M>,
|
||||
@@ -44,7 +44,7 @@ impl RealizedExtended {
|
||||
|
||||
macro_rules! import_rolling {
|
||||
($name:expr) => {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name($name),
|
||||
cfg.version + v1,
|
||||
@@ -54,7 +54,7 @@ impl RealizedExtended {
|
||||
}
|
||||
|
||||
Ok(RealizedExtended {
|
||||
realized_cap_rel_to_own_market_cap: ComputedFromHeightLast::forced_import(
|
||||
realized_cap_rel_to_own_market_cap: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_cap_rel_to_own_market_cap"),
|
||||
cfg.version,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, Sats, StoredF32, StoredF64, Version};
|
||||
use vecdb::{Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, LazyFromHeightLast,
|
||||
ComputedFromHeight, LazyFromHeight,
|
||||
NegPercentageDollarsF32, PercentageDollarsF32, PercentageSatsF64,
|
||||
StoredF32Identity,
|
||||
};
|
||||
@@ -17,19 +17,19 @@ use crate::distribution::metrics::{ImportConfig, RealizedBase, UnrealizedBase};
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeBase<M: StorageMode = Rw> {
|
||||
// === Supply in Profit/Loss Relative to Own Supply ===
|
||||
pub supply_in_profit_rel_to_own_supply: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub supply_in_loss_rel_to_own_supply: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub supply_in_profit_rel_to_own_supply: ComputedFromHeight<StoredF64, M>,
|
||||
pub supply_in_loss_rel_to_own_supply: ComputedFromHeight<StoredF64, M>,
|
||||
|
||||
// === Unrealized vs Market Cap ===
|
||||
pub unrealized_profit_rel_to_market_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub unrealized_loss_rel_to_market_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub neg_unrealized_loss_rel_to_market_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub net_unrealized_pnl_rel_to_market_cap: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub nupl: LazyFromHeightLast<StoredF32, StoredF32>,
|
||||
pub unrealized_profit_rel_to_market_cap: ComputedFromHeight<StoredF32, M>,
|
||||
pub unrealized_loss_rel_to_market_cap: ComputedFromHeight<StoredF32, M>,
|
||||
pub neg_unrealized_loss_rel_to_market_cap: ComputedFromHeight<StoredF32, M>,
|
||||
pub net_unrealized_pnl_rel_to_market_cap: ComputedFromHeight<StoredF32, M>,
|
||||
pub nupl: LazyFromHeight<StoredF32, StoredF32>,
|
||||
|
||||
// === Invested Capital in Profit/Loss as % of Realized Cap ===
|
||||
pub invested_capital_in_profit_pct: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub invested_capital_in_loss_pct: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub invested_capital_in_profit_pct: ComputedFromHeight<StoredF32, M>,
|
||||
pub invested_capital_in_loss_pct: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
impl RelativeBase {
|
||||
@@ -37,11 +37,11 @@ impl RelativeBase {
|
||||
let v1 = Version::ONE;
|
||||
let v2 = Version::new(2);
|
||||
|
||||
let net_unrealized_pnl_rel_to_market_cap = ComputedFromHeightLast::forced_import(
|
||||
let net_unrealized_pnl_rel_to_market_cap = ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("net_unrealized_pnl_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?;
|
||||
|
||||
let nupl = LazyFromHeightLast::from_computed::<StoredF32Identity>(
|
||||
let nupl = LazyFromHeight::from_computed::<StoredF32Identity>(
|
||||
&cfg.name("nupl"),
|
||||
cfg.version + v2,
|
||||
net_unrealized_pnl_rel_to_market_cap.height.read_only_boxed_clone(),
|
||||
@@ -49,27 +49,27 @@ impl RelativeBase {
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
supply_in_profit_rel_to_own_supply: ComputedFromHeightLast::forced_import(
|
||||
supply_in_profit_rel_to_own_supply: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("supply_in_profit_rel_to_own_supply"), cfg.version + v1, cfg.indexes,
|
||||
)?,
|
||||
supply_in_loss_rel_to_own_supply: ComputedFromHeightLast::forced_import(
|
||||
supply_in_loss_rel_to_own_supply: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("supply_in_loss_rel_to_own_supply"), cfg.version + v1, cfg.indexes,
|
||||
)?,
|
||||
unrealized_profit_rel_to_market_cap: ComputedFromHeightLast::forced_import(
|
||||
unrealized_profit_rel_to_market_cap: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("unrealized_profit_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?,
|
||||
unrealized_loss_rel_to_market_cap: ComputedFromHeightLast::forced_import(
|
||||
unrealized_loss_rel_to_market_cap: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("unrealized_loss_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?,
|
||||
neg_unrealized_loss_rel_to_market_cap: ComputedFromHeightLast::forced_import(
|
||||
neg_unrealized_loss_rel_to_market_cap: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("neg_unrealized_loss_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?,
|
||||
net_unrealized_pnl_rel_to_market_cap,
|
||||
nupl,
|
||||
invested_capital_in_profit_pct: ComputedFromHeightLast::forced_import(
|
||||
invested_capital_in_profit_pct: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("invested_capital_in_profit_pct"), cfg.version, cfg.indexes,
|
||||
)?,
|
||||
invested_capital_in_loss_pct: ComputedFromHeightLast::forced_import(
|
||||
invested_capital_in_loss_pct: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("invested_capital_in_loss_pct"), cfg.version, cfg.indexes,
|
||||
)?,
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, StoredF32};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, NegPercentageDollarsF32, PercentageDollarsF32,
|
||||
ComputedFromHeight, NegPercentageDollarsF32, PercentageDollarsF32,
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
@@ -13,13 +13,13 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeExtendedOwnMarketCap<M: StorageMode = Rw> {
|
||||
pub unrealized_profit_rel_to_own_market_cap:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub unrealized_loss_rel_to_own_market_cap:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub neg_unrealized_loss_rel_to_own_market_cap:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_market_cap:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
impl RelativeExtendedOwnMarketCap {
|
||||
@@ -30,28 +30,28 @@ impl RelativeExtendedOwnMarketCap {
|
||||
|
||||
Ok(Self {
|
||||
unrealized_profit_rel_to_own_market_cap:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_profit_rel_to_own_market_cap"),
|
||||
cfg.version + v2,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
unrealized_loss_rel_to_own_market_cap:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_loss_rel_to_own_market_cap"),
|
||||
cfg.version + v2,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
neg_unrealized_loss_rel_to_own_market_cap:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("neg_unrealized_loss_rel_to_own_market_cap"),
|
||||
cfg.version + v2,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
net_unrealized_pnl_rel_to_own_market_cap:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_unrealized_pnl_rel_to_own_market_cap"),
|
||||
cfg.version + v2,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, StoredF32};
|
||||
use vecdb::{Exit, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, NegPercentageDollarsF32, PercentageDollarsF32,
|
||||
ComputedFromHeight, NegPercentageDollarsF32, PercentageDollarsF32,
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
@@ -13,13 +13,13 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeExtendedOwnPnl<M: StorageMode = Rw> {
|
||||
pub unrealized_profit_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub neg_unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
impl RelativeExtendedOwnPnl {
|
||||
@@ -31,28 +31,28 @@ impl RelativeExtendedOwnPnl {
|
||||
|
||||
Ok(Self {
|
||||
unrealized_profit_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_profit_rel_to_own_total_unrealized_pnl"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_loss_rel_to_own_total_unrealized_pnl"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
neg_unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("neg_unrealized_loss_rel_to_own_total_unrealized_pnl"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
net_unrealized_pnl_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_unrealized_pnl_rel_to_own_total_unrealized_pnl"),
|
||||
cfg.version + v2,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Dollars, Height, StoredF32};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, PercentageDollarsF32,
|
||||
ComputedFromHeight, PercentageDollarsF32,
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
@@ -13,7 +13,7 @@ use crate::distribution::metrics::ImportConfig;
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativePeakRegret<M: StorageMode = Rw> {
|
||||
pub unrealized_peak_regret_rel_to_market_cap:
|
||||
ComputedFromHeightLast<StoredF32, M>,
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
impl RelativePeakRegret {
|
||||
@@ -22,7 +22,7 @@ impl RelativePeakRegret {
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
unrealized_peak_regret_rel_to_market_cap:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_peak_regret_rel_to_market_cap"),
|
||||
cfg.version,
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Sats, StoredF64};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, PercentageSatsF64};
|
||||
use crate::internal::{ComputedFromHeight, PercentageSatsF64};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
|
||||
@@ -11,11 +11,11 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeToAll<M: StorageMode = Rw> {
|
||||
pub supply_rel_to_circulating_supply:
|
||||
ComputedFromHeightLast<StoredF64, M>,
|
||||
ComputedFromHeight<StoredF64, M>,
|
||||
pub supply_in_profit_rel_to_circulating_supply:
|
||||
ComputedFromHeightLast<StoredF64, M>,
|
||||
ComputedFromHeight<StoredF64, M>,
|
||||
pub supply_in_loss_rel_to_circulating_supply:
|
||||
ComputedFromHeightLast<StoredF64, M>,
|
||||
ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl RelativeToAll {
|
||||
@@ -24,21 +24,21 @@ impl RelativeToAll {
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
supply_rel_to_circulating_supply:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("supply_rel_to_circulating_supply"),
|
||||
cfg.version + brk_types::Version::ONE,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
supply_in_profit_rel_to_circulating_supply:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("supply_in_profit_rel_to_circulating_supply"),
|
||||
cfg.version + brk_types::Version::ONE,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
supply_in_loss_rel_to_circulating_supply:
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("supply_in_loss_rel_to_circulating_supply"),
|
||||
cfg.version + brk_types::Version::ONE,
|
||||
|
||||
@@ -7,8 +7,8 @@ use rayon::prelude::*;
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::internal::{
|
||||
HalveDollars, HalveSats, HalveSatsToBitcoin,
|
||||
LazyValueFromHeightLast, ValueFromHeightChange, ValueFromHeightLast,
|
||||
HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin,
|
||||
LazyValueFromHeight, ValueFromHeightChange, ValueFromHeight,
|
||||
};
|
||||
|
||||
use super::ImportConfig;
|
||||
@@ -16,8 +16,8 @@ use super::ImportConfig;
|
||||
/// Supply metrics for a cohort.
|
||||
#[derive(Traversable)]
|
||||
pub struct SupplyMetrics<M: StorageMode = Rw> {
|
||||
pub total: ValueFromHeightLast<M>,
|
||||
pub halved: LazyValueFromHeightLast,
|
||||
pub total: ValueFromHeight<M>,
|
||||
pub halved: LazyValueFromHeight,
|
||||
/// 30-day change in supply (net position change) - sats, btc, usd
|
||||
pub _30d_change: ValueFromHeightChange<M>,
|
||||
}
|
||||
@@ -25,16 +25,17 @@ pub struct SupplyMetrics<M: StorageMode = Rw> {
|
||||
impl SupplyMetrics {
|
||||
/// Import supply metrics from database.
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let supply = ValueFromHeightLast::forced_import(
|
||||
let supply = ValueFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("supply"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let supply_halved = LazyValueFromHeightLast::from_block_source::<
|
||||
let supply_halved = LazyValueFromHeight::from_block_source::<
|
||||
HalveSats,
|
||||
HalveSatsToBitcoin,
|
||||
HalveCents,
|
||||
HalveDollars,
|
||||
>(&cfg.name("supply_halved"), &supply, cfg.version);
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ use crate::{
|
||||
ComputeIndexes,
|
||||
distribution::state::UnrealizedState,
|
||||
internal::{
|
||||
CentsSubtractToCentsSigned, FiatFromHeightLast, LazyFromHeightLast, NegCentsUnsignedToDollars,
|
||||
ValueFromHeightLast,
|
||||
CentsSubtractToCentsSigned, FiatFromHeight, LazyFromHeight, NegCentsUnsignedToDollars,
|
||||
ValueFromHeight,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -24,16 +24,16 @@ use crate::distribution::metrics::ImportConfig;
|
||||
#[derive(Traversable)]
|
||||
pub struct UnrealizedBase<M: StorageMode = Rw> {
|
||||
// === Supply in Profit/Loss ===
|
||||
pub supply_in_profit: ValueFromHeightLast<M>,
|
||||
pub supply_in_loss: ValueFromHeightLast<M>,
|
||||
pub supply_in_profit: ValueFromHeight<M>,
|
||||
pub supply_in_loss: ValueFromHeight<M>,
|
||||
|
||||
// === Unrealized Profit/Loss ===
|
||||
pub unrealized_profit: FiatFromHeightLast<Cents, M>,
|
||||
pub unrealized_loss: FiatFromHeightLast<Cents, M>,
|
||||
pub unrealized_profit: FiatFromHeight<Cents, M>,
|
||||
pub unrealized_loss: FiatFromHeight<Cents, M>,
|
||||
|
||||
// === Invested Capital in Profit/Loss ===
|
||||
pub invested_capital_in_profit: FiatFromHeightLast<Cents, M>,
|
||||
pub invested_capital_in_loss: FiatFromHeightLast<Cents, M>,
|
||||
pub invested_capital_in_profit: FiatFromHeight<Cents, M>,
|
||||
pub invested_capital_in_loss: FiatFromHeight<Cents, M>,
|
||||
|
||||
// === Raw values for precise aggregation (used to compute pain/greed indices) ===
|
||||
pub invested_capital_in_profit_raw: M::Stored<BytesVec<Height, CentsSats>>,
|
||||
@@ -42,53 +42,53 @@ pub struct UnrealizedBase<M: StorageMode = Rw> {
|
||||
pub investor_cap_in_loss_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
|
||||
|
||||
// === Pain/Greed Indices ===
|
||||
pub pain_index: FiatFromHeightLast<Cents, M>,
|
||||
pub greed_index: FiatFromHeightLast<Cents, M>,
|
||||
pub net_sentiment: FiatFromHeightLast<CentsSigned, M>,
|
||||
pub pain_index: FiatFromHeight<Cents, M>,
|
||||
pub greed_index: FiatFromHeight<Cents, M>,
|
||||
pub net_sentiment: FiatFromHeight<CentsSigned, M>,
|
||||
|
||||
// === Negated ===
|
||||
pub neg_unrealized_loss: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub neg_unrealized_loss: LazyFromHeight<Dollars, Cents>,
|
||||
|
||||
// === Net and Total ===
|
||||
pub net_unrealized_pnl: FiatFromHeightLast<CentsSigned, M>,
|
||||
pub total_unrealized_pnl: FiatFromHeightLast<Cents, M>,
|
||||
pub net_unrealized_pnl: FiatFromHeight<CentsSigned, M>,
|
||||
pub total_unrealized_pnl: FiatFromHeight<Cents, M>,
|
||||
}
|
||||
|
||||
impl UnrealizedBase {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let supply_in_profit = ValueFromHeightLast::forced_import(
|
||||
let supply_in_profit = ValueFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("supply_in_profit"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let supply_in_loss = ValueFromHeightLast::forced_import(
|
||||
let supply_in_loss = ValueFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("supply_in_loss"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let unrealized_profit = FiatFromHeightLast::forced_import(
|
||||
let unrealized_profit = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_profit"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let unrealized_loss = FiatFromHeightLast::forced_import(
|
||||
let unrealized_loss = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_loss"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let invested_capital_in_profit = FiatFromHeightLast::forced_import(
|
||||
let invested_capital_in_profit = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("invested_capital_in_profit"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let invested_capital_in_loss = FiatFromHeightLast::forced_import(
|
||||
let invested_capital_in_loss = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("invested_capital_in_loss"),
|
||||
cfg.version,
|
||||
@@ -116,39 +116,39 @@ impl UnrealizedBase {
|
||||
cfg.version,
|
||||
)?;
|
||||
|
||||
let pain_index = FiatFromHeightLast::forced_import(
|
||||
let pain_index = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("pain_index"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let greed_index = FiatFromHeightLast::forced_import(
|
||||
let greed_index = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("greed_index"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let net_sentiment = FiatFromHeightLast::forced_import(
|
||||
let net_sentiment = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_sentiment"),
|
||||
cfg.version + Version::ONE,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let neg_unrealized_loss = LazyFromHeightLast::from_computed::<NegCentsUnsignedToDollars>(
|
||||
let neg_unrealized_loss = LazyFromHeight::from_computed::<NegCentsUnsignedToDollars>(
|
||||
&cfg.name("neg_unrealized_loss"),
|
||||
cfg.version,
|
||||
unrealized_loss.cents.height.read_only_boxed_clone(),
|
||||
&unrealized_loss.cents,
|
||||
);
|
||||
|
||||
let net_unrealized_pnl = FiatFromHeightLast::forced_import(
|
||||
let net_unrealized_pnl = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_unrealized_pnl"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let total_unrealized_pnl = FiatFromHeightLast::forced_import(
|
||||
let total_unrealized_pnl = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("total_unrealized_pnl"),
|
||||
cfg.version,
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Cents;
|
||||
use vecdb::{AnyStoredVec, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{ComputeIndexes, internal::FiatFromHeightLast};
|
||||
use crate::{ComputeIndexes, internal::FiatFromHeight};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
@@ -11,13 +11,13 @@ use crate::distribution::metrics::ImportConfig;
|
||||
#[derive(Traversable)]
|
||||
pub struct UnrealizedPeakRegret<M: StorageMode = Rw> {
|
||||
/// Unrealized peak regret: sum of (peak_price - reference_price) x supply
|
||||
pub peak_regret: FiatFromHeightLast<Cents, M>,
|
||||
pub peak_regret: FiatFromHeight<Cents, M>,
|
||||
}
|
||||
|
||||
impl UnrealizedPeakRegret {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
Ok(Self {
|
||||
peak_regret: FiatFromHeightLast::forced_import(
|
||||
peak_regret: FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_peak_regret"),
|
||||
cfg.version,
|
||||
|
||||
Reference in New Issue
Block a user