mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-17 02:09:44 -07:00
global: snapshot
This commit is contained in:
@@ -1009,7 +1009,6 @@ impl CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSo
|
||||
investor_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "investor_price")),
|
||||
investor_price_ratio: BpsRatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")),
|
||||
investor_price_ratio_percentiles: RatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")),
|
||||
investor_price_ratio_std_dev: RatioPattern2::new(client.clone(), _m(&acc, "investor_price_ratio")),
|
||||
loss_value_created: MetricPattern1::new(client.clone(), _m(&acc, "loss_value_created")),
|
||||
loss_value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "loss_value_destroyed")),
|
||||
lower_price_band: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "lower_price_band")),
|
||||
@@ -1134,26 +1133,20 @@ pub struct GrossMvrvNegNetRealizedSentSoprValuePattern {
|
||||
pub mvrv: MetricPattern1<StoredF32>,
|
||||
pub neg_realized_loss: MetricPattern1<Dollars>,
|
||||
pub net_realized_pnl: CumulativeHeightPattern<CentsSigned>,
|
||||
pub net_realized_pnl_ema_1w: MetricPattern1<CentsSigned>,
|
||||
pub net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern,
|
||||
pub realized_cap: MetricPattern1<Dollars>,
|
||||
pub realized_cap_cents: MetricPattern1<Cents>,
|
||||
pub realized_cap_change_1m: MetricPattern1<CentsSigned>,
|
||||
pub realized_loss: CumulativeHeightPattern<Cents>,
|
||||
pub realized_loss_ema_1w: MetricPattern1<Cents>,
|
||||
pub realized_loss_rel_to_realized_cap: BpsPercentRatioPattern,
|
||||
pub realized_price: CentsSatsUsdPattern,
|
||||
pub realized_price_ratio: BpsRatioPattern,
|
||||
pub realized_price_ratio_percentiles: RatioPattern,
|
||||
pub realized_profit: CumulativeHeightPattern<Cents>,
|
||||
pub realized_profit_ema_1w: MetricPattern1<Cents>,
|
||||
pub realized_profit_rel_to_realized_cap: BpsPercentRatioPattern,
|
||||
pub sent_in_loss: BaseCumulativePattern,
|
||||
pub sent_in_loss_ema: _2wPattern,
|
||||
pub sent_in_profit: BaseCumulativePattern,
|
||||
pub sent_in_profit_ema: _2wPattern,
|
||||
pub sopr: _1m1w1y24hPattern<StoredF64>,
|
||||
pub sopr_24h_ema: _1m1wPattern,
|
||||
pub value_created: MetricPattern1<Cents>,
|
||||
pub value_created_sum: _1m1w1y24hPattern<Cents>,
|
||||
pub value_destroyed: MetricPattern1<Cents>,
|
||||
@@ -1168,26 +1161,20 @@ impl GrossMvrvNegNetRealizedSentSoprValuePattern {
|
||||
mvrv: MetricPattern1::new(client.clone(), _m(&acc, "mvrv")),
|
||||
neg_realized_loss: MetricPattern1::new(client.clone(), _m(&acc, "neg_realized_loss")),
|
||||
net_realized_pnl: CumulativeHeightPattern::new(client.clone(), _m(&acc, "net_realized_pnl")),
|
||||
net_realized_pnl_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "net_realized_pnl_ema_1w")),
|
||||
net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_realized_pnl_rel_to_realized_cap")),
|
||||
realized_cap: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap")),
|
||||
realized_cap_cents: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap_cents")),
|
||||
realized_cap_change_1m: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap_change_1m")),
|
||||
realized_loss: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_loss")),
|
||||
realized_loss_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "realized_loss_ema_1w")),
|
||||
realized_loss_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_loss_rel_to_realized_cap")),
|
||||
realized_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "realized_price")),
|
||||
realized_price_ratio: BpsRatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")),
|
||||
realized_price_ratio_percentiles: RatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")),
|
||||
realized_profit: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_profit")),
|
||||
realized_profit_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "realized_profit_ema_1w")),
|
||||
realized_profit_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_profit_rel_to_realized_cap")),
|
||||
sent_in_loss: BaseCumulativePattern::new(client.clone(), _m(&acc, "sent_in_loss")),
|
||||
sent_in_loss_ema: _2wPattern::new(client.clone(), _m(&acc, "sent_in_loss_ema_2w")),
|
||||
sent_in_profit: BaseCumulativePattern::new(client.clone(), _m(&acc, "sent_in_profit")),
|
||||
sent_in_profit_ema: _2wPattern::new(client.clone(), _m(&acc, "sent_in_profit_ema_2w")),
|
||||
sopr: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sopr")),
|
||||
sopr_24h_ema: _1m1wPattern::new(client.clone(), _m(&acc, "sopr_24h_ema")),
|
||||
value_created: MetricPattern1::new(client.clone(), _m(&acc, "value_created")),
|
||||
value_created_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "value_created")),
|
||||
value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "value_destroyed")),
|
||||
|
||||
@@ -16,8 +16,7 @@ use crate::{
|
||||
ComputedFromHeight, ComputedFromHeightCumulative,
|
||||
ComputedFromHeightRatioPercentiles, FiatFromHeight,
|
||||
LazyFromHeight, NegCentsUnsignedToDollars, PercentFromHeight, RatioCents64,
|
||||
RatioCentsBp32, RatioCentsSignedCentsBps32, RollingEmas1w1m, RollingEmas2w,
|
||||
RollingWindows, ValueFromHeightCumulative,
|
||||
RatioCentsBp32, RatioCentsSignedCentsBps32, RollingWindows, ValueFromHeightCumulative,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -37,12 +36,8 @@ pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
|
||||
pub neg_realized_loss: LazyFromHeight<Dollars, Cents>,
|
||||
pub net_realized_pnl: ComputedFromHeightCumulative<CentsSigned, M>,
|
||||
pub net_realized_pnl_ema_1w: ComputedFromHeight<CentsSigned, M>,
|
||||
pub gross_pnl: FiatFromHeight<Cents, M>,
|
||||
|
||||
pub realized_profit_ema_1w: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss_ema_1w: ComputedFromHeight<Cents, M>,
|
||||
|
||||
pub realized_profit_rel_to_realized_cap: PercentFromHeight<BasisPoints32, M>,
|
||||
pub realized_loss_rel_to_realized_cap: PercentFromHeight<BasisPoints32, M>,
|
||||
pub net_realized_pnl_rel_to_realized_cap: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
@@ -52,14 +47,11 @@ pub struct RealizedBase<M: StorageMode = Rw> {
|
||||
pub value_created_sum: RollingWindows<Cents, M>,
|
||||
pub value_destroyed_sum: RollingWindows<Cents, M>,
|
||||
pub sopr: RollingWindows<StoredF64, M>,
|
||||
pub sopr_24h_ema: RollingEmas1w1m<StoredF64, M>,
|
||||
|
||||
pub realized_price_ratio_percentiles: ComputedFromHeightRatioPercentiles<M>,
|
||||
|
||||
pub sent_in_profit: ValueFromHeightCumulative<M>,
|
||||
pub sent_in_loss: ValueFromHeightCumulative<M>,
|
||||
pub sent_in_profit_ema: RollingEmas2w<M>,
|
||||
pub sent_in_loss_ema: RollingEmas2w<M>,
|
||||
}
|
||||
|
||||
impl RealizedBase {
|
||||
@@ -76,11 +68,7 @@ impl RealizedBase {
|
||||
cfg.indexes,
|
||||
);
|
||||
|
||||
let realized_profit_ema_1w = cfg.import("realized_profit_ema_1w", v0)?;
|
||||
let realized_loss_ema_1w = cfg.import("realized_loss_ema_1w", v0)?;
|
||||
|
||||
let net_realized_pnl = cfg.import("net_realized_pnl", v0)?;
|
||||
let net_realized_pnl_ema_1w = cfg.import("net_realized_pnl_ema_1w", v0)?;
|
||||
let gross_pnl = cfg.import("realized_gross_pnl", v0)?;
|
||||
|
||||
let realized_profit_rel_to_realized_cap =
|
||||
@@ -95,7 +83,6 @@ impl RealizedBase {
|
||||
let value_created_sum = cfg.import("value_created", v1)?;
|
||||
let value_destroyed_sum = cfg.import("value_destroyed", v1)?;
|
||||
let sopr = cfg.import("sopr", v1)?;
|
||||
let sopr_24h_ema = cfg.import("sopr_24h", v1)?;
|
||||
|
||||
let realized_price_ratio_percentiles =
|
||||
ComputedFromHeightRatioPercentiles::forced_import(
|
||||
@@ -110,10 +97,7 @@ impl RealizedBase {
|
||||
realized_cap_change_1m: cfg.import("realized_cap_change_1m", v0)?,
|
||||
neg_realized_loss,
|
||||
net_realized_pnl,
|
||||
net_realized_pnl_ema_1w,
|
||||
gross_pnl,
|
||||
realized_profit_ema_1w,
|
||||
realized_loss_ema_1w,
|
||||
realized_profit_rel_to_realized_cap,
|
||||
realized_loss_rel_to_realized_cap,
|
||||
net_realized_pnl_rel_to_realized_cap,
|
||||
@@ -122,12 +106,9 @@ impl RealizedBase {
|
||||
value_created_sum,
|
||||
value_destroyed_sum,
|
||||
sopr,
|
||||
sopr_24h_ema,
|
||||
realized_price_ratio_percentiles,
|
||||
sent_in_profit: cfg.import("sent_in_profit", v0)?,
|
||||
sent_in_loss: cfg.import("sent_in_loss", v0)?,
|
||||
sent_in_profit_ema: cfg.import("sent_in_profit", v0)?,
|
||||
sent_in_loss_ema: cfg.import("sent_in_loss", v0)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -240,25 +221,6 @@ impl RealizedBase {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.realized_profit_ema_1w.height.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&self.minimal.realized_profit.height,
|
||||
exit,
|
||||
)?;
|
||||
self.realized_loss_ema_1w.height.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&self.minimal.realized_loss.height,
|
||||
exit,
|
||||
)?;
|
||||
self.net_realized_pnl_ema_1w.height.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&self.net_realized_pnl.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.realized_profit_rel_to_realized_cap
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||
starting_indexes.height,
|
||||
@@ -311,14 +273,6 @@ impl RealizedBase {
|
||||
)?;
|
||||
}
|
||||
|
||||
self.sopr_24h_ema.compute_from_24h(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.sopr._24h.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Realized price ratio percentiles
|
||||
self.realized_price_ratio_percentiles.compute(
|
||||
blocks,
|
||||
@@ -328,22 +282,6 @@ impl RealizedBase {
|
||||
&self.minimal.realized_price.cents.height,
|
||||
)?;
|
||||
|
||||
// Sent in profit/loss EMAs
|
||||
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_ema.compute(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_2w_ago,
|
||||
&self.sent_in_loss.base.sats.height,
|
||||
&self.sent_in_loss.base.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use crate::{
|
||||
ComputedFromHeightRatioStdDevBands, LazyFromHeight, PercentFromHeight,
|
||||
PercentRollingEmas1w1m, PercentRollingWindows, Price, RatioCents64, RatioCentsBp32,
|
||||
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
|
||||
RollingWindows,
|
||||
RollingEmas1w1m, RollingEmas2w, RollingWindows,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -70,6 +70,15 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
||||
pub realized_loss_sum: RollingWindows<Cents, M>,
|
||||
pub realized_profit_to_loss_ratio: RollingWindows<StoredF64, M>,
|
||||
|
||||
pub realized_profit_ema_1w: ComputedFromHeight<Cents, M>,
|
||||
pub realized_loss_ema_1w: ComputedFromHeight<Cents, M>,
|
||||
pub net_realized_pnl_ema_1w: ComputedFromHeight<CentsSigned, M>,
|
||||
|
||||
pub sopr_24h_ema: RollingEmas1w1m<StoredF64, M>,
|
||||
|
||||
pub sent_in_profit_ema: RollingEmas2w<M>,
|
||||
pub sent_in_loss_ema: RollingEmas2w<M>,
|
||||
|
||||
pub realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands<M>,
|
||||
pub investor_price_ratio_percentiles: ComputedFromHeightRatioPercentiles<M>,
|
||||
}
|
||||
@@ -125,6 +134,13 @@ impl RealizedFull {
|
||||
let investor_price_name = cfg.name("investor_price");
|
||||
let investor_price_version = cfg.version;
|
||||
|
||||
let realized_profit_ema_1w = cfg.import("realized_profit_ema_1w", v0)?;
|
||||
let realized_loss_ema_1w = cfg.import("realized_loss_ema_1w", v0)?;
|
||||
let net_realized_pnl_ema_1w = cfg.import("net_realized_pnl_ema_1w", v0)?;
|
||||
let sopr_24h_ema = cfg.import("sopr_24h", v1)?;
|
||||
let sent_in_profit_ema = cfg.import("sent_in_profit", v0)?;
|
||||
let sent_in_loss_ema = cfg.import("sent_in_loss", v0)?;
|
||||
|
||||
Ok(Self {
|
||||
core,
|
||||
profit_value_created,
|
||||
@@ -155,6 +171,12 @@ impl RealizedFull {
|
||||
realized_loss_sum: cfg.import("realized_loss", v1)?,
|
||||
realized_profit_to_loss_ratio: cfg
|
||||
.import("realized_profit_to_loss_ratio", v1)?,
|
||||
realized_profit_ema_1w,
|
||||
realized_loss_ema_1w,
|
||||
net_realized_pnl_ema_1w,
|
||||
sopr_24h_ema,
|
||||
sent_in_profit_ema,
|
||||
sent_in_loss_ema,
|
||||
realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands::forced_import(
|
||||
cfg.db,
|
||||
&realized_price_name,
|
||||
@@ -266,6 +288,47 @@ impl RealizedFull {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// EMAs
|
||||
self.realized_profit_ema_1w.height.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&self.core.minimal.realized_profit.height,
|
||||
exit,
|
||||
)?;
|
||||
self.realized_loss_ema_1w.height.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&self.core.minimal.realized_loss.height,
|
||||
exit,
|
||||
)?;
|
||||
self.net_realized_pnl_ema_1w.height.compute_rolling_ema(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&self.core.net_realized_pnl.height,
|
||||
exit,
|
||||
)?;
|
||||
self.sopr_24h_ema.compute_from_24h(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1w_ago,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.core.sopr._24h.height,
|
||||
exit,
|
||||
)?;
|
||||
self.sent_in_profit_ema.compute(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_2w_ago,
|
||||
&self.core.sent_in_profit.base.sats.height,
|
||||
&self.core.sent_in_profit.base.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
self.sent_in_loss_ema.compute(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_2w_ago,
|
||||
&self.core.sent_in_loss.base.sats.height,
|
||||
&self.core.sent_in_loss.base.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Gross PnL rolling sum
|
||||
let window_starts = blocks.count.window_starts();
|
||||
self.gross_pnl_sum.compute_rolling_sum(
|
||||
|
||||
Reference in New Issue
Block a user