mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -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