mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -61,8 +61,6 @@ impl TypeCohortMetrics {
|
||||
self.supply.compute(prices, starting_indexes.height, exit)?;
|
||||
self.realized
|
||||
.compute_rest_part1(starting_indexes, exit)?;
|
||||
self.unrealized
|
||||
.compute_rest(starting_indexes.height, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -42,14 +42,14 @@ impl RelativeExtendedOwnMarketCap {
|
||||
self.unrealized_profit_to_own_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.profit.base.usd.height,
|
||||
&unrealized.profit.usd.height,
|
||||
own_market_cap,
|
||||
exit,
|
||||
)?;
|
||||
self.unrealized_loss_to_own_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||
max_from,
|
||||
&unrealized.loss.base.usd.height,
|
||||
&unrealized.loss.usd.height,
|
||||
own_market_cap,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -43,14 +43,14 @@ impl RelativeExtendedOwnPnl {
|
||||
self.unrealized_profit_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.profit.base.usd.height,
|
||||
&unrealized.profit.usd.height,
|
||||
gross_pnl_usd,
|
||||
exit,
|
||||
)?;
|
||||
self.unrealized_loss_to_own_gross_pnl
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.loss.base.usd.height,
|
||||
&unrealized.loss.usd.height,
|
||||
gross_pnl_usd,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -64,14 +64,14 @@ impl RelativeFull {
|
||||
self.unrealized_profit_to_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.profit.base.usd.height,
|
||||
&unrealized.profit.usd.height,
|
||||
market_cap,
|
||||
exit,
|
||||
)?;
|
||||
self.unrealized_loss_to_mcap
|
||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||
max_from,
|
||||
&unrealized.loss.base.usd.height,
|
||||
&unrealized.loss.usd.height,
|
||||
market_cap,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, Dollars, Height, Indexes, Version};
|
||||
use brk_types::{Cents, Dollars, Indexes, Version};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableCloneableVec, Rw, StorageMode, WritableVec};
|
||||
|
||||
use crate::{
|
||||
distribution::{metrics::ImportConfig, state::UnrealizedState},
|
||||
internal::{FiatPerBlockCumulativeWithSums, LazyPerBlock, NegCentsUnsignedToDollars},
|
||||
internal::{FiatPerBlock, LazyPerBlock, NegCentsUnsignedToDollars},
|
||||
};
|
||||
|
||||
use super::UnrealizedMinimal;
|
||||
@@ -17,8 +17,8 @@ pub struct UnrealizedBasic<M: StorageMode = Rw> {
|
||||
#[deref_mut]
|
||||
#[traversable(flatten)]
|
||||
pub minimal: UnrealizedMinimal<M>,
|
||||
pub profit: FiatPerBlockCumulativeWithSums<Cents, M>,
|
||||
pub loss: FiatPerBlockCumulativeWithSums<Cents, M>,
|
||||
pub profit: FiatPerBlock<Cents, M>,
|
||||
pub loss: FiatPerBlock<Cents, M>,
|
||||
#[traversable(wrap = "loss", rename = "negative")]
|
||||
pub neg_loss: LazyPerBlock<Dollars, Cents>,
|
||||
}
|
||||
@@ -27,13 +27,13 @@ impl UnrealizedBasic {
|
||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let v1 = Version::ONE;
|
||||
|
||||
let loss: FiatPerBlockCumulativeWithSums<Cents> = cfg.import("unrealized_loss", v1)?;
|
||||
let loss: FiatPerBlock<Cents> = cfg.import("unrealized_loss", v1)?;
|
||||
|
||||
let neg_loss = LazyPerBlock::from_computed::<NegCentsUnsignedToDollars>(
|
||||
&cfg.name("neg_unrealized_loss"),
|
||||
cfg.version,
|
||||
loss.base.cents.height.read_only_boxed_clone(),
|
||||
&loss.base.cents,
|
||||
loss.cents.height.read_only_boxed_clone(),
|
||||
&loss.cents,
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
@@ -46,22 +46,19 @@ impl UnrealizedBasic {
|
||||
|
||||
pub(crate) fn min_stateful_len(&self) -> usize {
|
||||
self.profit
|
||||
.base
|
||||
.cents
|
||||
.height
|
||||
.len()
|
||||
.min(self.loss.base.cents.height.len())
|
||||
.min(self.loss.cents.height.len())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn push_state(&mut self, state: &UnrealizedState) {
|
||||
self.profit
|
||||
.base
|
||||
.cents
|
||||
.height
|
||||
.push(state.unrealized_profit);
|
||||
self.loss
|
||||
.base
|
||||
.cents
|
||||
.height
|
||||
.push(state.unrealized_loss);
|
||||
@@ -69,8 +66,8 @@ impl UnrealizedBasic {
|
||||
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
vec![
|
||||
&mut self.profit.base.cents.height as &mut dyn AnyStoredVec,
|
||||
&mut self.loss.base.cents.height,
|
||||
&mut self.profit.cents.height as &mut dyn AnyStoredVec,
|
||||
&mut self.loss.cents.height,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -80,18 +77,8 @@ impl UnrealizedBasic {
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
sum_others!(self, starting_indexes, others, exit; profit.base.cents.height);
|
||||
sum_others!(self, starting_indexes, others, exit; loss.base.cents.height);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn compute_rest(
|
||||
&mut self,
|
||||
max_from: Height,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.profit.compute_rest(max_from, exit)?;
|
||||
self.loss.compute_rest(max_from, exit)?;
|
||||
sum_others!(self, starting_indexes, others, exit; profit.cents.height);
|
||||
sum_others!(self, starting_indexes, others, exit; loss.cents.height);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,16 +65,13 @@ impl UnrealizedCore {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.basic
|
||||
.compute_rest(starting_indexes.height, exit)?;
|
||||
|
||||
self.net_pnl
|
||||
.cents
|
||||
.height
|
||||
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
||||
starting_indexes.height,
|
||||
&self.basic.profit.base.cents.height,
|
||||
&self.basic.loss.base.cents.height,
|
||||
&self.basic.profit.cents.height,
|
||||
&self.basic.loss.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@ impl UnrealizedFull {
|
||||
|
||||
self.gross_pnl.cents.height.compute_add(
|
||||
starting_indexes.height,
|
||||
&self.inner.core.basic.profit.base.cents.height,
|
||||
&self.inner.core.basic.loss.base.cents.height,
|
||||
&self.inner.core.basic.profit.cents.height,
|
||||
&self.inner.core.basic.loss.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user