mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 14:49:58 -07:00
global: snapshot
This commit is contained in:
@@ -6,7 +6,7 @@ use vecdb::{Database, ReadableCloneableVec};
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, ComputedHeightDerivedLast},
|
||||
internal::{ComputedFromHeight, ComputedHeightDerived},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -19,22 +19,22 @@ impl Vecs {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
raw: ComputedHeightDerivedLast::forced_import(
|
||||
raw: ComputedHeightDerived::forced_import(
|
||||
"difficulty",
|
||||
indexer.vecs.blocks.difficulty.read_only_boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
),
|
||||
as_hash: ComputedFromHeightLast::forced_import(db, "difficulty_as_hash", version, indexes)?,
|
||||
adjustment: ComputedFromHeightLast::forced_import(db, "difficulty_adjustment", version, indexes)?,
|
||||
epoch: ComputedFromHeightLast::forced_import(db, "difficulty_epoch", version, indexes)?,
|
||||
blocks_before_next_adjustment: ComputedFromHeightLast::forced_import(
|
||||
as_hash: ComputedFromHeight::forced_import(db, "difficulty_as_hash", version, indexes)?,
|
||||
adjustment: ComputedFromHeight::forced_import(db, "difficulty_adjustment", version, indexes)?,
|
||||
epoch: ComputedFromHeight::forced_import(db, "difficulty_epoch", version, indexes)?,
|
||||
blocks_before_next_adjustment: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"blocks_before_next_difficulty_adjustment",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
days_before_next_adjustment: ComputedFromHeightLast::forced_import(
|
||||
days_before_next_adjustment: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"days_before_next_difficulty_adjustment",
|
||||
version + v2,
|
||||
|
||||
@@ -2,15 +2,15 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{DifficultyEpoch, StoredF32, StoredF64, StoredU32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, ComputedHeightDerivedLast};
|
||||
use crate::internal::{ComputedFromHeight, ComputedHeightDerived};
|
||||
|
||||
/// Difficulty metrics: raw difficulty, derived stats, adjustment, and countdown
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub raw: ComputedHeightDerivedLast<StoredF64>,
|
||||
pub as_hash: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub adjustment: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub epoch: ComputedFromHeightLast<DifficultyEpoch, M>,
|
||||
pub blocks_before_next_adjustment: ComputedFromHeightLast<StoredU32, M>,
|
||||
pub days_before_next_adjustment: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub raw: ComputedHeightDerived<StoredF64>,
|
||||
pub as_hash: ComputedFromHeight<StoredF32, M>,
|
||||
pub adjustment: ComputedFromHeight<StoredF32, M>,
|
||||
pub epoch: ComputedFromHeight<DifficultyEpoch, M>,
|
||||
pub blocks_before_next_adjustment: ComputedFromHeight<StoredU32, M>,
|
||||
pub days_before_next_adjustment: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightLast};
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -14,14 +14,14 @@ impl Vecs {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
epoch: ComputedFromHeightLast::forced_import(db, "halving_epoch", version, indexes)?,
|
||||
blocks_before_next_halving: ComputedFromHeightLast::forced_import(
|
||||
epoch: ComputedFromHeight::forced_import(db, "halving_epoch", version, indexes)?,
|
||||
blocks_before_next_halving: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"blocks_before_next_halving",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
days_before_next_halving: ComputedFromHeightLast::forced_import(
|
||||
days_before_next_halving: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"days_before_next_halving",
|
||||
version + v2,
|
||||
|
||||
@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{HalvingEpoch, StoredF32, StoredU32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightLast;
|
||||
use crate::internal::ComputedFromHeight;
|
||||
|
||||
/// Halving epoch metrics and countdown
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub epoch: ComputedFromHeightLast<HalvingEpoch, M>,
|
||||
pub blocks_before_next_halving: ComputedFromHeightLast<StoredU32, M>,
|
||||
pub days_before_next_halving: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub epoch: ComputedFromHeight<HalvingEpoch, M>,
|
||||
pub blocks_before_next_halving: ComputedFromHeight<StoredU32, M>,
|
||||
pub days_before_next_halving: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightCumulativeFull, ComputedHeightDerivedCumulativeFull},
|
||||
internal::{ComputedFromHeightFull, ComputedHeightDerivedFull},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -15,13 +15,13 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
vbytes: ComputedFromHeightCumulativeFull::forced_import(
|
||||
vbytes: ComputedFromHeightFull::forced_import(
|
||||
db,
|
||||
"block_vbytes",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
size: ComputedHeightDerivedCumulativeFull::forced_import(
|
||||
size: ComputedHeightDerivedFull::forced_import(
|
||||
db,
|
||||
"block_size",
|
||||
version,
|
||||
|
||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredU64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightCumulativeFull, ComputedHeightDerivedCumulativeFull};
|
||||
use crate::internal::{ComputedFromHeightFull, ComputedHeightDerivedFull};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vbytes: ComputedFromHeightCumulativeFull<StoredU64, M>,
|
||||
pub size: ComputedHeightDerivedCumulativeFull<StoredU64, M>,
|
||||
pub vbytes: ComputedFromHeightFull<StoredU64, M>,
|
||||
pub size: ComputedHeightDerivedFull<StoredU64, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightDistribution, ComputedHeightDerivedCumulativeFull},
|
||||
internal::{ComputedFromHeightDistribution, ComputedHeightDerivedFull},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -14,7 +14,7 @@ impl Vecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let weight = ComputedHeightDerivedCumulativeFull::forced_import(
|
||||
let weight = ComputedHeightDerivedFull::forced_import(
|
||||
db,
|
||||
"block_weight",
|
||||
version,
|
||||
|
||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{StoredF32, Weight};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightDistribution, ComputedHeightDerivedCumulativeFull};
|
||||
use crate::internal::{ComputedFromHeightDistribution, ComputedHeightDerivedFull};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub weight: ComputedHeightDerivedCumulativeFull<Weight, M>,
|
||||
pub weight: ComputedHeightDerivedFull<Weight, M>,
|
||||
pub fullness: ComputedFromHeightDistribution<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightCumulativeSum, ComputedFromHeightLast},
|
||||
internal::{ComputedFromHeightCumulativeSum, ComputedFromHeight},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -23,9 +23,9 @@ impl Vecs {
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
liveliness: ComputedFromHeightLast::forced_import(db, "liveliness", version, indexes)?,
|
||||
vaultedness: ComputedFromHeightLast::forced_import(db, "vaultedness", version, indexes)?,
|
||||
activity_to_vaultedness_ratio: ComputedFromHeightLast::forced_import(
|
||||
liveliness: ComputedFromHeight::forced_import(db, "liveliness", version, indexes)?,
|
||||
vaultedness: ComputedFromHeight::forced_import(db, "vaultedness", version, indexes)?,
|
||||
activity_to_vaultedness_ratio: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"activity_to_vaultedness_ratio",
|
||||
version,
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredF64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightCumulativeSum, ComputedFromHeightLast};
|
||||
use crate::internal::{ComputedFromHeightCumulativeSum, ComputedFromHeight};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub coinblocks_created: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub coinblocks_stored: ComputedFromHeightCumulativeSum<StoredF64, M>,
|
||||
pub liveliness: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub vaultedness: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub activity_to_vaultedness_ratio: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub liveliness: ComputedFromHeight<StoredF64, M>,
|
||||
pub vaultedness: ComputedFromHeight<StoredF64, M>,
|
||||
pub activity_to_vaultedness_ratio: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -3,24 +3,24 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightLast};
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self {
|
||||
cointime_adj_inflation_rate: ComputedFromHeightLast::forced_import(
|
||||
cointime_adj_inflation_rate: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"cointime_adj_inflation_rate",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
cointime_adj_tx_btc_velocity: ComputedFromHeightLast::forced_import(
|
||||
cointime_adj_tx_btc_velocity: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"cointime_adj_tx_btc_velocity",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
cointime_adj_tx_usd_velocity: ComputedFromHeightLast::forced_import(
|
||||
cointime_adj_tx_usd_velocity: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"cointime_adj_tx_usd_velocity",
|
||||
version,
|
||||
|
||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{StoredF32, StoredF64};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightLast;
|
||||
use crate::internal::ComputedFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub cointime_adj_inflation_rate: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub cointime_adj_tx_btc_velocity: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub cointime_adj_tx_usd_velocity: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub cointime_adj_inflation_rate: ComputedFromHeight<StoredF32, M>,
|
||||
pub cointime_adj_tx_btc_velocity: ComputedFromHeight<StoredF64, M>,
|
||||
pub cointime_adj_tx_usd_velocity: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::FiatFromHeightLast};
|
||||
use crate::{indexes, internal::FiatFromHeight};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self {
|
||||
thermo_cap: FiatFromHeightLast::forced_import(db, "thermo_cap", version, indexes)?,
|
||||
investor_cap: FiatFromHeightLast::forced_import(db, "investor_cap", version, indexes)?,
|
||||
vaulted_cap: FiatFromHeightLast::forced_import(db, "vaulted_cap", version, indexes)?,
|
||||
active_cap: FiatFromHeightLast::forced_import(db, "active_cap", version, indexes)?,
|
||||
cointime_cap: FiatFromHeightLast::forced_import(db, "cointime_cap", version, indexes)?,
|
||||
thermo_cap: FiatFromHeight::forced_import(db, "thermo_cap", version, indexes)?,
|
||||
investor_cap: FiatFromHeight::forced_import(db, "investor_cap", version, indexes)?,
|
||||
vaulted_cap: FiatFromHeight::forced_import(db, "vaulted_cap", version, indexes)?,
|
||||
active_cap: FiatFromHeight::forced_import(db, "active_cap", version, indexes)?,
|
||||
cointime_cap: FiatFromHeight::forced_import(db, "cointime_cap", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Cents;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::FiatFromHeightLast;
|
||||
use crate::internal::FiatFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub thermo_cap: FiatFromHeightLast<Cents, M>,
|
||||
pub investor_cap: FiatFromHeightLast<Cents, M>,
|
||||
pub vaulted_cap: FiatFromHeightLast<Cents, M>,
|
||||
pub active_cap: FiatFromHeightLast<Cents, M>,
|
||||
pub cointime_cap: FiatFromHeightLast<Cents, M>,
|
||||
pub thermo_cap: FiatFromHeight<Cents, M>,
|
||||
pub investor_cap: FiatFromHeight<Cents, M>,
|
||||
pub vaulted_cap: FiatFromHeight<Cents, M>,
|
||||
pub active_cap: FiatFromHeight<Cents, M>,
|
||||
pub cointime_cap: FiatFromHeight<Cents, M>,
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Cents;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, ComputedFromHeightRatioExtended, Price};
|
||||
use crate::internal::{ComputedFromHeight, ComputedFromHeightRatioExtended, Price};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vaulted_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub vaulted_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub vaulted_price_ratio: ComputedFromHeightRatioExtended<M>,
|
||||
pub active_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub active_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub active_price_ratio: ComputedFromHeightRatioExtended<M>,
|
||||
pub true_market_mean: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub true_market_mean: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub true_market_mean_ratio: ComputedFromHeightRatioExtended<M>,
|
||||
pub cointime_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub cointime_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub cointime_price_ratio: ComputedFromHeightRatioExtended<M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::{Database, EagerVec, ImportableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightLast};
|
||||
use crate::{indexes, internal::ComputedFromHeight};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -15,7 +15,7 @@ impl Vecs {
|
||||
Ok(Self {
|
||||
vocdd_365d_median: EagerVec::forced_import(db, "vocdd_365d_median", v1)?,
|
||||
hodl_bank: EagerVec::forced_import(db, "hodl_bank", v1)?,
|
||||
reserve_risk: ComputedFromHeightLast::forced_import(db, "reserve_risk", v1, indexes)?,
|
||||
reserve_risk: ComputedFromHeight::forced_import(db, "reserve_risk", v1, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredF64};
|
||||
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightLast;
|
||||
use crate::internal::ComputedFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vocdd_365d_median: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
||||
pub hodl_bank: M::Stored<EagerVec<PcoVec<Height, StoredF64>>>,
|
||||
pub reserve_risk: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub reserve_risk: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ValueFromHeightLast};
|
||||
use crate::{indexes, internal::ValueFromHeight};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -12,13 +12,13 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
vaulted_supply: ValueFromHeightLast::forced_import(
|
||||
vaulted_supply: ValueFromHeight::forced_import(
|
||||
db,
|
||||
"vaulted_supply",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
active_supply: ValueFromHeightLast::forced_import(
|
||||
active_supply: ValueFromHeight::forced_import(
|
||||
db,
|
||||
"active_supply",
|
||||
version,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ValueFromHeightLast;
|
||||
use crate::internal::ValueFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vaulted_supply: ValueFromHeightLast<M>,
|
||||
pub active_supply: ValueFromHeightLast<M>,
|
||||
pub vaulted_supply: ValueFromHeight<M>,
|
||||
pub active_supply: ValueFromHeight<M>,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -3,11 +3,15 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightFull};
|
||||
use crate::{indexes, internal::ComputedFromHeightAggregated};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self(ComputedFromHeightFull::forced_import(
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self(ComputedFromHeightAggregated::forced_import(
|
||||
db,
|
||||
"input_count",
|
||||
version,
|
||||
|
||||
@@ -4,10 +4,9 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredU64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightFull;
|
||||
use crate::internal::ComputedFromHeightAggregated;
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw>(
|
||||
#[traversable(flatten)]
|
||||
pub ComputedFromHeightFull<StoredU64, M>,
|
||||
#[traversable(flatten)] pub ComputedFromHeightAggregated<StoredU64, M>,
|
||||
);
|
||||
|
||||
73
crates/brk_computer/src/internal/from_height/aggregated.rs
Normal file
73
crates/brk_computer/src/internal/from_height/aggregated.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
//! ComputedFromHeightAggregated - Full (distribution + sum + cumulative) + RollingFull.
|
||||
//!
|
||||
//! For metrics aggregated per-block from finer-grained sources (e.g., per-tx data),
|
||||
//! where we want full per-block stats plus rolling window stats.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{Full, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightAggregated<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
#[traversable(flatten)]
|
||||
pub full: Full<Height, T, M>,
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightAggregated<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = Full::forced_import(db, name, v)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
full: height,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute Full stats via closure, then rolling windows from the per-block sum.
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
windows: &WindowStarts<'_>,
|
||||
exit: &Exit,
|
||||
compute_full: impl FnOnce(&mut Full<Height, T>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + SubAssign + Copy + Ord,
|
||||
f64: From<T>,
|
||||
{
|
||||
compute_full(&mut self.full)?;
|
||||
self.rolling.compute(
|
||||
max_from,
|
||||
windows,
|
||||
self.full.sum_cumulative.sum.inner(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,11 @@ use vecdb::{
|
||||
|
||||
use crate::indexes;
|
||||
|
||||
use crate::internal::{ComputedHeightDerivedLast, ComputedVecValue, NumericValue};
|
||||
use crate::internal::{ComputedHeightDerived, ComputedVecValue, NumericValue};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct ComputedFromHeightLast<T, M: StorageMode = Rw>
|
||||
pub struct ComputedFromHeight<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -25,12 +25,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<ComputedHeightDerivedLast<T>>,
|
||||
pub rest: Box<ComputedHeightDerived<T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightLast<T>
|
||||
impl<T> ComputedFromHeight<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -44,7 +44,7 @@ where
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
|
||||
let rest = ComputedHeightDerivedLast::forced_import(
|
||||
let rest = ComputedHeightDerived::forced_import(
|
||||
name,
|
||||
height.read_only_boxed_clone(),
|
||||
v,
|
||||
@@ -10,7 +10,7 @@ use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsUnsignedToDollars, ComputedFromHeightLast, LazyFromHeightLast, SatsToBitcoin,
|
||||
CentsUnsignedToDollars, ComputedFromHeight, LazyFromHeight, SatsToBitcoin,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -19,10 +19,10 @@ pub use rolling_sum::*;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ByUnit<M: StorageMode = Rw> {
|
||||
pub sats: ComputedFromHeightLast<Sats, M>,
|
||||
pub btc: LazyFromHeightLast<Bitcoin, Sats>,
|
||||
pub cents: ComputedFromHeightLast<Cents, M>,
|
||||
pub usd: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub sats: ComputedFromHeight<Sats, M>,
|
||||
pub btc: LazyFromHeight<Bitcoin, Sats>,
|
||||
pub cents: ComputedFromHeight<Cents, M>,
|
||||
pub usd: LazyFromHeight<Dollars, Cents>,
|
||||
}
|
||||
|
||||
impl ByUnit {
|
||||
@@ -32,23 +32,23 @@ impl ByUnit {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let sats = ComputedFromHeightLast::forced_import(db, name, version, indexes)?;
|
||||
let sats = ComputedFromHeight::forced_import(db, name, version, indexes)?;
|
||||
|
||||
let btc = LazyFromHeightLast::from_computed::<SatsToBitcoin>(
|
||||
let btc = LazyFromHeight::from_computed::<SatsToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
version,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let cents = ComputedFromHeightLast::forced_import(
|
||||
let cents = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_cents"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let usd = LazyFromHeightLast::from_computed::<CentsUnsignedToDollars>(
|
||||
let usd = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! Like ComputedFromHeightCumulativeSum but without RollingWindows.
|
||||
//! Used for distribution metrics where rolling is optional per cohort.
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views.
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -12,7 +12,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue},
|
||||
internal::{ComputedFromHeight, NumericValue},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -21,7 +21,7 @@ where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
@@ -40,7 +40,7 @@ where
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let cumulative =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
|
||||
Ok(Self { height, cumulative })
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
//! ComputedFromHeightCumulativeFull - stored height + LazyAggVec + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics with stored per-block data, cumulative sums, and rolling windows.
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightCumulativeFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedFromHeightCumulativeFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let cumulative =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
cumulative,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute height data via closure, then cumulative + rolling.
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
windows: &WindowStarts<'_>,
|
||||
exit: &Exit,
|
||||
compute_height: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + SubAssign + Copy + Ord,
|
||||
f64: From<T>,
|
||||
{
|
||||
compute_height(&mut self.height)?;
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.height, exit)?;
|
||||
self.rolling
|
||||
.compute(max_from, windows, &self.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
//! ComputedFromHeightCumulativeSum - stored height + LazyAggVec + cumulative (from height) + RollingWindows (sum).
|
||||
//!
|
||||
//! Like ComputedFromHeightCumulativeFull but with rolling sum only (no distribution).
|
||||
//! Like ComputedFromHeightFull but with rolling sum only (no distribution).
|
||||
//! Used for count metrics where distribution stats aren't meaningful.
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -14,7 +14,7 @@ use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue, RollingWindows, WindowStarts},
|
||||
internal::{ComputedFromHeight, NumericValue, RollingWindows, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -23,7 +23,7 @@ where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
pub sum: RollingWindows<T, M>,
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ where
|
||||
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let cumulative =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let rolling = RollingWindows::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Cents, CentsSigned, Dollars, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, ReadableCloneableVec, Rw, StorageMode, UnaryTransform};
|
||||
|
||||
use super::{ComputedFromHeightLast, LazyFromHeightLast};
|
||||
use super::{ComputedFromHeight, LazyFromHeight};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CentsSignedToDollars, CentsUnsignedToDollars, NumericValue},
|
||||
@@ -26,25 +26,25 @@ impl CentsType for CentsSigned {
|
||||
/// Height-indexed fiat monetary value: cents (eager, integer) + usd (lazy, float).
|
||||
/// Generic over `C` to support both `Cents` (unsigned) and `CentsSigned` (signed).
|
||||
#[derive(Traversable)]
|
||||
pub struct FiatFromHeightLast<C: CentsType, M: StorageMode = Rw> {
|
||||
pub cents: ComputedFromHeightLast<C, M>,
|
||||
pub usd: LazyFromHeightLast<Dollars, C>,
|
||||
pub struct FiatFromHeight<C: CentsType, M: StorageMode = Rw> {
|
||||
pub cents: ComputedFromHeight<C, M>,
|
||||
pub usd: LazyFromHeight<Dollars, C>,
|
||||
}
|
||||
|
||||
impl<C: CentsType> FiatFromHeightLast<C> {
|
||||
impl<C: CentsType> FiatFromHeight<C> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents = ComputedFromHeightLast::forced_import(
|
||||
let cents = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_cents"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
let usd = LazyFromHeightLast::from_computed::<C::ToDollars>(
|
||||
let usd = LazyFromHeight::from_computed::<C::ToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! ComputedFromHeightFull - Full (distribution + sum + cumulative) + RollingFull.
|
||||
//! ComputedFromHeightFull - stored height + LazyAggVec + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics aggregated per-block from finer-grained sources (e.g., per-tx data),
|
||||
//! where we want full per-block stats plus rolling window stats.
|
||||
//! For metrics with stored per-block data, cumulative sums, and rolling windows.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -9,11 +9,11 @@ use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{Full, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
@@ -21,8 +21,9 @@ pub struct ComputedFromHeightFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub height: M::Stored<EagerVec<PcoVec<Height, T>>>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub full: Full<Height, T, M>,
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
@@ -40,34 +41,36 @@ where
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let height = Full::forced_import(db, name, v)?;
|
||||
let height: EagerVec<PcoVec<Height, T>> = EagerVec::forced_import(db, name, v)?;
|
||||
let cumulative =
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
full: height,
|
||||
height,
|
||||
cumulative,
|
||||
rolling,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute Full stats via closure, then rolling windows from the per-block sum.
|
||||
/// Compute height data via closure, then cumulative + rolling.
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
windows: &WindowStarts<'_>,
|
||||
exit: &Exit,
|
||||
compute_full: impl FnOnce(&mut Full<Height, T>) -> Result<()>,
|
||||
compute_height: impl FnOnce(&mut EagerVec<PcoVec<Height, T>>) -> Result<()>,
|
||||
) -> Result<()>
|
||||
where
|
||||
T: From<f64> + Default + SubAssign + Copy + Ord,
|
||||
f64: From<T>,
|
||||
{
|
||||
compute_full(&mut self.full)?;
|
||||
self.rolling.compute(
|
||||
max_from,
|
||||
windows,
|
||||
self.full.sum_cumulative.sum.inner(),
|
||||
exit,
|
||||
)?;
|
||||
compute_height(&mut self.height)?;
|
||||
self.cumulative
|
||||
.height
|
||||
.compute_cumulative(max_from, &self.height, exit)?;
|
||||
self.rolling
|
||||
.compute(max_from, windows, &self.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ use vecdb::{LazyVecFrom1, ReadableBoxedVec, ReadableCloneableVec, UnaryTransform
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, ComputedVecValue, LazyHeightDerivedLast, NumericValue},
|
||||
internal::{ComputedFromHeight, ComputedVecValue, LazyHeightDerived, NumericValue},
|
||||
};
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyFromHeightLast<T, S1T = T>
|
||||
pub struct LazyFromHeight<T, S1T = T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
S1T: ComputedVecValue,
|
||||
@@ -21,12 +21,12 @@ where
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<LazyHeightDerivedLast<T, S1T>>,
|
||||
pub rest: Box<LazyHeightDerived<T, S1T>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyFromHeightLast<T, S1T>
|
||||
impl<T, S1T> LazyFromHeight<T, S1T>
|
||||
where
|
||||
T: ComputedVecValue + JsonSchema + 'static,
|
||||
S1T: ComputedVecValue + JsonSchema,
|
||||
@@ -35,7 +35,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
height_source: ReadableBoxedVec<Height, S1T>,
|
||||
source: &ComputedFromHeightLast<S1T>,
|
||||
source: &ComputedFromHeight<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -43,7 +43,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source),
|
||||
rest: Box::new(LazyHeightDerivedLast::from_computed::<F>(name, v, source)),
|
||||
rest: Box::new(LazyHeightDerived::from_computed::<F>(name, v, source)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, height_source.clone()),
|
||||
rest: Box::new(LazyHeightDerivedLast::from_height_source::<F>(
|
||||
rest: Box::new(LazyHeightDerived::from_height_source::<F>(
|
||||
name,
|
||||
v,
|
||||
height_source,
|
||||
@@ -68,11 +68,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Create by unary-transforming a LazyFromHeightLast source (chaining lazy vecs).
|
||||
/// Create by unary-transforming a LazyFromHeight source (chaining lazy vecs).
|
||||
pub(crate) fn from_lazy<F, S2T>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &LazyFromHeightLast<S1T, S2T>,
|
||||
source: &LazyFromHeight<S1T, S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: UnaryTransform<S1T, T>,
|
||||
@@ -81,7 +81,7 @@ where
|
||||
let v = version + VERSION;
|
||||
Self {
|
||||
height: LazyVecFrom1::transformed::<F>(name, v, source.height.read_only_boxed_clone()),
|
||||
rest: Box::new(LazyHeightDerivedLast::from_lazy::<F, S2T>(
|
||||
rest: Box::new(LazyHeightDerived::from_lazy::<F, S2T>(
|
||||
name,
|
||||
v,
|
||||
&source.rest,
|
||||
@@ -1,43 +1,31 @@
|
||||
mod aggregated;
|
||||
mod base;
|
||||
mod by_unit;
|
||||
mod constant;
|
||||
mod cumulative;
|
||||
mod fiat;
|
||||
mod cumulative_full;
|
||||
mod cumulative_sum;
|
||||
mod distribution;
|
||||
mod fiat;
|
||||
mod full;
|
||||
mod last;
|
||||
mod value_cumulative;
|
||||
mod lazy_last;
|
||||
mod lazy_value_last;
|
||||
mod lazy_base;
|
||||
mod percentiles;
|
||||
mod price;
|
||||
mod ratio;
|
||||
mod stddev;
|
||||
mod value_change;
|
||||
mod value_full;
|
||||
mod value_last;
|
||||
mod value_last_rolling;
|
||||
mod value_sum_cumulative;
|
||||
mod value;
|
||||
|
||||
pub use aggregated::*;
|
||||
pub use base::*;
|
||||
pub use by_unit::*;
|
||||
pub use constant::*;
|
||||
pub use cumulative::*;
|
||||
pub use cumulative_full::*;
|
||||
pub use fiat::*;
|
||||
pub use cumulative_sum::*;
|
||||
pub use distribution::*;
|
||||
pub use fiat::*;
|
||||
pub use full::*;
|
||||
pub use last::*;
|
||||
pub use value_cumulative::*;
|
||||
pub use lazy_last::*;
|
||||
pub use lazy_value_last::*;
|
||||
pub use lazy_base::*;
|
||||
pub use percentiles::*;
|
||||
pub use price::*;
|
||||
pub use ratio::*;
|
||||
pub use stddev::*;
|
||||
pub use value_change::*;
|
||||
pub use value_full::*;
|
||||
pub use value_last::*;
|
||||
pub use value_last_rolling::*;
|
||||
pub use value_sum_cumulative::*;
|
||||
pub use value::*;
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Cents, Height, StoredF32, Version};
|
||||
use vecdb::{AnyExportableVec, Database, ReadOnlyClone, Ro, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::indexes;
|
||||
use crate::internal::{ComputedFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, Price};
|
||||
|
||||
pub const PERCENTILES: [u8; 19] = [
|
||||
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,
|
||||
@@ -68,7 +68,7 @@ pub(crate) fn compute_spot_percentile_rank(
|
||||
}
|
||||
|
||||
pub struct PercentilesVecs<M: StorageMode = Rw> {
|
||||
pub vecs: [Price<ComputedFromHeightLast<Cents, M>>; PERCENTILES_LEN],
|
||||
pub vecs: [Price<ComputedFromHeight<Cents, M>>; PERCENTILES_LEN],
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
@@ -130,7 +130,7 @@ impl ReadOnlyClone for PercentilesVecs {
|
||||
|
||||
impl<M: StorageMode> Traversable for PercentilesVecs<M>
|
||||
where
|
||||
Price<ComputedFromHeightLast<Cents, M>>: Traversable,
|
||||
Price<ComputedFromHeight<Cents, M>>: Traversable,
|
||||
{
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
|
||||
@@ -10,7 +10,7 @@ use brk_types::{Cents, Dollars, SatsFract, Version};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{Database, ReadableCloneableVec, UnaryTransform};
|
||||
|
||||
use super::{ComputedFromHeightLast, LazyFromHeightLast};
|
||||
use super::{ComputedFromHeight, LazyFromHeight};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CentsUnsignedToDollars, ComputedVecValue, DollarsToSatsFract, NumericValue},
|
||||
@@ -20,11 +20,11 @@ use crate::{
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Price<C> {
|
||||
pub cents: C,
|
||||
pub usd: LazyFromHeightLast<Dollars, Cents>,
|
||||
pub sats: LazyFromHeightLast<SatsFract, Dollars>,
|
||||
pub usd: LazyFromHeight<Dollars, Cents>,
|
||||
pub sats: LazyFromHeight<SatsFract, Dollars>,
|
||||
}
|
||||
|
||||
impl Price<ComputedFromHeightLast<Cents>> {
|
||||
impl Price<ComputedFromHeight<Cents>> {
|
||||
/// Import from database: stored cents, lazy USD + sats.
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
@@ -33,14 +33,14 @@ impl Price<ComputedFromHeightLast<Cents>> {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let cents =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyFromHeightLast::from_computed::<CentsUnsignedToDollars>(
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cents"), version, indexes)?;
|
||||
let usd = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
¢s,
|
||||
);
|
||||
let sats = LazyFromHeightLast::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
let sats = LazyFromHeight::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
&format!("{name}_sats"),
|
||||
version,
|
||||
&usd,
|
||||
@@ -49,7 +49,7 @@ impl Price<ComputedFromHeightLast<Cents>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<ST> Price<LazyFromHeightLast<Cents, ST>>
|
||||
impl<ST> Price<LazyFromHeight<Cents, ST>>
|
||||
where
|
||||
ST: ComputedVecValue + NumericValue + JsonSchema + 'static,
|
||||
{
|
||||
@@ -57,20 +57,20 @@ where
|
||||
pub(crate) fn from_cents_source<F: UnaryTransform<ST, Cents>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedFromHeightLast<ST>,
|
||||
source: &ComputedFromHeight<ST>,
|
||||
) -> Self {
|
||||
let cents = LazyFromHeightLast::from_computed::<F>(
|
||||
let cents = LazyFromHeight::from_computed::<F>(
|
||||
&format!("{name}_cents"),
|
||||
version,
|
||||
source.height.read_only_boxed_clone(),
|
||||
source,
|
||||
);
|
||||
let usd = LazyFromHeightLast::from_lazy::<CentsUnsignedToDollars, ST>(
|
||||
let usd = LazyFromHeight::from_lazy::<CentsUnsignedToDollars, ST>(
|
||||
&format!("{name}_usd"),
|
||||
version,
|
||||
¢s,
|
||||
);
|
||||
let sats = LazyFromHeightLast::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
let sats = LazyFromHeight::from_lazy::<DollarsToSatsFract, Cents>(
|
||||
&format!("{name}_sats"),
|
||||
version,
|
||||
&usd,
|
||||
|
||||
@@ -9,24 +9,24 @@ use crate::{
|
||||
};
|
||||
use brk_types::get_percentile;
|
||||
|
||||
use super::super::ComputedFromHeightLast;
|
||||
use super::super::ComputedFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightRatioExtension<M: StorageMode = Rw> {
|
||||
pub ratio_1w_sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_1m_sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct99: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct98: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct95: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct5: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct2: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct1: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio_pct99_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct98_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct95_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct5_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct2_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_pct1_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub ratio_1w_sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_1m_sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct99: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct98: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct95: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct5: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct2: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct1: ComputedFromHeight<StoredF32, M>,
|
||||
pub ratio_pct99_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct98_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct95_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct5_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct2_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub ratio_pct1_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
|
||||
pub ratio_sd: ComputedFromHeightStdDevExtended<M>,
|
||||
pub ratio_4y_sd: ComputedFromHeightStdDevExtended<M>,
|
||||
@@ -47,7 +47,7 @@ impl ComputedFromHeightRatioExtension {
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}", $suffix),
|
||||
v,
|
||||
|
||||
@@ -13,11 +13,11 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
use super::ComputedFromHeightLast;
|
||||
use super::ComputedFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightRatio<M: StorageMode = Rw> {
|
||||
pub ratio: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub ratio: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
@@ -32,7 +32,7 @@ impl ComputedFromHeightRatio {
|
||||
let v = version + VERSION;
|
||||
|
||||
Ok(Self {
|
||||
ratio: ComputedFromHeightLast::forced_import(db, &format!("{name}_ratio"), v, indexes)?,
|
||||
ratio: ComputedFromHeight::forced_import(db, &format!("{name}_ratio"), v, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Cents, Height, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, Price};
|
||||
use crate::{ComputeIndexes, blocks, indexes, prices};
|
||||
|
||||
use super::ComputedFromHeightRatioExtended;
|
||||
@@ -15,7 +15,7 @@ pub struct ComputedFromHeightPriceWithRatioExtended<M: StorageMode = Rw> {
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub inner: ComputedFromHeightRatioExtended<M>,
|
||||
pub price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price: Price<ComputedFromHeight<Cents, M>>,
|
||||
}
|
||||
|
||||
impl ComputedFromHeightPriceWithRatioExtended {
|
||||
|
||||
@@ -8,7 +8,7 @@ use vecdb::{
|
||||
|
||||
use crate::{ComputeIndexes, blocks, indexes};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, Price};
|
||||
|
||||
use super::ComputedFromHeightStdDev;
|
||||
|
||||
@@ -17,34 +17,34 @@ pub struct ComputedFromHeightStdDevExtended<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub base: ComputedFromHeightStdDev<M>,
|
||||
|
||||
pub zscore: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub zscore: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
pub p0_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p1sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p1_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p2sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p2_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p3sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m0_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m1sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m1_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m2sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m2_5sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub m3sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub p0_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p1sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p1_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p2sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p2_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub p3sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m0_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m1sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m1_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m2sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m2_5sd: ComputedFromHeight<StoredF32, M>,
|
||||
pub m3sd: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
pub _0sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p0_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p1sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p1_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p2sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p2_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub p3sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m0_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m1sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m1_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m2sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m2_5sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub m3sd_price: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub _0sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p0_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p1sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p1_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p2sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p2_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub p3sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m0_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m1sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m1_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m2sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m2_5sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub m3sd_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
}
|
||||
|
||||
impl ComputedFromHeightStdDevExtended {
|
||||
@@ -59,7 +59,7 @@ impl ComputedFromHeightStdDevExtended {
|
||||
|
||||
macro_rules! import {
|
||||
($suffix:expr) => {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_{}", $suffix),
|
||||
version,
|
||||
|
||||
@@ -9,13 +9,13 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode,
|
||||
|
||||
use crate::{ComputeIndexes, blocks, indexes};
|
||||
|
||||
use crate::internal::ComputedFromHeightLast;
|
||||
use crate::internal::ComputedFromHeight;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedFromHeightStdDev<M: StorageMode = Rw> {
|
||||
days: usize,
|
||||
pub sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sd: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub sd: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
impl ComputedFromHeightStdDev {
|
||||
@@ -28,13 +28,13 @@ impl ComputedFromHeightStdDev {
|
||||
) -> Result<Self> {
|
||||
let version = parent_version + Version::TWO;
|
||||
|
||||
let sma = ComputedFromHeightLast::forced_import(
|
||||
let sma = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_sma"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
let sd = ComputedFromHeightLast::forced_import(
|
||||
let sd = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_sd"),
|
||||
version,
|
||||
@@ -84,7 +84,7 @@ impl ComputedFromHeightStdDev {
|
||||
}
|
||||
|
||||
fn compute_sd(
|
||||
sd: &mut ComputedFromHeightLast<StoredF32>,
|
||||
sd: &mut ComputedFromHeight<StoredF32>,
|
||||
blocks: &blocks::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct ValueFromHeightLast<M: StorageMode = Rw> {
|
||||
pub struct ValueFromHeight<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
pub base: ByUnit<M>,
|
||||
@@ -19,7 +19,7 @@ pub struct ValueFromHeightLast<M: StorageMode = Rw> {
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
|
||||
impl ValueFromHeightLast {
|
||||
impl ValueFromHeight {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -8,7 +8,7 @@ use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
CentsSignedToDollars, ComputedFromHeightLast, LazyFromHeightLast, SatsSignedToBitcoin,
|
||||
CentsSignedToDollars, ComputedFromHeight, LazyFromHeight, SatsSignedToBitcoin,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -17,10 +17,10 @@ const VERSION: Version = Version::ZERO;
|
||||
/// Change values indexed by height - sats (stored), btc (lazy), cents (stored), usd (lazy).
|
||||
#[derive(Traversable)]
|
||||
pub struct ValueFromHeightChange<M: StorageMode = Rw> {
|
||||
pub sats: ComputedFromHeightLast<SatsSigned, M>,
|
||||
pub btc: LazyFromHeightLast<Bitcoin, SatsSigned>,
|
||||
pub cents: ComputedFromHeightLast<CentsSigned, M>,
|
||||
pub usd: LazyFromHeightLast<Dollars, CentsSigned>,
|
||||
pub sats: ComputedFromHeight<SatsSigned, M>,
|
||||
pub btc: LazyFromHeight<Bitcoin, SatsSigned>,
|
||||
pub cents: ComputedFromHeight<CentsSigned, M>,
|
||||
pub usd: LazyFromHeight<Dollars, CentsSigned>,
|
||||
}
|
||||
|
||||
impl ValueFromHeightChange {
|
||||
@@ -32,23 +32,23 @@ impl ValueFromHeightChange {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = ComputedFromHeightLast::forced_import(db, name, v, indexes)?;
|
||||
let sats = ComputedFromHeight::forced_import(db, name, v, indexes)?;
|
||||
|
||||
let btc = LazyFromHeightLast::from_computed::<SatsSignedToBitcoin>(
|
||||
let btc = LazyFromHeight::from_computed::<SatsSignedToBitcoin>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
sats.height.read_only_boxed_clone(),
|
||||
&sats,
|
||||
);
|
||||
|
||||
let cents = ComputedFromHeightLast::forced_import(
|
||||
let cents = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_cents"),
|
||||
v,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let usd = LazyFromHeightLast::from_computed::<CentsSignedToDollars>(
|
||||
let usd = LazyFromHeight::from_computed::<CentsSignedToDollars>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
cents.height.read_only_boxed_clone(),
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ValueFromHeightSumCumulative<M: StorageMode = Rw> {
|
||||
pub struct ValueFromHeightCumulativeSum<M: StorageMode = Rw> {
|
||||
pub base: ByUnit<M>,
|
||||
pub cumulative: ByUnit<M>,
|
||||
pub sum: RollingSumByUnit<M>,
|
||||
@@ -18,7 +18,7 @@ pub struct ValueFromHeightSumCumulative<M: StorageMode = Rw> {
|
||||
|
||||
const VERSION: Version = Version::TWO;
|
||||
|
||||
impl ValueFromHeightSumCumulative {
|
||||
impl ValueFromHeightCumulativeSum {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -1,44 +1,45 @@
|
||||
//! Lazy value wrapper for ValueFromHeightLast - all transforms are lazy.
|
||||
//! Lazy value wrapper for ValueFromHeight - all transforms are lazy.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Sats, Version};
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::internal::{LazyValueFromHeight, LazyValueHeightDerivedLast, ValueFromHeightLast};
|
||||
use crate::internal::{LazyValue, LazyValueHeightDerived, ValueFromHeight};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Lazy value wrapper with height + all derived last transforms from ValueFromHeightLast.
|
||||
/// Lazy value wrapper with height + all derived last transforms from ValueFromHeight.
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct LazyValueFromHeightLast {
|
||||
pub struct LazyValueFromHeight {
|
||||
#[traversable(flatten)]
|
||||
pub height: LazyValueFromHeight,
|
||||
pub height: LazyValue<Height>,
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub rest: Box<LazyValueHeightDerivedLast>,
|
||||
pub rest: Box<LazyValueHeightDerived>,
|
||||
}
|
||||
|
||||
impl LazyValueFromHeightLast {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
impl LazyValueFromHeight {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueFromHeightLast,
|
||||
source: &ValueFromHeight,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
SatsTransform: UnaryTransform<Sats, Sats>,
|
||||
BitcoinTransform: UnaryTransform<Sats, Bitcoin>,
|
||||
CentsTransform: UnaryTransform<Cents, Cents>,
|
||||
DollarsTransform: UnaryTransform<Dollars, Dollars>,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
let height =
|
||||
LazyValueFromHeight::from_block_source::<SatsTransform, BitcoinTransform, DollarsTransform>(name, source, v);
|
||||
LazyValue::from_block_source::<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(name, source, v);
|
||||
|
||||
let rest =
|
||||
LazyValueHeightDerivedLast::from_block_source::<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
LazyValueHeightDerived::from_block_source::<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(
|
||||
name, source, v,
|
||||
);
|
||||
|
||||
15
crates/brk_computer/src/internal/from_height/value/mod.rs
Normal file
15
crates/brk_computer/src/internal/from_height/value/mod.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
mod base;
|
||||
mod change;
|
||||
mod cumulative;
|
||||
mod cumulative_sum;
|
||||
mod full;
|
||||
mod lazy;
|
||||
mod rolling;
|
||||
|
||||
pub use base::*;
|
||||
pub use change::*;
|
||||
pub use cumulative::*;
|
||||
pub use cumulative_sum::*;
|
||||
pub use full::*;
|
||||
pub use lazy::*;
|
||||
pub use rolling::*;
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Value type for Height + Rolling pattern.
|
||||
//!
|
||||
//! Combines ValueFromHeight (sats/btc/usd per height, no period views) with
|
||||
//! ValueFromHeightLastWindows (rolling sums across 4 windows).
|
||||
//! Combines Value (sats/btc/usd per height, no period views) with
|
||||
//! ValueFromHeightWindows (rolling sums across 4 windows).
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
@@ -11,23 +11,23 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ValueFromHeightLastWindows, ValueFromHeight, WindowStarts},
|
||||
internal::{ValueFromHeightWindows, Value, WindowStarts},
|
||||
prices,
|
||||
};
|
||||
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct ValueFromHeightLastRolling<M: StorageMode = Rw> {
|
||||
pub struct ValueFromHeightRolling<M: StorageMode = Rw> {
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub value: ValueFromHeight<M>,
|
||||
pub value: Value<Height, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: ValueFromHeightLastWindows<M>,
|
||||
pub rolling: ValueFromHeightWindows<M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ValueFromHeightLastRolling {
|
||||
impl ValueFromHeightRolling {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -36,8 +36,8 @@ impl ValueFromHeightLastRolling {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
Ok(Self {
|
||||
value: ValueFromHeight::forced_import(db, name, v)?,
|
||||
rolling: ValueFromHeightLastWindows::forced_import(db, name, v, indexes)?,
|
||||
value: Value::forced_import(db, name, v)?,
|
||||
rolling: ValueFromHeightWindows::forced_import(db, name, v, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
mod lazy_value;
|
||||
mod value;
|
||||
|
||||
pub use lazy_value::*;
|
||||
pub use value::*;
|
||||
@@ -1,7 +1,7 @@
|
||||
//! ComputedHeightDerivedCumulativeFull - LazyAggVec index views + cumulative (from height) + RollingFull.
|
||||
//! ComputedHeightDerivedFull - LazyAggVec index views + cumulative (from height) + RollingFull.
|
||||
//!
|
||||
//! For metrics derived from indexer sources (no stored height vec).
|
||||
//! Cumulative gets its own ComputedFromHeightLast so it has LazyAggVec index views too.
|
||||
//! Cumulative gets its own ComputedFromHeight so it has LazyAggVec index views too.
|
||||
|
||||
use std::ops::SubAssign;
|
||||
|
||||
@@ -13,22 +13,22 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, NumericValue, RollingFull, WindowStarts},
|
||||
internal::{ComputedFromHeight, NumericValue, RollingFull, WindowStarts},
|
||||
};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ComputedHeightDerivedCumulativeFull<T, M: StorageMode = Rw>
|
||||
pub struct ComputedHeightDerivedFull<T, M: StorageMode = Rw>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
pub cumulative: ComputedFromHeightLast<T, M>,
|
||||
pub cumulative: ComputedFromHeight<T, M>,
|
||||
#[traversable(flatten)]
|
||||
pub rolling: RollingFull<T, M>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedCumulativeFull<T>
|
||||
impl<T> ComputedHeightDerivedFull<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
@@ -41,7 +41,7 @@ where
|
||||
let v = version + VERSION;
|
||||
|
||||
let cumulative =
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cumulative"), v, indexes)?;
|
||||
let rolling = RollingFull::forced_import(db, name, v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ComputedHeightDerivedLast — sparse time periods + dense epochs (last value).
|
||||
//! ComputedHeightDerived — sparse time periods + dense epochs (last value).
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
@@ -18,7 +18,7 @@ use crate::{
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct ComputedHeightDerivedLast<T>(
|
||||
pub struct ComputedHeightDerived<T>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub Indexes<
|
||||
LazyAggVec<Minute10, Option<T>, Height, Height, T>,
|
||||
@@ -42,7 +42,7 @@ where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
/// Already read-only (no StorageMode); cloning is sufficient.
|
||||
impl<T> ReadOnlyClone for ComputedHeightDerivedLast<T>
|
||||
impl<T> ReadOnlyClone for ComputedHeightDerived<T>
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema,
|
||||
{
|
||||
@@ -54,7 +54,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedHeightDerivedLast<T>
|
||||
impl<T> ComputedHeightDerived<T>
|
||||
where
|
||||
T: NumericValue + JsonSchema,
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! LazyHeightDerivedLast — unary transform of height-derived last values.
|
||||
//! LazyHeightDerived — unary transform of height-derived last values.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
@@ -16,7 +16,7 @@ use vecdb::{
|
||||
use crate::{
|
||||
indexes, indexes_from,
|
||||
internal::{
|
||||
ComputedFromHeightLast, ComputedHeightDerivedLast, ComputedVecValue, Indexes, NumericValue,
|
||||
ComputedFromHeight, ComputedHeightDerived, ComputedVecValue, Indexes, NumericValue,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -57,7 +57,7 @@ where
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct LazyHeightDerivedLast<T, S1T = T>(
|
||||
pub struct LazyHeightDerived<T, S1T = T>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub Indexes<
|
||||
LazyTransformLast<Minute10, Option<T>, Option<S1T>>,
|
||||
@@ -83,7 +83,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T, S1T> LazyHeightDerivedLast<T, S1T>
|
||||
impl<T, S1T> LazyHeightDerived<T, S1T>
|
||||
where
|
||||
T: VecValue + PartialOrd + JsonSchema + 'static,
|
||||
S1T: VecValue + PartialOrd + JsonSchema,
|
||||
@@ -91,7 +91,7 @@ where
|
||||
pub(crate) fn from_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedFromHeightLast<S1T>,
|
||||
source: &ComputedFromHeight<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -109,14 +109,14 @@ where
|
||||
S1T: NumericValue,
|
||||
{
|
||||
let derived =
|
||||
ComputedHeightDerivedLast::forced_import(name, height_source, version, indexes);
|
||||
ComputedHeightDerived::forced_import(name, height_source, version, indexes);
|
||||
Self::from_derived_computed::<F>(name, version, &derived)
|
||||
}
|
||||
|
||||
pub(crate) fn from_derived_computed<F: UnaryTransform<S1T, T>>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &ComputedHeightDerivedLast<S1T>,
|
||||
source: &ComputedHeightDerived<S1T>,
|
||||
) -> Self
|
||||
where
|
||||
S1T: NumericValue,
|
||||
@@ -145,7 +145,7 @@ where
|
||||
pub(crate) fn from_lazy<F, S2T>(
|
||||
name: &str,
|
||||
version: Version,
|
||||
source: &LazyHeightDerivedLast<S1T, S2T>,
|
||||
source: &LazyHeightDerived<S1T, S2T>,
|
||||
) -> Self
|
||||
where
|
||||
F: UnaryTransform<S1T, T>,
|
||||
|
||||
@@ -4,48 +4,56 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Sats, Version};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::internal::{LazyHeightDerivedLast, ValueFromHeightLast};
|
||||
use crate::internal::{LazyHeightDerived, ValueFromHeight};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyValueHeightDerivedLast {
|
||||
pub sats: LazyHeightDerivedLast<Sats, Sats>,
|
||||
pub btc: LazyHeightDerivedLast<Bitcoin, Sats>,
|
||||
pub usd: LazyHeightDerivedLast<Dollars, Dollars>,
|
||||
pub struct LazyValueHeightDerived {
|
||||
pub sats: LazyHeightDerived<Sats, Sats>,
|
||||
pub btc: LazyHeightDerived<Bitcoin, Sats>,
|
||||
pub cents: LazyHeightDerived<Cents, Cents>,
|
||||
pub usd: LazyHeightDerived<Dollars, Dollars>,
|
||||
}
|
||||
|
||||
impl LazyValueHeightDerivedLast {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
impl LazyValueHeightDerived {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueFromHeightLast,
|
||||
source: &ValueFromHeight,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
SatsTransform: UnaryTransform<Sats, Sats>,
|
||||
BitcoinTransform: UnaryTransform<Sats, Bitcoin>,
|
||||
CentsTransform: UnaryTransform<Cents, Cents>,
|
||||
DollarsTransform: UnaryTransform<Dollars, Dollars>,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
|
||||
let sats = LazyHeightDerivedLast::from_derived_computed::<SatsTransform>(
|
||||
let sats = LazyHeightDerived::from_derived_computed::<SatsTransform>(
|
||||
name,
|
||||
v,
|
||||
&source.sats.rest,
|
||||
);
|
||||
|
||||
let btc = LazyHeightDerivedLast::from_derived_computed::<BitcoinTransform>(
|
||||
let btc = LazyHeightDerived::from_derived_computed::<BitcoinTransform>(
|
||||
&format!("{name}_btc"),
|
||||
v,
|
||||
&source.sats.rest,
|
||||
);
|
||||
|
||||
let usd = LazyHeightDerivedLast::from_lazy::<DollarsTransform, Cents>(
|
||||
let cents = LazyHeightDerived::from_derived_computed::<CentsTransform>(
|
||||
&format!("{name}_cents"),
|
||||
v,
|
||||
&source.cents.rest,
|
||||
);
|
||||
|
||||
let usd = LazyHeightDerived::from_lazy::<DollarsTransform, Cents>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
&source.usd.rest,
|
||||
);
|
||||
|
||||
Self { sats, btc, usd }
|
||||
Self { sats, btc, cents, usd }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
mod cumulative_full;
|
||||
mod full;
|
||||
mod last;
|
||||
mod lazy_last;
|
||||
mod lazy_value_last;
|
||||
|
||||
pub use cumulative_full::*;
|
||||
pub use full::*;
|
||||
pub use last::*;
|
||||
pub use lazy_last::*;
|
||||
pub use lazy_value_last::*;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//! Fully lazy value type for Height indexing.
|
||||
//! Fully lazy value type.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Dollars, Height, Sats, Version};
|
||||
use vecdb::{ReadableCloneableVec, LazyVecFrom1, UnaryTransform};
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use vecdb::{ReadableCloneableVec, LazyVecFrom1, UnaryTransform, VecIndex};
|
||||
|
||||
use crate::internal::ValueFromHeightLast;
|
||||
use crate::internal::ValueFromHeight;
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
@@ -12,21 +12,23 @@ const VERSION: Version = Version::ZERO;
|
||||
///
|
||||
/// All fields are lazy transforms from existing sources - no storage.
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct LazyValueFromHeight {
|
||||
pub sats: LazyVecFrom1<Height, Sats, Height, Sats>,
|
||||
pub btc: LazyVecFrom1<Height, Bitcoin, Height, Sats>,
|
||||
pub usd: LazyVecFrom1<Height, Dollars, Height, Dollars>,
|
||||
pub struct LazyValue<I: VecIndex> {
|
||||
pub sats: LazyVecFrom1<I, Sats, I, Sats>,
|
||||
pub btc: LazyVecFrom1<I, Bitcoin, I, Sats>,
|
||||
pub cents: LazyVecFrom1<I, Cents, I, Cents>,
|
||||
pub usd: LazyVecFrom1<I, Dollars, I, Dollars>,
|
||||
}
|
||||
|
||||
impl LazyValueFromHeight {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, DollarsTransform>(
|
||||
impl LazyValue<Height> {
|
||||
pub(crate) fn from_block_source<SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform>(
|
||||
name: &str,
|
||||
source: &ValueFromHeightLast,
|
||||
source: &ValueFromHeight,
|
||||
version: Version,
|
||||
) -> Self
|
||||
where
|
||||
SatsTransform: UnaryTransform<Sats, Sats>,
|
||||
BitcoinTransform: UnaryTransform<Sats, Bitcoin>,
|
||||
CentsTransform: UnaryTransform<Cents, Cents>,
|
||||
DollarsTransform: UnaryTransform<Dollars, Dollars>,
|
||||
{
|
||||
let v = version + VERSION;
|
||||
@@ -40,12 +42,18 @@ impl LazyValueFromHeight {
|
||||
source.sats.height.read_only_boxed_clone(),
|
||||
);
|
||||
|
||||
let cents = LazyVecFrom1::transformed::<CentsTransform>(
|
||||
&format!("{name}_cents"),
|
||||
v,
|
||||
source.cents.height.read_only_boxed_clone(),
|
||||
);
|
||||
|
||||
let usd = LazyVecFrom1::transformed::<DollarsTransform>(
|
||||
&format!("{name}_usd"),
|
||||
v,
|
||||
source.usd.height.read_only_boxed_clone(),
|
||||
);
|
||||
|
||||
Self { sats, btc, usd }
|
||||
Self { sats, btc, cents, usd }
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,16 @@ mod eager_indexes;
|
||||
mod from_height;
|
||||
mod from_tx;
|
||||
mod group;
|
||||
mod height;
|
||||
mod height_derived;
|
||||
mod indexes;
|
||||
mod lazy_eager_indexes;
|
||||
mod lazy_value;
|
||||
mod rolling;
|
||||
pub(crate) mod sliding_window;
|
||||
mod traits;
|
||||
mod transform;
|
||||
mod tx_derived;
|
||||
mod value;
|
||||
mod vec;
|
||||
mod windows;
|
||||
|
||||
@@ -22,13 +23,14 @@ pub(crate) use eager_indexes::*;
|
||||
pub(crate) use from_height::*;
|
||||
pub(crate) use from_tx::*;
|
||||
pub(crate) use group::*;
|
||||
pub(crate) use height::*;
|
||||
pub(crate) use height_derived::*;
|
||||
pub(crate) use indexes::*;
|
||||
pub(crate) use lazy_eager_indexes::*;
|
||||
pub(crate) use lazy_value::*;
|
||||
pub(crate) use rolling::*;
|
||||
pub(crate) use traits::*;
|
||||
pub use transform::*;
|
||||
pub(crate) use tx_derived::*;
|
||||
pub(crate) use value::*;
|
||||
pub(crate) use vec::*;
|
||||
pub(crate) use windows::*;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! ValueFromHeightLastWindows - window-first ordering.
|
||||
//! ValueFromHeightWindows - window-first ordering.
|
||||
//!
|
||||
//! Access pattern: `coinbase_sum._24h.sats.height`
|
||||
//! Each window (24h, 7d, 30d, 1y) contains sats (stored) + btc (lazy) + usd (stored).
|
||||
@@ -14,21 +14,21 @@ use brk_types::{Cents, Sats};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ValueFromHeightLast, WindowStarts, Windows},
|
||||
internal::{ValueFromHeight, WindowStarts, Windows},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
/// Value rolling windows — window-first, currency-last.
|
||||
///
|
||||
/// Each window contains `ValueFromHeightLast` (sats + btc lazy + usd).
|
||||
/// Each window contains `ValueFromHeight` (sats + btc lazy + usd).
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct ValueFromHeightLastWindows<M: StorageMode = Rw>(
|
||||
pub Windows<ValueFromHeightLast<M>>,
|
||||
pub struct ValueFromHeightWindows<M: StorageMode = Rw>(
|
||||
pub Windows<ValueFromHeight<M>>,
|
||||
);
|
||||
|
||||
impl ValueFromHeightLastWindows {
|
||||
impl ValueFromHeightWindows {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -37,25 +37,25 @@ impl ValueFromHeightLastWindows {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
Ok(Self(Windows {
|
||||
_24h: ValueFromHeightLast::forced_import(
|
||||
_24h: ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_24h"),
|
||||
v,
|
||||
indexes,
|
||||
)?,
|
||||
_7d: ValueFromHeightLast::forced_import(
|
||||
_7d: ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_7d"),
|
||||
v,
|
||||
indexes,
|
||||
)?,
|
||||
_30d: ValueFromHeightLast::forced_import(
|
||||
_30d: ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_30d"),
|
||||
v,
|
||||
indexes,
|
||||
)?,
|
||||
_1y: ValueFromHeightLast::forced_import(
|
||||
_1y: ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_1y"),
|
||||
v,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! RollingWindows - newtype on Windows with ComputedFromHeightLast per window duration.
|
||||
//! RollingWindows - newtype on Windows with ComputedFromHeight per window duration.
|
||||
//!
|
||||
//! Each of the 4 windows (24h, 7d, 30d, 1y) contains a height-level stored vec
|
||||
//! plus all 17 LazyAggVec index views.
|
||||
@@ -15,7 +15,7 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, ComputedVecValue, NumericValue, Windows},
|
||||
internal::{ComputedFromHeight, ComputedVecValue, NumericValue, Windows},
|
||||
};
|
||||
|
||||
/// Rolling window start heights — references to the 4 height-ago vecs.
|
||||
@@ -35,7 +35,7 @@ impl<'a> WindowStarts<'a> {
|
||||
/// 4 rolling window vecs (24h, 7d, 30d, 1y), each with height data + all 17 index views.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct RollingWindows<T, M: StorageMode = Rw>(pub Windows<ComputedFromHeightLast<T, M>>)
|
||||
pub struct RollingWindows<T, M: StorageMode = Rw>(pub Windows<ComputedFromHeight<T, M>>)
|
||||
where
|
||||
T: ComputedVecValue + PartialOrd + JsonSchema;
|
||||
|
||||
@@ -53,10 +53,10 @@ where
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
Ok(Self(Windows {
|
||||
_24h: ComputedFromHeightLast::forced_import(db, &format!("{name}_24h"), v, indexes)?,
|
||||
_7d: ComputedFromHeightLast::forced_import(db, &format!("{name}_7d"), v, indexes)?,
|
||||
_30d: ComputedFromHeightLast::forced_import(db, &format!("{name}_30d"), v, indexes)?,
|
||||
_1y: ComputedFromHeightLast::forced_import(db, &format!("{name}_1y"), v, indexes)?,
|
||||
_24h: ComputedFromHeight::forced_import(db, &format!("{name}_24h"), v, indexes)?,
|
||||
_7d: ComputedFromHeight::forced_import(db, &format!("{name}_7d"), v, indexes)?,
|
||||
_30d: ComputedFromHeight::forced_import(db, &format!("{name}_30d"), v, indexes)?,
|
||||
_1y: ComputedFromHeight::forced_import(db, &format!("{name}_1y"), v, indexes)?,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
12
crates/brk_computer/src/internal/transform/cents_halve.rs
Normal file
12
crates/brk_computer/src/internal/transform/cents_halve.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use brk_types::Cents;
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
/// Cents -> Cents/2 (for supply_halved_cents)
|
||||
pub struct HalveCents;
|
||||
|
||||
impl UnaryTransform<Cents, Cents> for HalveCents {
|
||||
#[inline(always)]
|
||||
fn apply(cents: Cents) -> Cents {
|
||||
cents / 2u64
|
||||
}
|
||||
}
|
||||
12
crates/brk_computer/src/internal/transform/cents_identity.rs
Normal file
12
crates/brk_computer/src/internal/transform/cents_identity.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use brk_types::Cents;
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
/// Cents -> Cents (identity transform for lazy references)
|
||||
pub struct CentsIdentity;
|
||||
|
||||
impl UnaryTransform<Cents, Cents> for CentsIdentity {
|
||||
#[inline(always)]
|
||||
fn apply(cents: Cents) -> Cents {
|
||||
cents
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
mod block_count_target;
|
||||
mod cents_halve;
|
||||
mod cents_identity;
|
||||
mod cents_plus;
|
||||
mod cents_signed_to_dollars;
|
||||
mod cents_subtract_to_cents_signed;
|
||||
@@ -41,6 +43,8 @@ mod volatility_sqrt365;
|
||||
mod volatility_sqrt7;
|
||||
|
||||
pub use block_count_target::*;
|
||||
pub use cents_halve::*;
|
||||
pub use cents_identity::*;
|
||||
pub use cents_plus::*;
|
||||
pub use cents_signed_to_dollars::*;
|
||||
pub use cents_subtract_to_cents_signed::*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Value type with height-level data only (no period-derived views).
|
||||
//!
|
||||
//! Stores sats and cents per height, plus lazy btc and usd transforms.
|
||||
//! Stores sats and cents per index, plus lazy btc and usd transforms.
|
||||
//! Use when period views are unnecessary (e.g., rolling windows provide windowed data).
|
||||
|
||||
use brk_error::Result;
|
||||
@@ -8,22 +8,22 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version};
|
||||
use vecdb::{
|
||||
Database, EagerVec, Exit, ImportableVec, LazyVecFrom1, PcoVec, ReadableCloneableVec, Rw,
|
||||
StorageMode,
|
||||
StorageMode, VecIndex,
|
||||
};
|
||||
|
||||
use crate::{internal::{CentsUnsignedToDollars, SatsToBitcoin, SatsToCents}, prices};
|
||||
|
||||
const VERSION: Version = Version::TWO; // Match ValueFromHeightLast versioning
|
||||
const VERSION: Version = Version::TWO; // Match ValueFromHeight versioning
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ValueFromHeight<M: StorageMode = Rw> {
|
||||
pub sats: M::Stored<EagerVec<PcoVec<Height, Sats>>>,
|
||||
pub btc: LazyVecFrom1<Height, Bitcoin, Height, Sats>,
|
||||
pub cents: M::Stored<EagerVec<PcoVec<Height, Cents>>>,
|
||||
pub usd: LazyVecFrom1<Height, Dollars, Height, Cents>,
|
||||
pub struct Value<I: VecIndex, M: StorageMode = Rw> {
|
||||
pub sats: M::Stored<EagerVec<PcoVec<I, Sats>>>,
|
||||
pub btc: LazyVecFrom1<I, Bitcoin, I, Sats>,
|
||||
pub cents: M::Stored<EagerVec<PcoVec<I, Cents>>>,
|
||||
pub usd: LazyVecFrom1<I, Dollars, I, Cents>,
|
||||
}
|
||||
|
||||
impl ValueFromHeight {
|
||||
impl Value<Height> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
name: &str,
|
||||
@@ -6,7 +6,7 @@ use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeightLast, LazyHeightDerivedLast,
|
||||
ComputedFromHeight, LazyHeightDerived,
|
||||
Price, StoredU16ToYears,
|
||||
},
|
||||
};
|
||||
@@ -19,7 +19,7 @@ impl Vecs {
|
||||
) -> Result<Self> {
|
||||
let price_ath = Price::forced_import(db, "price_ath", version, indexes)?;
|
||||
|
||||
let max_days_between_price_aths = ComputedFromHeightLast::forced_import(
|
||||
let max_days_between_price_aths = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"max_days_between_price_aths",
|
||||
version,
|
||||
@@ -27,23 +27,23 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
let max_years_between_price_aths =
|
||||
LazyHeightDerivedLast::from_computed::<StoredU16ToYears>(
|
||||
LazyHeightDerived::from_computed::<StoredU16ToYears>(
|
||||
"max_years_between_price_aths",
|
||||
version,
|
||||
&max_days_between_price_aths,
|
||||
);
|
||||
|
||||
let days_since_price_ath =
|
||||
ComputedFromHeightLast::forced_import(db, "days_since_price_ath", version, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, "days_since_price_ath", version, indexes)?;
|
||||
|
||||
let years_since_price_ath = LazyHeightDerivedLast::from_computed::<StoredU16ToYears>(
|
||||
let years_since_price_ath = LazyHeightDerived::from_computed::<StoredU16ToYears>(
|
||||
"years_since_price_ath",
|
||||
version,
|
||||
&days_since_price_ath,
|
||||
);
|
||||
|
||||
let price_drawdown =
|
||||
ComputedFromHeightLast::forced_import(db, "price_drawdown", version, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, "price_drawdown", version, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
price_ath,
|
||||
|
||||
@@ -2,15 +2,15 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, StoredF32, StoredU16};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, LazyHeightDerivedLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, LazyHeightDerived, Price};
|
||||
|
||||
/// All-time high related metrics
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub price_ath: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_drawdown: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub days_since_price_ath: ComputedFromHeightLast<StoredU16, M>,
|
||||
pub years_since_price_ath: LazyHeightDerivedLast<StoredF32, StoredU16>,
|
||||
pub max_days_between_price_aths: ComputedFromHeightLast<StoredU16, M>,
|
||||
pub max_years_between_price_aths: LazyHeightDerivedLast<StoredF32, StoredU16>,
|
||||
pub price_ath: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_drawdown: ComputedFromHeight<StoredF32, M>,
|
||||
pub days_since_price_ath: ComputedFromHeight<StoredU16, M>,
|
||||
pub years_since_price_ath: LazyHeightDerived<StoredF32, StoredU16>,
|
||||
pub max_days_between_price_aths: ComputedFromHeight<StoredU16, M>,
|
||||
pub max_years_between_price_aths: LazyHeightDerived<StoredF32, StoredU16>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{AnyVec, EagerVec, Exit, ReadableOptionVec, ReadableVec, PcoVec, PcoV
|
||||
use super::{ByDcaClass, ByDcaPeriod, Vecs};
|
||||
use crate::{
|
||||
ComputeIndexes, blocks, indexes,
|
||||
internal::{ComputedFromHeightLast, PercentageDiffCents},
|
||||
internal::{ComputedFromHeight, PercentageDiffCents},
|
||||
market::lookback,
|
||||
prices,
|
||||
};
|
||||
@@ -300,11 +300,11 @@ fn sats_from_dca(price: Dollars) -> Sats {
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn compute_period_rolling(
|
||||
days_in_profit: &mut ByDcaPeriod<ComputedFromHeightLast<StoredU32>>,
|
||||
days_in_loss: &mut ByDcaPeriod<ComputedFromHeightLast<StoredU32>>,
|
||||
min_return: &mut ByDcaPeriod<ComputedFromHeightLast<StoredF32>>,
|
||||
max_return: &mut ByDcaPeriod<ComputedFromHeightLast<StoredF32>>,
|
||||
returns: &ByDcaPeriod<ComputedFromHeightLast<StoredF32>>,
|
||||
days_in_profit: &mut ByDcaPeriod<ComputedFromHeight<StoredU32>>,
|
||||
days_in_loss: &mut ByDcaPeriod<ComputedFromHeight<StoredU32>>,
|
||||
min_return: &mut ByDcaPeriod<ComputedFromHeight<StoredF32>>,
|
||||
max_return: &mut ByDcaPeriod<ComputedFromHeight<StoredF32>>,
|
||||
returns: &ByDcaPeriod<ComputedFromHeight<StoredF32>>,
|
||||
blocks: &blocks::Vecs,
|
||||
h2d: &EagerVec<PcoVec<Height, Day1>>,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
@@ -355,11 +355,11 @@ fn compute_period_rolling(
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn compute_class_cumulative(
|
||||
days_in_profit: &mut ByDcaClass<ComputedFromHeightLast<StoredU32>>,
|
||||
days_in_loss: &mut ByDcaClass<ComputedFromHeightLast<StoredU32>>,
|
||||
min_return: &mut ByDcaClass<ComputedFromHeightLast<StoredF32>>,
|
||||
max_return: &mut ByDcaClass<ComputedFromHeightLast<StoredF32>>,
|
||||
returns: &ByDcaClass<ComputedFromHeightLast<StoredF32>>,
|
||||
days_in_profit: &mut ByDcaClass<ComputedFromHeight<StoredU32>>,
|
||||
days_in_loss: &mut ByDcaClass<ComputedFromHeight<StoredU32>>,
|
||||
min_return: &mut ByDcaClass<ComputedFromHeight<StoredF32>>,
|
||||
max_return: &mut ByDcaClass<ComputedFromHeight<StoredF32>>,
|
||||
returns: &ByDcaClass<ComputedFromHeight<StoredF32>>,
|
||||
h2d: &EagerVec<PcoVec<Height, Day1>>,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
|
||||
@@ -6,8 +6,8 @@ use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod, Vecs};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeightLast, Price,
|
||||
ValueFromHeightLast,
|
||||
ComputedFromHeight, Price,
|
||||
ValueFromHeight,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Vecs {
|
||||
) -> Result<Self> {
|
||||
// DCA by period - stack (KISS)
|
||||
let period_stack = ByDcaPeriod::try_new(|name, _days| {
|
||||
ValueFromHeightLast::forced_import(
|
||||
ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_dca_stack"),
|
||||
version,
|
||||
@@ -38,7 +38,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let period_returns = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_dca_returns"),
|
||||
version,
|
||||
@@ -48,12 +48,12 @@ impl Vecs {
|
||||
|
||||
// DCA by period - CAGR
|
||||
let period_cagr = ByDcaCagr::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_dca_cagr"), version, indexes)
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_dca_cagr"), version, indexes)
|
||||
})?;
|
||||
|
||||
// DCA by period - profitability
|
||||
let period_days_in_profit = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_dca_days_in_profit"),
|
||||
version + Version::ONE,
|
||||
@@ -62,7 +62,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let period_days_in_loss = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_dca_days_in_loss"),
|
||||
version + Version::ONE,
|
||||
@@ -71,7 +71,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let period_min_return = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_dca_min_return"),
|
||||
version,
|
||||
@@ -80,7 +80,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let period_max_return = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_dca_max_return"),
|
||||
version,
|
||||
@@ -90,7 +90,7 @@ impl Vecs {
|
||||
|
||||
// Lump sum by period - stack (KISS)
|
||||
let period_lump_sum_stack = ByDcaPeriod::try_new(|name, _days| {
|
||||
ValueFromHeightLast::forced_import(
|
||||
ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_lump_sum_stack"),
|
||||
version,
|
||||
@@ -100,7 +100,7 @@ impl Vecs {
|
||||
|
||||
// Lump sum by period - returns
|
||||
let period_lump_sum_returns = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_lump_sum_returns"),
|
||||
version,
|
||||
@@ -110,7 +110,7 @@ impl Vecs {
|
||||
|
||||
// Lump sum by period - profitability
|
||||
let period_lump_sum_days_in_profit = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_lump_sum_days_in_profit"),
|
||||
version + Version::ONE,
|
||||
@@ -119,7 +119,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let period_lump_sum_days_in_loss = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_lump_sum_days_in_loss"),
|
||||
version + Version::ONE,
|
||||
@@ -128,7 +128,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let period_lump_sum_min_return = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_lump_sum_min_return"),
|
||||
version,
|
||||
@@ -137,7 +137,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let period_lump_sum_max_return = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_lump_sum_max_return"),
|
||||
version,
|
||||
@@ -147,7 +147,7 @@ impl Vecs {
|
||||
|
||||
// DCA by year class - stack (KISS)
|
||||
let class_stack = ByDcaClass::try_new(|name, _year, _day1| {
|
||||
ValueFromHeightLast::forced_import(
|
||||
ValueFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_stack"),
|
||||
version,
|
||||
@@ -161,7 +161,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let class_returns = ByDcaClass::try_new(|name, _year, _day1| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_returns"),
|
||||
version,
|
||||
@@ -171,7 +171,7 @@ impl Vecs {
|
||||
|
||||
// DCA by year class - profitability
|
||||
let class_days_in_profit = ByDcaClass::try_new(|name, _year, _day1| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_days_in_profit"),
|
||||
version,
|
||||
@@ -180,7 +180,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let class_days_in_loss = ByDcaClass::try_new(|name, _year, _day1| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_days_in_loss"),
|
||||
version,
|
||||
@@ -189,11 +189,11 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
let class_min_return = ByDcaClass::try_new(|name, _year, _day1| {
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_min_return"), version, indexes)
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_min_return"), version, indexes)
|
||||
})?;
|
||||
|
||||
let class_max_return = ByDcaClass::try_new(|name, _year, _day1| {
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_max_return"), version, indexes)
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_max_return"), version, indexes)
|
||||
})?;
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -4,7 +4,7 @@ use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod};
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, Price, ValueFromHeightLast,
|
||||
ComputedFromHeight, Price, ValueFromHeight,
|
||||
};
|
||||
|
||||
/// Dollar-cost averaging metrics by time period and year class
|
||||
@@ -15,35 +15,35 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub dca_sats_per_day: M::Stored<EagerVec<PcoVec<Height, Sats>>>,
|
||||
|
||||
// DCA by period - KISS types
|
||||
pub period_stack: ByDcaPeriod<ValueFromHeightLast<M>>,
|
||||
pub period_average_price: ByDcaPeriod<Price<ComputedFromHeightLast<Cents, M>>>,
|
||||
pub period_returns: ByDcaPeriod<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub period_cagr: ByDcaCagr<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub period_stack: ByDcaPeriod<ValueFromHeight<M>>,
|
||||
pub period_average_price: ByDcaPeriod<Price<ComputedFromHeight<Cents, M>>>,
|
||||
pub period_returns: ByDcaPeriod<ComputedFromHeight<StoredF32, M>>,
|
||||
pub period_cagr: ByDcaCagr<ComputedFromHeight<StoredF32, M>>,
|
||||
|
||||
// DCA by period - profitability
|
||||
pub period_days_in_profit: ByDcaPeriod<ComputedFromHeightLast<StoredU32, M>>,
|
||||
pub period_days_in_loss: ByDcaPeriod<ComputedFromHeightLast<StoredU32, M>>,
|
||||
pub period_min_return: ByDcaPeriod<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub period_max_return: ByDcaPeriod<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub period_days_in_profit: ByDcaPeriod<ComputedFromHeight<StoredU32, M>>,
|
||||
pub period_days_in_loss: ByDcaPeriod<ComputedFromHeight<StoredU32, M>>,
|
||||
pub period_min_return: ByDcaPeriod<ComputedFromHeight<StoredF32, M>>,
|
||||
pub period_max_return: ByDcaPeriod<ComputedFromHeight<StoredF32, M>>,
|
||||
|
||||
// Lump sum by period (for comparison with DCA) - KISS types
|
||||
pub period_lump_sum_stack: ByDcaPeriod<ValueFromHeightLast<M>>,
|
||||
pub period_lump_sum_returns: ByDcaPeriod<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub period_lump_sum_stack: ByDcaPeriod<ValueFromHeight<M>>,
|
||||
pub period_lump_sum_returns: ByDcaPeriod<ComputedFromHeight<StoredF32, M>>,
|
||||
|
||||
// Lump sum by period - profitability
|
||||
pub period_lump_sum_days_in_profit: ByDcaPeriod<ComputedFromHeightLast<StoredU32, M>>,
|
||||
pub period_lump_sum_days_in_loss: ByDcaPeriod<ComputedFromHeightLast<StoredU32, M>>,
|
||||
pub period_lump_sum_min_return: ByDcaPeriod<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub period_lump_sum_max_return: ByDcaPeriod<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub period_lump_sum_days_in_profit: ByDcaPeriod<ComputedFromHeight<StoredU32, M>>,
|
||||
pub period_lump_sum_days_in_loss: ByDcaPeriod<ComputedFromHeight<StoredU32, M>>,
|
||||
pub period_lump_sum_min_return: ByDcaPeriod<ComputedFromHeight<StoredF32, M>>,
|
||||
pub period_lump_sum_max_return: ByDcaPeriod<ComputedFromHeight<StoredF32, M>>,
|
||||
|
||||
// DCA by year class - KISS types
|
||||
pub class_stack: ByDcaClass<ValueFromHeightLast<M>>,
|
||||
pub class_average_price: ByDcaClass<Price<ComputedFromHeightLast<Cents, M>>>,
|
||||
pub class_returns: ByDcaClass<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub class_stack: ByDcaClass<ValueFromHeight<M>>,
|
||||
pub class_average_price: ByDcaClass<Price<ComputedFromHeight<Cents, M>>>,
|
||||
pub class_returns: ByDcaClass<ComputedFromHeight<StoredF32, M>>,
|
||||
|
||||
// DCA by year class - profitability
|
||||
pub class_days_in_profit: ByDcaClass<ComputedFromHeightLast<StoredU32, M>>,
|
||||
pub class_days_in_loss: ByDcaClass<ComputedFromHeightLast<StoredU32, M>>,
|
||||
pub class_min_return: ByDcaClass<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub class_max_return: ByDcaClass<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub class_days_in_profit: ByDcaClass<ComputedFromHeight<StoredU32, M>>,
|
||||
pub class_days_in_loss: ByDcaClass<ComputedFromHeight<StoredU32, M>>,
|
||||
pub class_min_return: ByDcaClass<ComputedFromHeight<StoredF32, M>>,
|
||||
pub class_max_return: ByDcaClass<ComputedFromHeight<StoredF32, M>>,
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ use brk_error::Result;
|
||||
use brk_types::{Day1, Sats, StoredF32, StoredU64, Version};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableOptionVec, VecIndex, WritableVec};
|
||||
|
||||
use crate::{ComputeIndexes, distribution, internal::ComputedFromHeightLast};
|
||||
use crate::{ComputeIndexes, distribution, internal::ComputedFromHeight};
|
||||
|
||||
pub(super) fn compute(
|
||||
gini: &mut ComputedFromHeightLast<StoredF32>,
|
||||
gini: &mut ComputedFromHeight<StoredF32>,
|
||||
distribution: &distribution::Vecs,
|
||||
h2d: &[Day1],
|
||||
total_heights: usize,
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::{ByIndicatorTimeframe, MacdChain, RsiChain, Vecs};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::ComputedFromHeightLast,
|
||||
internal::ComputedFromHeight,
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
@@ -19,7 +19,7 @@ impl RsiChain {
|
||||
) -> Result<Self> {
|
||||
macro_rules! import {
|
||||
($name:expr) => {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("rsi_{}_{}", $name, tf),
|
||||
version,
|
||||
@@ -31,7 +31,7 @@ impl RsiChain {
|
||||
let average_gain = import!("avg_gain");
|
||||
let average_loss = import!("avg_loss");
|
||||
|
||||
let rsi = ComputedFromHeightLast::forced_import(
|
||||
let rsi = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("rsi_{tf}"),
|
||||
version,
|
||||
@@ -60,20 +60,20 @@ impl MacdChain {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let line = ComputedFromHeightLast::forced_import(
|
||||
let line = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("macd_line_{tf}"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
let signal = ComputedFromHeightLast::forced_import(
|
||||
let signal = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("macd_signal_{tf}"),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let histogram = ComputedFromHeightLast::forced_import(
|
||||
let histogram = ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("macd_histogram_{tf}"),
|
||||
version,
|
||||
@@ -96,19 +96,19 @@ impl Vecs {
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
|
||||
let nvt = ComputedFromHeightLast::forced_import(db, "nvt", v, indexes)?;
|
||||
let nvt = ComputedFromHeight::forced_import(db, "nvt", v, indexes)?;
|
||||
|
||||
let rsi = ByIndicatorTimeframe::try_new(|tf| RsiChain::forced_import(db, tf, v, indexes))?;
|
||||
let macd = ByIndicatorTimeframe::try_new(|tf| MacdChain::forced_import(db, tf, v, indexes))?;
|
||||
|
||||
let stoch_k = ComputedFromHeightLast::forced_import(db, "stoch_k", v, indexes)?;
|
||||
let stoch_d = ComputedFromHeightLast::forced_import(db, "stoch_d", v, indexes)?;
|
||||
let gini = ComputedFromHeightLast::forced_import(db, "gini", v, indexes)?;
|
||||
let stoch_k = ComputedFromHeight::forced_import(db, "stoch_k", v, indexes)?;
|
||||
let stoch_d = ComputedFromHeight::forced_import(db, "stoch_d", v, indexes)?;
|
||||
let gini = ComputedFromHeight::forced_import(db, "gini", v, indexes)?;
|
||||
|
||||
let pi_cycle = ComputedFromHeightLast::forced_import(db, "pi_cycle", v, indexes)?;
|
||||
let pi_cycle = ComputedFromHeight::forced_import(db, "pi_cycle", v, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
puell_multiple: ComputedFromHeightLast::forced_import(db, "puell_multiple", v, indexes)?,
|
||||
puell_multiple: ComputedFromHeight::forced_import(db, "puell_multiple", v, indexes)?,
|
||||
nvt,
|
||||
rsi,
|
||||
stoch_k,
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredF32;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightLast;
|
||||
use crate::internal::ComputedFromHeight;
|
||||
|
||||
pub const TIMEFRAME_NAMES: [&str; 4] = ["1d", "1w", "1m", "1y"];
|
||||
|
||||
@@ -37,38 +37,38 @@ impl<T> ByIndicatorTimeframe<T> {
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RsiChain<M: StorageMode = Rw> {
|
||||
pub gains: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub losses: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub average_gain: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub average_loss: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub rsi: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub rsi_min: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub rsi_max: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub stoch_rsi: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub stoch_rsi_k: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub stoch_rsi_d: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub gains: ComputedFromHeight<StoredF32, M>,
|
||||
pub losses: ComputedFromHeight<StoredF32, M>,
|
||||
pub average_gain: ComputedFromHeight<StoredF32, M>,
|
||||
pub average_loss: ComputedFromHeight<StoredF32, M>,
|
||||
pub rsi: ComputedFromHeight<StoredF32, M>,
|
||||
pub rsi_min: ComputedFromHeight<StoredF32, M>,
|
||||
pub rsi_max: ComputedFromHeight<StoredF32, M>,
|
||||
pub stoch_rsi: ComputedFromHeight<StoredF32, M>,
|
||||
pub stoch_rsi_k: ComputedFromHeight<StoredF32, M>,
|
||||
pub stoch_rsi_d: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct MacdChain<M: StorageMode = Rw> {
|
||||
pub line: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub signal: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub histogram: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub line: ComputedFromHeight<StoredF32, M>,
|
||||
pub signal: ComputedFromHeight<StoredF32, M>,
|
||||
pub histogram: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub puell_multiple: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub nvt: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub puell_multiple: ComputedFromHeight<StoredF32, M>,
|
||||
pub nvt: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
pub rsi: ByIndicatorTimeframe<RsiChain<M>>,
|
||||
|
||||
pub stoch_k: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub stoch_d: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub stoch_k: ComputedFromHeight<StoredF32, M>,
|
||||
pub stoch_d: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
pub pi_cycle: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub pi_cycle: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
pub macd: ByIndicatorTimeframe<MacdChain<M>>,
|
||||
|
||||
pub gini: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub gini: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ use brk_types::Cents;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use super::ByLookbackPeriod;
|
||||
use crate::internal::{ComputedFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, Price};
|
||||
|
||||
/// Price lookback metrics
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub price_ago: ByLookbackPeriod<Price<ComputedFromHeightLast<Cents, M>>>,
|
||||
pub price_ago: ByLookbackPeriod<Price<ComputedFromHeight<Cents, M>>>,
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Cents;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightPriceWithRatioExtended, LazyFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeightPriceWithRatioExtended, LazyFromHeight, Price};
|
||||
|
||||
/// Simple and exponential moving average metrics
|
||||
#[derive(Traversable)]
|
||||
@@ -41,7 +41,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub price_200w_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_4y_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
|
||||
pub price_200d_sma_x2_4: Price<LazyFromHeightLast<Cents, Cents>>,
|
||||
pub price_200d_sma_x0_8: Price<LazyFromHeightLast<Cents, Cents>>,
|
||||
pub price_350d_sma_x2: Price<LazyFromHeightLast<Cents, Cents>>,
|
||||
pub price_200d_sma_x2_4: Price<LazyFromHeight<Cents, Cents>>,
|
||||
pub price_200d_sma_x0_8: Price<LazyFromHeight<Cents, Cents>>,
|
||||
pub price_350d_sma_x2: Price<LazyFromHeight<Cents, Cents>>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::{ComputedFromHeightLast, Price}};
|
||||
use crate::{indexes, internal::{ComputedFromHeight, Price}};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
@@ -18,13 +18,13 @@ impl Vecs {
|
||||
price_1m_max: Price::forced_import(db, "price_1m_max", version + v1, indexes)?,
|
||||
price_1y_min: Price::forced_import(db, "price_1y_min", version + v1, indexes)?,
|
||||
price_1y_max: Price::forced_import(db, "price_1y_max", version + v1, indexes)?,
|
||||
price_true_range: ComputedFromHeightLast::forced_import(
|
||||
price_true_range: ComputedFromHeight::forced_import(
|
||||
db, "price_true_range", version + v1, indexes,
|
||||
)?,
|
||||
price_true_range_2w_sum: ComputedFromHeightLast::forced_import(
|
||||
price_true_range_2w_sum: ComputedFromHeight::forced_import(
|
||||
db, "price_true_range_2w_sum", version + v1, indexes,
|
||||
)?,
|
||||
price_2w_choppiness_index: ComputedFromHeightLast::forced_import(
|
||||
price_2w_choppiness_index: ComputedFromHeight::forced_import(
|
||||
db, "price_2w_choppiness_index", version + v1, indexes,
|
||||
)?,
|
||||
})
|
||||
|
||||
@@ -2,20 +2,20 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, StoredF32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeight, Price};
|
||||
|
||||
/// Price range and choppiness metrics
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub price_1w_min: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_1w_max: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_2w_min: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_2w_max: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_1m_min: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_1m_max: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_1y_min: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_1y_max: Price<ComputedFromHeightLast<Cents, M>>,
|
||||
pub price_true_range: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub price_true_range_2w_sum: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub price_2w_choppiness_index: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub price_1w_min: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_1w_max: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_2w_min: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_2w_max: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_1m_min: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_1m_max: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_1y_min: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_1y_max: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub price_true_range: ComputedFromHeight<StoredF32, M>,
|
||||
pub price_true_range_2w_sum: ComputedFromHeight<StoredF32, M>,
|
||||
pub price_2w_choppiness_index: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::super::lookback::ByLookbackPeriod;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::ComputedFromHeightLast,
|
||||
internal::ComputedFromHeight,
|
||||
internal::ComputedFromHeightStdDev,
|
||||
market::dca::ByDcaCagr,
|
||||
};
|
||||
@@ -20,7 +20,7 @@ impl Vecs {
|
||||
let v1 = Version::ONE;
|
||||
|
||||
let price_returns = ByLookbackPeriod::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(
|
||||
ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_price_returns"),
|
||||
version,
|
||||
@@ -30,7 +30,7 @@ impl Vecs {
|
||||
|
||||
// CAGR (computed, 2y+ only)
|
||||
let cagr = ByDcaCagr::try_new(|name, _days| {
|
||||
ComputedFromHeightLast::forced_import(db, &format!("{name}_cagr"), version, indexes)
|
||||
ComputedFromHeight::forced_import(db, &format!("{name}_cagr"), version, indexes)
|
||||
})?;
|
||||
|
||||
let _1d_returns_1w_sd = ComputedFromHeightStdDev::forced_import(
|
||||
|
||||
@@ -3,17 +3,17 @@ use brk_types::{Height, StoredF32};
|
||||
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
internal::{ComputedFromHeightLast, ComputedFromHeightStdDev},
|
||||
internal::{ComputedFromHeight, ComputedFromHeightStdDev},
|
||||
market::{dca::ByDcaCagr, lookback::ByLookbackPeriod},
|
||||
};
|
||||
|
||||
/// Price returns, CAGR, and returns standard deviation metrics
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub price_returns: ByLookbackPeriod<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub price_returns: ByLookbackPeriod<ComputedFromHeight<StoredF32, M>>,
|
||||
|
||||
// CAGR (computed from returns, 2y+ only)
|
||||
pub cagr: ByDcaCagr<ComputedFromHeightLast<StoredF32, M>>,
|
||||
pub cagr: ByDcaCagr<ComputedFromHeight<StoredF32, M>>,
|
||||
|
||||
// Returns standard deviation (computed from 1d returns)
|
||||
pub _1d_returns_1w_sd: ComputedFromHeightStdDev<M>,
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::super::returns;
|
||||
use super::Vecs;
|
||||
use crate::indexes;
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, LazyFromHeightLast, StoredF32TimesSqrt7, StoredF32TimesSqrt30,
|
||||
ComputedFromHeight, LazyFromHeight, StoredF32TimesSqrt7, StoredF32TimesSqrt30,
|
||||
StoredF32TimesSqrt365,
|
||||
};
|
||||
|
||||
@@ -19,21 +19,21 @@ impl Vecs {
|
||||
) -> Result<Self> {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
let price_1w_volatility = LazyFromHeightLast::from_computed::<StoredF32TimesSqrt7>(
|
||||
let price_1w_volatility = LazyFromHeight::from_computed::<StoredF32TimesSqrt7>(
|
||||
"price_1w_volatility",
|
||||
version + v2,
|
||||
returns._1d_returns_1w_sd.sd.height.read_only_boxed_clone(),
|
||||
&returns._1d_returns_1w_sd.sd,
|
||||
);
|
||||
|
||||
let price_1m_volatility = LazyFromHeightLast::from_computed::<StoredF32TimesSqrt30>(
|
||||
let price_1m_volatility = LazyFromHeight::from_computed::<StoredF32TimesSqrt30>(
|
||||
"price_1m_volatility",
|
||||
version + v2,
|
||||
returns._1d_returns_1m_sd.sd.height.read_only_boxed_clone(),
|
||||
&returns._1d_returns_1m_sd.sd,
|
||||
);
|
||||
|
||||
let price_1y_volatility = LazyFromHeightLast::from_computed::<StoredF32TimesSqrt365>(
|
||||
let price_1y_volatility = LazyFromHeight::from_computed::<StoredF32TimesSqrt365>(
|
||||
"price_1y_volatility",
|
||||
version + v2,
|
||||
returns._1d_returns_1y_sd.sd.height.read_only_boxed_clone(),
|
||||
@@ -41,18 +41,18 @@ impl Vecs {
|
||||
);
|
||||
|
||||
let sharpe_1w =
|
||||
ComputedFromHeightLast::forced_import(db, "sharpe_1w", version + v2, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, "sharpe_1w", version + v2, indexes)?;
|
||||
let sharpe_1m =
|
||||
ComputedFromHeightLast::forced_import(db, "sharpe_1m", version + v2, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, "sharpe_1m", version + v2, indexes)?;
|
||||
let sharpe_1y =
|
||||
ComputedFromHeightLast::forced_import(db, "sharpe_1y", version + v2, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, "sharpe_1y", version + v2, indexes)?;
|
||||
|
||||
let sortino_1w =
|
||||
ComputedFromHeightLast::forced_import(db, "sortino_1w", version + v2, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, "sortino_1w", version + v2, indexes)?;
|
||||
let sortino_1m =
|
||||
ComputedFromHeightLast::forced_import(db, "sortino_1m", version + v2, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, "sortino_1m", version + v2, indexes)?;
|
||||
let sortino_1y =
|
||||
ComputedFromHeightLast::forced_import(db, "sortino_1y", version + v2, indexes)?;
|
||||
ComputedFromHeight::forced_import(db, "sortino_1y", version + v2, indexes)?;
|
||||
|
||||
Ok(Self {
|
||||
price_1w_volatility,
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
use brk_traversable::Traversable;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, LazyFromHeightLast};
|
||||
use crate::internal::{ComputedFromHeight, LazyFromHeight};
|
||||
|
||||
use brk_types::StoredF32;
|
||||
|
||||
/// Price volatility metrics (derived from returns standard deviation)
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub price_1w_volatility: LazyFromHeightLast<StoredF32>,
|
||||
pub price_1m_volatility: LazyFromHeightLast<StoredF32>,
|
||||
pub price_1y_volatility: LazyFromHeightLast<StoredF32>,
|
||||
pub price_1w_volatility: LazyFromHeight<StoredF32>,
|
||||
pub price_1m_volatility: LazyFromHeight<StoredF32>,
|
||||
pub price_1y_volatility: LazyFromHeight<StoredF32>,
|
||||
|
||||
pub sharpe_1w: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sharpe_1m: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sharpe_1y: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sharpe_1w: ComputedFromHeight<StoredF32, M>,
|
||||
pub sharpe_1m: ComputedFromHeight<StoredF32, M>,
|
||||
pub sharpe_1y: ComputedFromHeight<StoredF32, M>,
|
||||
|
||||
pub sortino_1w: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sortino_1m: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sortino_1y: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub sortino_1w: ComputedFromHeight<StoredF32, M>,
|
||||
pub sortino_1m: ComputedFromHeight<StoredF32, M>,
|
||||
pub sortino_1y: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::ComputedFromHeightLast,
|
||||
internal::ComputedFromHeight,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -18,98 +18,98 @@ impl Vecs {
|
||||
let v5 = Version::new(5);
|
||||
|
||||
Ok(Self {
|
||||
hash_rate: ComputedFromHeightLast::forced_import(db, "hash_rate", version + v5, indexes)?,
|
||||
hash_rate_1w_sma: ComputedFromHeightLast::forced_import(
|
||||
hash_rate: ComputedFromHeight::forced_import(db, "hash_rate", version + v5, indexes)?,
|
||||
hash_rate_1w_sma: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_rate_1w_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_1m_sma: ComputedFromHeightLast::forced_import(
|
||||
hash_rate_1m_sma: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_rate_1m_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_2m_sma: ComputedFromHeightLast::forced_import(
|
||||
hash_rate_2m_sma: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_rate_2m_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_1y_sma: ComputedFromHeightLast::forced_import(
|
||||
hash_rate_1y_sma: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_rate_1y_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_ath: ComputedFromHeightLast::forced_import(
|
||||
hash_rate_ath: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_rate_ath",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_drawdown: ComputedFromHeightLast::forced_import(
|
||||
hash_rate_drawdown: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_rate_drawdown",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_ths: ComputedFromHeightLast::forced_import(
|
||||
hash_price_ths: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_price_ths",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_ths_min: ComputedFromHeightLast::forced_import(
|
||||
hash_price_ths_min: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_price_ths_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_phs: ComputedFromHeightLast::forced_import(
|
||||
hash_price_phs: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_price_phs",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_phs_min: ComputedFromHeightLast::forced_import(
|
||||
hash_price_phs_min: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_price_phs_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_rebound: ComputedFromHeightLast::forced_import(
|
||||
hash_price_rebound: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_price_rebound",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_ths: ComputedFromHeightLast::forced_import(
|
||||
hash_value_ths: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_value_ths",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_ths_min: ComputedFromHeightLast::forced_import(
|
||||
hash_value_ths_min: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_value_ths_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_phs: ComputedFromHeightLast::forced_import(
|
||||
hash_value_phs: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_value_phs",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_phs_min: ComputedFromHeightLast::forced_import(
|
||||
hash_value_phs_min: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_value_phs_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_rebound: ComputedFromHeightLast::forced_import(
|
||||
hash_value_rebound: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"hash_value_rebound",
|
||||
version + v4,
|
||||
|
||||
@@ -2,26 +2,26 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{StoredF32, StoredF64};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightLast;
|
||||
use crate::internal::ComputedFromHeight;
|
||||
|
||||
/// Mining-related metrics: hash rate, hash price, hash value
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub hash_rate: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub hash_rate_1w_sma: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub hash_rate_1m_sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_rate_2m_sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_rate_1y_sma: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_rate_ath: ComputedFromHeightLast<StoredF64, M>,
|
||||
pub hash_rate_drawdown: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_price_ths: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_price_ths_min: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_price_phs: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_price_phs_min: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_price_rebound: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_value_ths: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_value_ths_min: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_value_phs: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_value_phs_min: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_value_rebound: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub hash_rate: ComputedFromHeight<StoredF64, M>,
|
||||
pub hash_rate_1w_sma: ComputedFromHeight<StoredF64, M>,
|
||||
pub hash_rate_1m_sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_rate_2m_sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_rate_1y_sma: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_rate_ath: ComputedFromHeight<StoredF64, M>,
|
||||
pub hash_rate_drawdown: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_price_ths: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_price_ths_min: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_price_phs: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_price_phs_min: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_price_rebound: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_value_ths: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_value_ths_min: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_value_phs: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_value_phs_min: ComputedFromHeight<StoredF32, M>,
|
||||
pub hash_value_rebound: ComputedFromHeight<StoredF32, M>,
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeightLast, FiatFromHeightLast, ValueFromHeightFull,
|
||||
ValueFromHeightSumCumulative,
|
||||
ComputedFromHeight, FiatFromHeight, ValueFromHeightFull,
|
||||
ValueFromHeightCumulativeSum,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -21,73 +21,73 @@ impl Vecs {
|
||||
coinbase: ValueFromHeightFull::forced_import(db, "coinbase", version, indexes)?,
|
||||
subsidy: ValueFromHeightFull::forced_import(db, "subsidy", version, indexes)?,
|
||||
fees: ValueFromHeightFull::forced_import(db, "fees", version, indexes)?,
|
||||
unclaimed_rewards: ValueFromHeightSumCumulative::forced_import(
|
||||
unclaimed_rewards: ValueFromHeightCumulativeSum::forced_import(
|
||||
db,
|
||||
"unclaimed_rewards",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
fee_dominance: ComputedFromHeightLast::forced_import(
|
||||
fee_dominance: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"fee_dominance",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
fee_dominance_24h: ComputedFromHeightLast::forced_import(
|
||||
fee_dominance_24h: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"fee_dominance_24h",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
fee_dominance_7d: ComputedFromHeightLast::forced_import(
|
||||
fee_dominance_7d: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"fee_dominance_7d",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
fee_dominance_30d: ComputedFromHeightLast::forced_import(
|
||||
fee_dominance_30d: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"fee_dominance_30d",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
fee_dominance_1y: ComputedFromHeightLast::forced_import(
|
||||
fee_dominance_1y: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"fee_dominance_1y",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
subsidy_dominance: ComputedFromHeightLast::forced_import(
|
||||
subsidy_dominance: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"subsidy_dominance",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
subsidy_dominance_24h: ComputedFromHeightLast::forced_import(
|
||||
subsidy_dominance_24h: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"subsidy_dominance_24h",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
subsidy_dominance_7d: ComputedFromHeightLast::forced_import(
|
||||
subsidy_dominance_7d: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"subsidy_dominance_7d",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
subsidy_dominance_30d: ComputedFromHeightLast::forced_import(
|
||||
subsidy_dominance_30d: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"subsidy_dominance_30d",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
subsidy_dominance_1y: ComputedFromHeightLast::forced_import(
|
||||
subsidy_dominance_1y: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"subsidy_dominance_1y",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
subsidy_usd_1y_sma: FiatFromHeightLast::forced_import(
|
||||
subsidy_usd_1y_sma: FiatFromHeight::forced_import(
|
||||
db,
|
||||
"subsidy_usd_1y_sma",
|
||||
version,
|
||||
|
||||
@@ -3,8 +3,8 @@ use brk_types::{Cents, StoredF32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, FiatFromHeightLast, ValueFromHeightFull,
|
||||
ValueFromHeightSumCumulative,
|
||||
ComputedFromHeight, FiatFromHeight, ValueFromHeightFull,
|
||||
ValueFromHeightCumulativeSum,
|
||||
};
|
||||
|
||||
/// Coinbase/subsidy/rewards metrics
|
||||
@@ -13,16 +13,16 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub coinbase: ValueFromHeightFull<M>,
|
||||
pub subsidy: ValueFromHeightFull<M>,
|
||||
pub fees: ValueFromHeightFull<M>,
|
||||
pub unclaimed_rewards: ValueFromHeightSumCumulative<M>,
|
||||
pub fee_dominance: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub fee_dominance_24h: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub fee_dominance_7d: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub fee_dominance_30d: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub fee_dominance_1y: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub subsidy_dominance: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub subsidy_dominance_24h: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub subsidy_dominance_7d: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub subsidy_dominance_30d: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub subsidy_dominance_1y: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub subsidy_usd_1y_sma: FiatFromHeightLast<Cents, M>,
|
||||
pub unclaimed_rewards: ValueFromHeightCumulativeSum<M>,
|
||||
pub fee_dominance: ComputedFromHeight<StoredF32, M>,
|
||||
pub fee_dominance_24h: ComputedFromHeight<StoredF32, M>,
|
||||
pub fee_dominance_7d: ComputedFromHeight<StoredF32, M>,
|
||||
pub fee_dominance_30d: ComputedFromHeight<StoredF32, M>,
|
||||
pub fee_dominance_1y: ComputedFromHeight<StoredF32, M>,
|
||||
pub subsidy_dominance: ComputedFromHeight<StoredF32, M>,
|
||||
pub subsidy_dominance_24h: ComputedFromHeight<StoredF32, M>,
|
||||
pub subsidy_dominance_7d: ComputedFromHeight<StoredF32, M>,
|
||||
pub subsidy_dominance_30d: ComputedFromHeight<StoredF32, M>,
|
||||
pub subsidy_dominance_1y: ComputedFromHeight<StoredF32, M>,
|
||||
pub subsidy_usd_1y_sma: FiatFromHeight<Cents, M>,
|
||||
}
|
||||
|
||||
@@ -5,14 +5,28 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightFull, ComputedFromHeightLast},
|
||||
internal::{ComputedFromHeightAggregated, ComputedFromHeight},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
total_count: ComputedFromHeightFull::forced_import(db, "output_count", version, indexes)?,
|
||||
utxo_count: ComputedFromHeightLast::forced_import(db, "exact_utxo_count", version, indexes)?,
|
||||
total_count: ComputedFromHeightAggregated::forced_import(
|
||||
db,
|
||||
"output_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
utxo_count: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
"exact_utxo_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user