mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-21 16:08:10 -07:00
global: big snapshot
This commit is contained in:
@@ -18,17 +18,39 @@ mod activity;
|
||||
/// `ExtendedAdjustedCohortMetrics`, Rust's auto-deref resolves these through `Deref`.
|
||||
macro_rules! impl_cohort_accessors {
|
||||
() => {
|
||||
fn filter(&self) -> &brk_cohort::Filter { &self.filter }
|
||||
fn supply(&self) -> &$crate::distribution::metrics::SupplyFull { &self.supply }
|
||||
fn supply_mut(&mut self) -> &mut $crate::distribution::metrics::SupplyFull { &mut self.supply }
|
||||
fn outputs(&self) -> &$crate::distribution::metrics::OutputsFull { &self.outputs }
|
||||
fn outputs_mut(&mut self) -> &mut $crate::distribution::metrics::OutputsFull { &mut self.outputs }
|
||||
fn activity(&self) -> &Self::ActivityVecs { &self.activity }
|
||||
fn activity_mut(&mut self) -> &mut Self::ActivityVecs { &mut self.activity }
|
||||
fn realized(&self) -> &Self::RealizedVecs { &self.realized }
|
||||
fn realized_mut(&mut self) -> &mut Self::RealizedVecs { &mut self.realized }
|
||||
fn unrealized(&self) -> &Self::UnrealizedVecs { &self.unrealized }
|
||||
fn unrealized_mut(&mut self) -> &mut Self::UnrealizedVecs { &mut self.unrealized }
|
||||
fn filter(&self) -> &brk_cohort::Filter {
|
||||
&self.filter
|
||||
}
|
||||
fn supply(&self) -> &$crate::distribution::metrics::SupplyCore {
|
||||
&self.supply
|
||||
}
|
||||
fn supply_mut(&mut self) -> &mut $crate::distribution::metrics::SupplyCore {
|
||||
&mut self.supply
|
||||
}
|
||||
fn outputs(&self) -> &$crate::distribution::metrics::OutputsBase {
|
||||
&self.outputs
|
||||
}
|
||||
fn outputs_mut(&mut self) -> &mut $crate::distribution::metrics::OutputsBase {
|
||||
&mut self.outputs
|
||||
}
|
||||
fn activity(&self) -> &Self::ActivityVecs {
|
||||
&self.activity
|
||||
}
|
||||
fn activity_mut(&mut self) -> &mut Self::ActivityVecs {
|
||||
&mut self.activity
|
||||
}
|
||||
fn realized(&self) -> &Self::RealizedVecs {
|
||||
&self.realized
|
||||
}
|
||||
fn realized_mut(&mut self) -> &mut Self::RealizedVecs {
|
||||
&mut self.realized
|
||||
}
|
||||
fn unrealized(&self) -> &Self::UnrealizedVecs {
|
||||
&self.unrealized
|
||||
}
|
||||
fn unrealized_mut(&mut self) -> &mut Self::UnrealizedVecs {
|
||||
&mut self.unrealized
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,29 +66,35 @@ mod unrealized;
|
||||
|
||||
pub use activity::{ActivityCore, ActivityFull, ActivityLike};
|
||||
pub use cohort::{
|
||||
AllCohortMetrics, BasicCohortMetrics, CoreCohortMetrics,
|
||||
ExtendedAdjustedCohortMetrics, ExtendedCohortMetrics, MinimalCohortMetrics, TypeCohortMetrics,
|
||||
AllCohortMetrics, BasicCohortMetrics, CoreCohortMetrics, ExtendedAdjustedCohortMetrics,
|
||||
ExtendedCohortMetrics, MinimalCohortMetrics, TypeCohortMetrics,
|
||||
};
|
||||
pub use config::ImportConfig;
|
||||
pub use cost_basis::CostBasis;
|
||||
pub use outputs::OutputsBase;
|
||||
pub use profitability::ProfitabilityMetrics;
|
||||
pub use outputs::{OutputsBase, OutputsFull};
|
||||
pub use realized::{
|
||||
AdjustedSopr, RealizedCore, RealizedFull, RealizedFullAccum, RealizedLike,
|
||||
RealizedMinimal,
|
||||
AdjustedSopr, RealizedCore, RealizedFull, RealizedFullAccum, RealizedLike, RealizedMinimal,
|
||||
};
|
||||
pub use relative::{
|
||||
RelativeForAll, RelativeToAll, RelativeWithExtended,
|
||||
pub use relative::{RelativeForAll, RelativeToAll, RelativeWithExtended};
|
||||
pub use supply::{SupplyBase, SupplyCore};
|
||||
pub use unrealized::{
|
||||
UnrealizedBase, UnrealizedBasic, UnrealizedCore, UnrealizedFull, UnrealizedLike,
|
||||
UnrealizedMinimal,
|
||||
};
|
||||
pub use supply::{SupplyBase, SupplyCore, SupplyFull};
|
||||
pub use unrealized::{UnrealizedBase, UnrealizedBasic, UnrealizedCore, UnrealizedFull, UnrealizedLike, UnrealizedMinimal};
|
||||
|
||||
use brk_cohort::Filter;
|
||||
use brk_error::Result;
|
||||
use brk_types::{Cents, Height, Indexes, Version};
|
||||
use vecdb::{AnyStoredVec, Exit, StorageMode};
|
||||
|
||||
use crate::{blocks, distribution::state::{WithoutCapital, WithCapital, CohortState, CostBasisData, CostBasisOps, CostBasisRaw, CoreRealizedState, MinimalRealizedState, RealizedOps, RealizedState}, prices};
|
||||
use crate::{
|
||||
distribution::state::{
|
||||
CohortState, CoreRealizedState, CostBasisData, CostBasisOps, CostBasisRaw,
|
||||
MinimalRealizedState, RealizedOps, RealizedState, WithCapital, WithoutCapital,
|
||||
},
|
||||
prices,
|
||||
};
|
||||
|
||||
pub trait CohortMetricsState {
|
||||
type Realized: RealizedOps;
|
||||
@@ -102,16 +130,18 @@ impl<M: StorageMode> CohortMetricsState for AllCohortMetrics<M> {
|
||||
type CostBasis = CostBasisData<WithCapital>;
|
||||
}
|
||||
|
||||
pub trait CohortMetricsBase: CohortMetricsState<Realized = RealizedState, CostBasis = CostBasisData<WithCapital>> + Send + Sync {
|
||||
pub trait CohortMetricsBase:
|
||||
CohortMetricsState<Realized = RealizedState, CostBasis = CostBasisData<WithCapital>> + Send + Sync
|
||||
{
|
||||
type ActivityVecs: ActivityLike;
|
||||
type RealizedVecs: RealizedLike;
|
||||
type UnrealizedVecs: UnrealizedLike;
|
||||
|
||||
fn filter(&self) -> &Filter;
|
||||
fn supply(&self) -> &SupplyFull;
|
||||
fn supply_mut(&mut self) -> &mut SupplyFull;
|
||||
fn outputs(&self) -> &OutputsFull;
|
||||
fn outputs_mut(&mut self) -> &mut OutputsFull;
|
||||
fn supply(&self) -> &SupplyCore;
|
||||
fn supply_mut(&mut self) -> &mut SupplyCore;
|
||||
fn outputs(&self) -> &OutputsBase;
|
||||
fn outputs_mut(&mut self) -> &mut OutputsBase;
|
||||
fn activity(&self) -> &Self::ActivityVecs;
|
||||
fn activity_mut(&mut self) -> &mut Self::ActivityVecs;
|
||||
fn realized(&self) -> &Self::RealizedVecs;
|
||||
@@ -120,20 +150,33 @@ pub trait CohortMetricsBase: CohortMetricsState<Realized = RealizedState, CostBa
|
||||
fn unrealized_mut(&mut self) -> &mut Self::UnrealizedVecs;
|
||||
|
||||
/// Convenience: access activity as `&ActivityCore` (via `ActivityLike::as_core`).
|
||||
fn activity_core(&self) -> &ActivityCore { self.activity().as_core() }
|
||||
fn activity_core_mut(&mut self) -> &mut ActivityCore { self.activity_mut().as_core_mut() }
|
||||
fn activity_core(&self) -> &ActivityCore {
|
||||
self.activity().as_core()
|
||||
}
|
||||
fn activity_core_mut(&mut self) -> &mut ActivityCore {
|
||||
self.activity_mut().as_core_mut()
|
||||
}
|
||||
|
||||
/// Convenience: access realized as `&RealizedCore` (via `RealizedLike::as_core`).
|
||||
fn realized_core(&self) -> &RealizedCore { self.realized().as_core() }
|
||||
fn realized_core_mut(&mut self) -> &mut RealizedCore { self.realized_mut().as_core_mut() }
|
||||
fn realized_core(&self) -> &RealizedCore {
|
||||
self.realized().as_core()
|
||||
}
|
||||
fn realized_core_mut(&mut self) -> &mut RealizedCore {
|
||||
self.realized_mut().as_core_mut()
|
||||
}
|
||||
|
||||
/// Convenience: access unrealized as `&UnrealizedBase` (via `UnrealizedLike::as_base`).
|
||||
fn unrealized_base(&self) -> &UnrealizedBase { self.unrealized().as_base() }
|
||||
fn unrealized_base_mut(&mut self) -> &mut UnrealizedBase { self.unrealized_mut().as_base_mut() }
|
||||
fn unrealized_base(&self) -> &UnrealizedBase {
|
||||
self.unrealized().as_base()
|
||||
}
|
||||
fn unrealized_base_mut(&mut self) -> &mut UnrealizedBase {
|
||||
self.unrealized_mut().as_base_mut()
|
||||
}
|
||||
|
||||
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
self.supply_mut().validate_computed_versions(base_version)?;
|
||||
self.activity_mut().validate_computed_versions(base_version)?;
|
||||
self.activity_mut()
|
||||
.validate_computed_versions(base_version)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -164,7 +207,11 @@ pub trait CohortMetricsBase: CohortMetricsState<Realized = RealizedState, CostBa
|
||||
.min(self.unrealized().min_stateful_len())
|
||||
}
|
||||
|
||||
fn truncate_push(&mut self, height: Height, state: &CohortState<RealizedState, CostBasisData<WithCapital>>) -> Result<()> {
|
||||
fn truncate_push(
|
||||
&mut self,
|
||||
height: Height,
|
||||
state: &CohortState<RealizedState, CostBasisData<WithCapital>>,
|
||||
) -> Result<()> {
|
||||
self.supply_mut().truncate_push(height, state)?;
|
||||
self.outputs_mut().truncate_push(height, state)?;
|
||||
self.activity_mut().truncate_push(height, state)?;
|
||||
@@ -175,27 +222,22 @@ pub trait CohortMetricsBase: CohortMetricsState<Realized = RealizedState, CostBa
|
||||
/// First phase of computed metrics (indexes from height).
|
||||
fn compute_rest_part1(
|
||||
&mut self,
|
||||
blocks: &blocks::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.supply_mut()
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
self.supply_mut()
|
||||
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
self.outputs_mut()
|
||||
.compute_rest(blocks, starting_indexes, exit)?;
|
||||
self.activity_mut()
|
||||
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
.compute_rest_part1(starting_indexes, exit)?;
|
||||
self.activity_core_mut()
|
||||
.compute_sent_profitability(blocks, prices, starting_indexes, exit)?;
|
||||
.compute_sent_profitability(prices, starting_indexes, exit)?;
|
||||
|
||||
self.realized_mut()
|
||||
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||
.compute_rest_part1(starting_indexes, exit)?;
|
||||
|
||||
self.unrealized_mut()
|
||||
.compute_rest(blocks, prices, starting_indexes, exit)?;
|
||||
.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
self.unrealized_mut()
|
||||
.compute_net_sentiment_height(starting_indexes, exit)?;
|
||||
@@ -232,7 +274,10 @@ pub trait CohortMetricsBase: CohortMetricsState<Realized = RealizedState, CostBa
|
||||
)?;
|
||||
self.unrealized_base_mut().compute_from_stateful(
|
||||
starting_indexes,
|
||||
&others.iter().map(|v| v.unrealized_base()).collect::<Vec<_>>(),
|
||||
&others
|
||||
.iter()
|
||||
.map(|v| v.unrealized_base())
|
||||
.collect::<Vec<_>>(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user