mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
computer: renames
This commit is contained in:
@@ -966,7 +966,7 @@ pub struct CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSell
|
|||||||
pub net_realized_pnl_sum: _24hPattern<CentsSigned>,
|
pub net_realized_pnl_sum: _24hPattern<CentsSigned>,
|
||||||
pub net_realized_pnl_sum_extended: _1m1w1yPattern<CentsSigned>,
|
pub net_realized_pnl_sum_extended: _1m1w1yPattern<CentsSigned>,
|
||||||
pub peak_regret: CumulativeHeightPattern<Cents>,
|
pub peak_regret: CumulativeHeightPattern<Cents>,
|
||||||
pub peak_regret_rel_to_realized_cap: BpsPercentRatioPattern,
|
pub peak_regret_rel_to_rcap: BpsPercentRatioPattern,
|
||||||
pub profit_flow: MetricPattern1<Dollars>,
|
pub profit_flow: MetricPattern1<Dollars>,
|
||||||
pub profit_value_created: MetricPattern1<Cents>,
|
pub profit_value_created: MetricPattern1<Cents>,
|
||||||
pub profit_value_created_sum: _1m1w1y24hPattern<Cents>,
|
pub profit_value_created_sum: _1m1w1y24hPattern<Cents>,
|
||||||
@@ -1037,7 +1037,7 @@ impl CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSo
|
|||||||
net_realized_pnl_sum: _24hPattern::new(client.clone(), _m(&acc, "net_realized_pnl_24h")),
|
net_realized_pnl_sum: _24hPattern::new(client.clone(), _m(&acc, "net_realized_pnl_24h")),
|
||||||
net_realized_pnl_sum_extended: _1m1w1yPattern::new(client.clone(), _m(&acc, "net_realized_pnl")),
|
net_realized_pnl_sum_extended: _1m1w1yPattern::new(client.clone(), _m(&acc, "net_realized_pnl")),
|
||||||
peak_regret: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_peak_regret")),
|
peak_regret: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_peak_regret")),
|
||||||
peak_regret_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_peak_regret_rel_to_realized_cap")),
|
peak_regret_rel_to_rcap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_peak_regret_rel_to_realized_cap")),
|
||||||
profit_flow: MetricPattern1::new(client.clone(), _m(&acc, "profit_flow")),
|
profit_flow: MetricPattern1::new(client.clone(), _m(&acc, "profit_flow")),
|
||||||
profit_value_created: MetricPattern1::new(client.clone(), _m(&acc, "profit_value_created")),
|
profit_value_created: MetricPattern1::new(client.clone(), _m(&acc, "profit_value_created")),
|
||||||
profit_value_created_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "profit_value_created")),
|
profit_value_created_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "profit_value_created")),
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ impl Vecs {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||||
let realized_cap_cents = &all_metrics.realized.realized_cap_cents.height;
|
let realized_cap_cents = &all_metrics.realized.cap_cents.height;
|
||||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||||
|
|
||||||
self.thermo_cap.cents.height.compute_transform(
|
self.thermo_cap.cents.height.compute_transform(
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ impl Vecs {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||||
let realized_price = &all_metrics.realized.realized_price.cents.height;
|
let realized_price = &all_metrics.realized.price.cents.height;
|
||||||
|
|
||||||
self.vaulted_price.cents.height.compute_transform2(
|
self.vaulted_price.cents.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ pub struct RealizedCore<M: StorageMode = Rw> {
|
|||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub minimal: RealizedMinimal<M>,
|
pub minimal: RealizedMinimal<M>,
|
||||||
|
|
||||||
pub realized_cap_delta: FiatRollingDelta1m<Cents, CentsSigned, M>,
|
pub cap_delta: FiatRollingDelta1m<Cents, CentsSigned, M>,
|
||||||
|
|
||||||
pub neg_realized_loss: LazyPerBlock<Dollars, Cents>,
|
pub neg_loss: LazyPerBlock<Dollars, Cents>,
|
||||||
pub net_realized_pnl: ComputedPerBlock<CentsSigned, M>,
|
pub net_pnl: ComputedPerBlock<CentsSigned, M>,
|
||||||
pub net_realized_pnl_sum: RollingWindow24h<CentsSigned, M>,
|
pub net_pnl_sum: RollingWindow24h<CentsSigned, M>,
|
||||||
|
|
||||||
pub value_created: ComputedPerBlock<Cents, M>,
|
pub value_created: ComputedPerBlock<Cents, M>,
|
||||||
pub value_destroyed: ComputedPerBlock<Cents, M>,
|
pub value_destroyed: ComputedPerBlock<Cents, M>,
|
||||||
@@ -50,7 +50,7 @@ impl RealizedCore {
|
|||||||
let neg_realized_loss = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
let neg_realized_loss = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
||||||
&cfg.name("neg_realized_loss"),
|
&cfg.name("neg_realized_loss"),
|
||||||
cfg.version + Version::ONE,
|
cfg.version + Version::ONE,
|
||||||
minimal.realized_loss.height.read_only_boxed_clone(),
|
minimal.loss.height.read_only_boxed_clone(),
|
||||||
cfg.indexes,
|
cfg.indexes,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -65,10 +65,10 @@ impl RealizedCore {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
minimal,
|
minimal,
|
||||||
realized_cap_delta: cfg.import("realized_cap_delta", v1)?,
|
cap_delta: cfg.import("realized_cap_delta", v1)?,
|
||||||
neg_realized_loss,
|
neg_loss: neg_realized_loss,
|
||||||
net_realized_pnl,
|
net_pnl: net_realized_pnl,
|
||||||
net_realized_pnl_sum,
|
net_pnl_sum: net_realized_pnl_sum,
|
||||||
value_created,
|
value_created,
|
||||||
value_destroyed,
|
value_destroyed,
|
||||||
value_created_sum,
|
value_created_sum,
|
||||||
@@ -124,12 +124,13 @@ impl RealizedCore {
|
|||||||
starting_indexes: &Indexes,
|
starting_indexes: &Indexes,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.minimal.compute_rest_part1(blocks, starting_indexes, exit)?;
|
self.minimal
|
||||||
|
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||||
|
|
||||||
self.net_realized_pnl.height.compute_transform2(
|
self.net_pnl.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.minimal.realized_profit.height,
|
&self.minimal.profit.height,
|
||||||
&self.minimal.realized_loss.height,
|
&self.minimal.loss.height,
|
||||||
|(i, profit, loss, ..)| {
|
|(i, profit, loss, ..)| {
|
||||||
(
|
(
|
||||||
i,
|
i,
|
||||||
@@ -153,17 +154,17 @@ impl RealizedCore {
|
|||||||
self.minimal
|
self.minimal
|
||||||
.compute_rest_part2(prices, starting_indexes, height_to_supply, exit)?;
|
.compute_rest_part2(prices, starting_indexes, height_to_supply, exit)?;
|
||||||
|
|
||||||
self.realized_cap_delta.compute(
|
self.cap_delta.compute(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.lookback.height_1m_ago,
|
&blocks.lookback.height_1m_ago,
|
||||||
&self.minimal.realized_cap_cents.height,
|
&self.minimal.cap_cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.net_realized_pnl_sum.compute_rolling_sum(
|
self.net_pnl_sum.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.lookback.height_24h_ago,
|
&blocks.lookback.height_24h_ago,
|
||||||
&self.net_realized_pnl.height,
|
&self.net_pnl.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -180,12 +181,14 @@ impl RealizedCore {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.sopr._24h.compute_binary::<Cents, Cents, RatioCents64>(
|
self.sopr
|
||||||
starting_indexes.height,
|
._24h
|
||||||
&self.value_created_sum._24h.height,
|
.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
&self.value_destroyed_sum._24h.height,
|
starting_indexes.height,
|
||||||
exit,
|
&self.value_created_sum._24h.height,
|
||||||
)?;
|
&self.value_destroyed_sum._24h.height,
|
||||||
|
exit,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,11 @@ use crate::{
|
|||||||
blocks,
|
blocks,
|
||||||
distribution::state::RealizedState,
|
distribution::state::RealizedState,
|
||||||
internal::{
|
internal::{
|
||||||
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative,
|
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative, FiatPerBlock,
|
||||||
RatioPerBlock, RatioPerBlockPercentiles,
|
FiatRollingDelta1m, FiatRollingDeltaExcept1m, LazyPerBlock, PercentPerBlock,
|
||||||
RatioPerBlockStdDevBands, FiatPerBlock, FiatRollingDelta1m,
|
PercentRollingWindows, Price, RatioCents64, RatioCentsBp32, RatioCentsSignedCentsBps32,
|
||||||
FiatRollingDeltaExcept1m, LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price,
|
RatioCentsSignedDollarsBps32, RatioDollarsBp32, RatioPerBlock, RatioPerBlockPercentiles,
|
||||||
RatioCents64, RatioCentsBp32, RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32,
|
RatioPerBlockStdDevBands, RollingWindows, RollingWindowsFrom1w,
|
||||||
RatioDollarsBp32, RollingWindows, RollingWindowsFrom1w,
|
|
||||||
},
|
},
|
||||||
prices,
|
prices,
|
||||||
};
|
};
|
||||||
@@ -37,9 +36,9 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
|||||||
|
|
||||||
pub gross_pnl: FiatPerBlock<Cents, M>,
|
pub gross_pnl: FiatPerBlock<Cents, M>,
|
||||||
|
|
||||||
pub realized_profit_rel_to_realized_cap: PercentPerBlock<BasisPoints32, M>,
|
pub profit_rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||||
pub realized_loss_rel_to_realized_cap: PercentPerBlock<BasisPoints32, M>,
|
pub loss_rel_to_rcap: PercentPerBlock<BasisPoints32, M>,
|
||||||
pub net_realized_pnl_rel_to_realized_cap: PercentPerBlock<BasisPointsSigned32, M>,
|
pub net_pnl_rel_to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||||
|
|
||||||
pub profit_value_created: ComputedPerBlock<Cents, M>,
|
pub profit_value_created: ComputedPerBlock<Cents, M>,
|
||||||
pub profit_value_destroyed: ComputedPerBlock<Cents, M>,
|
pub profit_value_destroyed: ComputedPerBlock<Cents, M>,
|
||||||
@@ -56,18 +55,18 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
|||||||
|
|
||||||
pub gross_pnl_sum: RollingWindows<Cents, M>,
|
pub gross_pnl_sum: RollingWindows<Cents, M>,
|
||||||
|
|
||||||
pub net_realized_pnl_cumulative: ComputedPerBlock<CentsSigned, M>,
|
pub net_pnl_cumulative: ComputedPerBlock<CentsSigned, M>,
|
||||||
#[traversable(rename = "net_realized_pnl_sum")]
|
#[traversable(rename = "net_pnl_sum")]
|
||||||
pub net_realized_pnl_sum_extended: RollingWindowsFrom1w<CentsSigned, M>,
|
pub net_pnl_sum_extended: RollingWindowsFrom1w<CentsSigned, M>,
|
||||||
|
|
||||||
pub net_pnl_delta: FiatRollingDelta1m<CentsSigned, CentsSigned, M>,
|
pub net_pnl_delta: FiatRollingDelta1m<CentsSigned, CentsSigned, M>,
|
||||||
#[traversable(rename = "net_pnl_delta")]
|
#[traversable(rename = "net_pnl_delta")]
|
||||||
pub net_pnl_delta_extended: FiatRollingDeltaExcept1m<CentsSigned, CentsSigned, M>,
|
pub net_pnl_delta_extended: FiatRollingDeltaExcept1m<CentsSigned, CentsSigned, M>,
|
||||||
pub net_pnl_change_1m_rel_to_realized_cap: PercentPerBlock<BasisPointsSigned32, M>,
|
pub net_pnl_change_1m_rel_to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||||
pub net_pnl_change_1m_rel_to_market_cap: PercentPerBlock<BasisPointsSigned32, M>,
|
pub net_pnl_change_1m_rel_to_mcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||||
|
|
||||||
#[traversable(rename = "realized_cap_delta")]
|
#[traversable(rename = "cap_delta")]
|
||||||
pub realized_cap_delta_extended: FiatRollingDeltaExcept1m<Cents, CentsSigned, M>,
|
pub cap_delta_extended: FiatRollingDeltaExcept1m<Cents, CentsSigned, M>,
|
||||||
|
|
||||||
pub investor_price: Price<ComputedPerBlock<Cents, M>>,
|
pub investor_price: Price<ComputedPerBlock<Cents, M>>,
|
||||||
pub investor_price_ratio: RatioPerBlock<M>,
|
pub investor_price_ratio: RatioPerBlock<M>,
|
||||||
@@ -83,13 +82,13 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
|||||||
pub peak_regret: ComputedPerBlockCumulative<Cents, M>,
|
pub peak_regret: ComputedPerBlockCumulative<Cents, M>,
|
||||||
pub peak_regret_rel_to_realized_cap: PercentPerBlock<BasisPoints32, M>,
|
pub peak_regret_rel_to_realized_cap: PercentPerBlock<BasisPoints32, M>,
|
||||||
|
|
||||||
pub realized_cap_rel_to_own_market_cap: PercentPerBlock<BasisPoints32, M>,
|
pub cap_rel_to_own_mcap: PercentPerBlock<BasisPoints32, M>,
|
||||||
|
|
||||||
#[traversable(rename = "realized_profit_sum")]
|
#[traversable(rename = "profit_sum")]
|
||||||
pub realized_profit_sum_extended: RollingWindowsFrom1w<Cents, M>,
|
pub profit_sum_extended: RollingWindowsFrom1w<Cents, M>,
|
||||||
#[traversable(rename = "realized_loss_sum")]
|
#[traversable(rename = "loss_sum")]
|
||||||
pub realized_loss_sum_extended: RollingWindowsFrom1w<Cents, M>,
|
pub loss_sum_extended: RollingWindowsFrom1w<Cents, M>,
|
||||||
pub realized_profit_to_loss_ratio: RollingWindows<StoredF64, M>,
|
pub profit_to_loss_ratio: RollingWindows<StoredF64, M>,
|
||||||
|
|
||||||
#[traversable(rename = "value_created_sum")]
|
#[traversable(rename = "value_created_sum")]
|
||||||
pub value_created_sum_extended: RollingWindowsFrom1w<Cents, M>,
|
pub value_created_sum_extended: RollingWindowsFrom1w<Cents, M>,
|
||||||
@@ -103,8 +102,8 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
|||||||
#[traversable(rename = "sent_in_loss_sum")]
|
#[traversable(rename = "sent_in_loss_sum")]
|
||||||
pub sent_in_loss_sum_extended: RollingWindowsFrom1w<Sats, M>,
|
pub sent_in_loss_sum_extended: RollingWindowsFrom1w<Sats, M>,
|
||||||
|
|
||||||
pub realized_price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
pub price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
||||||
pub realized_price_ratio_std_dev: RatioPerBlockStdDevBands<M>,
|
pub price_ratio_std_dev: RatioPerBlockStdDevBands<M>,
|
||||||
pub investor_price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
pub investor_price_ratio_percentiles: RatioPerBlockPercentiles<M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,8 +151,7 @@ impl RealizedFull {
|
|||||||
let cap_raw = cfg.import("cap_raw", v0)?;
|
let cap_raw = cfg.import("cap_raw", v0)?;
|
||||||
let investor_cap_raw = cfg.import("investor_cap_raw", v0)?;
|
let investor_cap_raw = cfg.import("investor_cap_raw", v0)?;
|
||||||
|
|
||||||
let sell_side_risk_ratio =
|
let sell_side_risk_ratio = cfg.import("sell_side_risk_ratio", Version::new(2))?;
|
||||||
cfg.import("sell_side_risk_ratio", Version::new(2))?;
|
|
||||||
|
|
||||||
let peak_regret = cfg.import("realized_peak_regret", Version::new(2))?;
|
let peak_regret = cfg.import("realized_peak_regret", Version::new(2))?;
|
||||||
let peak_regret_rel_to_realized_cap =
|
let peak_regret_rel_to_realized_cap =
|
||||||
@@ -178,9 +176,9 @@ impl RealizedFull {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
base,
|
base,
|
||||||
gross_pnl,
|
gross_pnl,
|
||||||
realized_profit_rel_to_realized_cap,
|
profit_rel_to_rcap: realized_profit_rel_to_realized_cap,
|
||||||
realized_loss_rel_to_realized_cap,
|
loss_rel_to_rcap: realized_loss_rel_to_realized_cap,
|
||||||
net_realized_pnl_rel_to_realized_cap,
|
net_pnl_rel_to_rcap: net_realized_pnl_rel_to_realized_cap,
|
||||||
profit_value_created,
|
profit_value_created,
|
||||||
profit_value_destroyed,
|
profit_value_destroyed,
|
||||||
loss_value_created,
|
loss_value_created,
|
||||||
@@ -192,15 +190,15 @@ impl RealizedFull {
|
|||||||
capitulation_flow,
|
capitulation_flow,
|
||||||
profit_flow,
|
profit_flow,
|
||||||
gross_pnl_sum,
|
gross_pnl_sum,
|
||||||
net_realized_pnl_cumulative: cfg.import("net_realized_pnl_cumulative", Version::ONE)?,
|
net_pnl_cumulative: cfg.import("net_realized_pnl_cumulative", Version::ONE)?,
|
||||||
net_realized_pnl_sum_extended: cfg.import("net_realized_pnl", Version::ONE)?,
|
net_pnl_sum_extended: cfg.import("net_realized_pnl", Version::ONE)?,
|
||||||
net_pnl_delta: cfg.import("net_pnl_delta", Version::new(5))?,
|
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_delta_extended: cfg.import("net_pnl_delta", Version::new(5))?,
|
||||||
net_pnl_change_1m_rel_to_realized_cap: cfg
|
net_pnl_change_1m_rel_to_rcap: cfg
|
||||||
.import("net_pnl_change_1m_rel_to_realized_cap", Version::new(4))?,
|
.import("net_pnl_change_1m_rel_to_realized_cap", Version::new(4))?,
|
||||||
net_pnl_change_1m_rel_to_market_cap: cfg
|
net_pnl_change_1m_rel_to_mcap: cfg
|
||||||
.import("net_pnl_change_1m_rel_to_market_cap", Version::new(4))?,
|
.import("net_pnl_change_1m_rel_to_market_cap", Version::new(4))?,
|
||||||
realized_cap_delta_extended: cfg.import("realized_cap_delta", Version::new(5))?,
|
cap_delta_extended: cfg.import("realized_cap_delta", Version::new(5))?,
|
||||||
investor_price,
|
investor_price,
|
||||||
investor_price_ratio,
|
investor_price_ratio,
|
||||||
lower_price_band,
|
lower_price_band,
|
||||||
@@ -210,24 +208,22 @@ impl RealizedFull {
|
|||||||
sell_side_risk_ratio,
|
sell_side_risk_ratio,
|
||||||
peak_regret,
|
peak_regret,
|
||||||
peak_regret_rel_to_realized_cap,
|
peak_regret_rel_to_realized_cap,
|
||||||
realized_cap_rel_to_own_market_cap: cfg
|
cap_rel_to_own_mcap: cfg.import("realized_cap_rel_to_own_market_cap", v1)?,
|
||||||
.import("realized_cap_rel_to_own_market_cap", v1)?,
|
profit_sum_extended: cfg.import("realized_profit", v1)?,
|
||||||
realized_profit_sum_extended: cfg.import("realized_profit", v1)?,
|
loss_sum_extended: cfg.import("realized_loss", v1)?,
|
||||||
realized_loss_sum_extended: cfg.import("realized_loss", v1)?,
|
profit_to_loss_ratio: cfg.import("realized_profit_to_loss_ratio", v1)?,
|
||||||
realized_profit_to_loss_ratio: cfg
|
|
||||||
.import("realized_profit_to_loss_ratio", v1)?,
|
|
||||||
value_created_sum_extended,
|
value_created_sum_extended,
|
||||||
value_destroyed_sum_extended,
|
value_destroyed_sum_extended,
|
||||||
sopr_extended,
|
sopr_extended,
|
||||||
sent_in_profit_sum_extended: cfg.import("sent_in_profit", v1)?,
|
sent_in_profit_sum_extended: cfg.import("sent_in_profit", v1)?,
|
||||||
sent_in_loss_sum_extended: cfg.import("sent_in_loss", v1)?,
|
sent_in_loss_sum_extended: cfg.import("sent_in_loss", v1)?,
|
||||||
realized_price_ratio_percentiles: RatioPerBlockPercentiles::forced_import(
|
price_ratio_percentiles: RatioPerBlockPercentiles::forced_import(
|
||||||
cfg.db,
|
cfg.db,
|
||||||
&realized_price_name,
|
&realized_price_name,
|
||||||
realized_price_version,
|
realized_price_version,
|
||||||
cfg.indexes,
|
cfg.indexes,
|
||||||
)?,
|
)?,
|
||||||
realized_price_ratio_std_dev: RatioPerBlockStdDevBands::forced_import(
|
price_ratio_std_dev: RatioPerBlockStdDevBands::forced_import(
|
||||||
cfg.db,
|
cfg.db,
|
||||||
&realized_price_name,
|
&realized_price_name,
|
||||||
realized_price_version,
|
realized_price_version,
|
||||||
@@ -355,15 +351,14 @@ impl RealizedFull {
|
|||||||
starting_indexes: &Indexes,
|
starting_indexes: &Indexes,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.base.compute_rest_part1(blocks, starting_indexes, exit)?;
|
self.base
|
||||||
|
.compute_rest_part1(blocks, starting_indexes, exit)?;
|
||||||
|
|
||||||
self.net_realized_pnl_cumulative
|
self.net_pnl_cumulative.height.compute_cumulative(
|
||||||
.height
|
starting_indexes.height,
|
||||||
.compute_cumulative(
|
&self.base.core.net_pnl.height,
|
||||||
starting_indexes.height,
|
exit,
|
||||||
&self.base.core.net_realized_pnl.height,
|
)?;
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.peak_regret
|
self.peak_regret
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_indexes.height, exit)?;
|
||||||
@@ -390,10 +385,10 @@ impl RealizedFull {
|
|||||||
let window_starts = blocks.lookback.window_starts();
|
let window_starts = blocks.lookback.window_starts();
|
||||||
|
|
||||||
// Extended rolling sum (1w, 1m, 1y) for net_realized_pnl
|
// Extended rolling sum (1w, 1m, 1y) for net_realized_pnl
|
||||||
self.net_realized_pnl_sum_extended.compute_rolling_sum(
|
self.net_pnl_sum_extended.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&window_starts,
|
&window_starts,
|
||||||
&self.base.core.net_realized_pnl.height,
|
&self.base.core.net_pnl.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -426,25 +421,25 @@ impl RealizedFull {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Realized P/L rel to realized cap
|
// Realized P/L rel to realized cap
|
||||||
self.realized_profit_rel_to_realized_cap
|
self.profit_rel_to_rcap
|
||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.base.core.minimal.realized_profit.height,
|
&self.base.core.minimal.profit.height,
|
||||||
&self.base.core.minimal.realized_cap_cents.height,
|
&self.base.core.minimal.cap_cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.realized_loss_rel_to_realized_cap
|
self.loss_rel_to_rcap
|
||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.base.core.minimal.realized_loss.height,
|
&self.base.core.minimal.loss.height,
|
||||||
&self.base.core.minimal.realized_cap_cents.height,
|
&self.base.core.minimal.cap_cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.net_realized_pnl_rel_to_realized_cap
|
self.net_pnl_rel_to_rcap
|
||||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.base.core.net_realized_pnl.height,
|
&self.base.core.net_pnl.height,
|
||||||
&self.base.core.minimal.realized_cap_cents.height,
|
&self.base.core.minimal.cap_cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -491,8 +486,8 @@ impl RealizedFull {
|
|||||||
// Gross PnL
|
// Gross PnL
|
||||||
self.gross_pnl.cents.height.compute_add(
|
self.gross_pnl.cents.height.compute_add(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.base.core.minimal.realized_profit.height,
|
&self.base.core.minimal.profit.height,
|
||||||
&self.base.core.minimal.realized_loss.height,
|
&self.base.core.minimal.loss.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -507,23 +502,23 @@ impl RealizedFull {
|
|||||||
self.net_pnl_delta.compute(
|
self.net_pnl_delta.compute(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.lookback.height_1m_ago,
|
&blocks.lookback.height_1m_ago,
|
||||||
&self.net_realized_pnl_cumulative.height,
|
&self.net_pnl_cumulative.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.net_pnl_delta_extended.compute(
|
self.net_pnl_delta_extended.compute(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&window_starts,
|
&window_starts,
|
||||||
&self.net_realized_pnl_cumulative.height,
|
&self.net_pnl_cumulative.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.net_pnl_change_1m_rel_to_realized_cap
|
self.net_pnl_change_1m_rel_to_rcap
|
||||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.net_pnl_delta.change_1m.cents.height,
|
&self.net_pnl_delta.change_1m.cents.height,
|
||||||
&self.base.core.minimal.realized_cap_cents.height,
|
&self.base.core.minimal.cap_cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.net_pnl_change_1m_rel_to_market_cap
|
self.net_pnl_change_1m_rel_to_mcap
|
||||||
.compute_binary::<CentsSigned, Dollars, RatioCentsSignedDollarsBps32>(
|
.compute_binary::<CentsSigned, Dollars, RatioCentsSignedDollarsBps32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.net_pnl_delta.change_1m.cents.height,
|
&self.net_pnl_delta.change_1m.cents.height,
|
||||||
@@ -532,10 +527,10 @@ impl RealizedFull {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Realized cap delta extended (24h/1w/1y — 1m is in RealizedCore)
|
// Realized cap delta extended (24h/1w/1y — 1m is in RealizedCore)
|
||||||
self.realized_cap_delta_extended.compute(
|
self.cap_delta_extended.compute(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&window_starts,
|
&window_starts,
|
||||||
&self.base.core.minimal.realized_cap_cents.height,
|
&self.base.core.minimal.cap_cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -544,7 +539,7 @@ impl RealizedFull {
|
|||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.peak_regret.height,
|
&self.peak_regret.height,
|
||||||
&self.base.core.minimal.realized_cap_cents.height,
|
&self.base.core.minimal.cap_cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -558,7 +553,7 @@ impl RealizedFull {
|
|||||||
|
|
||||||
self.lower_price_band.cents.height.compute_transform2(
|
self.lower_price_band.cents.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.base.core.minimal.realized_price.cents.height,
|
&self.base.core.minimal.price.cents.height,
|
||||||
&self.investor_price.cents.height,
|
&self.investor_price.cents.height,
|
||||||
|(i, rp, ip, ..)| {
|
|(i, rp, ip, ..)| {
|
||||||
let rp = rp.as_u128();
|
let rp = rp.as_u128();
|
||||||
@@ -575,7 +570,7 @@ impl RealizedFull {
|
|||||||
self.upper_price_band.cents.height.compute_transform2(
|
self.upper_price_band.cents.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.investor_price.cents.height,
|
&self.investor_price.cents.height,
|
||||||
&self.base.core.minimal.realized_price.cents.height,
|
&self.base.core.minimal.price.cents.height,
|
||||||
|(i, ip, rp, ..)| {
|
|(i, ip, rp, ..)| {
|
||||||
let ip = ip.as_u128();
|
let ip = ip.as_u128();
|
||||||
let rp = rp.as_u128();
|
let rp = rp.as_u128();
|
||||||
@@ -598,47 +593,49 @@ impl RealizedFull {
|
|||||||
ssrr.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
ssrr.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&rv.height,
|
&rv.height,
|
||||||
&self.base.core.minimal.realized_cap_cents.height,
|
&self.base.core.minimal.cap_cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extended: realized profit/loss rolling sums (1w, 1m, 1y)
|
// Extended: realized profit/loss rolling sums (1w, 1m, 1y)
|
||||||
self.realized_profit_sum_extended.compute_rolling_sum(
|
self.profit_sum_extended.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&window_starts,
|
&window_starts,
|
||||||
&self.base.core.minimal.realized_profit.height,
|
&self.base.core.minimal.profit.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.realized_loss_sum_extended.compute_rolling_sum(
|
self.loss_sum_extended.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&window_starts,
|
&window_starts,
|
||||||
&self.base.core.minimal.realized_loss.height,
|
&self.base.core.minimal.loss.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Realized cap relative to own market cap
|
// Realized cap relative to own market cap
|
||||||
self.realized_cap_rel_to_own_market_cap
|
self.cap_rel_to_own_mcap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.base.core.minimal.realized_cap.height,
|
&self.base.core.minimal.cap.height,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Realized profit to loss ratios
|
// Realized profit to loss ratios
|
||||||
self.realized_profit_to_loss_ratio._24h.compute_binary::<Cents, Cents, RatioCents64>(
|
self.profit_to_loss_ratio
|
||||||
starting_indexes.height,
|
._24h
|
||||||
&self.base.core.minimal.realized_profit_sum._24h.height,
|
.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
&self.base.core.minimal.realized_loss_sum._24h.height,
|
starting_indexes.height,
|
||||||
exit,
|
&self.base.core.minimal.profit_sum._24h.height,
|
||||||
)?;
|
&self.base.core.minimal.loss_sum._24h.height,
|
||||||
|
exit,
|
||||||
|
)?;
|
||||||
for ((ratio, profit), loss) in self
|
for ((ratio, profit), loss) in self
|
||||||
.realized_profit_to_loss_ratio
|
.profit_to_loss_ratio
|
||||||
.as_mut_array_from_1w()
|
.as_mut_array_from_1w()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(self.realized_profit_sum_extended.as_array())
|
.zip(self.profit_sum_extended.as_array())
|
||||||
.zip(self.realized_loss_sum_extended.as_array())
|
.zip(self.loss_sum_extended.as_array())
|
||||||
{
|
{
|
||||||
ratio.compute_binary::<Cents, Cents, RatioCents64>(
|
ratio.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
@@ -648,20 +645,20 @@ impl RealizedFull {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.realized_price_ratio_percentiles.compute(
|
self.price_ratio_percentiles.compute(
|
||||||
blocks,
|
blocks,
|
||||||
starting_indexes,
|
starting_indexes,
|
||||||
exit,
|
exit,
|
||||||
&self.base.core.minimal.realized_price_ratio.ratio.height,
|
&self.base.core.minimal.price_ratio.ratio.height,
|
||||||
&self.base.core.minimal.realized_price.cents.height,
|
&self.base.core.minimal.price.cents.height,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.realized_price_ratio_std_dev.compute(
|
self.price_ratio_std_dev.compute(
|
||||||
blocks,
|
blocks,
|
||||||
starting_indexes,
|
starting_indexes,
|
||||||
exit,
|
exit,
|
||||||
&self.base.core.minimal.realized_price_ratio.ratio.height,
|
&self.base.core.minimal.price_ratio.ratio.height,
|
||||||
&self.base.core.minimal.realized_price.cents.height,
|
&self.base.core.minimal.price.cents.height,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Investor price: percentiles
|
// Investor price: percentiles
|
||||||
|
|||||||
@@ -3,14 +3,16 @@ use brk_traversable::Traversable;
|
|||||||
use brk_types::{
|
use brk_types::{
|
||||||
BasisPoints32, Bitcoin, Cents, Dollars, Height, Indexes, Sats, StoredF32, Version,
|
BasisPoints32, Bitcoin, Cents, Dollars, Height, Indexes, Sats, StoredF32, Version,
|
||||||
};
|
};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{
|
||||||
|
AnyStoredVec, AnyVec, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode, WritableVec,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
blocks,
|
blocks,
|
||||||
distribution::state::RealizedOps,
|
distribution::state::RealizedOps,
|
||||||
internal::{
|
internal::{
|
||||||
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative,
|
CentsUnsignedToDollars, ComputedPerBlock, ComputedPerBlockCumulative, Identity,
|
||||||
RatioPerBlock, Identity, LazyPerBlock, Price, RollingWindow24h,
|
LazyPerBlock, Price, RatioPerBlock, RollingWindow24h,
|
||||||
},
|
},
|
||||||
prices,
|
prices,
|
||||||
};
|
};
|
||||||
@@ -19,16 +21,16 @@ use crate::distribution::metrics::ImportConfig;
|
|||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct RealizedMinimal<M: StorageMode = Rw> {
|
pub struct RealizedMinimal<M: StorageMode = Rw> {
|
||||||
pub realized_cap_cents: ComputedPerBlock<Cents, M>,
|
pub cap_cents: ComputedPerBlock<Cents, M>,
|
||||||
pub realized_profit: ComputedPerBlockCumulative<Cents, M>,
|
pub profit: ComputedPerBlockCumulative<Cents, M>,
|
||||||
pub realized_loss: ComputedPerBlockCumulative<Cents, M>,
|
pub loss: ComputedPerBlockCumulative<Cents, M>,
|
||||||
pub realized_cap: LazyPerBlock<Dollars, Cents>,
|
pub cap: LazyPerBlock<Dollars, Cents>,
|
||||||
pub realized_price: Price<ComputedPerBlock<Cents, M>>,
|
pub price: Price<ComputedPerBlock<Cents, M>>,
|
||||||
pub realized_price_ratio: RatioPerBlock<M>,
|
pub price_ratio: RatioPerBlock<M>,
|
||||||
pub mvrv: LazyPerBlock<StoredF32>,
|
pub mvrv: LazyPerBlock<StoredF32>,
|
||||||
|
|
||||||
pub realized_profit_sum: RollingWindow24h<Cents, M>,
|
pub profit_sum: RollingWindow24h<Cents, M>,
|
||||||
pub realized_loss_sum: RollingWindow24h<Cents, M>,
|
pub loss_sum: RollingWindow24h<Cents, M>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RealizedMinimal {
|
impl RealizedMinimal {
|
||||||
@@ -46,8 +48,7 @@ impl RealizedMinimal {
|
|||||||
let realized_loss = cfg.import("realized_loss", Version::ZERO)?;
|
let realized_loss = cfg.import("realized_loss", Version::ZERO)?;
|
||||||
|
|
||||||
let realized_price = cfg.import("realized_price", Version::ONE)?;
|
let realized_price = cfg.import("realized_price", Version::ONE)?;
|
||||||
let realized_price_ratio: RatioPerBlock =
|
let realized_price_ratio: RatioPerBlock = cfg.import("realized_price", Version::ONE)?;
|
||||||
cfg.import("realized_price", Version::ONE)?;
|
|
||||||
let mvrv = LazyPerBlock::from_lazy::<Identity<StoredF32>, BasisPoints32>(
|
let mvrv = LazyPerBlock::from_lazy::<Identity<StoredF32>, BasisPoints32>(
|
||||||
&cfg.name("mvrv"),
|
&cfg.name("mvrv"),
|
||||||
cfg.version,
|
cfg.version,
|
||||||
@@ -58,48 +59,38 @@ impl RealizedMinimal {
|
|||||||
let realized_loss_sum = cfg.import("realized_loss", Version::ONE)?;
|
let realized_loss_sum = cfg.import("realized_loss", Version::ONE)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
realized_cap_cents,
|
cap_cents: realized_cap_cents,
|
||||||
realized_profit,
|
profit: realized_profit,
|
||||||
realized_loss,
|
loss: realized_loss,
|
||||||
realized_cap,
|
cap: realized_cap,
|
||||||
realized_price,
|
price: realized_price,
|
||||||
realized_price_ratio,
|
price_ratio: realized_price_ratio,
|
||||||
mvrv,
|
mvrv,
|
||||||
realized_profit_sum,
|
profit_sum: realized_profit_sum,
|
||||||
realized_loss_sum,
|
loss_sum: realized_loss_sum,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn min_stateful_height_len(&self) -> usize {
|
pub(crate) fn min_stateful_height_len(&self) -> usize {
|
||||||
self.realized_cap_cents
|
self.cap_cents
|
||||||
.height
|
.height
|
||||||
.len()
|
.len()
|
||||||
.min(self.realized_profit.height.len())
|
.min(self.profit.height.len())
|
||||||
.min(self.realized_loss.height.len())
|
.min(self.loss.height.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn truncate_push(
|
pub(crate) fn truncate_push(&mut self, height: Height, state: &impl RealizedOps) -> Result<()> {
|
||||||
&mut self,
|
self.cap_cents.height.truncate_push(height, state.cap())?;
|
||||||
height: Height,
|
self.profit.height.truncate_push(height, state.profit())?;
|
||||||
state: &impl RealizedOps,
|
self.loss.height.truncate_push(height, state.loss())?;
|
||||||
) -> Result<()> {
|
|
||||||
self.realized_cap_cents
|
|
||||||
.height
|
|
||||||
.truncate_push(height, state.cap())?;
|
|
||||||
self.realized_profit
|
|
||||||
.height
|
|
||||||
.truncate_push(height, state.profit())?;
|
|
||||||
self.realized_loss
|
|
||||||
.height
|
|
||||||
.truncate_push(height, state.loss())?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||||
vec![
|
vec![
|
||||||
&mut self.realized_cap_cents.height as &mut dyn AnyStoredVec,
|
&mut self.cap_cents.height as &mut dyn AnyStoredVec,
|
||||||
&mut self.realized_profit.height,
|
&mut self.profit.height,
|
||||||
&mut self.realized_loss.height,
|
&mut self.loss.height,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,9 +100,9 @@ impl RealizedMinimal {
|
|||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
sum_others!(self, starting_indexes, others, exit; realized_cap_cents.height);
|
sum_others!(self, starting_indexes, others, exit; cap_cents.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; realized_profit.height);
|
sum_others!(self, starting_indexes, others, exit; profit.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; realized_loss.height);
|
sum_others!(self, starting_indexes, others, exit; loss.height);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,20 +112,18 @@ impl RealizedMinimal {
|
|||||||
starting_indexes: &Indexes,
|
starting_indexes: &Indexes,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.realized_profit
|
self.profit.compute_rest(starting_indexes.height, exit)?;
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
self.loss.compute_rest(starting_indexes.height, exit)?;
|
||||||
self.realized_loss
|
self.profit_sum.compute_rolling_sum(
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
|
||||||
self.realized_profit_sum.compute_rolling_sum(
|
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.lookback.height_24h_ago,
|
&blocks.lookback.height_24h_ago,
|
||||||
&self.realized_profit.height,
|
&self.profit.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.realized_loss_sum.compute_rolling_sum(
|
self.loss_sum.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.lookback.height_24h_ago,
|
&blocks.lookback.height_24h_ago,
|
||||||
&self.realized_loss.height,
|
&self.loss.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -147,9 +136,9 @@ impl RealizedMinimal {
|
|||||||
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.realized_price.cents.height.compute_transform2(
|
self.price.cents.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.realized_cap_cents.height,
|
&self.cap_cents.height,
|
||||||
height_to_supply,
|
height_to_supply,
|
||||||
|(i, cap_cents, supply, ..)| {
|
|(i, cap_cents, supply, ..)| {
|
||||||
let cap = cap_cents.as_u128();
|
let cap = cap_cents.as_u128();
|
||||||
@@ -163,10 +152,10 @@ impl RealizedMinimal {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.realized_price_ratio.compute_ratio(
|
self.price_ratio.compute_ratio(
|
||||||
starting_indexes,
|
starting_indexes,
|
||||||
&prices.price.cents.height,
|
&prices.price.cents.height,
|
||||||
&self.realized_price.cents.height,
|
&self.price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -39,21 +39,21 @@ impl RelativeExtendedOwnMarketCap {
|
|||||||
self.unrealized_profit_rel_to_own_market_cap
|
self.unrealized_profit_rel_to_own_market_cap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.unrealized_profit.usd.height,
|
&unrealized.profit.usd.height,
|
||||||
own_market_cap,
|
own_market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.unrealized_loss_rel_to_own_market_cap
|
self.unrealized_loss_rel_to_own_market_cap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.unrealized_loss.usd.height,
|
&unrealized.loss.usd.height,
|
||||||
own_market_cap,
|
own_market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.net_unrealized_pnl_rel_to_own_market_cap
|
self.net_unrealized_pnl_rel_to_own_market_cap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBps32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBps32>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.net_unrealized_pnl.usd.height,
|
&unrealized.net_pnl.usd.height,
|
||||||
own_market_cap,
|
own_market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -39,21 +39,21 @@ impl RelativeExtendedOwnPnl {
|
|||||||
self.unrealized_profit_rel_to_own_gross_pnl
|
self.unrealized_profit_rel_to_own_gross_pnl
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.unrealized_profit.usd.height,
|
&unrealized.profit.usd.height,
|
||||||
gross_pnl_usd,
|
gross_pnl_usd,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.unrealized_loss_rel_to_own_gross_pnl
|
self.unrealized_loss_rel_to_own_gross_pnl
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.unrealized_loss.usd.height,
|
&unrealized.loss.usd.height,
|
||||||
gross_pnl_usd,
|
gross_pnl_usd,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.net_unrealized_pnl_rel_to_own_gross_pnl
|
self.net_unrealized_pnl_rel_to_own_gross_pnl
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBps32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBps32>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.net_unrealized_pnl.usd.height,
|
&unrealized.net_pnl.usd.height,
|
||||||
gross_pnl_usd,
|
gross_pnl_usd,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{BasisPoints16, BasisPointsSigned32, Dollars, Height, Sats, StoredF32, Version};
|
||||||
BasisPoints16, BasisPointsSigned32, Dollars, Height, Sats, StoredF32, Version,
|
|
||||||
};
|
|
||||||
use vecdb::{Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
use vecdb::{Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::internal::{
|
use crate::internal::{
|
||||||
Bps32ToFloat, LazyPerBlock, PercentPerBlock, RatioDollarsBp16, RatioDollarsBps32,
|
Bps32ToFloat, LazyPerBlock, PercentPerBlock, RatioDollarsBp16, RatioDollarsBps32, RatioSatsBp16,
|
||||||
RatioSatsBp16,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::distribution::metrics::{ImportConfig, UnrealizedCore};
|
use crate::distribution::metrics::{ImportConfig, UnrealizedCore};
|
||||||
@@ -46,8 +43,7 @@ impl RelativeFull {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
supply_in_profit_rel_to_own_supply: cfg
|
supply_in_profit_rel_to_own_supply: cfg
|
||||||
.import("supply_in_profit_rel_to_own_supply", v1)?,
|
.import("supply_in_profit_rel_to_own_supply", v1)?,
|
||||||
supply_in_loss_rel_to_own_supply: cfg
|
supply_in_loss_rel_to_own_supply: cfg.import("supply_in_loss_rel_to_own_supply", v1)?,
|
||||||
.import("supply_in_loss_rel_to_own_supply", v1)?,
|
|
||||||
unrealized_profit_rel_to_market_cap: cfg
|
unrealized_profit_rel_to_market_cap: cfg
|
||||||
.import("unrealized_profit_rel_to_market_cap", v2)?,
|
.import("unrealized_profit_rel_to_market_cap", v2)?,
|
||||||
unrealized_loss_rel_to_market_cap: cfg
|
unrealized_loss_rel_to_market_cap: cfg
|
||||||
@@ -83,21 +79,21 @@ impl RelativeFull {
|
|||||||
self.unrealized_profit_rel_to_market_cap
|
self.unrealized_profit_rel_to_market_cap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.unrealized_profit.usd.height,
|
&unrealized.profit.usd.height,
|
||||||
market_cap,
|
market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.unrealized_loss_rel_to_market_cap
|
self.unrealized_loss_rel_to_market_cap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp16>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.unrealized_loss.usd.height,
|
&unrealized.loss.usd.height,
|
||||||
market_cap,
|
market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.net_unrealized_pnl_rel_to_market_cap
|
self.net_unrealized_pnl_rel_to_market_cap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBps32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBps32>(
|
||||||
max_from,
|
max_from,
|
||||||
&unrealized.net_unrealized_pnl.usd.height,
|
&unrealized.net_pnl.usd.height,
|
||||||
market_cap,
|
market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ use crate::{
|
|||||||
metrics::{ImportConfig, unrealized::UnrealizedMinimal},
|
metrics::{ImportConfig, unrealized::UnrealizedMinimal},
|
||||||
state::UnrealizedState,
|
state::UnrealizedState,
|
||||||
},
|
},
|
||||||
internal::{
|
internal::{CentsSubtractToCentsSigned, FiatPerBlock, LazyPerBlock, NegCentsUnsignedToDollars},
|
||||||
CentsSubtractToCentsSigned, FiatPerBlock, LazyPerBlock, NegCentsUnsignedToDollars,
|
|
||||||
},
|
|
||||||
prices,
|
prices,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,12 +22,10 @@ pub struct UnrealizedCore<M: StorageMode = Rw> {
|
|||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub minimal: UnrealizedMinimal<M>,
|
pub minimal: UnrealizedMinimal<M>,
|
||||||
|
|
||||||
pub unrealized_profit: FiatPerBlock<Cents, M>,
|
pub profit: FiatPerBlock<Cents, M>,
|
||||||
pub unrealized_loss: FiatPerBlock<Cents, M>,
|
pub loss: FiatPerBlock<Cents, M>,
|
||||||
|
pub neg_loss: LazyPerBlock<Dollars, Cents>,
|
||||||
pub neg_unrealized_loss: LazyPerBlock<Dollars, Cents>,
|
pub net_pnl: FiatPerBlock<CentsSigned, M>,
|
||||||
|
|
||||||
pub net_unrealized_pnl: FiatPerBlock<CentsSigned, M>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnrealizedCore {
|
impl UnrealizedCore {
|
||||||
@@ -52,18 +48,18 @@ impl UnrealizedCore {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
minimal,
|
minimal,
|
||||||
unrealized_profit,
|
profit: unrealized_profit,
|
||||||
unrealized_loss,
|
loss: unrealized_loss,
|
||||||
neg_unrealized_loss,
|
neg_loss: neg_unrealized_loss,
|
||||||
net_unrealized_pnl,
|
net_pnl: net_unrealized_pnl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn min_stateful_height_len(&self) -> usize {
|
pub(crate) fn min_stateful_height_len(&self) -> usize {
|
||||||
self.minimal
|
self.minimal
|
||||||
.min_stateful_height_len()
|
.min_stateful_height_len()
|
||||||
.min(self.unrealized_profit.cents.height.len())
|
.min(self.profit.cents.height.len())
|
||||||
.min(self.unrealized_loss.cents.height.len())
|
.min(self.loss.cents.height.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn truncate_push(
|
pub(crate) fn truncate_push(
|
||||||
@@ -72,11 +68,11 @@ impl UnrealizedCore {
|
|||||||
height_state: &UnrealizedState,
|
height_state: &UnrealizedState,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.minimal.truncate_push(height, height_state)?;
|
self.minimal.truncate_push(height, height_state)?;
|
||||||
self.unrealized_profit
|
self.profit
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, height_state.unrealized_profit)?;
|
.truncate_push(height, height_state.unrealized_profit)?;
|
||||||
self.unrealized_loss
|
self.loss
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.truncate_push(height, height_state.unrealized_loss)?;
|
.truncate_push(height, height_state.unrealized_loss)?;
|
||||||
@@ -86,8 +82,8 @@ impl UnrealizedCore {
|
|||||||
|
|
||||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||||
let mut vecs = self.minimal.collect_vecs_mut();
|
let mut vecs = self.minimal.collect_vecs_mut();
|
||||||
vecs.push(&mut self.unrealized_profit.cents.height);
|
vecs.push(&mut self.profit.cents.height);
|
||||||
vecs.push(&mut self.unrealized_loss.cents.height);
|
vecs.push(&mut self.loss.cents.height);
|
||||||
vecs
|
vecs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +97,8 @@ impl UnrealizedCore {
|
|||||||
self.minimal
|
self.minimal
|
||||||
.compute_from_sources(starting_indexes, &minimal_refs, exit)?;
|
.compute_from_sources(starting_indexes, &minimal_refs, exit)?;
|
||||||
|
|
||||||
sum_others!(self, starting_indexes, others, exit; unrealized_profit.cents.height);
|
sum_others!(self, starting_indexes, others, exit; profit.cents.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; unrealized_loss.cents.height);
|
sum_others!(self, starting_indexes, others, exit; loss.cents.height);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -117,13 +113,13 @@ impl UnrealizedCore {
|
|||||||
self.minimal
|
self.minimal
|
||||||
.compute_rest(prices, starting_indexes.height, exit)?;
|
.compute_rest(prices, starting_indexes.height, exit)?;
|
||||||
|
|
||||||
self.net_unrealized_pnl
|
self.net_pnl
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.unrealized_profit.cents.height,
|
&self.profit.cents.height,
|
||||||
&self.unrealized_loss.cents.height,
|
&self.loss.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -88,24 +88,30 @@ impl UnrealizedFull {
|
|||||||
|
|
||||||
self.gross_pnl.cents.height.compute_add(
|
self.gross_pnl.cents.height.compute_add(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&self.inner.core.unrealized_profit.cents.height,
|
&self.inner.core.profit.cents.height,
|
||||||
&self.inner.core.unrealized_loss.cents.height,
|
&self.inner.core.loss.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.invested_capital_in_profit.cents.height.compute_transform(
|
self.invested_capital_in_profit
|
||||||
starting_indexes.height,
|
.cents
|
||||||
&self.inner.invested_capital_in_profit_raw,
|
.height
|
||||||
|(h, raw, ..)| (h, CentsSats::to_cents(raw)),
|
.compute_transform(
|
||||||
exit,
|
starting_indexes.height,
|
||||||
)?;
|
&self.inner.invested_capital_in_profit_raw,
|
||||||
|
|(h, raw, ..)| (h, CentsSats::to_cents(raw)),
|
||||||
|
exit,
|
||||||
|
)?;
|
||||||
|
|
||||||
self.invested_capital_in_loss.cents.height.compute_transform(
|
self.invested_capital_in_loss
|
||||||
starting_indexes.height,
|
.cents
|
||||||
&self.inner.invested_capital_in_loss_raw,
|
.height
|
||||||
|(h, raw, ..)| (h, CentsSats::to_cents(raw)),
|
.compute_transform(
|
||||||
exit,
|
starting_indexes.height,
|
||||||
)?;
|
&self.inner.invested_capital_in_loss_raw,
|
||||||
|
|(h, raw, ..)| (h, CentsSats::to_cents(raw)),
|
||||||
|
exit,
|
||||||
|
)?;
|
||||||
|
|
||||||
self.compute_rest_extended(prices, starting_indexes, exit)?;
|
self.compute_rest_extended(prices, starting_indexes, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ impl Vecs {
|
|||||||
|
|
||||||
// 24h, 1w, 1y from extended; 1m from core delta
|
// 24h, 1w, 1y from extended; 1m from core delta
|
||||||
let rcr_rates = [
|
let rcr_rates = [
|
||||||
&all_realized.realized_cap_delta_extended.rate_24h.bps.height,
|
&all_realized.cap_delta_extended.rate_24h.bps.height,
|
||||||
&all_realized.realized_cap_delta_extended.rate_1w.bps.height,
|
&all_realized.cap_delta_extended.rate_1w.bps.height,
|
||||||
&all_realized.realized_cap_delta.rate_1m.bps.height,
|
&all_realized.cap_delta.rate_1m.bps.height,
|
||||||
&all_realized.realized_cap_delta_extended.rate_1y.bps.height,
|
&all_realized.cap_delta_extended.rate_1y.bps.height,
|
||||||
];
|
];
|
||||||
|
|
||||||
for i in 0..4 {
|
for i in 0..4 {
|
||||||
|
|||||||
Reference in New Issue
Block a user