global: snapshot

This commit is contained in:
nym21
2026-03-19 14:13:37 +01:00
parent b18cca92ab
commit 2df9ee4a1d
7 changed files with 569 additions and 876 deletions

View File

@@ -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)?,

View File

@@ -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,
)?;