mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -1077,7 +1077,7 @@ pub struct CapGrossInvestorLossMvrvNetPeakPriceProfitSellSoprPattern {
|
||||
pub loss: BaseCapitulationCumulativeNegativeSumToValuePattern,
|
||||
pub mvrv: SeriesPattern1<StoredF32>,
|
||||
pub net_pnl: BaseChangeCumulativeDeltaSumToPattern,
|
||||
pub peak_regret: BaseCumulativeToPattern,
|
||||
pub peak_regret: BaseCumulativeSumToPattern,
|
||||
pub price: BpsCentsPercentilesRatioSatsSmaStdUsdPattern,
|
||||
pub profit: BaseCumulativeDistributionSumToValuePattern,
|
||||
pub profit_to_loss_ratio: _1m1w1y24hPattern<StoredF64>,
|
||||
@@ -1259,7 +1259,7 @@ pub struct BaseCapitulationCumulativeNegativeSumToValuePattern {
|
||||
pub base: CentsUsdPattern2,
|
||||
pub capitulation_flow: SeriesPattern1<Dollars>,
|
||||
pub cumulative: CentsUsdPattern2,
|
||||
pub negative: SeriesPattern1<Dollars>,
|
||||
pub negative: BaseSumPattern,
|
||||
pub sum: _1m1w1y24hPattern4,
|
||||
pub to_rcap: BpsPercentRatioPattern4,
|
||||
pub value_created: BaseCumulativeSumPattern<Cents>,
|
||||
@@ -2042,7 +2042,7 @@ impl BaseCumulativeDeltaSumPattern {
|
||||
pub struct BaseCumulativeNegativeSumPattern {
|
||||
pub base: CentsUsdPattern2,
|
||||
pub cumulative: CentsUsdPattern2,
|
||||
pub negative: SeriesPattern1<Dollars>,
|
||||
pub negative: BaseSumPattern,
|
||||
pub sum: _1m1w1y24hPattern4,
|
||||
}
|
||||
|
||||
@@ -2052,12 +2052,32 @@ impl BaseCumulativeNegativeSumPattern {
|
||||
Self {
|
||||
base: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_loss")),
|
||||
cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "realized_loss_cumulative")),
|
||||
negative: SeriesPattern1::new(client.clone(), _m(&acc, "neg_realized_loss")),
|
||||
negative: BaseSumPattern::new(client.clone(), _m(&acc, "neg_realized_loss")),
|
||||
sum: _1m1w1y24hPattern4::new(client.clone(), _m(&acc, "realized_loss_sum")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BaseCumulativeSumToPattern {
|
||||
pub base: CentsUsdPattern2,
|
||||
pub cumulative: CentsUsdPattern2,
|
||||
pub sum: _1m1w1y24hPattern4,
|
||||
pub to_rcap: BpsPercentRatioPattern4,
|
||||
}
|
||||
|
||||
impl BaseCumulativeSumToPattern {
|
||||
/// Create a new pattern node with accumulated series name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
|
||||
Self {
|
||||
base: CentsUsdPattern2::new(client.clone(), acc.clone()),
|
||||
cumulative: CentsUsdPattern2::new(client.clone(), _m(&acc, "cumulative")),
|
||||
sum: _1m1w1y24hPattern4::new(client.clone(), _m(&acc, "sum")),
|
||||
to_rcap: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "to_rcap")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BothReactivatedReceivingSendingPattern {
|
||||
pub both: _1m1w1y24hBasePattern<StoredU32>,
|
||||
@@ -2244,24 +2264,6 @@ impl BaseCumulativeSumPattern4 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BaseCumulativeToPattern {
|
||||
pub base: SeriesPattern1<Cents>,
|
||||
pub cumulative: SeriesPattern1<Cents>,
|
||||
pub to_rcap: BpsPercentRatioPattern4,
|
||||
}
|
||||
|
||||
impl BaseCumulativeToPattern {
|
||||
/// Create a new pattern node with accumulated series name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
|
||||
Self {
|
||||
base: SeriesPattern1::new(client.clone(), acc.clone()),
|
||||
cumulative: SeriesPattern1::new(client.clone(), _m(&acc, "cumulative")),
|
||||
to_rcap: BpsPercentRatioPattern4::new(client.clone(), _m(&acc, "to_rcap")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BaseCumulativeSumPattern3 {
|
||||
pub base: CentsUsdPattern2,
|
||||
@@ -2682,6 +2684,22 @@ impl AllSthPattern {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BaseSumPattern {
|
||||
pub base: SeriesPattern1<Dollars>,
|
||||
pub sum: _1m1w1y24hPattern<Dollars>,
|
||||
}
|
||||
|
||||
impl BaseSumPattern {
|
||||
/// Create a new pattern node with accumulated series name.
|
||||
pub fn new(client: Arc<BrkClientBase>, acc: String) -> Self {
|
||||
Self {
|
||||
base: SeriesPattern1::new(client.clone(), acc.clone()),
|
||||
sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sum")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pattern struct for repeated tree structure.
|
||||
pub struct BaseDeltaPattern {
|
||||
pub base: SeriesPattern1<StoredU64>,
|
||||
@@ -6322,7 +6340,7 @@ pub struct SeriesTree_Cohorts_Utxo_All_Realized {
|
||||
pub net_pnl: BaseChangeCumulativeDeltaSumToPattern,
|
||||
pub gross_pnl: BaseCumulativeSumPattern3,
|
||||
pub sell_side_risk_ratio: _1m1w1y24hPattern6,
|
||||
pub peak_regret: BaseCumulativeToPattern,
|
||||
pub peak_regret: BaseCumulativeSumToPattern,
|
||||
pub investor: PricePattern,
|
||||
pub profit_to_loss_ratio: _1m1w1y24hPattern<StoredF64>,
|
||||
}
|
||||
@@ -6339,7 +6357,7 @@ impl SeriesTree_Cohorts_Utxo_All_Realized {
|
||||
net_pnl: BaseChangeCumulativeDeltaSumToPattern::new(client.clone(), "net".to_string()),
|
||||
gross_pnl: BaseCumulativeSumPattern3::new(client.clone(), "realized_gross_pnl".to_string()),
|
||||
sell_side_risk_ratio: _1m1w1y24hPattern6::new(client.clone(), "sell_side_risk_ratio".to_string()),
|
||||
peak_regret: BaseCumulativeToPattern::new(client.clone(), "realized_peak_regret".to_string()),
|
||||
peak_regret: BaseCumulativeSumToPattern::new(client.clone(), "realized_peak_regret".to_string()),
|
||||
investor: PricePattern::new(client.clone(), "investor_price".to_string()),
|
||||
profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), "realized_profit_to_loss_ratio".to_string()),
|
||||
}
|
||||
@@ -6376,7 +6394,7 @@ pub struct SeriesTree_Cohorts_Utxo_All_Realized_Loss {
|
||||
pub base: CentsUsdPattern2,
|
||||
pub cumulative: CentsUsdPattern2,
|
||||
pub sum: _1m1w1y24hPattern4,
|
||||
pub negative: SeriesPattern1<Dollars>,
|
||||
pub negative: BaseSumPattern,
|
||||
pub to_rcap: BpsPercentRatioPattern4,
|
||||
pub value_created: BaseCumulativeSumPattern<Cents>,
|
||||
pub value_destroyed: BaseCumulativeSumPattern<Cents>,
|
||||
@@ -6389,7 +6407,7 @@ impl SeriesTree_Cohorts_Utxo_All_Realized_Loss {
|
||||
base: CentsUsdPattern2::new(client.clone(), "realized_loss".to_string()),
|
||||
cumulative: CentsUsdPattern2::new(client.clone(), "realized_loss_cumulative".to_string()),
|
||||
sum: _1m1w1y24hPattern4::new(client.clone(), "realized_loss_sum".to_string()),
|
||||
negative: SeriesPattern1::new(client.clone(), "neg_realized_loss".to_string()),
|
||||
negative: BaseSumPattern::new(client.clone(), "neg_realized_loss".to_string()),
|
||||
to_rcap: BpsPercentRatioPattern4::new(client.clone(), "realized_loss_to_rcap".to_string()),
|
||||
value_created: BaseCumulativeSumPattern::new(client.clone(), "loss_value_created".to_string()),
|
||||
value_destroyed: BaseCumulativeSumPattern::new(client.clone(), "loss_value_destroyed".to_string()),
|
||||
@@ -6817,7 +6835,7 @@ pub struct SeriesTree_Cohorts_Utxo_Sth_Realized {
|
||||
pub net_pnl: BaseChangeCumulativeDeltaSumToPattern,
|
||||
pub gross_pnl: BaseCumulativeSumPattern3,
|
||||
pub sell_side_risk_ratio: _1m1w1y24hPattern6,
|
||||
pub peak_regret: BaseCumulativeToPattern,
|
||||
pub peak_regret: BaseCumulativeSumToPattern,
|
||||
pub investor: PricePattern,
|
||||
pub profit_to_loss_ratio: _1m1w1y24hPattern<StoredF64>,
|
||||
}
|
||||
@@ -6834,7 +6852,7 @@ impl SeriesTree_Cohorts_Utxo_Sth_Realized {
|
||||
net_pnl: BaseChangeCumulativeDeltaSumToPattern::new(client.clone(), "sth_net".to_string()),
|
||||
gross_pnl: BaseCumulativeSumPattern3::new(client.clone(), "sth_realized_gross_pnl".to_string()),
|
||||
sell_side_risk_ratio: _1m1w1y24hPattern6::new(client.clone(), "sth_sell_side_risk_ratio".to_string()),
|
||||
peak_regret: BaseCumulativeToPattern::new(client.clone(), "sth_realized_peak_regret".to_string()),
|
||||
peak_regret: BaseCumulativeSumToPattern::new(client.clone(), "sth_realized_peak_regret".to_string()),
|
||||
investor: PricePattern::new(client.clone(), "sth_investor_price".to_string()),
|
||||
profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), "sth_realized_profit_to_loss_ratio".to_string()),
|
||||
}
|
||||
@@ -6871,7 +6889,7 @@ pub struct SeriesTree_Cohorts_Utxo_Sth_Realized_Loss {
|
||||
pub base: CentsUsdPattern2,
|
||||
pub cumulative: CentsUsdPattern2,
|
||||
pub sum: _1m1w1y24hPattern4,
|
||||
pub negative: SeriesPattern1<Dollars>,
|
||||
pub negative: BaseSumPattern,
|
||||
pub to_rcap: BpsPercentRatioPattern4,
|
||||
pub value_created: BaseCumulativeSumPattern<Cents>,
|
||||
pub value_destroyed: BaseCumulativeSumPattern<Cents>,
|
||||
@@ -6884,7 +6902,7 @@ impl SeriesTree_Cohorts_Utxo_Sth_Realized_Loss {
|
||||
base: CentsUsdPattern2::new(client.clone(), "sth_realized_loss".to_string()),
|
||||
cumulative: CentsUsdPattern2::new(client.clone(), "sth_realized_loss_cumulative".to_string()),
|
||||
sum: _1m1w1y24hPattern4::new(client.clone(), "sth_realized_loss_sum".to_string()),
|
||||
negative: SeriesPattern1::new(client.clone(), "sth_neg_realized_loss".to_string()),
|
||||
negative: BaseSumPattern::new(client.clone(), "sth_neg_realized_loss".to_string()),
|
||||
to_rcap: BpsPercentRatioPattern4::new(client.clone(), "sth_realized_loss_to_rcap".to_string()),
|
||||
value_created: BaseCumulativeSumPattern::new(client.clone(), "sth_loss_value_created".to_string()),
|
||||
value_destroyed: BaseCumulativeSumPattern::new(client.clone(), "sth_loss_value_destroyed".to_string()),
|
||||
@@ -7255,7 +7273,7 @@ pub struct SeriesTree_Cohorts_Utxo_Lth_Realized {
|
||||
pub net_pnl: BaseChangeCumulativeDeltaSumToPattern,
|
||||
pub gross_pnl: BaseCumulativeSumPattern3,
|
||||
pub sell_side_risk_ratio: _1m1w1y24hPattern6,
|
||||
pub peak_regret: BaseCumulativeToPattern,
|
||||
pub peak_regret: BaseCumulativeSumToPattern,
|
||||
pub investor: PricePattern,
|
||||
pub profit_to_loss_ratio: _1m1w1y24hPattern<StoredF64>,
|
||||
}
|
||||
@@ -7272,7 +7290,7 @@ impl SeriesTree_Cohorts_Utxo_Lth_Realized {
|
||||
net_pnl: BaseChangeCumulativeDeltaSumToPattern::new(client.clone(), "lth_net".to_string()),
|
||||
gross_pnl: BaseCumulativeSumPattern3::new(client.clone(), "lth_realized_gross_pnl".to_string()),
|
||||
sell_side_risk_ratio: _1m1w1y24hPattern6::new(client.clone(), "lth_sell_side_risk_ratio".to_string()),
|
||||
peak_regret: BaseCumulativeToPattern::new(client.clone(), "lth_realized_peak_regret".to_string()),
|
||||
peak_regret: BaseCumulativeSumToPattern::new(client.clone(), "lth_realized_peak_regret".to_string()),
|
||||
investor: PricePattern::new(client.clone(), "lth_investor_price".to_string()),
|
||||
profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), "lth_realized_profit_to_loss_ratio".to_string()),
|
||||
}
|
||||
@@ -7309,7 +7327,7 @@ pub struct SeriesTree_Cohorts_Utxo_Lth_Realized_Loss {
|
||||
pub base: CentsUsdPattern2,
|
||||
pub cumulative: CentsUsdPattern2,
|
||||
pub sum: _1m1w1y24hPattern4,
|
||||
pub negative: SeriesPattern1<Dollars>,
|
||||
pub negative: BaseSumPattern,
|
||||
pub to_rcap: BpsPercentRatioPattern4,
|
||||
pub value_created: BaseCumulativeSumPattern<Cents>,
|
||||
pub value_destroyed: BaseCumulativeSumPattern<Cents>,
|
||||
@@ -7322,7 +7340,7 @@ impl SeriesTree_Cohorts_Utxo_Lth_Realized_Loss {
|
||||
base: CentsUsdPattern2::new(client.clone(), "lth_realized_loss".to_string()),
|
||||
cumulative: CentsUsdPattern2::new(client.clone(), "lth_realized_loss_cumulative".to_string()),
|
||||
sum: _1m1w1y24hPattern4::new(client.clone(), "lth_realized_loss_sum".to_string()),
|
||||
negative: SeriesPattern1::new(client.clone(), "lth_neg_realized_loss".to_string()),
|
||||
negative: BaseSumPattern::new(client.clone(), "lth_neg_realized_loss".to_string()),
|
||||
to_rcap: BpsPercentRatioPattern4::new(client.clone(), "lth_realized_loss_to_rcap".to_string()),
|
||||
value_created: BaseCumulativeSumPattern::new(client.clone(), "lth_loss_value_created".to_string()),
|
||||
value_destroyed: BaseCumulativeSumPattern::new(client.clone(), "lth_loss_value_destroyed".to_string()),
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
distribution::state::{CohortState, CostBasisOps, RealizedOps},
|
||||
internal::{
|
||||
FiatPerBlockCumulativeWithSumsAndDeltas, LazyPerBlock, NegCentsUnsignedToDollars,
|
||||
RatioCents64, RollingWindow24hPerBlock,
|
||||
RatioCents64, RollingWindow24hPerBlock, Windows,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
@@ -19,6 +19,13 @@ use crate::distribution::metrics::ImportConfig;
|
||||
|
||||
use super::RealizedMinimal;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct NegRealizedLoss {
|
||||
#[traversable(flatten)]
|
||||
pub base: LazyPerBlock<Dollars, Cents>,
|
||||
pub sum: Windows<LazyPerBlock<Dollars, Cents>>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedSoprCore<M: StorageMode = Rw> {
|
||||
pub ratio: RollingWindow24hPerBlock<StoredF64, M>,
|
||||
@@ -32,7 +39,7 @@ pub struct RealizedCore<M: StorageMode = Rw> {
|
||||
pub minimal: RealizedMinimal<M>,
|
||||
|
||||
#[traversable(wrap = "loss", rename = "negative")]
|
||||
pub neg_loss: LazyPerBlock<Dollars, Cents>,
|
||||
pub neg_loss: NegRealizedLoss,
|
||||
pub net_pnl: FiatPerBlockCumulativeWithSumsAndDeltas<CentsSigned, CentsSigned, BasisPointsSigned32, M>,
|
||||
pub sopr: RealizedSoprCore<M>,
|
||||
}
|
||||
@@ -43,13 +50,27 @@ impl RealizedCore {
|
||||
|
||||
let minimal = RealizedMinimal::forced_import(cfg)?;
|
||||
|
||||
let neg_realized_loss = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
||||
let neg_loss_base = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
||||
&cfg.name("neg_realized_loss"),
|
||||
cfg.version + Version::ONE,
|
||||
minimal.loss.base.cents.height.read_only_boxed_clone(),
|
||||
cfg.indexes,
|
||||
);
|
||||
|
||||
let neg_loss_sum = minimal.loss.sum.0.map_with_suffix(|suffix, slot| {
|
||||
LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
||||
&cfg.name(&format!("neg_realized_loss_sum_{suffix}")),
|
||||
cfg.version + Version::ONE,
|
||||
slot.cents.height.read_only_boxed_clone(),
|
||||
cfg.indexes,
|
||||
)
|
||||
});
|
||||
|
||||
let neg_loss = NegRealizedLoss {
|
||||
base: neg_loss_base,
|
||||
sum: neg_loss_sum,
|
||||
};
|
||||
|
||||
let net_pnl = FiatPerBlockCumulativeWithSumsAndDeltas::forced_import(
|
||||
cfg.db,
|
||||
&cfg.name("net_realized_pnl"),
|
||||
@@ -61,7 +82,7 @@ impl RealizedCore {
|
||||
|
||||
Ok(Self {
|
||||
minimal,
|
||||
neg_loss: neg_realized_loss,
|
||||
neg_loss,
|
||||
net_pnl,
|
||||
sopr: RealizedSoprCore {
|
||||
ratio: cfg.import("sopr", v1)?,
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::{
|
||||
blocks,
|
||||
distribution::state::{WithCapital, CohortState, CostBasisData, RealizedState},
|
||||
internal::{
|
||||
CentsUnsignedToDollars, PerBlockCumulative,
|
||||
CentsUnsignedToDollars,
|
||||
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
|
||||
LazyPerBlock, PercentPerBlock, PercentRollingWindows,
|
||||
PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
|
||||
@@ -63,7 +63,7 @@ pub struct RealizedSopr<M: StorageMode = Rw> {
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub value: PerBlockCumulative<Cents, M>,
|
||||
pub value: FiatPerBlockCumulativeWithSums<Cents, M>,
|
||||
pub to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ impl RealizedFull {
|
||||
.min(self.investor.price.cents.height.len())
|
||||
.min(self.cap_raw.len())
|
||||
.min(self.investor.cap_raw.len())
|
||||
.min(self.peak_regret.value.base.height.len())
|
||||
.min(self.peak_regret.value.base.cents.height.len())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -269,6 +269,7 @@ impl RealizedFull {
|
||||
self.peak_regret
|
||||
.value
|
||||
.base
|
||||
.cents
|
||||
.height
|
||||
.push(state.realized.peak_regret());
|
||||
}
|
||||
@@ -282,7 +283,7 @@ impl RealizedFull {
|
||||
vecs.push(&mut self.investor.price.cents.height);
|
||||
vecs.push(&mut self.cap_raw as &mut dyn AnyStoredVec);
|
||||
vecs.push(&mut self.investor.cap_raw as &mut dyn AnyStoredVec);
|
||||
vecs.push(&mut self.peak_regret.value.base.height);
|
||||
vecs.push(&mut self.peak_regret.value.base.cents.height);
|
||||
vecs
|
||||
}
|
||||
|
||||
@@ -346,6 +347,7 @@ impl RealizedFull {
|
||||
self.peak_regret
|
||||
.value
|
||||
.base
|
||||
.cents
|
||||
.height
|
||||
.push(accum.peak_regret());
|
||||
}
|
||||
@@ -470,7 +472,7 @@ impl RealizedFull {
|
||||
.to_rcap
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||
starting_indexes.height,
|
||||
&self.peak_regret.value.base.height,
|
||||
&self.peak_regret.value.base.cents.height,
|
||||
&self.core.minimal.cap.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Reference in New Issue
Block a user