mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-27 08:09:58 -07:00
global: snapshot
This commit is contained in:
@@ -11,12 +11,12 @@ use vecdb::{
|
||||
|
||||
use crate::{ComputeIndexes, blocks, indexes, internal::ComputedFromHeight};
|
||||
|
||||
/// Address count with 30d change metric for a single type.
|
||||
/// Address count with 1m change metric for a single type.
|
||||
#[derive(Traversable)]
|
||||
pub struct AddrCountVecs<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub count: ComputedFromHeight<StoredU64, M>,
|
||||
pub _30d_change: ComputedFromHeight<StoredF64, M>,
|
||||
pub change_1m: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl AddrCountVecs {
|
||||
@@ -28,9 +28,9 @@ impl AddrCountVecs {
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
count: ComputedFromHeight::forced_import(db, name, version, indexes)?,
|
||||
_30d_change: ComputedFromHeight::forced_import(
|
||||
change_1m: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&format!("{name}_30d_change"),
|
||||
&format!("{name}_change_1m"),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
@@ -43,7 +43,7 @@ impl AddrCountVecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self._30d_change.height.compute_rolling_change(
|
||||
self.change_1m.height.compute_rolling_change(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.count.height,
|
||||
@@ -85,7 +85,7 @@ impl From<(&AddressTypeToAddrCountVecs, Height)> for AddressTypeToAddressCount {
|
||||
}
|
||||
}
|
||||
|
||||
/// Address count per address type, with height + derived indexes + 30d change.
|
||||
/// Address count per address type, with height + derived indexes + 1m change.
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
pub struct AddressTypeToAddrCountVecs<M: StorageMode = Rw>(ByAddressType<AddrCountVecs<M>>);
|
||||
|
||||
@@ -290,7 +290,7 @@ impl AddrCountsVecs {
|
||||
.height
|
||||
.compute_sum_of_others(starting_indexes.height, &sources, exit)?;
|
||||
|
||||
self.all._30d_change.height.compute_rolling_change(
|
||||
self.all.change_1m.height.compute_rolling_change(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.all.count.height,
|
||||
|
||||
@@ -99,9 +99,9 @@ impl AddressCohorts {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// 1. Compute addr_count_30d_change using rolling window
|
||||
// 1. Compute addr_count_change_1m using rolling window
|
||||
self.par_iter_mut().try_for_each(|v| {
|
||||
v.addr_count_30d_change.height.compute_rolling_change(
|
||||
v.addr_count_change_1m.height.compute_rolling_change(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1m_ago,
|
||||
&v.addr_count.height,
|
||||
|
||||
@@ -36,7 +36,7 @@ pub struct AddressCohortVecs<M: StorageMode = Rw> {
|
||||
pub metrics: BasicCohortMetrics<M>,
|
||||
|
||||
pub addr_count: ComputedFromHeight<StoredU64, M>,
|
||||
pub addr_count_30d_change: ComputedFromHeight<StoredF64, M>,
|
||||
pub addr_count_change_1m: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl AddressCohortVecs {
|
||||
@@ -73,9 +73,9 @@ impl AddressCohortVecs {
|
||||
version + VERSION,
|
||||
indexes,
|
||||
)?,
|
||||
addr_count_30d_change: ComputedFromHeight::forced_import(
|
||||
addr_count_change_1m: ComputedFromHeight::forced_import(
|
||||
db,
|
||||
&cfg.name("addr_count_30d_change"),
|
||||
&cfg.name("addr_count_change_1m"),
|
||||
version + VERSION,
|
||||
indexes,
|
||||
)?,
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{AnyStoredVec, AnyVec, EagerVec, Exit, ImportableVec, PcoVec, Rw, Sto
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
internal::{ComputedFromHeightCumulativeSum, ValueFromHeightCumulative, ValueFromHeight},
|
||||
internal::{ComputedFromHeightCumulativeSum, RollingEmas2w, ValueFromHeightCumulative},
|
||||
};
|
||||
|
||||
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: ValueFromHeight<M>,
|
||||
pub sent_ema: RollingEmas2w<M>,
|
||||
|
||||
/// Satoshi-blocks destroyed (supply * blocks_old when spent)
|
||||
pub satblocks_destroyed: M::Stored<EagerVec<PcoVec<Height, Sats>>>,
|
||||
@@ -44,9 +44,9 @@ impl ActivityMetrics {
|
||||
cfg.indexes,
|
||||
)?,
|
||||
|
||||
sent_14d_ema: ValueFromHeight::forced_import(
|
||||
sent_ema: RollingEmas2w::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("sent_14d_ema"),
|
||||
&cfg.name("sent"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
@@ -166,7 +166,7 @@ impl ActivityMetrics {
|
||||
let window_starts = blocks.count.window_starts();
|
||||
|
||||
// 14-day EMA of sent (sats and dollars)
|
||||
self.sent_14d_ema.compute_ema(
|
||||
self.sent_ema.compute(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_2w_ago,
|
||||
&self.sent.base.sats.height,
|
||||
|
||||
@@ -26,13 +26,13 @@ impl CostBasisBase {
|
||||
Ok(Self {
|
||||
min: Price::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("min_cost_basis"),
|
||||
&cfg.name("cost_basis_min"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
max: Price::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("max_cost_basis"),
|
||||
&cfg.name("cost_basis_max"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
|
||||
@@ -12,7 +12,7 @@ use super::ImportConfig;
|
||||
#[derive(Traversable)]
|
||||
pub struct OutputsMetrics<M: StorageMode = Rw> {
|
||||
pub utxo_count: ComputedFromHeight<StoredU64, M>,
|
||||
pub utxo_count_30d_change: ComputedFromHeight<StoredF64, M>,
|
||||
pub utxo_count_change_1m: ComputedFromHeight<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl OutputsMetrics {
|
||||
@@ -25,9 +25,9 @@ impl OutputsMetrics {
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
utxo_count_30d_change: ComputedFromHeight::forced_import(
|
||||
utxo_count_change_1m: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("utxo_count_30d_change"),
|
||||
&cfg.name("utxo_count_change_1m"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
@@ -77,7 +77,7 @@ impl OutputsMetrics {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.utxo_count_30d_change.height.compute_rolling_change(
|
||||
self.utxo_count_change_1m.height.compute_rolling_change(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.utxo_count.height,
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
internal::{ComputedFromHeight, RatioCents64, RollingEmas7d30d, RollingWindows},
|
||||
internal::{ComputedFromHeight, RatioCents64, RollingEmas1w1m, RollingWindows},
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
@@ -23,7 +23,7 @@ pub struct RealizedAdjusted<M: StorageMode = Rw> {
|
||||
|
||||
// === Adjusted SOPR (rolling window ratios) ===
|
||||
pub adjusted_sopr: RollingWindows<StoredF64, M>,
|
||||
pub adjusted_sopr_ema: RollingEmas7d30d<StoredF64, M>,
|
||||
pub adjusted_sopr_ema: RollingEmas1w1m<StoredF64, M>,
|
||||
}
|
||||
|
||||
impl RealizedAdjusted {
|
||||
@@ -52,7 +52,7 @@ impl RealizedAdjusted {
|
||||
let adjusted_sopr = RollingWindows::forced_import(
|
||||
cfg.db, &cfg.name("adjusted_sopr"), cfg.version + v1, cfg.indexes,
|
||||
)?;
|
||||
let adjusted_sopr_ema = RollingEmas7d30d::forced_import(
|
||||
let adjusted_sopr_ema = RollingEmas1w1m::forced_import(
|
||||
cfg.db, &cfg.name("adjusted_sopr_24h"), cfg.version + v1, cfg.indexes,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
BasisPoints16, BasisPointsSigned16,
|
||||
Bitcoin, Cents, CentsSats, CentsSigned, CentsSquaredSats, Dollars, Height, Sats, StoredF32, StoredF64, Version,
|
||||
};
|
||||
use vecdb::{
|
||||
@@ -12,10 +13,13 @@ use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
distribution::state::RealizedState,
|
||||
internal::{
|
||||
Bp16ToFloat, Bp16ToPercent, Bps16ToFloat, Bps16ToPercent,
|
||||
CentsPlus, CentsUnsignedToDollars, ComputedFromHeightCumulative, ComputedFromHeight,
|
||||
ComputedFromHeightRatio, NegCentsUnsignedToDollars, ValueFromHeightCumulative, LazyFromHeight,
|
||||
PercentageCentsF32, PercentageCentsSignedCentsF32, PercentageCentsSignedDollarsF32, Price, RatioCents64,
|
||||
RollingEmas7d30d, RollingWindows, Identity, ValueFromHeight,
|
||||
ComputedFromHeightRatio, FiatFromHeight, NegCentsUnsignedToDollars, PercentFromHeight,
|
||||
PercentRollingEmas1w1m, PercentRollingWindows, ValueFromHeightCumulative, LazyFromHeight,
|
||||
Price,
|
||||
RatioCentsBp16, RatioCentsSignedCentsBps16, RatioCentsSignedDollarsBps16, RatioCents64,
|
||||
RollingEmas1w1m, RollingEmas2w, RollingWindows, Identity,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -29,12 +33,12 @@ pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
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: ComputedFromHeight<CentsSigned, M>,
|
||||
pub realized_price_ratio: ComputedFromHeightRatio<M>,
|
||||
pub realized_cap_change_1m: ComputedFromHeight<CentsSigned, M>,
|
||||
|
||||
// === Investor Price ===
|
||||
pub investor_price: Price<ComputedFromHeight<Cents, M>>,
|
||||
pub investor_price_extra: ComputedFromHeightRatio<M>,
|
||||
pub investor_price_ratio: ComputedFromHeightRatio<M>,
|
||||
|
||||
// === Floor/Ceiling Price Bands ===
|
||||
pub lower_price_band: Price<ComputedFromHeight<Cents, M>>,
|
||||
@@ -49,21 +53,18 @@ pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
|
||||
// === Realized Profit/Loss ===
|
||||
pub realized_profit: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub realized_profit_7d_ema: ComputedFromHeight<Cents, M>,
|
||||
pub realized_profit_ema_1w: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub realized_loss_7d_ema: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss_ema_1w: ComputedFromHeight<Cents, M>,
|
||||
pub neg_realized_loss: LazyFromHeight<Dollars, Cents>,
|
||||
pub net_realized_pnl: ComputedFromHeightCumulative<CentsSigned, M>,
|
||||
pub net_realized_pnl_7d_ema: ComputedFromHeight<CentsSigned, M>,
|
||||
pub realized_value: ComputedFromHeight<Cents, M>,
|
||||
pub net_realized_pnl_ema_1w: ComputedFromHeight<CentsSigned, M>,
|
||||
pub gross_pnl: FiatFromHeight<Cents, M>,
|
||||
|
||||
// === Realized vs Realized Cap Ratios ===
|
||||
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: LazyFromHeight<Dollars, Cents>,
|
||||
pub realized_profit_rel_to_realized_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
pub realized_loss_rel_to_realized_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
pub net_realized_pnl_rel_to_realized_cap: PercentFromHeight<BasisPointsSigned16, M>,
|
||||
|
||||
// === Value Created/Destroyed Splits (stored) ===
|
||||
pub profit_value_created: ComputedFromHeight<Cents, M>,
|
||||
@@ -85,29 +86,29 @@ pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
|
||||
// === SOPR (rolling window ratios) ===
|
||||
pub sopr: RollingWindows<StoredF64, M>,
|
||||
pub sopr_ema: RollingEmas7d30d<StoredF64, M>,
|
||||
pub sopr_24h_ema: RollingEmas1w1m<StoredF64, M>,
|
||||
|
||||
// === Sell Side Risk ===
|
||||
pub realized_value_sum: RollingWindows<Cents, M>,
|
||||
pub sell_side_risk_ratio: RollingWindows<StoredF32, M>,
|
||||
pub sell_side_risk_ratio_ema: RollingEmas7d30d<StoredF32, M>,
|
||||
pub gross_pnl_sum: RollingWindows<Cents, M>,
|
||||
pub sell_side_risk_ratio: PercentRollingWindows<BasisPoints16, M>,
|
||||
pub sell_side_risk_ratio_24h_ema: PercentRollingEmas1w1m<BasisPoints16, M>,
|
||||
|
||||
// === Net Realized PnL Deltas ===
|
||||
pub net_realized_pnl_cumulative_30d_delta: ComputedFromHeight<CentsSigned, M>,
|
||||
pub net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub net_realized_pnl_cumulative_30d_delta_rel_to_market_cap:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub net_pnl_change_1m: ComputedFromHeight<CentsSigned, M>,
|
||||
pub net_pnl_change_1m_rel_to_realized_cap:
|
||||
PercentFromHeight<BasisPointsSigned16, M>,
|
||||
pub net_pnl_change_1m_rel_to_market_cap:
|
||||
PercentFromHeight<BasisPointsSigned16, M>,
|
||||
|
||||
// === Peak Regret ===
|
||||
pub peak_regret: ComputedFromHeightCumulative<Cents, M>,
|
||||
pub peak_regret_rel_to_realized_cap: ComputedFromHeight<StoredF32, M>,
|
||||
pub peak_regret_rel_to_realized_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
|
||||
// === Sent in Profit/Loss ===
|
||||
pub sent_in_profit: ValueFromHeightCumulative<M>,
|
||||
pub sent_in_profit_14d_ema: ValueFromHeight<M>,
|
||||
pub sent_in_profit_ema: RollingEmas2w<M>,
|
||||
pub sent_in_loss: ValueFromHeightCumulative<M>,
|
||||
pub sent_in_loss_14d_ema: ValueFromHeight<M>,
|
||||
pub sent_in_loss_ema: RollingEmas2w<M>,
|
||||
}
|
||||
|
||||
impl RealizedBase {
|
||||
@@ -138,9 +139,9 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_profit_7d_ema = ComputedFromHeight::forced_import(
|
||||
let realized_profit_ema_1w = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_profit_7d_ema"),
|
||||
&cfg.name("realized_profit_ema_1w"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
@@ -152,9 +153,9 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_loss_7d_ema = ComputedFromHeight::forced_import(
|
||||
let realized_loss_ema_1w = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_loss_7d_ema"),
|
||||
&cfg.name("realized_loss_ema_1w"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
@@ -173,9 +174,9 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let net_realized_pnl_7d_ema = ComputedFromHeight::forced_import(
|
||||
let net_realized_pnl_ema_1w = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_7d_ema"),
|
||||
&cfg.name("net_realized_pnl_ema_1w"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
@@ -187,40 +188,36 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_value = ComputedFromHeight::forced_import(
|
||||
let gross_pnl = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_value"),
|
||||
&cfg.name("gross_pnl"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
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 =
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("realized_profit_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
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 =
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("realized_loss_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
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 = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let net_realized_pnl_rel_to_realized_cap =
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let realized_price = Price::forced_import(
|
||||
cfg.db,
|
||||
@@ -236,7 +233,7 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
let investor_price_extra = ComputedFromHeightRatio::forced_import(
|
||||
let investor_price_ratio = ComputedFromHeightRatio::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("investor_price"),
|
||||
cfg.version,
|
||||
@@ -312,7 +309,7 @@ impl RealizedBase {
|
||||
&profit_value_destroyed,
|
||||
);
|
||||
|
||||
let realized_price_extra = ComputedFromHeightRatio::forced_import(
|
||||
let realized_price_ratio = ComputedFromHeightRatio::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_price"),
|
||||
cfg.version + v1,
|
||||
@@ -322,8 +319,8 @@ impl RealizedBase {
|
||||
let mvrv = LazyFromHeight::from_computed::<Identity<StoredF32>>(
|
||||
&cfg.name("mvrv"),
|
||||
cfg.version,
|
||||
realized_price_extra.ratio.height.read_only_boxed_clone(),
|
||||
&realized_price_extra.ratio,
|
||||
realized_price_ratio.ratio.height.read_only_boxed_clone(),
|
||||
&realized_price_ratio.ratio,
|
||||
);
|
||||
|
||||
// === Rolling windows ===
|
||||
@@ -333,61 +330,61 @@ impl RealizedBase {
|
||||
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 gross_pnl_sum = RollingWindows::forced_import(
|
||||
cfg.db, &cfg.name("gross_pnl_sum"), 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(
|
||||
let sell_side_risk_ratio = PercentRollingWindows::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db, &cfg.name("sell_side_risk_ratio"), cfg.version + v1, cfg.indexes,
|
||||
)?;
|
||||
|
||||
// === EMA imports ===
|
||||
let sopr_ema = RollingEmas7d30d::forced_import(
|
||||
let sopr_24h_ema = RollingEmas1w1m::forced_import(
|
||||
cfg.db, &cfg.name("sopr_24h"), cfg.version + v1, cfg.indexes,
|
||||
)?;
|
||||
let sell_side_risk_ratio_ema = RollingEmas7d30d::forced_import(
|
||||
let sell_side_risk_ratio_24h_ema = PercentRollingEmas1w1m::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db, &cfg.name("sell_side_risk_ratio_24h"), cfg.version + v1, cfg.indexes,
|
||||
)?;
|
||||
|
||||
let peak_regret_rel_to_realized_cap = ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("peak_regret_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let peak_regret_rel_to_realized_cap =
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("realized_peak_regret_rel_to_realized_cap"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
realized_cap_cents,
|
||||
realized_cap,
|
||||
realized_price,
|
||||
realized_price_extra,
|
||||
realized_cap_30d_delta: ComputedFromHeight::forced_import(
|
||||
realized_price_ratio,
|
||||
realized_cap_change_1m: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("realized_cap_30d_delta"),
|
||||
&cfg.name("realized_cap_change_1m"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
investor_price,
|
||||
investor_price_extra,
|
||||
investor_price_ratio,
|
||||
lower_price_band,
|
||||
upper_price_band,
|
||||
cap_raw,
|
||||
investor_cap_raw,
|
||||
mvrv,
|
||||
realized_profit,
|
||||
realized_profit_7d_ema,
|
||||
realized_profit_ema_1w,
|
||||
realized_loss,
|
||||
realized_loss_7d_ema,
|
||||
realized_loss_ema_1w,
|
||||
neg_realized_loss,
|
||||
net_realized_pnl,
|
||||
net_realized_pnl_7d_ema,
|
||||
realized_value,
|
||||
net_realized_pnl_ema_1w,
|
||||
gross_pnl,
|
||||
realized_profit_rel_to_realized_cap,
|
||||
realized_loss_rel_to_realized_cap,
|
||||
net_realized_pnl_rel_to_realized_cap,
|
||||
total_realized_pnl,
|
||||
profit_value_created,
|
||||
profit_value_destroyed,
|
||||
loss_value_created,
|
||||
@@ -399,27 +396,27 @@ impl RealizedBase {
|
||||
value_created_sum,
|
||||
value_destroyed_sum,
|
||||
sopr,
|
||||
sopr_ema,
|
||||
realized_value_sum,
|
||||
sopr_24h_ema,
|
||||
gross_pnl_sum,
|
||||
sell_side_risk_ratio,
|
||||
sell_side_risk_ratio_ema,
|
||||
net_realized_pnl_cumulative_30d_delta: ComputedFromHeight::forced_import(
|
||||
sell_side_risk_ratio_24h_ema,
|
||||
net_pnl_change_1m: ComputedFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_cumulative_30d_delta"),
|
||||
&cfg.name("net_pnl_change_1m"),
|
||||
cfg.version + v3,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap:
|
||||
ComputedFromHeight::forced_import(
|
||||
net_pnl_change_1m_rel_to_realized_cap:
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap"),
|
||||
&cfg.name("net_pnl_change_1m_rel_to_realized_cap"),
|
||||
cfg.version + v3,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
net_realized_pnl_cumulative_30d_delta_rel_to_market_cap:
|
||||
ComputedFromHeight::forced_import(
|
||||
net_pnl_change_1m_rel_to_market_cap:
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl_cumulative_30d_delta_rel_to_market_cap"),
|
||||
&cfg.name("net_pnl_change_1m_rel_to_market_cap"),
|
||||
cfg.version + v3,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
@@ -431,9 +428,9 @@ impl RealizedBase {
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
sent_in_profit_14d_ema: ValueFromHeight::forced_import(
|
||||
sent_in_profit_ema: RollingEmas2w::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("sent_in_profit_14d_ema"),
|
||||
&cfg.name("sent_in_profit"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
@@ -443,9 +440,9 @@ impl RealizedBase {
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
sent_in_loss_14d_ema: ValueFromHeight::forced_import(
|
||||
sent_in_loss_ema: RollingEmas2w::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("sent_in_loss_14d_ema"),
|
||||
&cfg.name("sent_in_loss"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
@@ -710,7 +707,7 @@ impl RealizedBase {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.realized_value.height.compute_add(
|
||||
self.gross_pnl.cents.height.compute_add(
|
||||
starting_indexes.height,
|
||||
&self.realized_profit.height,
|
||||
&self.realized_loss.height,
|
||||
@@ -750,14 +747,14 @@ impl RealizedBase {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.realized_price_extra.compute_ratio(
|
||||
self.realized_price_ratio.compute_ratio(
|
||||
starting_indexes,
|
||||
&prices.price.cents.height,
|
||||
&self.realized_price.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.investor_price_extra.compute_ratio(
|
||||
self.investor_price_ratio.compute_ratio(
|
||||
starting_indexes,
|
||||
&prices.price.cents.height,
|
||||
&self.investor_price.cents.height,
|
||||
@@ -796,7 +793,7 @@ impl RealizedBase {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.realized_cap_30d_delta.height.compute_rolling_change(
|
||||
self.realized_cap_change_1m.height.compute_rolling_change(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.realized_cap_cents.height,
|
||||
@@ -827,8 +824,8 @@ impl RealizedBase {
|
||||
self.value_destroyed_sum.compute_rolling_sum(
|
||||
starting_indexes.height, &window_starts, &self.value_destroyed.height, exit,
|
||||
)?;
|
||||
self.realized_value_sum.compute_rolling_sum(
|
||||
starting_indexes.height, &window_starts, &self.realized_value.height, exit,
|
||||
self.gross_pnl_sum.compute_rolling_sum(
|
||||
starting_indexes.height, &window_starts, &self.gross_pnl.cents.height, exit,
|
||||
)?;
|
||||
|
||||
// Compute SOPR from rolling sums
|
||||
@@ -843,27 +840,27 @@ impl RealizedBase {
|
||||
|
||||
// Compute sell-side risk ratios
|
||||
for (ssrr, rv) in self.sell_side_risk_ratio.as_mut_array().into_iter()
|
||||
.zip(self.realized_value_sum.as_array())
|
||||
.zip(self.gross_pnl_sum.as_array())
|
||||
{
|
||||
ssrr.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
||||
ssrr.compute_binary::<Cents, Cents, RatioCentsBp16>(
|
||||
starting_indexes.height, &rv.height, &self.realized_cap_cents.height, exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
// 7d EMAs
|
||||
self.realized_profit_7d_ema.height.compute_rolling_ema(
|
||||
self.realized_profit_ema_1w.height.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&self.realized_profit.height,
|
||||
exit,
|
||||
)?;
|
||||
self.realized_loss_7d_ema.height.compute_rolling_ema(
|
||||
self.realized_loss_ema_1w.height.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&self.realized_loss.height,
|
||||
exit,
|
||||
)?;
|
||||
self.net_realized_pnl_7d_ema
|
||||
self.net_realized_pnl_ema_1w
|
||||
.height
|
||||
.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
@@ -873,14 +870,14 @@ impl RealizedBase {
|
||||
)?;
|
||||
|
||||
// 14-day EMA of sent in profit/loss
|
||||
self.sent_in_profit_14d_ema.compute_ema(
|
||||
self.sent_in_profit_ema.compute(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_2w_ago,
|
||||
&self.sent_in_profit.base.sats.height,
|
||||
&self.sent_in_profit.base.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
self.sent_in_loss_14d_ema.compute_ema(
|
||||
self.sent_in_loss_ema.compute(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_2w_ago,
|
||||
&self.sent_in_loss.base.sats.height,
|
||||
@@ -889,7 +886,7 @@ impl RealizedBase {
|
||||
)?;
|
||||
|
||||
// SOPR EMAs (based on 24h window)
|
||||
self.sopr_ema.compute_from_24h(
|
||||
self.sopr_24h_ema.compute_from_24h(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&blocks.count.height_1m_ago,
|
||||
@@ -898,38 +895,38 @@ impl RealizedBase {
|
||||
)?;
|
||||
|
||||
// Sell side risk EMAs (based on 24h window)
|
||||
self.sell_side_risk_ratio_ema.compute_from_24h(
|
||||
self.sell_side_risk_ratio_24h_ema.compute_from_24h(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.sell_side_risk_ratio._24h.height,
|
||||
&self.sell_side_risk_ratio._24h.bps.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Realized profit/loss/net relative to realized cap
|
||||
self.realized_profit_rel_to_realized_cap
|
||||
.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp16>(
|
||||
starting_indexes.height,
|
||||
&self.realized_profit.height,
|
||||
&self.realized_cap_cents.height,
|
||||
exit,
|
||||
)?;
|
||||
self.realized_loss_rel_to_realized_cap
|
||||
.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp16>(
|
||||
starting_indexes.height,
|
||||
&self.realized_loss.height,
|
||||
&self.realized_cap_cents.height,
|
||||
exit,
|
||||
)?;
|
||||
self.net_realized_pnl_rel_to_realized_cap
|
||||
.compute_binary::<CentsSigned, Cents, PercentageCentsSignedCentsF32>(
|
||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps16>(
|
||||
starting_indexes.height,
|
||||
&self.net_realized_pnl.height,
|
||||
&self.realized_cap_cents.height,
|
||||
exit,
|
||||
)?;
|
||||
self.peak_regret_rel_to_realized_cap
|
||||
.compute_binary::<Cents, Cents, PercentageCentsF32>(
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp16>(
|
||||
starting_indexes.height,
|
||||
&self.peak_regret.height,
|
||||
&self.realized_cap_cents.height,
|
||||
@@ -937,7 +934,7 @@ impl RealizedBase {
|
||||
)?;
|
||||
|
||||
// Net realized PnL cumulative 30d delta
|
||||
self.net_realized_pnl_cumulative_30d_delta
|
||||
self.net_pnl_change_1m
|
||||
.height
|
||||
.compute_rolling_change(
|
||||
starting_indexes.height,
|
||||
@@ -946,18 +943,18 @@ impl RealizedBase {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.net_realized_pnl_cumulative_30d_delta_rel_to_realized_cap
|
||||
.compute_binary::<CentsSigned, Cents, PercentageCentsSignedCentsF32>(
|
||||
self.net_pnl_change_1m_rel_to_realized_cap
|
||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps16>(
|
||||
starting_indexes.height,
|
||||
&self.net_realized_pnl_cumulative_30d_delta.height,
|
||||
&self.net_pnl_change_1m.height,
|
||||
&self.realized_cap_cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.net_realized_pnl_cumulative_30d_delta_rel_to_market_cap
|
||||
.compute_binary::<CentsSigned, Dollars, PercentageCentsSignedDollarsF32>(
|
||||
self.net_pnl_change_1m_rel_to_market_cap
|
||||
.compute_binary::<CentsSigned, Dollars, RatioCentsSignedDollarsBps16>(
|
||||
starting_indexes.height,
|
||||
&self.net_realized_pnl_cumulative_30d_delta.height,
|
||||
&self.net_pnl_change_1m.height,
|
||||
height_to_market_cap,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Dollars, Height, StoredF32, StoredF64, Version};
|
||||
use brk_types::{BasisPoints16, Cents, Dollars, Height, StoredF64, Version};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, blocks,
|
||||
internal::{ComputedFromHeight, ComputedFromHeightRatioExtension, RatioCents64, RollingWindows},
|
||||
internal::{
|
||||
Bp16ToFloat, Bp16ToPercent, ComputedFromHeightRatioExtension, PercentFromHeight,
|
||||
RatioCents64, RatioDollarsBp16, RollingWindows,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::ImportConfig;
|
||||
@@ -15,7 +18,7 @@ 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: ComputedFromHeight<StoredF32, M>,
|
||||
pub realized_cap_rel_to_own_market_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
|
||||
// === Realized Profit/Loss Rolling Sums ===
|
||||
pub realized_profit_sum: RollingWindows<Cents, M>,
|
||||
@@ -34,7 +37,7 @@ impl RealizedExtended {
|
||||
let v1 = Version::ONE;
|
||||
|
||||
Ok(RealizedExtended {
|
||||
realized_cap_rel_to_own_market_cap: ComputedFromHeight::forced_import(
|
||||
realized_cap_rel_to_own_market_cap: PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("realized_cap_rel_to_own_market_cap"),
|
||||
cfg.version,
|
||||
@@ -84,8 +87,7 @@ impl RealizedExtended {
|
||||
|
||||
// Realized cap relative to own market cap
|
||||
self.realized_cap_rel_to_own_market_cap
|
||||
.height
|
||||
.compute_percentage(
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
starting_indexes.height,
|
||||
&base.realized_cap.height,
|
||||
height_to_market_cap,
|
||||
@@ -107,7 +109,7 @@ impl RealizedExtended {
|
||||
blocks,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&base.realized_price_extra.ratio.height,
|
||||
&base.realized_price_ratio.ratio.height,
|
||||
)?;
|
||||
self.realized_price_ratio_ext.compute_cents_bands(
|
||||
starting_indexes,
|
||||
@@ -119,7 +121,7 @@ impl RealizedExtended {
|
||||
blocks,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&base.investor_price_extra.ratio.height,
|
||||
&base.investor_price_ratio.ratio.height,
|
||||
)?;
|
||||
self.investor_price_ratio_ext.compute_cents_bands(
|
||||
starting_indexes,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, Sats, StoredF32, StoredF64, Version};
|
||||
use brk_types::{BasisPoints16, BasisPointsSigned16, Dollars, Height, Sats, StoredF32, Version};
|
||||
use vecdb::{Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeight, Identity, LazyFromHeight,
|
||||
NegPercentageDollarsF32, PercentageDollarsF32, PercentageSatsF64,
|
||||
Bp16ToFloat, Bp16ToPercent, Bps16ToFloat, Bps16ToPercent, LazyFromHeight,
|
||||
NegRatioDollarsBps16, PercentFromHeight, RatioDollarsBp16, RatioDollarsBps16, RatioSatsBp16,
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, RealizedBase, UnrealizedBase};
|
||||
@@ -16,19 +16,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: ComputedFromHeight<StoredF64, M>,
|
||||
pub supply_in_loss_rel_to_own_supply: ComputedFromHeight<StoredF64, M>,
|
||||
pub supply_in_profit_rel_to_own_supply: PercentFromHeight<BasisPoints16, M>,
|
||||
pub supply_in_loss_rel_to_own_supply: PercentFromHeight<BasisPoints16, M>,
|
||||
|
||||
// === Unrealized vs Market Cap ===
|
||||
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>,
|
||||
pub unrealized_profit_rel_to_market_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_market_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
pub neg_unrealized_loss_rel_to_market_cap: PercentFromHeight<BasisPointsSigned16, M>,
|
||||
pub net_unrealized_pnl_rel_to_market_cap: PercentFromHeight<BasisPointsSigned16, M>,
|
||||
pub nupl: LazyFromHeight<StoredF32, BasisPointsSigned16>,
|
||||
|
||||
// === Invested Capital in Profit/Loss as % of Realized Cap ===
|
||||
pub invested_capital_in_profit_pct: ComputedFromHeight<StoredF32, M>,
|
||||
pub invested_capital_in_loss_pct: ComputedFromHeight<StoredF32, M>,
|
||||
pub invested_capital_in_profit_rel_to_realized_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
pub invested_capital_in_loss_rel_to_realized_cap: PercentFromHeight<BasisPoints16, M>,
|
||||
}
|
||||
|
||||
impl RelativeBase {
|
||||
@@ -36,41 +36,49 @@ impl RelativeBase {
|
||||
let v1 = Version::ONE;
|
||||
let v2 = Version::new(2);
|
||||
|
||||
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 net_unrealized_pnl_rel_to_market_cap =
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
cfg.db, &cfg.name("net_unrealized_pnl_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?;
|
||||
|
||||
let nupl = LazyFromHeight::from_computed::<Identity<StoredF32>>(
|
||||
let nupl = LazyFromHeight::from_computed::<Bps16ToFloat>(
|
||||
&cfg.name("nupl"),
|
||||
cfg.version + v2,
|
||||
net_unrealized_pnl_rel_to_market_cap.height.read_only_boxed_clone(),
|
||||
&net_unrealized_pnl_rel_to_market_cap,
|
||||
net_unrealized_pnl_rel_to_market_cap.bps.height.read_only_boxed_clone(),
|
||||
&net_unrealized_pnl_rel_to_market_cap.bps,
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
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: 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: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("unrealized_profit_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?,
|
||||
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: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("neg_unrealized_loss_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?,
|
||||
supply_in_profit_rel_to_own_supply:
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db, &cfg.name("supply_in_profit_rel_to_own_supply"), cfg.version + v1, cfg.indexes,
|
||||
)?,
|
||||
supply_in_loss_rel_to_own_supply:
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db, &cfg.name("supply_in_loss_rel_to_own_supply"), cfg.version + v1, cfg.indexes,
|
||||
)?,
|
||||
unrealized_profit_rel_to_market_cap:
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db, &cfg.name("unrealized_profit_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?,
|
||||
unrealized_loss_rel_to_market_cap:
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db, &cfg.name("unrealized_loss_rel_to_market_cap"), cfg.version + v2, cfg.indexes,
|
||||
)?,
|
||||
neg_unrealized_loss_rel_to_market_cap:
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
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: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("invested_capital_in_profit_pct"), cfg.version, cfg.indexes,
|
||||
)?,
|
||||
invested_capital_in_loss_pct: ComputedFromHeight::forced_import(
|
||||
cfg.db, &cfg.name("invested_capital_in_loss_pct"), cfg.version, cfg.indexes,
|
||||
)?,
|
||||
invested_capital_in_profit_rel_to_realized_cap:
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db, &cfg.name("invested_capital_in_profit_rel_to_realized_cap"), cfg.version, cfg.indexes,
|
||||
)?,
|
||||
invested_capital_in_loss_rel_to_realized_cap:
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db, &cfg.name("invested_capital_in_loss_rel_to_realized_cap"), cfg.version, cfg.indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -84,35 +92,35 @@ impl RelativeBase {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.supply_in_profit_rel_to_own_supply
|
||||
.compute_binary::<Sats, Sats, PercentageSatsF64>(
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from, &unrealized.supply_in_profit.sats.height, supply_total_sats, exit,
|
||||
)?;
|
||||
self.supply_in_loss_rel_to_own_supply
|
||||
.compute_binary::<Sats, Sats, PercentageSatsF64>(
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from, &unrealized.supply_in_loss.sats.height, supply_total_sats, exit,
|
||||
)?;
|
||||
self.unrealized_profit_rel_to_market_cap
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from, &unrealized.unrealized_profit.usd.height, market_cap, exit,
|
||||
)?;
|
||||
self.unrealized_loss_rel_to_market_cap
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from, &unrealized.unrealized_loss.usd.height, market_cap, exit,
|
||||
)?;
|
||||
self.neg_unrealized_loss_rel_to_market_cap
|
||||
.compute_binary::<Dollars, Dollars, NegPercentageDollarsF32>(
|
||||
.compute_binary::<Dollars, Dollars, NegRatioDollarsBps16>(
|
||||
max_from, &unrealized.unrealized_loss.usd.height, market_cap, exit,
|
||||
)?;
|
||||
self.net_unrealized_pnl_rel_to_market_cap
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBps16>(
|
||||
max_from, &unrealized.net_unrealized_pnl.usd.height, market_cap, exit,
|
||||
)?;
|
||||
self.invested_capital_in_profit_pct
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
self.invested_capital_in_profit_rel_to_realized_cap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from, &unrealized.invested_capital_in_profit.usd.height, &realized.realized_cap.height, exit,
|
||||
)?;
|
||||
self.invested_capital_in_loss_pct
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
self.invested_capital_in_loss_rel_to_realized_cap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from, &unrealized.invested_capital_in_loss.usd.height, &realized.realized_cap.height, exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, StoredF32};
|
||||
use brk_types::{BasisPoints16, BasisPointsSigned16, Dollars, Height};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeight, NegPercentageDollarsF32, PercentageDollarsF32,
|
||||
Bp16ToFloat, Bp16ToPercent, Bps16ToFloat, Bps16ToPercent,
|
||||
NegRatioDollarsBps16, PercentFromHeight, RatioDollarsBp16, RatioDollarsBps16,
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
@@ -13,13 +14,13 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeExtendedOwnMarketCap<M: StorageMode = Rw> {
|
||||
pub unrealized_profit_rel_to_own_market_cap:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
PercentFromHeight<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_own_market_cap:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
PercentFromHeight<BasisPoints16, M>,
|
||||
pub neg_unrealized_loss_rel_to_own_market_cap:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
PercentFromHeight<BasisPointsSigned16, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_market_cap:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
PercentFromHeight<BasisPointsSigned16, M>,
|
||||
}
|
||||
|
||||
impl RelativeExtendedOwnMarketCap {
|
||||
@@ -30,28 +31,28 @@ impl RelativeExtendedOwnMarketCap {
|
||||
|
||||
Ok(Self {
|
||||
unrealized_profit_rel_to_own_market_cap:
|
||||
ComputedFromHeight::forced_import(
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_profit_rel_to_own_market_cap"),
|
||||
cfg.version + v2,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
unrealized_loss_rel_to_own_market_cap:
|
||||
ComputedFromHeight::forced_import(
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_loss_rel_to_own_market_cap"),
|
||||
cfg.version + v2,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
neg_unrealized_loss_rel_to_own_market_cap:
|
||||
ComputedFromHeight::forced_import(
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
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:
|
||||
ComputedFromHeight::forced_import(
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("net_unrealized_pnl_rel_to_own_market_cap"),
|
||||
cfg.version + v2,
|
||||
@@ -68,19 +69,19 @@ impl RelativeExtendedOwnMarketCap {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.unrealized_profit_rel_to_own_market_cap
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from, &unrealized.unrealized_profit.usd.height, own_market_cap, exit,
|
||||
)?;
|
||||
self.unrealized_loss_rel_to_own_market_cap
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from, &unrealized.unrealized_loss.usd.height, own_market_cap, exit,
|
||||
)?;
|
||||
self.neg_unrealized_loss_rel_to_own_market_cap
|
||||
.compute_binary::<Dollars, Dollars, NegPercentageDollarsF32>(
|
||||
.compute_binary::<Dollars, Dollars, NegRatioDollarsBps16>(
|
||||
max_from, &unrealized.unrealized_loss.usd.height, own_market_cap, exit,
|
||||
)?;
|
||||
self.net_unrealized_pnl_rel_to_own_market_cap
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBps16>(
|
||||
max_from, &unrealized.net_unrealized_pnl.usd.height, own_market_cap, exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, Height, StoredF32};
|
||||
use brk_types::{BasisPoints16, BasisPointsSigned16, Dollars, Height};
|
||||
use vecdb::{Exit, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeight, NegPercentageDollarsF32, PercentageDollarsF32,
|
||||
Bp16ToFloat, Bp16ToPercent, Bps16ToFloat, Bps16ToPercent,
|
||||
NegRatioDollarsBps16, PercentFromHeight, RatioDollarsBp16, RatioDollarsBps16,
|
||||
};
|
||||
|
||||
use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
@@ -12,14 +13,14 @@ use crate::distribution::metrics::{ImportConfig, UnrealizedBase};
|
||||
/// Extended relative metrics for own total unrealized PnL (extended only).
|
||||
#[derive(Traversable)]
|
||||
pub struct RelativeExtendedOwnPnl<M: StorageMode = Rw> {
|
||||
pub unrealized_profit_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub neg_unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeight<StoredF32, M>,
|
||||
pub unrealized_profit_rel_to_own_gross_pnl:
|
||||
PercentFromHeight<BasisPoints16, M>,
|
||||
pub unrealized_loss_rel_to_own_gross_pnl:
|
||||
PercentFromHeight<BasisPoints16, M>,
|
||||
pub neg_unrealized_loss_rel_to_own_gross_pnl:
|
||||
PercentFromHeight<BasisPointsSigned16, M>,
|
||||
pub net_unrealized_pnl_rel_to_own_gross_pnl:
|
||||
PercentFromHeight<BasisPointsSigned16, M>,
|
||||
}
|
||||
|
||||
impl RelativeExtendedOwnPnl {
|
||||
@@ -30,31 +31,31 @@ impl RelativeExtendedOwnPnl {
|
||||
let v2 = brk_types::Version::new(2);
|
||||
|
||||
Ok(Self {
|
||||
unrealized_profit_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeight::forced_import(
|
||||
unrealized_profit_rel_to_own_gross_pnl:
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_profit_rel_to_own_total_unrealized_pnl"),
|
||||
&cfg.name("unrealized_profit_rel_to_own_gross_pnl"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeight::forced_import(
|
||||
unrealized_loss_rel_to_own_gross_pnl:
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("unrealized_loss_rel_to_own_total_unrealized_pnl"),
|
||||
&cfg.name("unrealized_loss_rel_to_own_gross_pnl"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
neg_unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeight::forced_import(
|
||||
neg_unrealized_loss_rel_to_own_gross_pnl:
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("neg_unrealized_loss_rel_to_own_total_unrealized_pnl"),
|
||||
&cfg.name("neg_unrealized_loss_rel_to_own_gross_pnl"),
|
||||
cfg.version + v1,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
net_unrealized_pnl_rel_to_own_total_unrealized_pnl:
|
||||
ComputedFromHeight::forced_import(
|
||||
net_unrealized_pnl_rel_to_own_gross_pnl:
|
||||
PercentFromHeight::forced_import::<Bps16ToFloat, Bps16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("net_unrealized_pnl_rel_to_own_total_unrealized_pnl"),
|
||||
&cfg.name("net_unrealized_pnl_rel_to_own_gross_pnl"),
|
||||
cfg.version + v2,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
@@ -67,21 +68,21 @@ impl RelativeExtendedOwnPnl {
|
||||
unrealized: &UnrealizedBase,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.unrealized_profit_rel_to_own_total_unrealized_pnl
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
max_from, &unrealized.unrealized_profit.usd.height, &unrealized.total_unrealized_pnl.usd.height, exit,
|
||||
self.unrealized_profit_rel_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from, &unrealized.unrealized_profit.usd.height, &unrealized.gross_pnl.usd.height, exit,
|
||||
)?;
|
||||
self.unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
max_from, &unrealized.unrealized_loss.usd.height, &unrealized.total_unrealized_pnl.usd.height, exit,
|
||||
self.unrealized_loss_rel_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from, &unrealized.unrealized_loss.usd.height, &unrealized.gross_pnl.usd.height, exit,
|
||||
)?;
|
||||
self.neg_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.compute_binary::<Dollars, Dollars, NegPercentageDollarsF32>(
|
||||
max_from, &unrealized.unrealized_loss.usd.height, &unrealized.total_unrealized_pnl.usd.height, exit,
|
||||
self.neg_unrealized_loss_rel_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, NegRatioDollarsBps16>(
|
||||
max_from, &unrealized.unrealized_loss.usd.height, &unrealized.gross_pnl.usd.height, exit,
|
||||
)?;
|
||||
self.net_unrealized_pnl_rel_to_own_total_unrealized_pnl
|
||||
.compute_binary::<Dollars, Dollars, PercentageDollarsF32>(
|
||||
max_from, &unrealized.net_unrealized_pnl.usd.height, &unrealized.total_unrealized_pnl.usd.height, exit,
|
||||
self.net_unrealized_pnl_rel_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBps16>(
|
||||
max_from, &unrealized.net_unrealized_pnl.usd.height, &unrealized.gross_pnl.usd.height, exit,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Sats, StoredF64};
|
||||
use brk_types::{BasisPoints16, Height, Sats};
|
||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeight, PercentageSatsF64};
|
||||
use crate::internal::{Bp16ToFloat, Bp16ToPercent, PercentFromHeight, RatioSatsBp16};
|
||||
|
||||
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:
|
||||
ComputedFromHeight<StoredF64, M>,
|
||||
PercentFromHeight<BasisPoints16, M>,
|
||||
pub supply_in_profit_rel_to_circulating_supply:
|
||||
ComputedFromHeight<StoredF64, M>,
|
||||
PercentFromHeight<BasisPoints16, M>,
|
||||
pub supply_in_loss_rel_to_circulating_supply:
|
||||
ComputedFromHeight<StoredF64, M>,
|
||||
PercentFromHeight<BasisPoints16, M>,
|
||||
}
|
||||
|
||||
impl RelativeToAll {
|
||||
@@ -24,21 +24,21 @@ impl RelativeToAll {
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
supply_rel_to_circulating_supply:
|
||||
ComputedFromHeight::forced_import(
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("supply_rel_to_circulating_supply"),
|
||||
cfg.version + brk_types::Version::ONE,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
supply_in_profit_rel_to_circulating_supply:
|
||||
ComputedFromHeight::forced_import(
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
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:
|
||||
ComputedFromHeight::forced_import(
|
||||
PercentFromHeight::forced_import::<Bp16ToFloat, Bp16ToPercent>(
|
||||
cfg.db,
|
||||
&cfg.name("supply_in_loss_rel_to_circulating_supply"),
|
||||
cfg.version + brk_types::Version::ONE,
|
||||
@@ -56,15 +56,15 @@ impl RelativeToAll {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.supply_rel_to_circulating_supply
|
||||
.compute_binary::<Sats, Sats, PercentageSatsF64>(
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from, supply_total_sats, all_supply_sats, exit,
|
||||
)?;
|
||||
self.supply_in_profit_rel_to_circulating_supply
|
||||
.compute_binary::<Sats, Sats, PercentageSatsF64>(
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from, &unrealized.supply_in_profit.sats.height, all_supply_sats, exit,
|
||||
)?;
|
||||
self.supply_in_loss_rel_to_circulating_supply
|
||||
.compute_binary::<Sats, Sats, PercentageSatsF64>(
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
max_from, &unrealized.supply_in_loss.sats.height, all_supply_sats, exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -18,8 +18,8 @@ use super::ImportConfig;
|
||||
pub struct SupplyMetrics<M: StorageMode = Rw> {
|
||||
pub total: ValueFromHeight<M>,
|
||||
pub halved: LazyValueFromHeight,
|
||||
/// 30-day change in supply (net position change) - sats, btc, usd
|
||||
pub _30d_change: ValueFromHeightChange<M>,
|
||||
/// 1-month change in supply (net position change) - sats, btc, usd
|
||||
pub change_1m: ValueFromHeightChange<M>,
|
||||
}
|
||||
|
||||
impl SupplyMetrics {
|
||||
@@ -39,9 +39,9 @@ impl SupplyMetrics {
|
||||
HalveDollars,
|
||||
>(&cfg.name("supply_halved"), &supply, cfg.version);
|
||||
|
||||
let _30d_change = ValueFromHeightChange::forced_import(
|
||||
let change_1m = ValueFromHeightChange::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("_30d_change"),
|
||||
&cfg.name("supply_change_1m"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
@@ -49,7 +49,7 @@ impl SupplyMetrics {
|
||||
Ok(Self {
|
||||
total: supply,
|
||||
halved: supply_halved,
|
||||
_30d_change,
|
||||
change_1m,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ impl SupplyMetrics {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self._30d_change.compute_rolling(
|
||||
self.change_1m.compute_rolling(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.total.sats.height,
|
||||
|
||||
@@ -51,7 +51,7 @@ pub struct UnrealizedBase<M: StorageMode = Rw> {
|
||||
|
||||
// === Net and Total ===
|
||||
pub net_unrealized_pnl: FiatFromHeight<CentsSigned, M>,
|
||||
pub total_unrealized_pnl: FiatFromHeight<Cents, M>,
|
||||
pub gross_pnl: FiatFromHeight<Cents, M>,
|
||||
}
|
||||
|
||||
impl UnrealizedBase {
|
||||
@@ -148,9 +148,9 @@ impl UnrealizedBase {
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
let total_unrealized_pnl = FiatFromHeight::forced_import(
|
||||
let gross_pnl = FiatFromHeight::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("total_unrealized_pnl"),
|
||||
&cfg.name("gross_pnl"),
|
||||
cfg.version,
|
||||
cfg.indexes,
|
||||
)?;
|
||||
@@ -171,7 +171,7 @@ impl UnrealizedBase {
|
||||
net_sentiment,
|
||||
neg_unrealized_loss,
|
||||
net_unrealized_pnl,
|
||||
total_unrealized_pnl,
|
||||
gross_pnl,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ impl UnrealizedBase {
|
||||
&self.unrealized_loss.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
self.total_unrealized_pnl.cents.height.compute_add(
|
||||
self.gross_pnl.cents.height.compute_add(
|
||||
starting_indexes.height,
|
||||
&self.unrealized_profit.cents.height,
|
||||
&self.unrealized_loss.cents.height,
|
||||
|
||||
Reference in New Issue
Block a user