mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-28 11:18:17 -07:00
global: snapshot
This commit is contained in:
@@ -5182,9 +5182,9 @@ pub struct MetricsTree_Market_Ath {
|
||||
pub high: CentsSatsUsdPattern,
|
||||
pub drawdown: BpsPercentRatioPattern5,
|
||||
pub days_since: MetricPattern1<StoredF32>,
|
||||
pub years_since: MetricPattern2<StoredF32>,
|
||||
pub years_since: MetricPattern1<StoredF32>,
|
||||
pub max_days_between: MetricPattern1<StoredF32>,
|
||||
pub max_years_between: MetricPattern2<StoredF32>,
|
||||
pub max_years_between: MetricPattern1<StoredF32>,
|
||||
}
|
||||
|
||||
impl MetricsTree_Market_Ath {
|
||||
@@ -5193,9 +5193,9 @@ impl MetricsTree_Market_Ath {
|
||||
high: CentsSatsUsdPattern::new(client.clone(), "price_ath".to_string()),
|
||||
drawdown: BpsPercentRatioPattern5::new(client.clone(), "price_drawdown".to_string()),
|
||||
days_since: MetricPattern1::new(client.clone(), "days_since_price_ath".to_string()),
|
||||
years_since: MetricPattern2::new(client.clone(), "years_since_price_ath".to_string()),
|
||||
years_since: MetricPattern1::new(client.clone(), "years_since_price_ath".to_string()),
|
||||
max_days_between: MetricPattern1::new(client.clone(), "max_days_between_price_ath".to_string()),
|
||||
max_years_between: MetricPattern2::new(client.clone(), "max_years_between_price_ath".to_string()),
|
||||
max_years_between: MetricPattern1::new(client.clone(), "max_years_between_price_ath".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,22 +313,22 @@ impl RealizedFull {
|
||||
.value_created
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.profit_value_created)?;
|
||||
.truncate_push(height, accum.profit_value_created())?;
|
||||
self.profit
|
||||
.value_destroyed
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.profit_value_destroyed)?;
|
||||
.truncate_push(height, accum.profit_value_destroyed())?;
|
||||
self.loss
|
||||
.value_created
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.loss_value_created)?;
|
||||
.truncate_push(height, accum.loss_value_created())?;
|
||||
self.loss
|
||||
.value_destroyed
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.loss_value_destroyed)?;
|
||||
.truncate_push(height, accum.loss_value_destroyed())?;
|
||||
self.cap_raw
|
||||
.truncate_push(height, accum.cap_raw)?;
|
||||
self.investor
|
||||
@@ -353,7 +353,7 @@ impl RealizedFull {
|
||||
.value
|
||||
.base
|
||||
.height
|
||||
.truncate_push(height, accum.peak_regret)?;
|
||||
.truncate_push(height, accum.peak_regret())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -600,23 +600,43 @@ impl RealizedFull {
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RealizedFullAccum {
|
||||
pub(crate) profit_value_created: Cents,
|
||||
pub(crate) profit_value_destroyed: Cents,
|
||||
pub(crate) loss_value_created: Cents,
|
||||
pub(crate) loss_value_destroyed: Cents,
|
||||
profit_value_created: CentsSats,
|
||||
profit_value_destroyed: CentsSats,
|
||||
loss_value_created: CentsSats,
|
||||
loss_value_destroyed: CentsSats,
|
||||
pub(crate) cap_raw: CentsSats,
|
||||
pub(crate) investor_cap_raw: CentsSquaredSats,
|
||||
pub(crate) peak_regret: Cents,
|
||||
peak_regret: CentsSats,
|
||||
}
|
||||
|
||||
impl RealizedFullAccum {
|
||||
pub(crate) fn add(&mut self, state: &RealizedState) {
|
||||
self.profit_value_created += state.profit_value_created();
|
||||
self.profit_value_destroyed += state.profit_value_destroyed();
|
||||
self.loss_value_created += state.loss_value_created();
|
||||
self.loss_value_destroyed += state.loss_value_destroyed();
|
||||
self.profit_value_created += CentsSats::new(state.profit_value_created_raw());
|
||||
self.profit_value_destroyed += CentsSats::new(state.profit_value_destroyed_raw());
|
||||
self.loss_value_created += CentsSats::new(state.loss_value_created_raw());
|
||||
self.loss_value_destroyed += CentsSats::new(state.loss_value_destroyed_raw());
|
||||
self.cap_raw += state.cap_raw();
|
||||
self.investor_cap_raw += state.investor_cap_raw();
|
||||
self.peak_regret += state.peak_regret();
|
||||
self.peak_regret += CentsSats::new(state.peak_regret_raw());
|
||||
}
|
||||
|
||||
pub(crate) fn profit_value_created(&self) -> Cents {
|
||||
self.profit_value_created.to_cents()
|
||||
}
|
||||
|
||||
pub(crate) fn profit_value_destroyed(&self) -> Cents {
|
||||
self.profit_value_destroyed.to_cents()
|
||||
}
|
||||
|
||||
pub(crate) fn loss_value_created(&self) -> Cents {
|
||||
self.loss_value_created.to_cents()
|
||||
}
|
||||
|
||||
pub(crate) fn loss_value_destroyed(&self) -> Cents {
|
||||
self.loss_value_destroyed.to_cents()
|
||||
}
|
||||
|
||||
pub(crate) fn peak_regret(&self) -> Cents {
|
||||
self.peak_regret.to_cents()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
use vecdb::{Database, ReadableCloneableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{PerBlock, DaysToYears, DerivedResolutions, PercentPerBlock, Price},
|
||||
internal::{DaysToYears, LazyPerBlock, PerBlock, PercentPerBlock, Price},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
@@ -23,18 +23,20 @@ impl Vecs {
|
||||
let max_days_between =
|
||||
PerBlock::forced_import(db, "max_days_between_price_ath", v, indexes)?;
|
||||
|
||||
let max_years_between = DerivedResolutions::from_computed::<DaysToYears>(
|
||||
let max_years_between = LazyPerBlock::from_computed::<DaysToYears>(
|
||||
"max_years_between_price_ath",
|
||||
v,
|
||||
max_days_between.height.read_only_boxed_clone(),
|
||||
&max_days_between,
|
||||
);
|
||||
|
||||
let days_since =
|
||||
PerBlock::forced_import(db, "days_since_price_ath", v, indexes)?;
|
||||
|
||||
let years_since = DerivedResolutions::from_computed::<DaysToYears>(
|
||||
let years_since = LazyPerBlock::from_computed::<DaysToYears>(
|
||||
"years_since_price_ath",
|
||||
v,
|
||||
days_since.height.read_only_boxed_clone(),
|
||||
&days_since,
|
||||
);
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPointsSigned16, Cents, StoredF32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{PerBlock, DerivedResolutions, PercentPerBlock, Price};
|
||||
use crate::internal::{LazyPerBlock, PerBlock, PercentPerBlock, Price};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub high: Price<PerBlock<Cents, M>>,
|
||||
pub drawdown: PercentPerBlock<BasisPointsSigned16, M>,
|
||||
pub days_since: PerBlock<StoredF32, M>,
|
||||
pub years_since: DerivedResolutions<StoredF32, StoredF32>,
|
||||
pub years_since: LazyPerBlock<StoredF32>,
|
||||
pub max_days_between: PerBlock<StoredF32, M>,
|
||||
pub max_years_between: DerivedResolutions<StoredF32, StoredF32>,
|
||||
pub max_years_between: LazyPerBlock<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -79,12 +79,12 @@ impl From<BasisPoints16> for u16 {
|
||||
impl From<f32> for BasisPoints16 {
|
||||
#[inline]
|
||||
fn from(value: f32) -> Self {
|
||||
let value = value.max(0.0);
|
||||
let scaled = (value * 10000.0).round();
|
||||
debug_assert!(
|
||||
value <= u16::MAX as f32 / 10000.0,
|
||||
scaled >= 0.0 && scaled <= u16::MAX as f32,
|
||||
"f32 out of BasisPoints16 range: {value}"
|
||||
);
|
||||
Self((value * 10000.0).round() as u16)
|
||||
Self(scaled as u16)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,12 +93,12 @@ impl From<f32> for BasisPoints16 {
|
||||
impl From<f64> for BasisPoints16 {
|
||||
#[inline]
|
||||
fn from(value: f64) -> Self {
|
||||
let value = value.max(0.0);
|
||||
let scaled = (value * 10000.0).round();
|
||||
debug_assert!(
|
||||
value <= u16::MAX as f64 / 10000.0,
|
||||
scaled >= 0.0 && scaled <= u16::MAX as f64,
|
||||
"f64 out of BasisPoints16 range: {value}"
|
||||
);
|
||||
Self((value * 10000.0).round() as u16)
|
||||
Self(scaled as u16)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,10 @@ impl From<f64> for BasisPointsSigned32 {
|
||||
impl From<f32> for BasisPointsSigned32 {
|
||||
#[inline]
|
||||
fn from(value: f32) -> Self {
|
||||
Self((value * 10000.0).round() as i32)
|
||||
let scaled = (value * 10000.0)
|
||||
.round()
|
||||
.clamp(i32::MIN as f32, i32::MAX as f32);
|
||||
Self(scaled as i32)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -257,13 +257,6 @@ impl From<f32> for Sats {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Sats> for f32 {
|
||||
#[inline]
|
||||
fn from(value: Sats) -> Self {
|
||||
value.0 as f32
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for Sats {
|
||||
#[inline]
|
||||
fn from(value: f64) -> Self {
|
||||
|
||||
@@ -11,7 +11,7 @@ use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use vecdb::{CheckedSub, Formattable, Pco, PrintableIndex};
|
||||
|
||||
use crate::{Close, Sats, StoredU32};
|
||||
use crate::{Close, StoredU32};
|
||||
|
||||
use super::{Dollars, StoredF64};
|
||||
|
||||
@@ -143,13 +143,6 @@ impl From<Dollars> for StoredF32 {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Sats> for StoredF32 {
|
||||
#[inline]
|
||||
fn from(value: Sats) -> Self {
|
||||
Self(f32::from(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Close<Dollars>> for StoredF32 {
|
||||
#[inline]
|
||||
fn from(value: Close<Dollars>) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user