mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-05 00:03:40 -07:00
global: snapshot
This commit is contained in:
@@ -960,8 +960,11 @@ pub struct CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSell
|
||||
pub net_pnl_change_1m_rel_to_realized_cap: BpsPercentRatioPattern,
|
||||
pub net_pnl_delta: ChangeRatePattern<CentsSigned>,
|
||||
pub net_pnl_delta_extended: _24hChangeRatePattern<CentsSigned>,
|
||||
pub net_realized_pnl: CumulativeHeightPattern<CentsSigned>,
|
||||
pub net_realized_pnl: MetricPattern1<CentsSigned>,
|
||||
pub net_realized_pnl_cumulative: MetricPattern1<CentsSigned>,
|
||||
pub net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern,
|
||||
pub net_realized_pnl_sum: _24hPattern<CentsSigned>,
|
||||
pub net_realized_pnl_sum_extended: _1m1w1yPattern<CentsSigned>,
|
||||
pub peak_regret: CumulativeHeightPattern<Cents>,
|
||||
pub peak_regret_rel_to_realized_cap: BpsPercentRatioPattern,
|
||||
pub profit_flow: MetricPattern1<Dollars>,
|
||||
@@ -1028,8 +1031,11 @@ impl CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSo
|
||||
net_pnl_change_1m_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_pnl_change_1m_rel_to_realized_cap")),
|
||||
net_pnl_delta: ChangeRatePattern::new(client.clone(), _m(&acc, "net_pnl_delta")),
|
||||
net_pnl_delta_extended: _24hChangeRatePattern::new(client.clone(), _m(&acc, "net_pnl_delta")),
|
||||
net_realized_pnl: CumulativeHeightPattern::new(client.clone(), _m(&acc, "net_realized_pnl")),
|
||||
net_realized_pnl: MetricPattern1::new(client.clone(), _m(&acc, "net_realized_pnl")),
|
||||
net_realized_pnl_cumulative: MetricPattern1::new(client.clone(), _m(&acc, "net_realized_pnl_cumulative")),
|
||||
net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_realized_pnl_rel_to_realized_cap")),
|
||||
net_realized_pnl_sum: _24hPattern::new(client.clone(), _m(&acc, "net_realized_pnl_24h")),
|
||||
net_realized_pnl_sum_extended: _1m1w1yPattern::new(client.clone(), _m(&acc, "net_realized_pnl")),
|
||||
peak_regret: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_peak_regret")),
|
||||
peak_regret_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_peak_regret_rel_to_realized_cap")),
|
||||
profit_flow: MetricPattern1::new(client.clone(), _m(&acc, "profit_flow")),
|
||||
@@ -1147,7 +1153,8 @@ impl _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern {
|
||||
pub struct MvrvNegNetRealizedSentSoprValuePattern {
|
||||
pub mvrv: MetricPattern1<StoredF32>,
|
||||
pub neg_realized_loss: MetricPattern1<Dollars>,
|
||||
pub net_realized_pnl: CumulativeHeightPattern<CentsSigned>,
|
||||
pub net_realized_pnl: MetricPattern1<CentsSigned>,
|
||||
pub net_realized_pnl_sum: _24hPattern<CentsSigned>,
|
||||
pub realized_cap: MetricPattern1<Dollars>,
|
||||
pub realized_cap_cents: MetricPattern1<Cents>,
|
||||
pub realized_cap_delta: ChangeRatePattern<CentsSigned>,
|
||||
@@ -1174,7 +1181,8 @@ impl MvrvNegNetRealizedSentSoprValuePattern {
|
||||
Self {
|
||||
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: MetricPattern1::new(client.clone(), _m(&acc, "net_realized_pnl")),
|
||||
net_realized_pnl_sum: _24hPattern::new(client.clone(), _m(&acc, "net_realized_pnl_24h")),
|
||||
realized_cap: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap")),
|
||||
realized_cap_cents: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap_cents")),
|
||||
realized_cap_delta: ChangeRatePattern::new(client.clone(), _m(&acc, "realized_cap_delta")),
|
||||
@@ -1251,7 +1259,8 @@ impl Pct05Pct10Pct15Pct20Pct25Pct30Pct35Pct40Pct45Pct50Pct55Pct60Pct65Pct70Pct75
|
||||
pub struct MvrvNegNetRealizedSoprValuePattern {
|
||||
pub mvrv: MetricPattern1<StoredF32>,
|
||||
pub neg_realized_loss: MetricPattern1<Dollars>,
|
||||
pub net_realized_pnl: CumulativeHeightPattern<CentsSigned>,
|
||||
pub net_realized_pnl: MetricPattern1<CentsSigned>,
|
||||
pub net_realized_pnl_sum: _24hPattern<CentsSigned>,
|
||||
pub realized_cap: MetricPattern1<Dollars>,
|
||||
pub realized_cap_cents: MetricPattern1<Cents>,
|
||||
pub realized_cap_delta: ChangeRatePattern<CentsSigned>,
|
||||
@@ -1274,7 +1283,8 @@ impl MvrvNegNetRealizedSoprValuePattern {
|
||||
Self {
|
||||
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: MetricPattern1::new(client.clone(), _m(&acc, "net_realized_pnl")),
|
||||
net_realized_pnl_sum: _24hPattern::new(client.clone(), _m(&acc, "net_realized_pnl_24h")),
|
||||
realized_cap: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap")),
|
||||
realized_cap_cents: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap_cents")),
|
||||
realized_cap_delta: ChangeRatePattern::new(client.clone(), _m(&acc, "realized_cap_delta")),
|
||||
|
||||
@@ -10,8 +10,8 @@ use crate::{
|
||||
blocks,
|
||||
distribution::state::RealizedOps,
|
||||
internal::{
|
||||
ComputedFromHeight, ComputedFromHeightCumulative, LazyFromHeight,
|
||||
NegCentsUnsignedToDollars, RatioCents64, RollingDelta1m, RollingWindow24h,
|
||||
ComputedFromHeight, LazyFromHeight, NegCentsUnsignedToDollars, RatioCents64,
|
||||
RollingDelta1m, RollingWindow24h,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -30,7 +30,8 @@ pub struct RealizedCore<M: StorageMode = Rw> {
|
||||
pub realized_cap_delta: RollingDelta1m<Cents, CentsSigned, M>,
|
||||
|
||||
pub neg_realized_loss: LazyFromHeight<Dollars, Cents>,
|
||||
pub net_realized_pnl: ComputedFromHeightCumulative<CentsSigned, M>,
|
||||
pub net_realized_pnl: ComputedFromHeight<CentsSigned, M>,
|
||||
pub net_realized_pnl_sum: RollingWindow24h<CentsSigned, M>,
|
||||
|
||||
pub value_created: ComputedFromHeight<Cents, M>,
|
||||
pub value_destroyed: ComputedFromHeight<Cents, M>,
|
||||
@@ -53,7 +54,8 @@ impl RealizedCore {
|
||||
cfg.indexes,
|
||||
);
|
||||
|
||||
let net_realized_pnl = cfg.import("net_realized_pnl", v0)?;
|
||||
let net_realized_pnl = cfg.import("net_realized_pnl", v1)?;
|
||||
let net_realized_pnl_sum = cfg.import("net_realized_pnl", v1)?;
|
||||
|
||||
let value_created = cfg.import("value_created", v0)?;
|
||||
let value_destroyed = cfg.import("value_destroyed", v0)?;
|
||||
@@ -66,6 +68,7 @@ impl RealizedCore {
|
||||
realized_cap_delta: cfg.import("realized_cap_delta", v1)?,
|
||||
neg_realized_loss,
|
||||
net_realized_pnl,
|
||||
net_realized_pnl_sum,
|
||||
value_created,
|
||||
value_destroyed,
|
||||
value_created_sum,
|
||||
@@ -123,22 +126,18 @@ impl RealizedCore {
|
||||
) -> Result<()> {
|
||||
self.minimal.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
|
||||
self.net_realized_pnl
|
||||
.compute(starting_indexes.height, exit, |vec| {
|
||||
vec.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.minimal.realized_profit.height,
|
||||
&self.minimal.realized_loss.height,
|
||||
|(i, profit, loss, ..)| {
|
||||
(
|
||||
i,
|
||||
CentsSigned::new(profit.inner() as i64 - loss.inner() as i64),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
self.net_realized_pnl.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.minimal.realized_profit.height,
|
||||
&self.minimal.realized_loss.height,
|
||||
|(i, profit, loss, ..)| {
|
||||
(
|
||||
i,
|
||||
CentsSigned::new(profit.inner() as i64 - loss.inner() as i64),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -161,6 +160,13 @@ impl RealizedCore {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.net_realized_pnl_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_24h_ago,
|
||||
&self.net_realized_pnl.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.value_created_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_24h_ago,
|
||||
|
||||
@@ -56,6 +56,9 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
||||
|
||||
pub gross_pnl_sum: RollingWindows<Cents, M>,
|
||||
|
||||
pub net_realized_pnl_cumulative: ComputedFromHeight<CentsSigned, M>,
|
||||
pub net_realized_pnl_sum_extended: RollingWindowsFrom1w<CentsSigned, M>,
|
||||
|
||||
pub net_pnl_delta: RollingDelta1m<CentsSigned, CentsSigned, M>,
|
||||
pub net_pnl_delta_extended: RollingDeltaExcept1m<CentsSigned, CentsSigned, M>,
|
||||
pub net_pnl_change_1m_rel_to_realized_cap: PercentFromHeight<BasisPointsSigned32, M>,
|
||||
@@ -179,6 +182,8 @@ impl RealizedFull {
|
||||
capitulation_flow,
|
||||
profit_flow,
|
||||
gross_pnl_sum,
|
||||
net_realized_pnl_cumulative: cfg.import("net_realized_pnl_cumulative", Version::ONE)?,
|
||||
net_realized_pnl_sum_extended: cfg.import("net_realized_pnl", Version::ONE)?,
|
||||
net_pnl_delta: cfg.import("net_pnl_delta", Version::new(5))?,
|
||||
net_pnl_delta_extended: cfg.import("net_pnl_delta", Version::new(5))?,
|
||||
net_pnl_change_1m_rel_to_realized_cap: cfg
|
||||
@@ -300,6 +305,15 @@ impl RealizedFull {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.base.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
|
||||
self.net_realized_pnl_cumulative
|
||||
.height
|
||||
.compute_cumulative(
|
||||
starting_indexes.height,
|
||||
&self.base.core.net_realized_pnl.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.peak_regret
|
||||
.compute_rest(starting_indexes.height, exit)?;
|
||||
Ok(())
|
||||
@@ -324,6 +338,14 @@ impl RealizedFull {
|
||||
|
||||
let window_starts = blocks.count.window_starts();
|
||||
|
||||
// Extended rolling sum (1w, 1m, 1y) for net_realized_pnl
|
||||
self.net_realized_pnl_sum_extended.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.base.core.net_realized_pnl.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Extended rolling windows (1w, 1m, 1y) for value_created/destroyed/sopr
|
||||
self.value_created_sum_extended.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
@@ -434,13 +456,13 @@ impl RealizedFull {
|
||||
self.net_pnl_delta.compute(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1m_ago,
|
||||
&self.base.core.net_realized_pnl.cumulative.height,
|
||||
&self.net_realized_pnl_cumulative.height,
|
||||
exit,
|
||||
)?;
|
||||
self.net_pnl_delta_extended.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.base.core.net_realized_pnl.cumulative.height,
|
||||
&self.net_realized_pnl_cumulative.height,
|
||||
exit,
|
||||
)?;
|
||||
self.net_pnl_change_1m_rel_to_realized_cap
|
||||
|
||||
Reference in New Issue
Block a user