mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-23 17:08:10 -07:00
global: snapshot
This commit is contained in:
@@ -3,7 +3,7 @@ use brk_indexer::Indexer;
|
|||||||
use brk_types::{Height, StoredU32, Timestamp};
|
use brk_types::{Height, StoredU32, Timestamp};
|
||||||
use vecdb::{AnyVec, Cursor, EagerVec, Exit, PcoVec, ReadableVec, VecIndex};
|
use vecdb::{AnyVec, Cursor, EagerVec, Exit, PcoVec, ReadableVec, VecIndex};
|
||||||
|
|
||||||
use crate::ComputeIndexes;
|
use crate::{internal::WindowStarts, ComputeIndexes};
|
||||||
|
|
||||||
use super::{super::time, Vecs};
|
use super::{super::time, Vecs};
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ impl Vecs {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Compute rolling window block counts (both block_count's own rolling + separate block_count_sum)
|
// Compute rolling window block counts (both block_count's own rolling + separate block_count_sum)
|
||||||
let ws = crate::internal::WindowStarts {
|
let ws = WindowStarts {
|
||||||
_24h: &self.height_24h_ago,
|
_24h: &self.height_24h_ago,
|
||||||
_7d: &self.height_1w_ago,
|
_7d: &self.height_1w_ago,
|
||||||
_30d: &self.height_1m_ago,
|
_30d: &self.height_1m_ago,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use vecdb::{Exit, Ident, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ComputeIndexes, blocks,
|
ComputeIndexes, blocks,
|
||||||
internal::{ComputedFromHeight, LazyFromHeight, RatioCents64},
|
internal::{ComputedFromHeight, LazyFromHeight, RatioCents64, RollingWindows},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::distribution::metrics::ImportConfig;
|
use crate::distribution::metrics::ImportConfig;
|
||||||
@@ -18,21 +18,11 @@ pub struct RealizedAdjusted<M: StorageMode = Rw> {
|
|||||||
pub adjusted_value_destroyed: ComputedFromHeight<Cents, M>,
|
pub adjusted_value_destroyed: ComputedFromHeight<Cents, M>,
|
||||||
|
|
||||||
// === Adjusted Value Created/Destroyed Rolling Sums ===
|
// === Adjusted Value Created/Destroyed Rolling Sums ===
|
||||||
pub adjusted_value_created_24h: ComputedFromHeight<Cents, M>,
|
pub adjusted_value_created_sum: RollingWindows<Cents, M>,
|
||||||
pub adjusted_value_created_7d: ComputedFromHeight<Cents, M>,
|
pub adjusted_value_destroyed_sum: RollingWindows<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) ===
|
// === Adjusted SOPR (rolling window ratios) ===
|
||||||
pub adjusted_sopr: LazyFromHeight<StoredF64>,
|
pub adjusted_sopr: RollingWindows<StoredF64, M>,
|
||||||
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_24h_7d_ema: ComputedFromHeight<StoredF64, M>,
|
||||||
pub adjusted_sopr_7d_ema: LazyFromHeight<StoredF64>,
|
pub adjusted_sopr_7d_ema: LazyFromHeight<StoredF64>,
|
||||||
pub adjusted_sopr_24h_30d_ema: ComputedFromHeight<StoredF64, M>,
|
pub adjusted_sopr_24h_30d_ema: ComputedFromHeight<StoredF64, M>,
|
||||||
@@ -43,17 +33,6 @@ impl RealizedAdjusted {
|
|||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
let v1 = Version::ONE;
|
let v1 = Version::ONE;
|
||||||
|
|
||||||
macro_rules! import_rolling {
|
|
||||||
($name:expr) => {
|
|
||||||
ComputedFromHeight::forced_import(
|
|
||||||
cfg.db,
|
|
||||||
&cfg.name($name),
|
|
||||||
cfg.version + v1,
|
|
||||||
cfg.indexes,
|
|
||||||
)?
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let adjusted_value_created = ComputedFromHeight::forced_import(
|
let adjusted_value_created = ComputedFromHeight::forced_import(
|
||||||
cfg.db,
|
cfg.db,
|
||||||
&cfg.name("adjusted_value_created"),
|
&cfg.name("adjusted_value_created"),
|
||||||
@@ -67,54 +46,35 @@ impl RealizedAdjusted {
|
|||||||
cfg.indexes,
|
cfg.indexes,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let adjusted_value_created_24h = import_rolling!("adjusted_value_created_24h");
|
let adjusted_value_created_sum = RollingWindows::forced_import(
|
||||||
let adjusted_value_created_7d = import_rolling!("adjusted_value_created_7d");
|
cfg.db, &cfg.name("adjusted_value_created"), cfg.version + v1, cfg.indexes,
|
||||||
let adjusted_value_created_30d = import_rolling!("adjusted_value_created_30d");
|
)?;
|
||||||
let adjusted_value_created_1y = import_rolling!("adjusted_value_created_1y");
|
let adjusted_value_destroyed_sum = RollingWindows::forced_import(
|
||||||
let adjusted_value_destroyed_24h = import_rolling!("adjusted_value_destroyed_24h");
|
cfg.db, &cfg.name("adjusted_value_destroyed"), cfg.version + v1, cfg.indexes,
|
||||||
let adjusted_value_destroyed_7d = import_rolling!("adjusted_value_destroyed_7d");
|
)?;
|
||||||
let adjusted_value_destroyed_30d = import_rolling!("adjusted_value_destroyed_30d");
|
let adjusted_sopr = RollingWindows::forced_import(
|
||||||
let adjusted_value_destroyed_1y = import_rolling!("adjusted_value_destroyed_1y");
|
cfg.db, &cfg.name("adjusted_sopr"), cfg.version + v1, cfg.indexes,
|
||||||
|
)?;
|
||||||
|
|
||||||
let adjusted_sopr_24h = ComputedFromHeight::forced_import(
|
macro_rules! import_computed {
|
||||||
cfg.db,
|
($name:expr) => {
|
||||||
&cfg.name("adjusted_sopr_24h"),
|
ComputedFromHeight::forced_import(
|
||||||
cfg.version + v1,
|
cfg.db,
|
||||||
cfg.indexes,
|
&cfg.name($name),
|
||||||
)?;
|
cfg.version + v1,
|
||||||
let adjusted_sopr_7d = ComputedFromHeight::forced_import(
|
cfg.indexes,
|
||||||
cfg.db,
|
)?
|
||||||
&cfg.name("adjusted_sopr_7d"),
|
};
|
||||||
cfg.version + v1,
|
}
|
||||||
cfg.indexes,
|
|
||||||
)?;
|
|
||||||
let adjusted_sopr_30d = ComputedFromHeight::forced_import(
|
|
||||||
cfg.db,
|
|
||||||
&cfg.name("adjusted_sopr_30d"),
|
|
||||||
cfg.version + v1,
|
|
||||||
cfg.indexes,
|
|
||||||
)?;
|
|
||||||
let adjusted_sopr_1y = ComputedFromHeight::forced_import(
|
|
||||||
cfg.db,
|
|
||||||
&cfg.name("adjusted_sopr_1y"),
|
|
||||||
cfg.version + v1,
|
|
||||||
cfg.indexes,
|
|
||||||
)?;
|
|
||||||
let adjusted_sopr = LazyFromHeight::from_computed::<Ident>(
|
|
||||||
&cfg.name("adjusted_sopr"),
|
|
||||||
cfg.version + v1,
|
|
||||||
adjusted_sopr_24h.height.read_only_boxed_clone(),
|
|
||||||
&adjusted_sopr_24h,
|
|
||||||
);
|
|
||||||
|
|
||||||
let adjusted_sopr_24h_7d_ema = import_rolling!("adjusted_sopr_24h_7d_ema");
|
let adjusted_sopr_24h_7d_ema = import_computed!("adjusted_sopr_24h_7d_ema");
|
||||||
let adjusted_sopr_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
let adjusted_sopr_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||||
&cfg.name("adjusted_sopr_7d_ema"),
|
&cfg.name("adjusted_sopr_7d_ema"),
|
||||||
cfg.version + v1,
|
cfg.version + v1,
|
||||||
adjusted_sopr_24h_7d_ema.height.read_only_boxed_clone(),
|
adjusted_sopr_24h_7d_ema.height.read_only_boxed_clone(),
|
||||||
&adjusted_sopr_24h_7d_ema,
|
&adjusted_sopr_24h_7d_ema,
|
||||||
);
|
);
|
||||||
let adjusted_sopr_24h_30d_ema = import_rolling!("adjusted_sopr_24h_30d_ema");
|
let adjusted_sopr_24h_30d_ema = import_computed!("adjusted_sopr_24h_30d_ema");
|
||||||
let adjusted_sopr_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
let adjusted_sopr_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||||
&cfg.name("adjusted_sopr_30d_ema"),
|
&cfg.name("adjusted_sopr_30d_ema"),
|
||||||
cfg.version + v1,
|
cfg.version + v1,
|
||||||
@@ -125,19 +85,9 @@ impl RealizedAdjusted {
|
|||||||
Ok(RealizedAdjusted {
|
Ok(RealizedAdjusted {
|
||||||
adjusted_value_created,
|
adjusted_value_created,
|
||||||
adjusted_value_destroyed,
|
adjusted_value_destroyed,
|
||||||
adjusted_value_created_24h,
|
adjusted_value_created_sum,
|
||||||
adjusted_value_created_7d,
|
adjusted_value_destroyed_sum,
|
||||||
adjusted_value_created_30d,
|
|
||||||
adjusted_value_created_1y,
|
|
||||||
adjusted_value_destroyed_24h,
|
|
||||||
adjusted_value_destroyed_7d,
|
|
||||||
adjusted_value_destroyed_30d,
|
|
||||||
adjusted_value_destroyed_1y,
|
|
||||||
adjusted_sopr,
|
adjusted_sopr,
|
||||||
adjusted_sopr_24h,
|
|
||||||
adjusted_sopr_7d,
|
|
||||||
adjusted_sopr_30d,
|
|
||||||
adjusted_sopr_1y,
|
|
||||||
adjusted_sopr_24h_7d_ema,
|
adjusted_sopr_24h_7d_ema,
|
||||||
adjusted_sopr_7d_ema,
|
adjusted_sopr_7d_ema,
|
||||||
adjusted_sopr_24h_30d_ema,
|
adjusted_sopr_24h_30d_ema,
|
||||||
@@ -171,101 +121,31 @@ impl RealizedAdjusted {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Adjusted value created/destroyed rolling sums
|
// Adjusted value created/destroyed rolling sums
|
||||||
self.adjusted_value_created_24h.height.compute_rolling_sum(
|
let window_starts = blocks.count.window_starts();
|
||||||
starting_indexes.height,
|
self.adjusted_value_created_sum.compute_rolling_sum(
|
||||||
&blocks.count.height_24h_ago,
|
starting_indexes.height, &window_starts, &self.adjusted_value_created.height, exit,
|
||||||
&self.adjusted_value_created.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
)?;
|
||||||
self.adjusted_value_created_7d.height.compute_rolling_sum(
|
self.adjusted_value_destroyed_sum.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_indexes.height, &window_starts, &self.adjusted_value_destroyed.height, exit,
|
||||||
&blocks.count.height_1w_ago,
|
|
||||||
&self.adjusted_value_created.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
)?;
|
||||||
self.adjusted_value_created_30d.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1m_ago,
|
|
||||||
&self.adjusted_value_created.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.adjusted_value_created_1y.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1y_ago,
|
|
||||||
&self.adjusted_value_created.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.adjusted_value_destroyed_24h
|
|
||||||
.height
|
|
||||||
.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_24h_ago,
|
|
||||||
&self.adjusted_value_destroyed.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.adjusted_value_destroyed_7d
|
|
||||||
.height
|
|
||||||
.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1w_ago,
|
|
||||||
&self.adjusted_value_destroyed.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.adjusted_value_destroyed_30d
|
|
||||||
.height
|
|
||||||
.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1m_ago,
|
|
||||||
&self.adjusted_value_destroyed.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.adjusted_value_destroyed_1y
|
|
||||||
.height
|
|
||||||
.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1y_ago,
|
|
||||||
&self.adjusted_value_destroyed.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// SOPR ratios from rolling sums
|
// SOPR ratios from rolling sums
|
||||||
self.adjusted_sopr_24h
|
for ((sopr, vc), vd) in self.adjusted_sopr.as_mut_array().into_iter()
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
.zip(self.adjusted_value_created_sum.as_array())
|
||||||
starting_indexes.height,
|
.zip(self.adjusted_value_destroyed_sum.as_array())
|
||||||
&self.adjusted_value_created_24h.height,
|
{
|
||||||
&self.adjusted_value_destroyed_24h.height,
|
sopr.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
exit,
|
starting_indexes.height, &vc.height, &vd.height, exit,
|
||||||
)?;
|
|
||||||
self.adjusted_sopr_7d
|
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.adjusted_value_created_7d.height,
|
|
||||||
&self.adjusted_value_destroyed_7d.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.adjusted_sopr_30d
|
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.adjusted_value_created_30d.height,
|
|
||||||
&self.adjusted_value_destroyed_30d.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.adjusted_sopr_1y
|
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.adjusted_value_created_1y.height,
|
|
||||||
&self.adjusted_value_destroyed_1y.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
// Adjusted SOPR EMAs
|
// Adjusted SOPR EMAs (based on 24h window)
|
||||||
self.adjusted_sopr_24h_7d_ema
|
self.adjusted_sopr_24h_7d_ema
|
||||||
.height
|
.height
|
||||||
.compute_rolling_ema(
|
.compute_rolling_ema(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.count.height_1w_ago,
|
&blocks.count.height_1w_ago,
|
||||||
&self.adjusted_sopr.height,
|
&self.adjusted_sopr._24h.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.adjusted_sopr_24h_30d_ema
|
self.adjusted_sopr_24h_30d_ema
|
||||||
@@ -273,7 +153,7 @@ impl RealizedAdjusted {
|
|||||||
.compute_rolling_ema(
|
.compute_rolling_ema(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.count.height_1m_ago,
|
&blocks.count.height_1m_ago,
|
||||||
&self.adjusted_sopr.height,
|
&self.adjusted_sopr._24h.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use crate::{
|
|||||||
CentsPlus, CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeight,
|
CentsPlus, CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeight,
|
||||||
ComputedFromHeightRatio, NegCentsUnsignedToDollars, ValueFromHeightCumulative, LazyFromHeight,
|
ComputedFromHeightRatio, NegCentsUnsignedToDollars, ValueFromHeightCumulative, LazyFromHeight,
|
||||||
PercentageCentsF32, PercentageCentsSignedCentsF32, PercentageCentsSignedDollarsF32, Price, RatioCents64,
|
PercentageCentsF32, PercentageCentsSignedCentsF32, PercentageCentsSignedDollarsF32, Price, RatioCents64,
|
||||||
Identity, ValueFromHeight,
|
RollingWindows, Identity, ValueFromHeight,
|
||||||
},
|
},
|
||||||
prices,
|
prices,
|
||||||
};
|
};
|
||||||
@@ -80,38 +80,19 @@ pub struct RealizedBase<M: StorageMode = Rw> {
|
|||||||
pub profit_flow: LazyFromHeight<Dollars, Cents>,
|
pub profit_flow: LazyFromHeight<Dollars, Cents>,
|
||||||
|
|
||||||
// === Value Created/Destroyed Rolling Sums ===
|
// === Value Created/Destroyed Rolling Sums ===
|
||||||
pub value_created_24h: ComputedFromHeight<Cents, M>,
|
pub value_created_sum: RollingWindows<Cents, M>,
|
||||||
pub value_created_7d: ComputedFromHeight<Cents, M>,
|
pub value_destroyed_sum: RollingWindows<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) ===
|
// === SOPR (rolling window ratios) ===
|
||||||
pub sopr: LazyFromHeight<StoredF64>,
|
pub sopr: RollingWindows<StoredF64, M>,
|
||||||
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_24h_7d_ema: ComputedFromHeight<StoredF64, M>,
|
||||||
pub sopr_7d_ema: LazyFromHeight<StoredF64>,
|
pub sopr_7d_ema: LazyFromHeight<StoredF64>,
|
||||||
pub sopr_24h_30d_ema: ComputedFromHeight<StoredF64, M>,
|
pub sopr_24h_30d_ema: ComputedFromHeight<StoredF64, M>,
|
||||||
pub sopr_30d_ema: LazyFromHeight<StoredF64>,
|
pub sopr_30d_ema: LazyFromHeight<StoredF64>,
|
||||||
|
|
||||||
// === Sell Side Risk Rolling Sum Intermediates ===
|
// === Sell Side Risk ===
|
||||||
pub realized_value_24h: ComputedFromHeight<Cents, M>,
|
pub realized_value_sum: RollingWindows<Cents, M>,
|
||||||
pub realized_value_7d: ComputedFromHeight<Cents, M>,
|
pub sell_side_risk_ratio: RollingWindows<StoredF32, 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: 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_24h_7d_ema: ComputedFromHeight<StoredF32, M>,
|
||||||
pub sell_side_risk_ratio_7d_ema: LazyFromHeight<StoredF32>,
|
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_24h_30d_ema: ComputedFromHeight<StoredF32, M>,
|
||||||
@@ -351,8 +332,25 @@ impl RealizedBase {
|
|||||||
&realized_price_extra.ratio,
|
&realized_price_extra.ratio,
|
||||||
);
|
);
|
||||||
|
|
||||||
// === Rolling sum intermediates ===
|
// === Rolling windows ===
|
||||||
macro_rules! import_rolling {
|
let value_created_sum = RollingWindows::forced_import(
|
||||||
|
cfg.db, &cfg.name("value_created"), cfg.version + v1, cfg.indexes,
|
||||||
|
)?;
|
||||||
|
let value_destroyed_sum = RollingWindows::forced_import(
|
||||||
|
cfg.db, &cfg.name("value_destroyed"), cfg.version + v1, cfg.indexes,
|
||||||
|
)?;
|
||||||
|
let realized_value_sum = RollingWindows::forced_import(
|
||||||
|
cfg.db, &cfg.name("realized_value"), cfg.version + v1, cfg.indexes,
|
||||||
|
)?;
|
||||||
|
let sopr = RollingWindows::forced_import(
|
||||||
|
cfg.db, &cfg.name("sopr"), cfg.version + v1, cfg.indexes,
|
||||||
|
)?;
|
||||||
|
let sell_side_risk_ratio = RollingWindows::forced_import(
|
||||||
|
cfg.db, &cfg.name("sell_side_risk_ratio"), cfg.version + v1, cfg.indexes,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// === EMA imports + identity aliases ===
|
||||||
|
macro_rules! import_computed {
|
||||||
($name:expr) => {
|
($name:expr) => {
|
||||||
ComputedFromHeight::forced_import(
|
ComputedFromHeight::forced_import(
|
||||||
cfg.db,
|
cfg.db,
|
||||||
@@ -363,52 +361,14 @@ impl RealizedBase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let value_created_24h = import_rolling!("value_created_24h");
|
let sopr_24h_7d_ema = import_computed!("sopr_24h_7d_ema");
|
||||||
let value_created_7d = import_rolling!("value_created_7d");
|
|
||||||
let value_created_30d = import_rolling!("value_created_30d");
|
|
||||||
let value_created_1y = import_rolling!("value_created_1y");
|
|
||||||
let value_destroyed_24h = import_rolling!("value_destroyed_24h");
|
|
||||||
let value_destroyed_7d = import_rolling!("value_destroyed_7d");
|
|
||||||
let value_destroyed_30d = import_rolling!("value_destroyed_30d");
|
|
||||||
let value_destroyed_1y = import_rolling!("value_destroyed_1y");
|
|
||||||
|
|
||||||
let realized_value_24h = import_rolling!("realized_value_24h");
|
|
||||||
let realized_value_7d = import_rolling!("realized_value_7d");
|
|
||||||
let realized_value_30d = import_rolling!("realized_value_30d");
|
|
||||||
let realized_value_1y = import_rolling!("realized_value_1y");
|
|
||||||
|
|
||||||
// === Rolling window stored ratios ===
|
|
||||||
let sopr_24h = import_rolling!("sopr_24h");
|
|
||||||
let sopr_7d = import_rolling!("sopr_7d");
|
|
||||||
let sopr_30d = import_rolling!("sopr_30d");
|
|
||||||
let sopr_1y = import_rolling!("sopr_1y");
|
|
||||||
let sopr = LazyFromHeight::from_computed::<Ident>(
|
|
||||||
&cfg.name("sopr"),
|
|
||||||
cfg.version + v1,
|
|
||||||
sopr_24h.height.read_only_boxed_clone(),
|
|
||||||
&sopr_24h,
|
|
||||||
);
|
|
||||||
|
|
||||||
let sell_side_risk_ratio_24h = import_rolling!("sell_side_risk_ratio_24h");
|
|
||||||
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 = LazyFromHeight::from_computed::<Ident>(
|
|
||||||
&cfg.name("sell_side_risk_ratio"),
|
|
||||||
cfg.version + v1,
|
|
||||||
sell_side_risk_ratio_24h.height.read_only_boxed_clone(),
|
|
||||||
&sell_side_risk_ratio_24h,
|
|
||||||
);
|
|
||||||
|
|
||||||
// === EMA imports + identity aliases ===
|
|
||||||
let sopr_24h_7d_ema = import_rolling!("sopr_24h_7d_ema");
|
|
||||||
let sopr_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
let sopr_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||||
&cfg.name("sopr_7d_ema"),
|
&cfg.name("sopr_7d_ema"),
|
||||||
cfg.version + v1,
|
cfg.version + v1,
|
||||||
sopr_24h_7d_ema.height.read_only_boxed_clone(),
|
sopr_24h_7d_ema.height.read_only_boxed_clone(),
|
||||||
&sopr_24h_7d_ema,
|
&sopr_24h_7d_ema,
|
||||||
);
|
);
|
||||||
let sopr_24h_30d_ema = import_rolling!("sopr_24h_30d_ema");
|
let sopr_24h_30d_ema = import_computed!("sopr_24h_30d_ema");
|
||||||
let sopr_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
let sopr_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||||
&cfg.name("sopr_30d_ema"),
|
&cfg.name("sopr_30d_ema"),
|
||||||
cfg.version + v1,
|
cfg.version + v1,
|
||||||
@@ -416,7 +376,7 @@ impl RealizedBase {
|
|||||||
&sopr_24h_30d_ema,
|
&sopr_24h_30d_ema,
|
||||||
);
|
);
|
||||||
|
|
||||||
let sell_side_risk_ratio_24h_7d_ema = import_rolling!("sell_side_risk_ratio_24h_7d_ema");
|
let sell_side_risk_ratio_24h_7d_ema = import_computed!("sell_side_risk_ratio_24h_7d_ema");
|
||||||
let sell_side_risk_ratio_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
let sell_side_risk_ratio_7d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||||
&cfg.name("sell_side_risk_ratio_7d_ema"),
|
&cfg.name("sell_side_risk_ratio_7d_ema"),
|
||||||
cfg.version + v1,
|
cfg.version + v1,
|
||||||
@@ -425,7 +385,7 @@ impl RealizedBase {
|
|||||||
.read_only_boxed_clone(),
|
.read_only_boxed_clone(),
|
||||||
&sell_side_risk_ratio_24h_7d_ema,
|
&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_24h_30d_ema = import_computed!("sell_side_risk_ratio_24h_30d_ema");
|
||||||
let sell_side_risk_ratio_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
let sell_side_risk_ratio_30d_ema = LazyFromHeight::from_computed::<Ident>(
|
||||||
&cfg.name("sell_side_risk_ratio_30d_ema"),
|
&cfg.name("sell_side_risk_ratio_30d_ema"),
|
||||||
cfg.version + v1,
|
cfg.version + v1,
|
||||||
@@ -480,32 +440,15 @@ impl RealizedBase {
|
|||||||
value_destroyed,
|
value_destroyed,
|
||||||
capitulation_flow,
|
capitulation_flow,
|
||||||
profit_flow,
|
profit_flow,
|
||||||
value_created_24h,
|
value_created_sum,
|
||||||
value_created_7d,
|
value_destroyed_sum,
|
||||||
value_created_30d,
|
|
||||||
value_created_1y,
|
|
||||||
value_destroyed_24h,
|
|
||||||
value_destroyed_7d,
|
|
||||||
value_destroyed_30d,
|
|
||||||
value_destroyed_1y,
|
|
||||||
sopr,
|
sopr,
|
||||||
sopr_24h,
|
|
||||||
sopr_7d,
|
|
||||||
sopr_30d,
|
|
||||||
sopr_1y,
|
|
||||||
sopr_24h_7d_ema,
|
sopr_24h_7d_ema,
|
||||||
sopr_7d_ema,
|
sopr_7d_ema,
|
||||||
sopr_24h_30d_ema,
|
sopr_24h_30d_ema,
|
||||||
sopr_30d_ema,
|
sopr_30d_ema,
|
||||||
realized_value_24h,
|
realized_value_sum,
|
||||||
realized_value_7d,
|
|
||||||
realized_value_30d,
|
|
||||||
realized_value_1y,
|
|
||||||
sell_side_risk_ratio,
|
sell_side_risk_ratio,
|
||||||
sell_side_risk_ratio_24h,
|
|
||||||
sell_side_risk_ratio_7d,
|
|
||||||
sell_side_risk_ratio_30d,
|
|
||||||
sell_side_risk_ratio_1y,
|
|
||||||
sell_side_risk_ratio_24h_7d_ema,
|
sell_side_risk_ratio_24h_7d_ema,
|
||||||
sell_side_risk_ratio_7d_ema,
|
sell_side_risk_ratio_7d_ema,
|
||||||
sell_side_risk_ratio_24h_30d_ema,
|
sell_side_risk_ratio_24h_30d_ema,
|
||||||
@@ -927,135 +870,35 @@ impl RealizedBase {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// === Rolling sum intermediates ===
|
// === Rolling sum intermediates ===
|
||||||
macro_rules! rolling_sum {
|
let window_starts = blocks.count.window_starts();
|
||||||
($target:expr, $window:expr, $source:expr) => {
|
self.value_created_sum.compute_rolling_sum(
|
||||||
$target.height.compute_rolling_sum(
|
starting_indexes.height, &window_starts, &self.value_created.height, exit,
|
||||||
starting_indexes.height,
|
)?;
|
||||||
$window,
|
self.value_destroyed_sum.compute_rolling_sum(
|
||||||
$source,
|
starting_indexes.height, &window_starts, &self.value_destroyed.height, exit,
|
||||||
exit,
|
)?;
|
||||||
)?
|
self.realized_value_sum.compute_rolling_sum(
|
||||||
};
|
starting_indexes.height, &window_starts, &self.realized_value.height, exit,
|
||||||
}
|
)?;
|
||||||
|
|
||||||
rolling_sum!(
|
|
||||||
self.value_created_24h,
|
|
||||||
&blocks.count.height_24h_ago,
|
|
||||||
&self.value_created.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.value_created_7d,
|
|
||||||
&blocks.count.height_1w_ago,
|
|
||||||
&self.value_created.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.value_created_30d,
|
|
||||||
&blocks.count.height_1m_ago,
|
|
||||||
&self.value_created.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.value_created_1y,
|
|
||||||
&blocks.count.height_1y_ago,
|
|
||||||
&self.value_created.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.value_destroyed_24h,
|
|
||||||
&blocks.count.height_24h_ago,
|
|
||||||
&self.value_destroyed.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.value_destroyed_7d,
|
|
||||||
&blocks.count.height_1w_ago,
|
|
||||||
&self.value_destroyed.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.value_destroyed_30d,
|
|
||||||
&blocks.count.height_1m_ago,
|
|
||||||
&self.value_destroyed.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.value_destroyed_1y,
|
|
||||||
&blocks.count.height_1y_ago,
|
|
||||||
&self.value_destroyed.height
|
|
||||||
);
|
|
||||||
|
|
||||||
// Realized value rolling sums
|
|
||||||
rolling_sum!(
|
|
||||||
self.realized_value_24h,
|
|
||||||
&blocks.count.height_24h_ago,
|
|
||||||
&self.realized_value.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.realized_value_7d,
|
|
||||||
&blocks.count.height_1w_ago,
|
|
||||||
&self.realized_value.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.realized_value_30d,
|
|
||||||
&blocks.count.height_1m_ago,
|
|
||||||
&self.realized_value.height
|
|
||||||
);
|
|
||||||
rolling_sum!(
|
|
||||||
self.realized_value_1y,
|
|
||||||
&blocks.count.height_1y_ago,
|
|
||||||
&self.realized_value.height
|
|
||||||
);
|
|
||||||
|
|
||||||
// Compute SOPR from rolling sums
|
// Compute SOPR from rolling sums
|
||||||
self.sopr_24h.compute_binary::<Cents, Cents, RatioCents64>(
|
for ((sopr, vc), vd) in self.sopr.as_mut_array().into_iter()
|
||||||
starting_indexes.height,
|
.zip(self.value_created_sum.as_array())
|
||||||
&self.value_created_24h.height,
|
.zip(self.value_destroyed_sum.as_array())
|
||||||
&self.value_destroyed_24h.height,
|
{
|
||||||
exit,
|
sopr.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
)?;
|
starting_indexes.height, &vc.height, &vd.height, exit,
|
||||||
self.sopr_7d.compute_binary::<Cents, Cents, RatioCents64>(
|
)?;
|
||||||
starting_indexes.height,
|
}
|
||||||
&self.value_created_7d.height,
|
|
||||||
&self.value_destroyed_7d.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.sopr_30d.compute_binary::<Cents, Cents, RatioCents64>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.value_created_30d.height,
|
|
||||||
&self.value_destroyed_30d.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.sopr_1y.compute_binary::<Cents, Cents, RatioCents64>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.value_created_1y.height,
|
|
||||||
&self.value_destroyed_1y.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Compute sell-side risk ratios
|
// Compute sell-side risk ratios
|
||||||
self.sell_side_risk_ratio_24h
|
for (ssrr, rv) in self.sell_side_risk_ratio.as_mut_array().into_iter()
|
||||||
.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
.zip(self.realized_value_sum.as_array())
|
||||||
starting_indexes.height,
|
{
|
||||||
&self.realized_value_24h.height,
|
ssrr.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
||||||
&self.realized_cap_cents.height,
|
starting_indexes.height, &rv.height, &self.realized_cap_cents.height, exit,
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.sell_side_risk_ratio_7d
|
|
||||||
.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.realized_value_7d.height,
|
|
||||||
&self.realized_cap_cents.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.sell_side_risk_ratio_30d
|
|
||||||
.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.realized_value_30d.height,
|
|
||||||
&self.realized_cap_cents.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.sell_side_risk_ratio_1y
|
|
||||||
.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.realized_value_1y.height,
|
|
||||||
&self.realized_cap_cents.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
// 7d EMAs
|
// 7d EMAs
|
||||||
self.realized_profit_7d_ema.height.compute_rolling_ema(
|
self.realized_profit_7d_ema.height.compute_rolling_ema(
|
||||||
@@ -1095,27 +938,27 @@ impl RealizedBase {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// SOPR EMAs
|
// SOPR EMAs (based on 24h window)
|
||||||
self.sopr_24h_7d_ema.height.compute_rolling_ema(
|
self.sopr_24h_7d_ema.height.compute_rolling_ema(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.count.height_1w_ago,
|
&blocks.count.height_1w_ago,
|
||||||
&self.sopr.height,
|
&self.sopr._24h.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.sopr_24h_30d_ema.height.compute_rolling_ema(
|
self.sopr_24h_30d_ema.height.compute_rolling_ema(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.count.height_1m_ago,
|
&blocks.count.height_1m_ago,
|
||||||
&self.sopr.height,
|
&self.sopr._24h.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Sell side risk EMAs
|
// Sell side risk EMAs (based on 24h window)
|
||||||
self.sell_side_risk_ratio_24h_7d_ema
|
self.sell_side_risk_ratio_24h_7d_ema
|
||||||
.height
|
.height
|
||||||
.compute_rolling_ema(
|
.compute_rolling_ema(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.count.height_1w_ago,
|
&blocks.count.height_1w_ago,
|
||||||
&self.sell_side_risk_ratio.height,
|
&self.sell_side_risk_ratio._24h.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.sell_side_risk_ratio_24h_30d_ema
|
self.sell_side_risk_ratio_24h_30d_ema
|
||||||
@@ -1123,7 +966,7 @@ impl RealizedBase {
|
|||||||
.compute_rolling_ema(
|
.compute_rolling_ema(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.count.height_1m_ago,
|
&blocks.count.height_1m_ago,
|
||||||
&self.sell_side_risk_ratio.height,
|
&self.sell_side_risk_ratio._24h.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ComputeIndexes, blocks,
|
ComputeIndexes, blocks,
|
||||||
internal::{ComputedFromHeight, ComputedFromHeightRatioExtension, RatioCents64},
|
internal::{ComputedFromHeight, ComputedFromHeightRatioExtension, RatioCents64, RollingWindows},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::distribution::metrics::ImportConfig;
|
use crate::distribution::metrics::ImportConfig;
|
||||||
@@ -18,20 +18,11 @@ pub struct RealizedExtended<M: StorageMode = Rw> {
|
|||||||
pub realized_cap_rel_to_own_market_cap: ComputedFromHeight<StoredF32, M>,
|
pub realized_cap_rel_to_own_market_cap: ComputedFromHeight<StoredF32, M>,
|
||||||
|
|
||||||
// === Realized Profit/Loss Rolling Sums ===
|
// === Realized Profit/Loss Rolling Sums ===
|
||||||
pub realized_profit_24h: ComputedFromHeight<Cents, M>,
|
pub realized_profit_sum: RollingWindows<Cents, M>,
|
||||||
pub realized_profit_7d: ComputedFromHeight<Cents, M>,
|
pub realized_loss_sum: RollingWindows<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) ===
|
// === Realized Profit to Loss Ratio (from rolling sums) ===
|
||||||
pub realized_profit_to_loss_ratio_24h: ComputedFromHeight<StoredF64, M>,
|
pub realized_profit_to_loss_ratio: RollingWindows<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 ===
|
// === Extended ratio metrics for realized/investor price ===
|
||||||
pub realized_price_ratio_ext: ComputedFromHeightRatioExtension<M>,
|
pub realized_price_ratio_ext: ComputedFromHeightRatioExtension<M>,
|
||||||
@@ -42,17 +33,6 @@ impl RealizedExtended {
|
|||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
let v1 = Version::ONE;
|
let v1 = Version::ONE;
|
||||||
|
|
||||||
macro_rules! import_rolling {
|
|
||||||
($name:expr) => {
|
|
||||||
ComputedFromHeight::forced_import(
|
|
||||||
cfg.db,
|
|
||||||
&cfg.name($name),
|
|
||||||
cfg.version + v1,
|
|
||||||
cfg.indexes,
|
|
||||||
)?
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(RealizedExtended {
|
Ok(RealizedExtended {
|
||||||
realized_cap_rel_to_own_market_cap: ComputedFromHeight::forced_import(
|
realized_cap_rel_to_own_market_cap: ComputedFromHeight::forced_import(
|
||||||
cfg.db,
|
cfg.db,
|
||||||
@@ -60,18 +40,15 @@ impl RealizedExtended {
|
|||||||
cfg.version,
|
cfg.version,
|
||||||
cfg.indexes,
|
cfg.indexes,
|
||||||
)?,
|
)?,
|
||||||
realized_profit_24h: import_rolling!("realized_profit_24h"),
|
realized_profit_sum: RollingWindows::forced_import(
|
||||||
realized_profit_7d: import_rolling!("realized_profit_7d"),
|
cfg.db, &cfg.name("realized_profit"), cfg.version + v1, cfg.indexes,
|
||||||
realized_profit_30d: import_rolling!("realized_profit_30d"),
|
)?,
|
||||||
realized_profit_1y: import_rolling!("realized_profit_1y"),
|
realized_loss_sum: RollingWindows::forced_import(
|
||||||
realized_loss_24h: import_rolling!("realized_loss_24h"),
|
cfg.db, &cfg.name("realized_loss"), cfg.version + v1, cfg.indexes,
|
||||||
realized_loss_7d: import_rolling!("realized_loss_7d"),
|
)?,
|
||||||
realized_loss_30d: import_rolling!("realized_loss_30d"),
|
realized_profit_to_loss_ratio: RollingWindows::forced_import(
|
||||||
realized_loss_1y: import_rolling!("realized_loss_1y"),
|
cfg.db, &cfg.name("realized_profit_to_loss_ratio"), cfg.version + v1, cfg.indexes,
|
||||||
realized_profit_to_loss_ratio_24h: import_rolling!("realized_profit_to_loss_ratio_24h"),
|
)?,
|
||||||
realized_profit_to_loss_ratio_7d: import_rolling!("realized_profit_to_loss_ratio_7d"),
|
|
||||||
realized_profit_to_loss_ratio_30d: import_rolling!("realized_profit_to_loss_ratio_30d"),
|
|
||||||
realized_profit_to_loss_ratio_1y: import_rolling!("realized_profit_to_loss_ratio_1y"),
|
|
||||||
realized_price_ratio_ext: ComputedFromHeightRatioExtension::forced_import(
|
realized_price_ratio_ext: ComputedFromHeightRatioExtension::forced_import(
|
||||||
cfg.db,
|
cfg.db,
|
||||||
&cfg.name("realized_price"),
|
&cfg.name("realized_price"),
|
||||||
@@ -97,53 +74,12 @@ impl RealizedExtended {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Realized profit/loss rolling sums
|
// Realized profit/loss rolling sums
|
||||||
self.realized_profit_24h.height.compute_rolling_sum(
|
let window_starts = blocks.count.window_starts();
|
||||||
starting_indexes.height,
|
self.realized_profit_sum.compute_rolling_sum(
|
||||||
&blocks.count.height_24h_ago,
|
starting_indexes.height, &window_starts, &base.realized_profit.height, exit,
|
||||||
&base.realized_profit.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
)?;
|
||||||
self.realized_profit_7d.height.compute_rolling_sum(
|
self.realized_loss_sum.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_indexes.height, &window_starts, &base.realized_loss.height, exit,
|
||||||
&blocks.count.height_1w_ago,
|
|
||||||
&base.realized_profit.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.realized_profit_30d.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1m_ago,
|
|
||||||
&base.realized_profit.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.realized_profit_1y.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1y_ago,
|
|
||||||
&base.realized_profit.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.realized_loss_24h.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_24h_ago,
|
|
||||||
&base.realized_loss.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.realized_loss_7d.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1w_ago,
|
|
||||||
&base.realized_loss.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.realized_loss_30d.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1m_ago,
|
|
||||||
&base.realized_loss.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.realized_loss_1y.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1y_ago,
|
|
||||||
&base.realized_loss.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Realized cap relative to own market cap
|
// Realized cap relative to own market cap
|
||||||
@@ -157,34 +93,14 @@ impl RealizedExtended {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Realized profit to loss ratios
|
// Realized profit to loss ratios
|
||||||
self.realized_profit_to_loss_ratio_24h
|
for ((ratio, profit), loss) in self.realized_profit_to_loss_ratio.as_mut_array().into_iter()
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
.zip(self.realized_profit_sum.as_array())
|
||||||
starting_indexes.height,
|
.zip(self.realized_loss_sum.as_array())
|
||||||
&self.realized_profit_24h.height,
|
{
|
||||||
&self.realized_loss_24h.height,
|
ratio.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
exit,
|
starting_indexes.height, &profit.height, &loss.height, exit,
|
||||||
)?;
|
|
||||||
self.realized_profit_to_loss_ratio_7d
|
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.realized_profit_7d.height,
|
|
||||||
&self.realized_loss_7d.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.realized_profit_to_loss_ratio_30d
|
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.realized_profit_30d.height,
|
|
||||||
&self.realized_loss_30d.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.realized_profit_to_loss_ratio_1y
|
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.realized_profit_1y.height,
|
|
||||||
&self.realized_loss_1y.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
// Extended ratio metrics
|
// Extended ratio metrics
|
||||||
self.realized_price_ratio_ext.compute_rest(
|
self.realized_price_ratio_ext.compute_rest(
|
||||||
|
|||||||
@@ -92,12 +92,9 @@ impl RollingFullByUnit {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let v = version + VERSION;
|
let v = version + VERSION;
|
||||||
Ok(Self(Windows {
|
Ok(Self(Windows::try_from_fn(|suffix| {
|
||||||
_24h: RollingFullSlot::forced_import(db, &format!("{name}_24h"), v, indexes)?,
|
RollingFullSlot::forced_import(db, &format!("{name}_{suffix}"), v, indexes)
|
||||||
_7d: RollingFullSlot::forced_import(db, &format!("{name}_7d"), v, indexes)?,
|
})?))
|
||||||
_30d: RollingFullSlot::forced_import(db, &format!("{name}_30d"), v, indexes)?,
|
|
||||||
_1y: RollingFullSlot::forced_import(db, &format!("{name}_1y"), v, indexes)?,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
@@ -109,7 +106,7 @@ impl RollingFullByUnit {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (slot, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
|
for (slot, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
|
||||||
slot.compute(max_from, starts, sats_source, cents_source, exit)?;
|
slot.compute(max_from, *starts, sats_source, cents_source, exit)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ impl RollingSumByUnit {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
|
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
|
||||||
w.sats.height.compute_rolling_sum(max_from, starts, sats_source, exit)?;
|
w.sats.height.compute_rolling_sum(max_from, *starts, sats_source, exit)?;
|
||||||
w.cents.height.compute_rolling_sum(max_from, starts, cents_source, exit)?;
|
w.cents.height.compute_rolling_sum(max_from, *starts, cents_source, exit)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,8 @@ impl Windows<ByUnit> {
|
|||||||
version: Version,
|
version: Version,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Windows::try_from_fn(|suffix| {
|
||||||
_24h: ByUnit::forced_import(db, &format!("{name}_24h"), version, indexes)?,
|
ByUnit::forced_import(db, &format!("{name}_{suffix}"), version, indexes)
|
||||||
_7d: ByUnit::forced_import(db, &format!("{name}_7d"), version, indexes)?,
|
|
||||||
_30d: ByUnit::forced_import(db, &format!("{name}_30d"), version, indexes)?,
|
|
||||||
_1y: ByUnit::forced_import(db, &format!("{name}_1y"), version, indexes)?,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,32 +36,9 @@ impl ValueFromHeightWindows {
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let v = version + VERSION;
|
let v = version + VERSION;
|
||||||
Ok(Self(Windows {
|
Ok(Self(Windows::try_from_fn(|suffix| {
|
||||||
_24h: ValueFromHeight::forced_import(
|
ValueFromHeight::forced_import(db, &format!("{name}_{suffix}"), v, indexes)
|
||||||
db,
|
})?))
|
||||||
&format!("{name}_24h"),
|
|
||||||
v,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
_7d: ValueFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
&format!("{name}_7d"),
|
|
||||||
v,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
_30d: ValueFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
&format!("{name}_30d"),
|
|
||||||
v,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
_1y: ValueFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
&format!("{name}_1y"),
|
|
||||||
v,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rolling_sum(
|
pub(crate) fn compute_rolling_sum(
|
||||||
@@ -73,7 +50,7 @@ impl ValueFromHeightWindows {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
|
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
|
||||||
w.compute_rolling_sum(max_from, starts, sats_source, cents_source, exit)?;
|
w.compute_rolling_sum(max_from, *starts, sats_source, cents_source, exit)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,19 +18,8 @@ use crate::{
|
|||||||
internal::{ComputedFromHeight, ComputedVecValue, NumericValue, Windows},
|
internal::{ComputedFromHeight, ComputedVecValue, NumericValue, Windows},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Rolling window start heights — references to the 4 height-ago vecs.
|
/// Rolling window start heights — the 4 height-ago vecs (24h, 7d, 30d, 1y).
|
||||||
pub struct WindowStarts<'a> {
|
pub type WindowStarts<'a> = Windows<&'a EagerVec<PcoVec<Height, Height>>>;
|
||||||
pub _24h: &'a EagerVec<PcoVec<Height, Height>>,
|
|
||||||
pub _7d: &'a EagerVec<PcoVec<Height, Height>>,
|
|
||||||
pub _30d: &'a EagerVec<PcoVec<Height, Height>>,
|
|
||||||
pub _1y: &'a EagerVec<PcoVec<Height, Height>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> WindowStarts<'a> {
|
|
||||||
pub fn as_array(&self) -> [&'a EagerVec<PcoVec<Height, Height>>; 4] {
|
|
||||||
[self._24h, self._7d, self._30d, self._1y]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 4 rolling window vecs (24h, 7d, 30d, 1y), each with height data + all 17 index views.
|
/// 4 rolling window vecs (24h, 7d, 30d, 1y), each with height data + all 17 index views.
|
||||||
#[derive(Deref, DerefMut, Traversable)]
|
#[derive(Deref, DerefMut, Traversable)]
|
||||||
@@ -52,12 +41,9 @@ where
|
|||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let v = version + VERSION;
|
let v = version + VERSION;
|
||||||
Ok(Self(Windows {
|
Ok(Self(Windows::try_from_fn(|suffix| {
|
||||||
_24h: ComputedFromHeight::forced_import(db, &format!("{name}_24h"), v, indexes)?,
|
ComputedFromHeight::forced_import(db, &format!("{name}_{suffix}"), 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)?,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rolling_sum(
|
pub(crate) fn compute_rolling_sum(
|
||||||
@@ -71,7 +57,7 @@ where
|
|||||||
T: Default + SubAssign,
|
T: Default + SubAssign,
|
||||||
{
|
{
|
||||||
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
|
for (w, starts) in self.0.as_mut_array().into_iter().zip(windows.as_array()) {
|
||||||
w.height.compute_rolling_sum(max_from, starts, source, exit)?;
|
w.height.compute_rolling_sum(max_from, *starts, source, exit)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,23 @@ pub struct Windows<A, B = A, C = A, D = A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<A> Windows<A> {
|
impl<A> Windows<A> {
|
||||||
|
pub const SUFFIXES: [&'static str; 4] = ["24h", "7d", "30d", "1y"];
|
||||||
|
|
||||||
|
pub fn try_from_fn<E>(
|
||||||
|
mut f: impl FnMut(&str) -> std::result::Result<A, E>,
|
||||||
|
) -> std::result::Result<Self, E> {
|
||||||
|
Ok(Self {
|
||||||
|
_24h: f(Self::SUFFIXES[0])?,
|
||||||
|
_7d: f(Self::SUFFIXES[1])?,
|
||||||
|
_30d: f(Self::SUFFIXES[2])?,
|
||||||
|
_1y: f(Self::SUFFIXES[3])?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_array(&self) -> [&A; 4] {
|
||||||
|
[&self._24h, &self._7d, &self._30d, &self._1y]
|
||||||
|
}
|
||||||
|
|
||||||
pub fn as_mut_array(&mut self) -> [&mut A; 4] {
|
pub fn as_mut_array(&mut self) -> [&mut A; 4] {
|
||||||
[&mut self._24h, &mut self._7d, &mut self._30d, &mut self._1y]
|
[&mut self._24h, &mut self._7d, &mut self._30d, &mut self._1y]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,30 +130,20 @@ impl Vecs {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Rolling fee dominance = sum(fees) / sum(coinbase) * 100
|
// Rolling fee dominance = sum(fees) / sum(coinbase) * 100
|
||||||
self.fee_dominance_24h.height.compute_percentage(
|
for ((fee_dom, fees_w), coinbase_w) in self
|
||||||
starting_indexes.height,
|
.fee_dominance_rolling
|
||||||
&self.fees.rolling._24h.sum.sats.height,
|
.as_mut_array()
|
||||||
&self.coinbase.rolling._24h.sum.sats.height,
|
.into_iter()
|
||||||
exit,
|
.zip(self.fees.rolling.as_array())
|
||||||
)?;
|
.zip(self.coinbase.rolling.as_array())
|
||||||
self.fee_dominance_7d.height.compute_percentage(
|
{
|
||||||
starting_indexes.height,
|
fee_dom.height.compute_percentage(
|
||||||
&self.fees.rolling._7d.sum.sats.height,
|
starting_indexes.height,
|
||||||
&self.coinbase.rolling._7d.sum.sats.height,
|
&fees_w.sum.sats.height,
|
||||||
exit,
|
&coinbase_w.sum.sats.height,
|
||||||
)?;
|
exit,
|
||||||
self.fee_dominance_30d.height.compute_percentage(
|
)?;
|
||||||
starting_indexes.height,
|
}
|
||||||
&self.fees.rolling._30d.sum.sats.height,
|
|
||||||
&self.coinbase.rolling._30d.sum.sats.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.fee_dominance_1y.height.compute_percentage(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.fees.rolling._1y.sum.sats.height,
|
|
||||||
&self.coinbase.rolling._1y.sum.sats.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// All-time cumulative subsidy dominance
|
// All-time cumulative subsidy dominance
|
||||||
self.subsidy_dominance.height.compute_percentage(
|
self.subsidy_dominance.height.compute_percentage(
|
||||||
@@ -165,30 +155,19 @@ impl Vecs {
|
|||||||
|
|
||||||
// Rolling subsidy dominance = 100 - fee_dominance
|
// Rolling subsidy dominance = 100 - fee_dominance
|
||||||
let hundred = StoredF32::from(100u8);
|
let hundred = StoredF32::from(100u8);
|
||||||
self.subsidy_dominance_24h.height.compute_transform(
|
for (sub_dom, fee_dom) in self
|
||||||
starting_indexes.height,
|
.subsidy_dominance_rolling
|
||||||
&self.fee_dominance_24h.height,
|
.as_mut_array()
|
||||||
|(height, fee_dom, _)| (height, hundred - fee_dom),
|
.into_iter()
|
||||||
exit,
|
.zip(self.fee_dominance_rolling.as_array())
|
||||||
)?;
|
{
|
||||||
self.subsidy_dominance_7d.height.compute_transform(
|
sub_dom.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.fee_dominance_7d.height,
|
&fee_dom.height,
|
||||||
|(height, fee_dom, _)| (height, hundred - fee_dom),
|
|(height, fee_dom, _)| (height, hundred - fee_dom),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.subsidy_dominance_30d.height.compute_transform(
|
}
|
||||||
starting_indexes.height,
|
|
||||||
&self.fee_dominance_30d.height,
|
|
||||||
|(height, fee_dom, _)| (height, hundred - fee_dom),
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.subsidy_dominance_1y.height.compute_transform(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.fee_dominance_1y.height,
|
|
||||||
|(height, fee_dom, _)| (height, hundred - fee_dom),
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.subsidy_usd_1y_sma.cents.height.compute_rolling_average(
|
self.subsidy_usd_1y_sma.cents.height.compute_rolling_average(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use super::Vecs;
|
|||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{
|
internal::{
|
||||||
ComputedFromHeight, FiatFromHeight, ValueFromHeightFull,
|
ComputedFromHeight, FiatFromHeight, RollingWindows, ValueFromHeightFull,
|
||||||
ValueFromHeightCumulativeSum,
|
ValueFromHeightCumulativeSum,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -33,27 +33,9 @@ impl Vecs {
|
|||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
)?,
|
)?,
|
||||||
fee_dominance_24h: ComputedFromHeight::forced_import(
|
fee_dominance_rolling: RollingWindows::forced_import(
|
||||||
db,
|
db,
|
||||||
"fee_dominance_24h",
|
"fee_dominance",
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
fee_dominance_7d: ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
"fee_dominance_7d",
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
fee_dominance_30d: ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
"fee_dominance_30d",
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
fee_dominance_1y: ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
"fee_dominance_1y",
|
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
)?,
|
)?,
|
||||||
@@ -63,27 +45,9 @@ impl Vecs {
|
|||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
)?,
|
)?,
|
||||||
subsidy_dominance_24h: ComputedFromHeight::forced_import(
|
subsidy_dominance_rolling: RollingWindows::forced_import(
|
||||||
db,
|
db,
|
||||||
"subsidy_dominance_24h",
|
"subsidy_dominance",
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
subsidy_dominance_7d: ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
"subsidy_dominance_7d",
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
subsidy_dominance_30d: ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
"subsidy_dominance_30d",
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
subsidy_dominance_1y: ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
"subsidy_dominance_1y",
|
|
||||||
version,
|
version,
|
||||||
indexes,
|
indexes,
|
||||||
)?,
|
)?,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use brk_types::{Cents, StoredF32};
|
|||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{
|
use crate::internal::{
|
||||||
ComputedFromHeight, FiatFromHeight, ValueFromHeightFull,
|
ComputedFromHeight, FiatFromHeight, RollingWindows, ValueFromHeightFull,
|
||||||
ValueFromHeightCumulativeSum,
|
ValueFromHeightCumulativeSum,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -15,14 +15,8 @@ pub struct Vecs<M: StorageMode = Rw> {
|
|||||||
pub fees: ValueFromHeightFull<M>,
|
pub fees: ValueFromHeightFull<M>,
|
||||||
pub unclaimed_rewards: ValueFromHeightCumulativeSum<M>,
|
pub unclaimed_rewards: ValueFromHeightCumulativeSum<M>,
|
||||||
pub fee_dominance: ComputedFromHeight<StoredF32, M>,
|
pub fee_dominance: ComputedFromHeight<StoredF32, M>,
|
||||||
pub fee_dominance_24h: ComputedFromHeight<StoredF32, M>,
|
pub fee_dominance_rolling: RollingWindows<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: ComputedFromHeight<StoredF32, M>,
|
||||||
pub subsidy_dominance_24h: ComputedFromHeight<StoredF32, M>,
|
pub subsidy_dominance_rolling: RollingWindows<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>,
|
pub subsidy_usd_1y_sma: FiatFromHeight<Cents, M>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
indexes::{self, ComputeIndexes},
|
indexes::{self, ComputeIndexes},
|
||||||
internal::{
|
internal::{
|
||||||
ComputedFromHeightCumulativeSum, ComputedFromHeight, MaskSats, PercentageU32F32,
|
ComputedFromHeightCumulativeSum, ComputedFromHeight, MaskSats, PercentageU32F32,
|
||||||
ValueFromHeightCumulativeSum,
|
RollingWindows, ValueFromHeightCumulativeSum,
|
||||||
},
|
},
|
||||||
mining, prices,
|
mining, prices,
|
||||||
};
|
};
|
||||||
@@ -18,19 +18,12 @@ pub struct Vecs<M: StorageMode = Rw> {
|
|||||||
slug: PoolSlug,
|
slug: PoolSlug,
|
||||||
|
|
||||||
pub blocks_mined: ComputedFromHeightCumulativeSum<StoredU32, M>,
|
pub blocks_mined: ComputedFromHeightCumulativeSum<StoredU32, M>,
|
||||||
pub blocks_mined_24h_sum: ComputedFromHeight<StoredU32, M>,
|
pub blocks_mined_sum: RollingWindows<StoredU32, M>,
|
||||||
pub blocks_mined_1w_sum: ComputedFromHeight<StoredU32, M>,
|
|
||||||
pub blocks_mined_1m_sum: ComputedFromHeight<StoredU32, M>,
|
|
||||||
pub blocks_mined_1y_sum: ComputedFromHeight<StoredU32, M>,
|
|
||||||
pub subsidy: ValueFromHeightCumulativeSum<M>,
|
pub subsidy: ValueFromHeightCumulativeSum<M>,
|
||||||
pub fee: ValueFromHeightCumulativeSum<M>,
|
pub fee: ValueFromHeightCumulativeSum<M>,
|
||||||
pub coinbase: ValueFromHeightCumulativeSum<M>,
|
pub coinbase: ValueFromHeightCumulativeSum<M>,
|
||||||
pub dominance: ComputedFromHeight<StoredF32, M>,
|
pub dominance: ComputedFromHeight<StoredF32, M>,
|
||||||
|
pub dominance_rolling: RollingWindows<StoredF32, M>,
|
||||||
pub dominance_24h: ComputedFromHeight<StoredF32, M>,
|
|
||||||
pub dominance_1w: ComputedFromHeight<StoredF32, M>,
|
|
||||||
pub dominance_1m: ComputedFromHeight<StoredF32, M>,
|
|
||||||
pub dominance_1y: ComputedFromHeight<StoredF32, M>,
|
|
||||||
pub blocks_since_block: ComputedFromHeight<StoredU32, M>,
|
pub blocks_since_block: ComputedFromHeight<StoredU32, M>,
|
||||||
pub days_since_block: ComputedFromHeight<StoredU16, M>,
|
pub days_since_block: ComputedFromHeight<StoredU16, M>,
|
||||||
}
|
}
|
||||||
@@ -52,30 +45,8 @@ impl Vecs {
|
|||||||
indexes,
|
indexes,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let blocks_mined_24h_sum = ComputedFromHeight::forced_import(
|
let blocks_mined_sum =
|
||||||
db,
|
RollingWindows::forced_import(db, &suffix("blocks_mined_sum"), version, indexes)?;
|
||||||
&suffix("blocks_mined_24h_sum"),
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?;
|
|
||||||
let blocks_mined_1w_sum = ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
&suffix("blocks_mined_1w_sum"),
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?;
|
|
||||||
let blocks_mined_1m_sum = ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
&suffix("blocks_mined_1m_sum"),
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?;
|
|
||||||
let blocks_mined_1y_sum = ComputedFromHeight::forced_import(
|
|
||||||
db,
|
|
||||||
&suffix("blocks_mined_1y_sum"),
|
|
||||||
version,
|
|
||||||
indexes,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let subsidy =
|
let subsidy =
|
||||||
ValueFromHeightCumulativeSum::forced_import(db, &suffix("subsidy"), version, indexes)?;
|
ValueFromHeightCumulativeSum::forced_import(db, &suffix("subsidy"), version, indexes)?;
|
||||||
@@ -88,27 +59,15 @@ impl Vecs {
|
|||||||
|
|
||||||
let dominance =
|
let dominance =
|
||||||
ComputedFromHeight::forced_import(db, &suffix("dominance"), version, indexes)?;
|
ComputedFromHeight::forced_import(db, &suffix("dominance"), version, indexes)?;
|
||||||
let dominance_24h =
|
let dominance_rolling =
|
||||||
ComputedFromHeight::forced_import(db, &suffix("dominance_24h"), version, indexes)?;
|
RollingWindows::forced_import(db, &suffix("dominance"), version, indexes)?;
|
||||||
let dominance_1w =
|
|
||||||
ComputedFromHeight::forced_import(db, &suffix("dominance_1w"), version, indexes)?;
|
|
||||||
let dominance_1m =
|
|
||||||
ComputedFromHeight::forced_import(db, &suffix("dominance_1m"), version, indexes)?;
|
|
||||||
let dominance_1y =
|
|
||||||
ComputedFromHeight::forced_import(db, &suffix("dominance_1y"), version, indexes)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
dominance,
|
dominance,
|
||||||
dominance_24h,
|
dominance_rolling,
|
||||||
dominance_1w,
|
|
||||||
dominance_1m,
|
|
||||||
dominance_1y,
|
|
||||||
slug,
|
slug,
|
||||||
blocks_mined,
|
blocks_mined,
|
||||||
blocks_mined_24h_sum,
|
blocks_mined_sum,
|
||||||
blocks_mined_1w_sum,
|
|
||||||
blocks_mined_1m_sum,
|
|
||||||
blocks_mined_1y_sum,
|
|
||||||
coinbase,
|
coinbase,
|
||||||
subsidy,
|
subsidy,
|
||||||
fee,
|
fee,
|
||||||
@@ -159,31 +118,9 @@ impl Vecs {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Compute rolling window blocks mined using the start heights from blocks.count
|
self.blocks_mined_sum.compute_rolling_sum(
|
||||||
self.blocks_mined_24h_sum.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.count.height_24h_ago,
|
&window_starts,
|
||||||
&self.blocks_mined.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.blocks_mined_1w_sum.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1w_ago,
|
|
||||||
&self.blocks_mined.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.blocks_mined_1m_sum.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1m_ago,
|
|
||||||
&self.blocks_mined.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.blocks_mined_1y_sum.height.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
|
||||||
&blocks.count.height_1y_ago,
|
|
||||||
&self.blocks_mined.height,
|
&self.blocks_mined.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -196,37 +133,20 @@ impl Vecs {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.dominance_24h
|
for ((dom, mined), total) in self
|
||||||
.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
|
.dominance_rolling
|
||||||
|
.as_mut_array()
|
||||||
|
.into_iter()
|
||||||
|
.zip(self.blocks_mined_sum.as_array())
|
||||||
|
.zip(blocks.count.block_count_sum.as_array())
|
||||||
|
{
|
||||||
|
dom.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.blocks_mined_24h_sum.height,
|
&mined.height,
|
||||||
&blocks.count.block_count_sum._24h.height,
|
&total.height,
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.dominance_1w
|
|
||||||
.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.blocks_mined_1w_sum.height,
|
|
||||||
&blocks.count.block_count_sum._7d.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.dominance_1m
|
|
||||||
.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.blocks_mined_1m_sum.height,
|
|
||||||
&blocks.count.block_count_sum._30d.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.dominance_1y
|
|
||||||
.compute_binary::<StoredU32, StoredU32, PercentageU32F32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.blocks_mined_1y_sum.height,
|
|
||||||
&blocks.count.block_count_sum._1y.height,
|
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
self.subsidy.compute(
|
self.subsidy.compute(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
|
|||||||
Reference in New Issue
Block a user