diff --git a/crates/brk_client/src/lib.rs b/crates/brk_client/src/lib.rs index e7e51ff37..feeb0c233 100644 --- a/crates/brk_client/src/lib.rs +++ b/crates/brk_client/src/lib.rs @@ -954,7 +954,8 @@ pub struct AdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitReal pub investor_cap_raw: MetricPattern18, pub investor_price: CentsSatsUsdPattern, pub investor_price_ratio: BpsRatioPattern, - pub investor_price_ratio_ext: RatioPattern, + pub investor_price_ratio_percentiles: RatioPattern, + pub investor_price_ratio_std_dev: RatioPattern2, pub loss_value_created: MetricPattern1, pub loss_value_destroyed: MetricPattern1, pub lower_price_band: CentsSatsUsdPattern, @@ -981,7 +982,8 @@ pub struct AdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitReal pub realized_loss_sum: _1m1w1y24hPattern, pub realized_price: CentsSatsUsdPattern, pub realized_price_ratio: BpsRatioPattern, - pub realized_price_ratio_ext: RatioPattern, + pub realized_price_ratio_percentiles: RatioPattern, + pub realized_price_ratio_std_dev: RatioPattern2, pub realized_profit: CumulativeHeightPattern, pub realized_profit_ema_1w: MetricPattern1, pub realized_profit_rel_to_realized_cap: BpsPercentRatioPattern, @@ -1019,7 +1021,8 @@ impl AdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSe investor_cap_raw: MetricPattern18::new(client.clone(), _m(&acc, "investor_cap_raw")), investor_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "investor_price")), investor_price_ratio: BpsRatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")), - investor_price_ratio_ext: RatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")), + investor_price_ratio_percentiles: RatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")), + investor_price_ratio_std_dev: RatioPattern2::new(client.clone(), _m(&acc, "investor_price_ratio")), loss_value_created: MetricPattern1::new(client.clone(), _m(&acc, "loss_value_created")), loss_value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "loss_value_destroyed")), lower_price_band: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "lower_price_band")), @@ -1046,7 +1049,130 @@ impl AdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSe realized_loss_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "realized_loss")), realized_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "realized_price")), realized_price_ratio: BpsRatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")), - realized_price_ratio_ext: RatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")), + realized_price_ratio_percentiles: RatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")), + realized_price_ratio_std_dev: RatioPattern2::new(client.clone(), _m(&acc, "realized_price_ratio")), + realized_profit: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_profit")), + realized_profit_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "realized_profit_ema_1w")), + realized_profit_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_profit_rel_to_realized_cap")), + realized_profit_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "realized_profit")), + realized_profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "realized_profit_to_loss_ratio")), + sell_side_risk_ratio: _1m1w1y24hPattern2::new(client.clone(), _m(&acc, "sell_side_risk_ratio")), + sell_side_risk_ratio_24h_ema: _1m1wPattern::new(client.clone(), _m(&acc, "sell_side_risk_ratio_24h_ema")), + sent_in_loss: BaseCumulativePattern::new(client.clone(), _m(&acc, "sent_in_loss")), + sent_in_loss_ema: _2wPattern::new(client.clone(), _m(&acc, "sent_in_loss_ema_2w")), + sent_in_profit: BaseCumulativePattern::new(client.clone(), _m(&acc, "sent_in_profit")), + sent_in_profit_ema: _2wPattern::new(client.clone(), _m(&acc, "sent_in_profit_ema_2w")), + sopr: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sopr")), + sopr_24h_ema: _1m1wPattern2::new(client.clone(), _m(&acc, "sopr_24h_ema")), + upper_price_band: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "upper_price_band")), + value_created: MetricPattern1::new(client.clone(), _m(&acc, "value_created")), + value_created_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "value_created")), + value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "value_destroyed")), + value_destroyed_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "value_destroyed")), + } + } +} + +/// Pattern struct for repeated tree structure. +pub struct CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2 { + pub cap_raw: MetricPattern18, + pub capitulation_flow: MetricPattern1, + pub gross_pnl: CentsUsdPattern, + pub gross_pnl_sum: _1m1w1y24hPattern, + pub investor_cap_raw: MetricPattern18, + pub investor_price: CentsSatsUsdPattern, + pub investor_price_ratio: BpsRatioPattern, + pub investor_price_ratio_percentiles: RatioPattern, + pub investor_price_ratio_std_dev: RatioPattern2, + pub loss_value_created: MetricPattern1, + pub loss_value_destroyed: MetricPattern1, + pub lower_price_band: CentsSatsUsdPattern, + pub mvrv: MetricPattern1, + pub neg_realized_loss: MetricPattern1, + pub net_pnl_change_1m: MetricPattern1, + pub net_pnl_change_1m_rel_to_market_cap: BpsPercentRatioPattern, + pub net_pnl_change_1m_rel_to_realized_cap: BpsPercentRatioPattern, + pub net_realized_pnl: CumulativeHeightPattern, + pub net_realized_pnl_ema_1w: MetricPattern1, + pub net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern, + pub peak_regret: CumulativeHeightPattern, + pub peak_regret_rel_to_realized_cap: BpsPercentRatioPattern, + pub profit_flow: MetricPattern1, + pub profit_value_created: MetricPattern1, + pub profit_value_destroyed: MetricPattern1, + pub realized_cap: MetricPattern1, + pub realized_cap_cents: MetricPattern1, + pub realized_cap_change_1m: MetricPattern1, + pub realized_cap_rel_to_own_market_cap: BpsPercentRatioPattern, + pub realized_loss: CumulativeHeightPattern, + pub realized_loss_ema_1w: MetricPattern1, + pub realized_loss_rel_to_realized_cap: BpsPercentRatioPattern, + pub realized_loss_sum: _1m1w1y24hPattern, + pub realized_price: CentsSatsUsdPattern, + pub realized_price_ratio: BpsRatioPattern, + pub realized_price_ratio_percentiles: RatioPattern, + pub realized_price_ratio_std_dev: RatioPattern2, + pub realized_profit: CumulativeHeightPattern, + pub realized_profit_ema_1w: MetricPattern1, + pub realized_profit_rel_to_realized_cap: BpsPercentRatioPattern, + pub realized_profit_sum: _1m1w1y24hPattern, + pub realized_profit_to_loss_ratio: _1m1w1y24hPattern, + pub sell_side_risk_ratio: _1m1w1y24hPattern2, + pub sell_side_risk_ratio_24h_ema: _1m1wPattern, + pub sent_in_loss: BaseCumulativePattern, + pub sent_in_loss_ema: _2wPattern, + pub sent_in_profit: BaseCumulativePattern, + pub sent_in_profit_ema: _2wPattern, + pub sopr: _1m1w1y24hPattern, + pub sopr_24h_ema: _1m1wPattern2, + pub upper_price_band: CentsSatsUsdPattern, + pub value_created: MetricPattern1, + pub value_created_sum: _1m1w1y24hPattern, + pub value_destroyed: MetricPattern1, + pub value_destroyed_sum: _1m1w1y24hPattern, +} + +impl CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2 { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + cap_raw: MetricPattern18::new(client.clone(), _m(&acc, "cap_raw")), + capitulation_flow: MetricPattern1::new(client.clone(), _m(&acc, "capitulation_flow")), + gross_pnl: CentsUsdPattern::new(client.clone(), _m(&acc, "realized_gross_pnl")), + gross_pnl_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "gross_pnl_sum")), + investor_cap_raw: MetricPattern18::new(client.clone(), _m(&acc, "investor_cap_raw")), + investor_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "investor_price")), + investor_price_ratio: BpsRatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")), + investor_price_ratio_percentiles: RatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")), + investor_price_ratio_std_dev: RatioPattern2::new(client.clone(), _m(&acc, "investor_price_ratio")), + loss_value_created: MetricPattern1::new(client.clone(), _m(&acc, "loss_value_created")), + loss_value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "loss_value_destroyed")), + lower_price_band: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "lower_price_band")), + mvrv: MetricPattern1::new(client.clone(), _m(&acc, "mvrv")), + neg_realized_loss: MetricPattern1::new(client.clone(), _m(&acc, "neg_realized_loss")), + net_pnl_change_1m: MetricPattern1::new(client.clone(), _m(&acc, "net_pnl_change_1m")), + net_pnl_change_1m_rel_to_market_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_pnl_change_1m_rel_to_market_cap")), + net_pnl_change_1m_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_pnl_change_1m_rel_to_realized_cap")), + net_realized_pnl: CumulativeHeightPattern::new(client.clone(), _m(&acc, "net_realized_pnl")), + net_realized_pnl_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "net_realized_pnl_ema_1w")), + net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_realized_pnl_rel_to_realized_cap")), + 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")), + profit_flow: MetricPattern1::new(client.clone(), _m(&acc, "profit_flow")), + profit_value_created: MetricPattern1::new(client.clone(), _m(&acc, "profit_value_created")), + profit_value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "profit_value_destroyed")), + realized_cap: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap")), + realized_cap_cents: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap_cents")), + realized_cap_change_1m: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap_change_1m")), + realized_cap_rel_to_own_market_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_cap_rel_to_own_market_cap")), + realized_loss: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_loss")), + realized_loss_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "realized_loss_ema_1w")), + realized_loss_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_loss_rel_to_realized_cap")), + realized_loss_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "realized_loss")), + realized_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "realized_price")), + realized_price_ratio: BpsRatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")), + realized_price_ratio_percentiles: RatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")), + realized_price_ratio_std_dev: RatioPattern2::new(client.clone(), _m(&acc, "realized_price_ratio")), realized_profit: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_profit")), realized_profit_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "realized_profit_ema_1w")), realized_profit_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_profit_rel_to_realized_cap")), @@ -1187,124 +1313,6 @@ impl AdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSe } } -/// Pattern struct for repeated tree structure. -pub struct CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2 { - pub cap_raw: MetricPattern18, - pub capitulation_flow: MetricPattern1, - pub gross_pnl: CentsUsdPattern, - pub gross_pnl_sum: _1m1w1y24hPattern, - pub investor_cap_raw: MetricPattern18, - pub investor_price: CentsSatsUsdPattern, - pub investor_price_ratio: BpsRatioPattern, - pub investor_price_ratio_ext: RatioPattern, - pub loss_value_created: MetricPattern1, - pub loss_value_destroyed: MetricPattern1, - pub lower_price_band: CentsSatsUsdPattern, - pub mvrv: MetricPattern1, - pub neg_realized_loss: MetricPattern1, - pub net_pnl_change_1m: MetricPattern1, - pub net_pnl_change_1m_rel_to_market_cap: BpsPercentRatioPattern, - pub net_pnl_change_1m_rel_to_realized_cap: BpsPercentRatioPattern, - pub net_realized_pnl: CumulativeHeightPattern, - pub net_realized_pnl_ema_1w: MetricPattern1, - pub net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern, - pub peak_regret: CumulativeHeightPattern, - pub peak_regret_rel_to_realized_cap: BpsPercentRatioPattern, - pub profit_flow: MetricPattern1, - pub profit_value_created: MetricPattern1, - pub profit_value_destroyed: MetricPattern1, - pub realized_cap: MetricPattern1, - pub realized_cap_cents: MetricPattern1, - pub realized_cap_change_1m: MetricPattern1, - pub realized_cap_rel_to_own_market_cap: BpsPercentRatioPattern, - pub realized_loss: CumulativeHeightPattern, - pub realized_loss_ema_1w: MetricPattern1, - pub realized_loss_rel_to_realized_cap: BpsPercentRatioPattern, - pub realized_loss_sum: _1m1w1y24hPattern, - pub realized_price: CentsSatsUsdPattern, - pub realized_price_ratio: BpsRatioPattern, - pub realized_price_ratio_ext: RatioPattern, - pub realized_profit: CumulativeHeightPattern, - pub realized_profit_ema_1w: MetricPattern1, - pub realized_profit_rel_to_realized_cap: BpsPercentRatioPattern, - pub realized_profit_sum: _1m1w1y24hPattern, - pub realized_profit_to_loss_ratio: _1m1w1y24hPattern, - pub sell_side_risk_ratio: _1m1w1y24hPattern2, - pub sell_side_risk_ratio_24h_ema: _1m1wPattern, - pub sent_in_loss: BaseCumulativePattern, - pub sent_in_loss_ema: _2wPattern, - pub sent_in_profit: BaseCumulativePattern, - pub sent_in_profit_ema: _2wPattern, - pub sopr: _1m1w1y24hPattern, - pub sopr_24h_ema: _1m1wPattern2, - pub upper_price_band: CentsSatsUsdPattern, - pub value_created: MetricPattern1, - pub value_created_sum: _1m1w1y24hPattern, - pub value_destroyed: MetricPattern1, - pub value_destroyed_sum: _1m1w1y24hPattern, -} - -impl CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2 { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - cap_raw: MetricPattern18::new(client.clone(), _m(&acc, "cap_raw")), - capitulation_flow: MetricPattern1::new(client.clone(), _m(&acc, "capitulation_flow")), - gross_pnl: CentsUsdPattern::new(client.clone(), _m(&acc, "realized_gross_pnl")), - gross_pnl_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "gross_pnl_sum")), - investor_cap_raw: MetricPattern18::new(client.clone(), _m(&acc, "investor_cap_raw")), - investor_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "investor_price")), - investor_price_ratio: BpsRatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")), - investor_price_ratio_ext: RatioPattern::new(client.clone(), _m(&acc, "investor_price_ratio")), - loss_value_created: MetricPattern1::new(client.clone(), _m(&acc, "loss_value_created")), - loss_value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "loss_value_destroyed")), - lower_price_band: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "lower_price_band")), - mvrv: MetricPattern1::new(client.clone(), _m(&acc, "mvrv")), - neg_realized_loss: MetricPattern1::new(client.clone(), _m(&acc, "neg_realized_loss")), - net_pnl_change_1m: MetricPattern1::new(client.clone(), _m(&acc, "net_pnl_change_1m")), - net_pnl_change_1m_rel_to_market_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_pnl_change_1m_rel_to_market_cap")), - net_pnl_change_1m_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_pnl_change_1m_rel_to_realized_cap")), - net_realized_pnl: CumulativeHeightPattern::new(client.clone(), _m(&acc, "net_realized_pnl")), - net_realized_pnl_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "net_realized_pnl_ema_1w")), - net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "net_realized_pnl_rel_to_realized_cap")), - 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")), - profit_flow: MetricPattern1::new(client.clone(), _m(&acc, "profit_flow")), - profit_value_created: MetricPattern1::new(client.clone(), _m(&acc, "profit_value_created")), - profit_value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "profit_value_destroyed")), - realized_cap: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap")), - realized_cap_cents: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap_cents")), - realized_cap_change_1m: MetricPattern1::new(client.clone(), _m(&acc, "realized_cap_change_1m")), - realized_cap_rel_to_own_market_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_cap_rel_to_own_market_cap")), - realized_loss: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_loss")), - realized_loss_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "realized_loss_ema_1w")), - realized_loss_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_loss_rel_to_realized_cap")), - realized_loss_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "realized_loss")), - realized_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "realized_price")), - realized_price_ratio: BpsRatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")), - realized_price_ratio_ext: RatioPattern::new(client.clone(), _m(&acc, "realized_price_ratio")), - realized_profit: CumulativeHeightPattern::new(client.clone(), _m(&acc, "realized_profit")), - realized_profit_ema_1w: MetricPattern1::new(client.clone(), _m(&acc, "realized_profit_ema_1w")), - realized_profit_rel_to_realized_cap: BpsPercentRatioPattern::new(client.clone(), _m(&acc, "realized_profit_rel_to_realized_cap")), - realized_profit_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "realized_profit")), - realized_profit_to_loss_ratio: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "realized_profit_to_loss_ratio")), - sell_side_risk_ratio: _1m1w1y24hPattern2::new(client.clone(), _m(&acc, "sell_side_risk_ratio")), - sell_side_risk_ratio_24h_ema: _1m1wPattern::new(client.clone(), _m(&acc, "sell_side_risk_ratio_24h_ema")), - sent_in_loss: BaseCumulativePattern::new(client.clone(), _m(&acc, "sent_in_loss")), - sent_in_loss_ema: _2wPattern::new(client.clone(), _m(&acc, "sent_in_loss_ema_2w")), - sent_in_profit: BaseCumulativePattern::new(client.clone(), _m(&acc, "sent_in_profit")), - sent_in_profit_ema: _2wPattern::new(client.clone(), _m(&acc, "sent_in_profit_ema_2w")), - sopr: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "sopr")), - sopr_24h_ema: _1m1wPattern2::new(client.clone(), _m(&acc, "sopr_24h_ema")), - upper_price_band: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "upper_price_band")), - value_created: MetricPattern1::new(client.clone(), _m(&acc, "value_created")), - value_created_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "value_created")), - value_destroyed: MetricPattern1::new(client.clone(), _m(&acc, "value_destroyed")), - value_destroyed_sum: _1m1w1y24hPattern::new(client.clone(), _m(&acc, "value_destroyed")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern { pub cap_raw: MetricPattern18, @@ -1479,58 +1487,6 @@ impl _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern { } } -/// Pattern struct for repeated tree structure. -pub struct BpsRatioPattern2 { - pub bps: MetricPattern1, - pub ratio: MetricPattern1, - pub ratio_pct1: BpsRatioPattern, - pub ratio_pct1_price: CentsSatsUsdPattern, - pub ratio_pct2: BpsRatioPattern, - pub ratio_pct2_price: CentsSatsUsdPattern, - pub ratio_pct5: BpsRatioPattern, - pub ratio_pct5_price: CentsSatsUsdPattern, - pub ratio_pct95: BpsRatioPattern, - pub ratio_pct95_price: CentsSatsUsdPattern, - pub ratio_pct98: BpsRatioPattern, - pub ratio_pct98_price: CentsSatsUsdPattern, - pub ratio_pct99: BpsRatioPattern, - pub ratio_pct99_price: CentsSatsUsdPattern, - pub ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, - pub ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, - pub ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, - pub ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, - pub ratio_sma_1m: BpsRatioPattern, - pub ratio_sma_1w: BpsRatioPattern, -} - -impl BpsRatioPattern2 { - /// Create a new pattern node with accumulated metric name. - pub fn new(client: Arc, acc: String) -> Self { - Self { - bps: MetricPattern1::new(client.clone(), _m(&acc, "bps")), - ratio: MetricPattern1::new(client.clone(), acc.clone()), - ratio_pct1: BpsRatioPattern::new(client.clone(), _m(&acc, "pct1")), - ratio_pct1_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct1")), - ratio_pct2: BpsRatioPattern::new(client.clone(), _m(&acc, "pct2")), - ratio_pct2_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct2")), - ratio_pct5: BpsRatioPattern::new(client.clone(), _m(&acc, "pct5")), - ratio_pct5_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct5")), - ratio_pct95: BpsRatioPattern::new(client.clone(), _m(&acc, "pct95")), - ratio_pct95_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct95")), - ratio_pct98: BpsRatioPattern::new(client.clone(), _m(&acc, "pct98")), - ratio_pct98_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct98")), - ratio_pct99: BpsRatioPattern::new(client.clone(), _m(&acc, "pct99")), - ratio_pct99_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct99")), - ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), - ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), - ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), - ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), - ratio_sma_1m: BpsRatioPattern::new(client.clone(), _m(&acc, "sma_1m")), - ratio_sma_1w: BpsRatioPattern::new(client.clone(), _m(&acc, "sma_1w")), - } - } -} - /// Pattern struct for repeated tree structure. pub struct InvestedNegNetNuplSupplyUnrealizedPattern2 { pub invested_capital_in_loss_rel_to_realized_cap: BpsPercentRatioPattern, @@ -1634,7 +1590,9 @@ impl Pct05Pct10Pct15Pct20Pct25Pct30Pct35Pct40Pct45Pct50Pct55Pct60Pct65Pct70Pct75 } /// Pattern struct for repeated tree structure. -pub struct RatioPattern { +pub struct BpsRatioPattern2 { + pub bps: MetricPattern1, + pub ratio: MetricPattern1, pub ratio_pct1: BpsRatioPattern, pub ratio_pct1_price: CentsSatsUsdPattern, pub ratio_pct2: BpsRatioPattern, @@ -1647,18 +1605,16 @@ pub struct RatioPattern { pub ratio_pct98_price: CentsSatsUsdPattern, pub ratio_pct99: BpsRatioPattern, pub ratio_pct99_price: CentsSatsUsdPattern, - pub ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, - pub ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, - pub ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, - pub ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, pub ratio_sma_1m: BpsRatioPattern, pub ratio_sma_1w: BpsRatioPattern, } -impl RatioPattern { +impl BpsRatioPattern2 { /// Create a new pattern node with accumulated metric name. pub fn new(client: Arc, acc: String) -> Self { Self { + bps: MetricPattern1::new(client.clone(), _m(&acc, "bps")), + ratio: MetricPattern1::new(client.clone(), acc.clone()), ratio_pct1: BpsRatioPattern::new(client.clone(), _m(&acc, "pct1")), ratio_pct1_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct1")), ratio_pct2: BpsRatioPattern::new(client.clone(), _m(&acc, "pct2")), @@ -1671,10 +1627,6 @@ impl RatioPattern { ratio_pct98_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct98")), ratio_pct99: BpsRatioPattern::new(client.clone(), _m(&acc, "pct99")), ratio_pct99_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct99")), - ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), - ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), - ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), - ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), ratio_sma_1m: BpsRatioPattern::new(client.clone(), _m(&acc, "sma_1m")), ratio_sma_1w: BpsRatioPattern::new(client.clone(), _m(&acc, "sma_1w")), } @@ -1725,6 +1677,46 @@ impl GreedGrossInvestedInvestorNegNetPainSupplyUnrealizedPattern { } } +/// Pattern struct for repeated tree structure. +pub struct RatioPattern { + pub ratio_pct1: BpsRatioPattern, + pub ratio_pct1_price: CentsSatsUsdPattern, + pub ratio_pct2: BpsRatioPattern, + pub ratio_pct2_price: CentsSatsUsdPattern, + pub ratio_pct5: BpsRatioPattern, + pub ratio_pct5_price: CentsSatsUsdPattern, + pub ratio_pct95: BpsRatioPattern, + pub ratio_pct95_price: CentsSatsUsdPattern, + pub ratio_pct98: BpsRatioPattern, + pub ratio_pct98_price: CentsSatsUsdPattern, + pub ratio_pct99: BpsRatioPattern, + pub ratio_pct99_price: CentsSatsUsdPattern, + pub ratio_sma_1m: BpsRatioPattern, + pub ratio_sma_1w: BpsRatioPattern, +} + +impl RatioPattern { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + ratio_pct1: BpsRatioPattern::new(client.clone(), _m(&acc, "pct1")), + ratio_pct1_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct1")), + ratio_pct2: BpsRatioPattern::new(client.clone(), _m(&acc, "pct2")), + ratio_pct2_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct2")), + ratio_pct5: BpsRatioPattern::new(client.clone(), _m(&acc, "pct5")), + ratio_pct5_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct5")), + ratio_pct95: BpsRatioPattern::new(client.clone(), _m(&acc, "pct95")), + ratio_pct95_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct95")), + ratio_pct98: BpsRatioPattern::new(client.clone(), _m(&acc, "pct98")), + ratio_pct98_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct98")), + ratio_pct99: BpsRatioPattern::new(client.clone(), _m(&acc, "pct99")), + ratio_pct99_price: CentsSatsUsdPattern::new(client.clone(), _m(&acc, "pct99")), + ratio_sma_1m: BpsRatioPattern::new(client.clone(), _m(&acc, "sma_1m")), + ratio_sma_1w: BpsRatioPattern::new(client.clone(), _m(&acc, "sma_1w")), + } + } +} + /// Pattern struct for repeated tree structure. pub struct _10y1m1w1y2y3m3y4y5y6m6y8yPattern2 { pub _10y: BpsPercentRatioPattern, @@ -2433,6 +2425,26 @@ impl InvestedMaxMinPercentilesPattern { } } +/// Pattern struct for repeated tree structure. +pub struct RatioPattern2 { + pub ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, + pub ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, + pub ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, + pub ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern, +} + +impl RatioPattern2 { + /// Create a new pattern node with accumulated metric name. + pub fn new(client: Arc, acc: String) -> Self { + Self { + ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), + ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), + ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), + ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern::new(client.clone(), acc.clone()), + } + } +} + /// Pattern struct for repeated tree structure. pub struct _1m1w1y24hPattern { pub _1m: MetricPattern1, diff --git a/crates/brk_computer/src/distribution/metrics/realized/extended.rs b/crates/brk_computer/src/distribution/metrics/realized/extended.rs index b6a5ccedb..d86cf6f70 100644 --- a/crates/brk_computer/src/distribution/metrics/realized/extended.rs +++ b/crates/brk_computer/src/distribution/metrics/realized/extended.rs @@ -6,8 +6,8 @@ use vecdb::{Exit, ReadableVec, Rw, StorageMode}; use crate::{ blocks, internal::{ - ComputedFromHeightRatioExtension, PercentFromHeight, RatioCents64, RatioDollarsBp32, - RollingWindows, + ComputedFromHeightRatioPercentiles, ComputedFromHeightRatioStdDevBands, + PercentFromHeight, RatioCents64, RatioDollarsBp32, RollingWindows, }, }; @@ -24,8 +24,10 @@ pub struct RealizedExtended { pub realized_profit_to_loss_ratio: RollingWindows, - pub realized_price_ratio_ext: ComputedFromHeightRatioExtension, - pub investor_price_ratio_ext: ComputedFromHeightRatioExtension, + pub realized_price_ratio_percentiles: ComputedFromHeightRatioPercentiles, + pub realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands, + pub investor_price_ratio_percentiles: ComputedFromHeightRatioPercentiles, + pub investor_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands, } impl RealizedExtended { @@ -37,13 +39,27 @@ impl RealizedExtended { realized_loss_sum: cfg.import_rolling("realized_loss", Version::ONE)?, realized_profit_to_loss_ratio: cfg .import_rolling("realized_profit_to_loss_ratio", Version::ONE)?, - realized_price_ratio_ext: ComputedFromHeightRatioExtension::forced_import( + realized_price_ratio_percentiles: + ComputedFromHeightRatioPercentiles::forced_import( + cfg.db, + &cfg.name("realized_price"), + cfg.version + Version::ONE, + cfg.indexes, + )?, + realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands::forced_import( cfg.db, &cfg.name("realized_price"), cfg.version + Version::ONE, cfg.indexes, )?, - investor_price_ratio_ext: ComputedFromHeightRatioExtension::forced_import( + investor_price_ratio_percentiles: + ComputedFromHeightRatioPercentiles::forced_import( + cfg.db, + &cfg.name("investor_price"), + cfg.version, + cfg.indexes, + )?, + investor_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands::forced_import( cfg.db, &cfg.name("investor_price"), cfg.version, @@ -101,29 +117,36 @@ impl RealizedExtended { )?; } - // Extended ratio metrics - self.realized_price_ratio_ext.compute_rest( + // Realized price ratio: percentiles + stddev + self.realized_price_ratio_percentiles.compute( blocks, starting_indexes, exit, &base.realized_price_ratio.ratio.height, - )?; - self.realized_price_ratio_ext.compute_cents_bands( - starting_indexes, &base.realized_price.cents.height, + )?; + self.realized_price_ratio_std_dev.compute( + blocks, + starting_indexes, exit, + &base.realized_price_ratio.ratio.height, + &base.realized_price.cents.height, )?; - self.investor_price_ratio_ext.compute_rest( + // Investor price ratio: percentiles + stddev + self.investor_price_ratio_percentiles.compute( blocks, starting_indexes, exit, &base.investor_price_ratio.ratio.height, - )?; - self.investor_price_ratio_ext.compute_cents_bands( - starting_indexes, &base.investor_price.cents.height, + )?; + self.investor_price_ratio_std_dev.compute( + blocks, + starting_indexes, exit, + &base.investor_price_ratio.ratio.height, + &base.investor_price.cents.height, )?; Ok(()) diff --git a/crates/brk_computer/src/internal/from_height/ratio/extended.rs b/crates/brk_computer/src/internal/from_height/ratio/extended.rs index 8d7d9e70e..73ec23ddd 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/extended.rs +++ b/crates/brk_computer/src/internal/from_height/ratio/extended.rs @@ -6,7 +6,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; use crate::{blocks, indexes, prices}; -use super::{ComputedFromHeightRatio, ComputedFromHeightRatioExtension}; +use super::{ComputedFromHeightRatio, ComputedFromHeightRatioPercentiles}; #[derive(Deref, DerefMut, Traversable)] pub struct ComputedFromHeightRatioExtended { @@ -15,7 +15,7 @@ pub struct ComputedFromHeightRatioExtended { #[traversable(flatten)] pub base: ComputedFromHeightRatio, #[traversable(flatten)] - pub extended: ComputedFromHeightRatioExtension, + pub percentiles: ComputedFromHeightRatioPercentiles, } impl ComputedFromHeightRatioExtended { @@ -27,11 +27,13 @@ impl ComputedFromHeightRatioExtended { ) -> Result { Ok(Self { base: ComputedFromHeightRatio::forced_import(db, name, version, indexes)?, - extended: ComputedFromHeightRatioExtension::forced_import(db, name, version, indexes)?, + percentiles: ComputedFromHeightRatioPercentiles::forced_import( + db, name, version, indexes, + )?, }) } - /// Compute ratio and all extended metrics from an externally-provided metric price (in cents). + /// Compute ratio and all percentile metrics from an externally-provided metric price (in cents). pub(crate) fn compute_rest( &mut self, blocks: &blocks::Vecs, @@ -43,10 +45,8 @@ impl ComputedFromHeightRatioExtended { let close_price = &prices.price.cents.height; self.base .compute_ratio(starting_indexes, close_price, metric_price, exit)?; - self.extended - .compute_rest(blocks, starting_indexes, exit, &self.base.ratio.height)?; - self.extended - .compute_cents_bands(starting_indexes, metric_price, exit)?; + self.percentiles + .compute(blocks, starting_indexes, exit, &self.base.ratio.height, metric_price)?; Ok(()) } } diff --git a/crates/brk_computer/src/internal/from_height/ratio/full.rs b/crates/brk_computer/src/internal/from_height/ratio/full.rs new file mode 100644 index 000000000..c4a2c0450 --- /dev/null +++ b/crates/brk_computer/src/internal/from_height/ratio/full.rs @@ -0,0 +1,51 @@ +use brk_error::Result; +use brk_traversable::Traversable; +use brk_types::{Cents, Height, Indexes, Version}; +use derive_more::{Deref, DerefMut}; +use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; + +use crate::{blocks, indexes, prices}; + +use super::{ComputedFromHeightRatioExtended, ComputedFromHeightRatioStdDevBands}; + +#[derive(Deref, DerefMut, Traversable)] +pub struct ComputedFromHeightRatioFull { + #[deref] + #[deref_mut] + #[traversable(flatten)] + pub base: ComputedFromHeightRatioExtended, + #[traversable(flatten)] + pub std_dev: ComputedFromHeightRatioStdDevBands, +} + +impl ComputedFromHeightRatioFull { + pub(crate) fn forced_import( + db: &Database, + name: &str, + version: Version, + indexes: &indexes::Vecs, + ) -> Result { + Ok(Self { + base: ComputedFromHeightRatioExtended::forced_import(db, name, version, indexes)?, + std_dev: ComputedFromHeightRatioStdDevBands::forced_import( + db, name, version, indexes, + )?, + }) + } + + /// Compute ratio, percentiles, and all stddev bands from an externally-provided metric price (in cents). + pub(crate) fn compute_rest( + &mut self, + blocks: &blocks::Vecs, + prices: &prices::Vecs, + starting_indexes: &Indexes, + exit: &Exit, + metric_price: &impl ReadableVec, + ) -> Result<()> { + self.base + .compute_rest(blocks, prices, starting_indexes, exit, metric_price)?; + self.std_dev + .compute(blocks, starting_indexes, exit, &self.base.base.ratio.height, metric_price)?; + Ok(()) + } +} diff --git a/crates/brk_computer/src/internal/from_height/ratio/mod.rs b/crates/brk_computer/src/internal/from_height/ratio/mod.rs index de4b44287..b30c7b32d 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/mod.rs +++ b/crates/brk_computer/src/internal/from_height/ratio/mod.rs @@ -1,10 +1,14 @@ mod extended; -mod extension; +mod full; +mod percentiles; mod price_extended; +mod std_dev_bands; pub use extended::*; -pub use extension::*; +pub use full::*; +pub use percentiles::*; pub use price_extended::*; +pub use std_dev_bands::*; use brk_error::Result; use brk_traversable::Traversable; diff --git a/crates/brk_computer/src/internal/from_height/ratio/extension.rs b/crates/brk_computer/src/internal/from_height/ratio/percentiles.rs similarity index 77% rename from crates/brk_computer/src/internal/from_height/ratio/extension.rs rename to crates/brk_computer/src/internal/from_height/ratio/percentiles.rs index 0fa58ccfc..1f8ea1016 100644 --- a/crates/brk_computer/src/internal/from_height/ratio/extension.rs +++ b/crates/brk_computer/src/internal/from_height/ratio/percentiles.rs @@ -8,13 +8,13 @@ use vecdb::{ use crate::{ blocks, indexes, - internal::{ComputedFromHeightStdDevExtended, ExpandingPercentiles, Price, PriceTimesRatioBp32Cents}, + internal::{ExpandingPercentiles, Price, PriceTimesRatioBp32Cents}, }; use super::{super::ComputedFromHeight, ComputedFromHeightRatio}; #[derive(Traversable)] -pub struct ComputedFromHeightRatioExtension { +pub struct ComputedFromHeightRatioPercentiles { pub ratio_sma_1w: ComputedFromHeightRatio, pub ratio_sma_1m: ComputedFromHeightRatio, pub ratio_pct99: ComputedFromHeightRatio, @@ -30,18 +30,13 @@ pub struct ComputedFromHeightRatioExtension { pub ratio_pct2_price: Price>, pub ratio_pct1_price: Price>, - pub ratio_sd: ComputedFromHeightStdDevExtended, - pub ratio_sd_4y: ComputedFromHeightStdDevExtended, - pub ratio_sd_2y: ComputedFromHeightStdDevExtended, - pub ratio_sd_1y: ComputedFromHeightStdDevExtended, - #[traversable(skip)] expanding_pct: ExpandingPercentiles, } const VERSION: Version = Version::new(4); -impl ComputedFromHeightRatioExtension { +impl ComputedFromHeightRatioPercentiles { pub(crate) fn forced_import( db: &Database, name: &str, @@ -61,19 +56,6 @@ impl ComputedFromHeightRatioExtension { }; } - macro_rules! import_sd { - ($suffix:expr, $period:expr, $days:expr) => { - ComputedFromHeightStdDevExtended::forced_import( - db, - &format!("{name}_{}", $suffix), - $period, - $days, - v, - indexes, - )? - }; - } - macro_rules! import_price { ($suffix:expr) => { Price::forced_import(db, &format!("{name}_{}", $suffix), v, indexes)? @@ -83,10 +65,6 @@ impl ComputedFromHeightRatioExtension { Ok(Self { ratio_sma_1w: import_ratio!("ratio_sma_1w"), ratio_sma_1m: import_ratio!("ratio_sma_1m"), - ratio_sd: import_sd!("ratio", "", usize::MAX), - ratio_sd_1y: import_sd!("ratio", "1y", 365), - ratio_sd_2y: import_sd!("ratio", "2y", 2 * 365), - ratio_sd_4y: import_sd!("ratio", "4y", 4 * 365), ratio_pct99: import_ratio!("ratio_pct99"), ratio_pct98: import_ratio!("ratio_pct98"), ratio_pct95: import_ratio!("ratio_pct95"), @@ -103,14 +81,14 @@ impl ComputedFromHeightRatioExtension { }) } - pub(crate) fn compute_rest( + pub(crate) fn compute( &mut self, blocks: &blocks::Vecs, starting_indexes: &Indexes, exit: &Exit, ratio_source: &impl ReadableVec, + metric_price: &impl ReadableVec, ) -> Result<()> { - // SMA using lookback vecs self.ratio_sma_1w.bps.height.compute_rolling_average( starting_indexes.height, &blocks.count.height_1w_ago, @@ -151,7 +129,6 @@ impl ComputedFromHeightRatioExtension { } } - // Process new blocks [start, ratio_len) let new_ratios = ratio_source.collect_range_at(start, ratio_len); let mut pct_vecs: [&mut EagerVec>; 6] = [ &mut self.ratio_pct1.bps.height, @@ -179,25 +156,7 @@ impl ComputedFromHeightRatioExtension { self.mut_pct_vecs().try_for_each(|v| v.flush())?; } - // Compute stddev at height level - for sd in [ - &mut self.ratio_sd, - &mut self.ratio_sd_4y, - &mut self.ratio_sd_2y, - &mut self.ratio_sd_1y, - ] { - sd.compute_all(blocks, starting_indexes, exit, ratio_source)?; - } - - Ok(()) - } - - pub(crate) fn compute_cents_bands( - &mut self, - starting_indexes: &Indexes, - metric_price: &impl ReadableVec, - exit: &Exit, - ) -> Result<()> { + // Cents bands macro_rules! compute_band { ($usd_field:ident, $band_source:expr) => { self.$usd_field @@ -218,16 +177,6 @@ impl ComputedFromHeightRatioExtension { compute_band!(ratio_pct2_price, &self.ratio_pct2.bps.height); compute_band!(ratio_pct1_price, &self.ratio_pct1.bps.height); - // Stddev cents bands - for sd in [ - &mut self.ratio_sd, - &mut self.ratio_sd_4y, - &mut self.ratio_sd_2y, - &mut self.ratio_sd_1y, - ] { - sd.compute_cents_bands(starting_indexes, metric_price, exit)?; - } - Ok(()) } diff --git a/crates/brk_computer/src/internal/from_height/ratio/std_dev_bands.rs b/crates/brk_computer/src/internal/from_height/ratio/std_dev_bands.rs new file mode 100644 index 000000000..645a76b03 --- /dev/null +++ b/crates/brk_computer/src/internal/from_height/ratio/std_dev_bands.rs @@ -0,0 +1,68 @@ +use brk_error::Result; +use brk_traversable::Traversable; +use brk_types::{Cents, Height, Indexes, StoredF32, Version}; +use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode}; + +use crate::{blocks, indexes, internal::ComputedFromHeightStdDevExtended}; + +#[derive(Traversable)] +pub struct ComputedFromHeightRatioStdDevBands { + pub ratio_sd: ComputedFromHeightStdDevExtended, + pub ratio_sd_4y: ComputedFromHeightStdDevExtended, + pub ratio_sd_2y: ComputedFromHeightStdDevExtended, + pub ratio_sd_1y: ComputedFromHeightStdDevExtended, +} + +const VERSION: Version = Version::new(4); + +impl ComputedFromHeightRatioStdDevBands { + pub(crate) fn forced_import( + db: &Database, + name: &str, + version: Version, + indexes: &indexes::Vecs, + ) -> Result { + let v = version + VERSION; + + macro_rules! import_sd { + ($suffix:expr, $period:expr, $days:expr) => { + ComputedFromHeightStdDevExtended::forced_import( + db, + &format!("{name}_{}", $suffix), + $period, + $days, + v, + indexes, + )? + }; + } + + Ok(Self { + ratio_sd: import_sd!("ratio", "", usize::MAX), + ratio_sd_1y: import_sd!("ratio", "1y", 365), + ratio_sd_2y: import_sd!("ratio", "2y", 2 * 365), + ratio_sd_4y: import_sd!("ratio", "4y", 4 * 365), + }) + } + + pub(crate) fn compute( + &mut self, + blocks: &blocks::Vecs, + starting_indexes: &Indexes, + exit: &Exit, + ratio_source: &impl ReadableVec, + metric_price: &impl ReadableVec, + ) -> Result<()> { + for sd in [ + &mut self.ratio_sd, + &mut self.ratio_sd_4y, + &mut self.ratio_sd_2y, + &mut self.ratio_sd_1y, + ] { + sd.compute_all(blocks, starting_indexes, exit, ratio_source)?; + sd.compute_cents_bands(starting_indexes, metric_price, exit)?; + } + + Ok(()) + } +} diff --git a/crates/brk_computer/src/market/dca/compute.rs b/crates/brk_computer/src/market/dca/compute.rs index d81e8b625..57a845a78 100644 --- a/crates/brk_computer/src/market/dca/compute.rs +++ b/crates/brk_computer/src/market/dca/compute.rs @@ -61,12 +61,12 @@ impl Vecs { } // DCA by period - average price (derived from stack) - let sh = starting_indexes.height.to_usize(); + let starting_height = starting_indexes.height.to_usize(); for (average_price, stack, days) in self.period_cost_basis.zip_mut_with_days(&self.period_stack) { let days = days as usize; - let start = average_price.cents.height.len().min(starting_indexes.height.to_usize()); + let start = average_price.cents.height.len().min(starting_height); let stack_data = stack .sats .height @@ -124,7 +124,7 @@ impl Vecs { self.period_lump_sum_stack.zip_mut_with_days(&lookback_dca) { let total_invested = DCA_AMOUNT * days as usize; - let ls_start = stack.sats.height.len().min(starting_indexes.height.to_usize()); + let ls_start = stack.sats.height.len().min(starting_height); let lookback_data = lookback_price .cents .height @@ -163,8 +163,8 @@ impl Vecs { let start_days = super::ByDcaClass::<()>::start_days(); for (stack, day1) in self.class_stack.iter_mut().zip(start_days) { let mut last_di: Option = None; - let mut prev_value = if sh > 0 { - stack.sats.height.collect_one_at(sh - 1).unwrap_or_default() + let mut prev_value = if starting_height > 0 { + stack.sats.height.collect_one_at(starting_height - 1).unwrap_or_default() } else { Sats::ZERO }; @@ -219,7 +219,7 @@ impl Vecs { .zip(start_days) { let from_usize = from.to_usize(); - let cls_start = average_price.cents.height.len().min(starting_indexes.height.to_usize()); + let cls_start = average_price.cents.height.len().min(starting_height); let stack_data = stack .sats .height diff --git a/modules/brk-client/index.js b/modules/brk-client/index.js index cf8964988..3924e3c4d 100644 --- a/modules/brk-client/index.js +++ b/modules/brk-client/index.js @@ -1584,7 +1584,8 @@ function createMetricPattern35(client, name) { return /** @type {MetricPattern35 * @property {MetricPattern18} investorCapRaw * @property {CentsSatsUsdPattern} investorPrice * @property {BpsRatioPattern} investorPriceRatio - * @property {RatioPattern} investorPriceRatioExt + * @property {RatioPattern} investorPriceRatioPercentiles + * @property {RatioPattern2} investorPriceRatioStdDev * @property {MetricPattern1} lossValueCreated * @property {MetricPattern1} lossValueDestroyed * @property {CentsSatsUsdPattern} lowerPriceBand @@ -1611,7 +1612,8 @@ function createMetricPattern35(client, name) { return /** @type {MetricPattern35 * @property {_1m1w1y24hPattern} realizedLossSum * @property {CentsSatsUsdPattern} realizedPrice * @property {BpsRatioPattern} realizedPriceRatio - * @property {RatioPattern} realizedPriceRatioExt + * @property {RatioPattern} realizedPriceRatioPercentiles + * @property {RatioPattern2} realizedPriceRatioStdDev * @property {CumulativeHeightPattern} realizedProfit * @property {MetricPattern1} realizedProfitEma1w * @property {BpsPercentRatioPattern} realizedProfitRelToRealizedCap @@ -1653,7 +1655,8 @@ function createAdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfit investorCapRaw: createMetricPattern18(client, _m(acc, 'investor_cap_raw')), investorPrice: createCentsSatsUsdPattern(client, _m(acc, 'investor_price')), investorPriceRatio: createBpsRatioPattern(client, _m(acc, 'investor_price_ratio')), - investorPriceRatioExt: createRatioPattern(client, _m(acc, 'investor_price_ratio')), + investorPriceRatioPercentiles: createRatioPattern(client, _m(acc, 'investor_price_ratio')), + investorPriceRatioStdDev: createRatioPattern2(client, _m(acc, 'investor_price_ratio')), lossValueCreated: createMetricPattern1(client, _m(acc, 'loss_value_created')), lossValueDestroyed: createMetricPattern1(client, _m(acc, 'loss_value_destroyed')), lowerPriceBand: createCentsSatsUsdPattern(client, _m(acc, 'lower_price_band')), @@ -1680,7 +1683,133 @@ function createAdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfit realizedLossSum: create_1m1w1y24hPattern(client, _m(acc, 'realized_loss')), realizedPrice: createCentsSatsUsdPattern(client, _m(acc, 'realized_price')), realizedPriceRatio: createBpsRatioPattern(client, _m(acc, 'realized_price_ratio')), - realizedPriceRatioExt: createRatioPattern(client, _m(acc, 'realized_price_ratio')), + realizedPriceRatioPercentiles: createRatioPattern(client, _m(acc, 'realized_price_ratio')), + realizedPriceRatioStdDev: createRatioPattern2(client, _m(acc, 'realized_price_ratio')), + realizedProfit: createCumulativeHeightPattern(client, _m(acc, 'realized_profit')), + realizedProfitEma1w: createMetricPattern1(client, _m(acc, 'realized_profit_ema_1w')), + realizedProfitRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_realized_cap')), + realizedProfitSum: create_1m1w1y24hPattern(client, _m(acc, 'realized_profit')), + realizedProfitToLossRatio: create_1m1w1y24hPattern(client, _m(acc, 'realized_profit_to_loss_ratio')), + sellSideRiskRatio: create_1m1w1y24hPattern2(client, _m(acc, 'sell_side_risk_ratio')), + sellSideRiskRatio24hEma: create_1m1wPattern(client, _m(acc, 'sell_side_risk_ratio_24h_ema')), + sentInLoss: createBaseCumulativePattern(client, _m(acc, 'sent_in_loss')), + sentInLossEma: create_2wPattern(client, _m(acc, 'sent_in_loss_ema_2w')), + sentInProfit: createBaseCumulativePattern(client, _m(acc, 'sent_in_profit')), + sentInProfitEma: create_2wPattern(client, _m(acc, 'sent_in_profit_ema_2w')), + sopr: create_1m1w1y24hPattern(client, _m(acc, 'sopr')), + sopr24hEma: create_1m1wPattern2(client, _m(acc, 'sopr_24h_ema')), + upperPriceBand: createCentsSatsUsdPattern(client, _m(acc, 'upper_price_band')), + valueCreated: createMetricPattern1(client, _m(acc, 'value_created')), + valueCreatedSum: create_1m1w1y24hPattern(client, _m(acc, 'value_created')), + valueDestroyed: createMetricPattern1(client, _m(acc, 'value_destroyed')), + valueDestroyedSum: create_1m1w1y24hPattern(client, _m(acc, 'value_destroyed')), + }; +} + +/** + * @typedef {Object} CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2 + * @property {MetricPattern18} capRaw + * @property {MetricPattern1} capitulationFlow + * @property {CentsUsdPattern} grossPnl + * @property {_1m1w1y24hPattern} grossPnlSum + * @property {MetricPattern18} investorCapRaw + * @property {CentsSatsUsdPattern} investorPrice + * @property {BpsRatioPattern} investorPriceRatio + * @property {RatioPattern} investorPriceRatioPercentiles + * @property {RatioPattern2} investorPriceRatioStdDev + * @property {MetricPattern1} lossValueCreated + * @property {MetricPattern1} lossValueDestroyed + * @property {CentsSatsUsdPattern} lowerPriceBand + * @property {MetricPattern1} mvrv + * @property {MetricPattern1} negRealizedLoss + * @property {MetricPattern1} netPnlChange1m + * @property {BpsPercentRatioPattern} netPnlChange1mRelToMarketCap + * @property {BpsPercentRatioPattern} netPnlChange1mRelToRealizedCap + * @property {CumulativeHeightPattern} netRealizedPnl + * @property {MetricPattern1} netRealizedPnlEma1w + * @property {BpsPercentRatioPattern} netRealizedPnlRelToRealizedCap + * @property {CumulativeHeightPattern} peakRegret + * @property {BpsPercentRatioPattern} peakRegretRelToRealizedCap + * @property {MetricPattern1} profitFlow + * @property {MetricPattern1} profitValueCreated + * @property {MetricPattern1} profitValueDestroyed + * @property {MetricPattern1} realizedCap + * @property {MetricPattern1} realizedCapCents + * @property {MetricPattern1} realizedCapChange1m + * @property {BpsPercentRatioPattern} realizedCapRelToOwnMarketCap + * @property {CumulativeHeightPattern} realizedLoss + * @property {MetricPattern1} realizedLossEma1w + * @property {BpsPercentRatioPattern} realizedLossRelToRealizedCap + * @property {_1m1w1y24hPattern} realizedLossSum + * @property {CentsSatsUsdPattern} realizedPrice + * @property {BpsRatioPattern} realizedPriceRatio + * @property {RatioPattern} realizedPriceRatioPercentiles + * @property {RatioPattern2} realizedPriceRatioStdDev + * @property {CumulativeHeightPattern} realizedProfit + * @property {MetricPattern1} realizedProfitEma1w + * @property {BpsPercentRatioPattern} realizedProfitRelToRealizedCap + * @property {_1m1w1y24hPattern} realizedProfitSum + * @property {_1m1w1y24hPattern} realizedProfitToLossRatio + * @property {_1m1w1y24hPattern2} sellSideRiskRatio + * @property {_1m1wPattern} sellSideRiskRatio24hEma + * @property {BaseCumulativePattern} sentInLoss + * @property {_2wPattern} sentInLossEma + * @property {BaseCumulativePattern} sentInProfit + * @property {_2wPattern} sentInProfitEma + * @property {_1m1w1y24hPattern} sopr + * @property {_1m1wPattern2} sopr24hEma + * @property {CentsSatsUsdPattern} upperPriceBand + * @property {MetricPattern1} valueCreated + * @property {_1m1w1y24hPattern} valueCreatedSum + * @property {MetricPattern1} valueDestroyed + * @property {_1m1w1y24hPattern} valueDestroyedSum + */ + +/** + * Create a CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2 pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2} + */ +function createCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2(client, acc) { + return { + capRaw: createMetricPattern18(client, _m(acc, 'cap_raw')), + capitulationFlow: createMetricPattern1(client, _m(acc, 'capitulation_flow')), + grossPnl: createCentsUsdPattern(client, _m(acc, 'realized_gross_pnl')), + grossPnlSum: create_1m1w1y24hPattern(client, _m(acc, 'gross_pnl_sum')), + investorCapRaw: createMetricPattern18(client, _m(acc, 'investor_cap_raw')), + investorPrice: createCentsSatsUsdPattern(client, _m(acc, 'investor_price')), + investorPriceRatio: createBpsRatioPattern(client, _m(acc, 'investor_price_ratio')), + investorPriceRatioPercentiles: createRatioPattern(client, _m(acc, 'investor_price_ratio')), + investorPriceRatioStdDev: createRatioPattern2(client, _m(acc, 'investor_price_ratio')), + lossValueCreated: createMetricPattern1(client, _m(acc, 'loss_value_created')), + lossValueDestroyed: createMetricPattern1(client, _m(acc, 'loss_value_destroyed')), + lowerPriceBand: createCentsSatsUsdPattern(client, _m(acc, 'lower_price_band')), + mvrv: createMetricPattern1(client, _m(acc, 'mvrv')), + negRealizedLoss: createMetricPattern1(client, _m(acc, 'neg_realized_loss')), + netPnlChange1m: createMetricPattern1(client, _m(acc, 'net_pnl_change_1m')), + netPnlChange1mRelToMarketCap: createBpsPercentRatioPattern(client, _m(acc, 'net_pnl_change_1m_rel_to_market_cap')), + netPnlChange1mRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'net_pnl_change_1m_rel_to_realized_cap')), + netRealizedPnl: createCumulativeHeightPattern(client, _m(acc, 'net_realized_pnl')), + netRealizedPnlEma1w: createMetricPattern1(client, _m(acc, 'net_realized_pnl_ema_1w')), + netRealizedPnlRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'net_realized_pnl_rel_to_realized_cap')), + peakRegret: createCumulativeHeightPattern(client, _m(acc, 'realized_peak_regret')), + peakRegretRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_peak_regret_rel_to_realized_cap')), + profitFlow: createMetricPattern1(client, _m(acc, 'profit_flow')), + profitValueCreated: createMetricPattern1(client, _m(acc, 'profit_value_created')), + profitValueDestroyed: createMetricPattern1(client, _m(acc, 'profit_value_destroyed')), + realizedCap: createMetricPattern1(client, _m(acc, 'realized_cap')), + realizedCapCents: createMetricPattern1(client, _m(acc, 'realized_cap_cents')), + realizedCapChange1m: createMetricPattern1(client, _m(acc, 'realized_cap_change_1m')), + realizedCapRelToOwnMarketCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_cap_rel_to_own_market_cap')), + realizedLoss: createCumulativeHeightPattern(client, _m(acc, 'realized_loss')), + realizedLossEma1w: createMetricPattern1(client, _m(acc, 'realized_loss_ema_1w')), + realizedLossRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_loss_rel_to_realized_cap')), + realizedLossSum: create_1m1w1y24hPattern(client, _m(acc, 'realized_loss')), + realizedPrice: createCentsSatsUsdPattern(client, _m(acc, 'realized_price')), + realizedPriceRatio: createBpsRatioPattern(client, _m(acc, 'realized_price_ratio')), + realizedPriceRatioPercentiles: createRatioPattern(client, _m(acc, 'realized_price_ratio')), + realizedPriceRatioStdDev: createRatioPattern2(client, _m(acc, 'realized_price_ratio')), realizedProfit: createCumulativeHeightPattern(client, _m(acc, 'realized_profit')), realizedProfitEma1w: createMetricPattern1(client, _m(acc, 'realized_profit_ema_1w')), realizedProfitRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_realized_cap')), @@ -1823,127 +1952,6 @@ function createAdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfit }; } -/** - * @typedef {Object} CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2 - * @property {MetricPattern18} capRaw - * @property {MetricPattern1} capitulationFlow - * @property {CentsUsdPattern} grossPnl - * @property {_1m1w1y24hPattern} grossPnlSum - * @property {MetricPattern18} investorCapRaw - * @property {CentsSatsUsdPattern} investorPrice - * @property {BpsRatioPattern} investorPriceRatio - * @property {RatioPattern} investorPriceRatioExt - * @property {MetricPattern1} lossValueCreated - * @property {MetricPattern1} lossValueDestroyed - * @property {CentsSatsUsdPattern} lowerPriceBand - * @property {MetricPattern1} mvrv - * @property {MetricPattern1} negRealizedLoss - * @property {MetricPattern1} netPnlChange1m - * @property {BpsPercentRatioPattern} netPnlChange1mRelToMarketCap - * @property {BpsPercentRatioPattern} netPnlChange1mRelToRealizedCap - * @property {CumulativeHeightPattern} netRealizedPnl - * @property {MetricPattern1} netRealizedPnlEma1w - * @property {BpsPercentRatioPattern} netRealizedPnlRelToRealizedCap - * @property {CumulativeHeightPattern} peakRegret - * @property {BpsPercentRatioPattern} peakRegretRelToRealizedCap - * @property {MetricPattern1} profitFlow - * @property {MetricPattern1} profitValueCreated - * @property {MetricPattern1} profitValueDestroyed - * @property {MetricPattern1} realizedCap - * @property {MetricPattern1} realizedCapCents - * @property {MetricPattern1} realizedCapChange1m - * @property {BpsPercentRatioPattern} realizedCapRelToOwnMarketCap - * @property {CumulativeHeightPattern} realizedLoss - * @property {MetricPattern1} realizedLossEma1w - * @property {BpsPercentRatioPattern} realizedLossRelToRealizedCap - * @property {_1m1w1y24hPattern} realizedLossSum - * @property {CentsSatsUsdPattern} realizedPrice - * @property {BpsRatioPattern} realizedPriceRatio - * @property {RatioPattern} realizedPriceRatioExt - * @property {CumulativeHeightPattern} realizedProfit - * @property {MetricPattern1} realizedProfitEma1w - * @property {BpsPercentRatioPattern} realizedProfitRelToRealizedCap - * @property {_1m1w1y24hPattern} realizedProfitSum - * @property {_1m1w1y24hPattern} realizedProfitToLossRatio - * @property {_1m1w1y24hPattern2} sellSideRiskRatio - * @property {_1m1wPattern} sellSideRiskRatio24hEma - * @property {BaseCumulativePattern} sentInLoss - * @property {_2wPattern} sentInLossEma - * @property {BaseCumulativePattern} sentInProfit - * @property {_2wPattern} sentInProfitEma - * @property {_1m1w1y24hPattern} sopr - * @property {_1m1wPattern2} sopr24hEma - * @property {CentsSatsUsdPattern} upperPriceBand - * @property {MetricPattern1} valueCreated - * @property {_1m1w1y24hPattern} valueCreatedSum - * @property {MetricPattern1} valueDestroyed - * @property {_1m1w1y24hPattern} valueDestroyedSum - */ - -/** - * Create a CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2 pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2} - */ -function createCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2(client, acc) { - return { - capRaw: createMetricPattern18(client, _m(acc, 'cap_raw')), - capitulationFlow: createMetricPattern1(client, _m(acc, 'capitulation_flow')), - grossPnl: createCentsUsdPattern(client, _m(acc, 'realized_gross_pnl')), - grossPnlSum: create_1m1w1y24hPattern(client, _m(acc, 'gross_pnl_sum')), - investorCapRaw: createMetricPattern18(client, _m(acc, 'investor_cap_raw')), - investorPrice: createCentsSatsUsdPattern(client, _m(acc, 'investor_price')), - investorPriceRatio: createBpsRatioPattern(client, _m(acc, 'investor_price_ratio')), - investorPriceRatioExt: createRatioPattern(client, _m(acc, 'investor_price_ratio')), - lossValueCreated: createMetricPattern1(client, _m(acc, 'loss_value_created')), - lossValueDestroyed: createMetricPattern1(client, _m(acc, 'loss_value_destroyed')), - lowerPriceBand: createCentsSatsUsdPattern(client, _m(acc, 'lower_price_band')), - mvrv: createMetricPattern1(client, _m(acc, 'mvrv')), - negRealizedLoss: createMetricPattern1(client, _m(acc, 'neg_realized_loss')), - netPnlChange1m: createMetricPattern1(client, _m(acc, 'net_pnl_change_1m')), - netPnlChange1mRelToMarketCap: createBpsPercentRatioPattern(client, _m(acc, 'net_pnl_change_1m_rel_to_market_cap')), - netPnlChange1mRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'net_pnl_change_1m_rel_to_realized_cap')), - netRealizedPnl: createCumulativeHeightPattern(client, _m(acc, 'net_realized_pnl')), - netRealizedPnlEma1w: createMetricPattern1(client, _m(acc, 'net_realized_pnl_ema_1w')), - netRealizedPnlRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'net_realized_pnl_rel_to_realized_cap')), - peakRegret: createCumulativeHeightPattern(client, _m(acc, 'realized_peak_regret')), - peakRegretRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_peak_regret_rel_to_realized_cap')), - profitFlow: createMetricPattern1(client, _m(acc, 'profit_flow')), - profitValueCreated: createMetricPattern1(client, _m(acc, 'profit_value_created')), - profitValueDestroyed: createMetricPattern1(client, _m(acc, 'profit_value_destroyed')), - realizedCap: createMetricPattern1(client, _m(acc, 'realized_cap')), - realizedCapCents: createMetricPattern1(client, _m(acc, 'realized_cap_cents')), - realizedCapChange1m: createMetricPattern1(client, _m(acc, 'realized_cap_change_1m')), - realizedCapRelToOwnMarketCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_cap_rel_to_own_market_cap')), - realizedLoss: createCumulativeHeightPattern(client, _m(acc, 'realized_loss')), - realizedLossEma1w: createMetricPattern1(client, _m(acc, 'realized_loss_ema_1w')), - realizedLossRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_loss_rel_to_realized_cap')), - realizedLossSum: create_1m1w1y24hPattern(client, _m(acc, 'realized_loss')), - realizedPrice: createCentsSatsUsdPattern(client, _m(acc, 'realized_price')), - realizedPriceRatio: createBpsRatioPattern(client, _m(acc, 'realized_price_ratio')), - realizedPriceRatioExt: createRatioPattern(client, _m(acc, 'realized_price_ratio')), - realizedProfit: createCumulativeHeightPattern(client, _m(acc, 'realized_profit')), - realizedProfitEma1w: createMetricPattern1(client, _m(acc, 'realized_profit_ema_1w')), - realizedProfitRelToRealizedCap: createBpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_realized_cap')), - realizedProfitSum: create_1m1w1y24hPattern(client, _m(acc, 'realized_profit')), - realizedProfitToLossRatio: create_1m1w1y24hPattern(client, _m(acc, 'realized_profit_to_loss_ratio')), - sellSideRiskRatio: create_1m1w1y24hPattern2(client, _m(acc, 'sell_side_risk_ratio')), - sellSideRiskRatio24hEma: create_1m1wPattern(client, _m(acc, 'sell_side_risk_ratio_24h_ema')), - sentInLoss: createBaseCumulativePattern(client, _m(acc, 'sent_in_loss')), - sentInLossEma: create_2wPattern(client, _m(acc, 'sent_in_loss_ema_2w')), - sentInProfit: createBaseCumulativePattern(client, _m(acc, 'sent_in_profit')), - sentInProfitEma: create_2wPattern(client, _m(acc, 'sent_in_profit_ema_2w')), - sopr: create_1m1w1y24hPattern(client, _m(acc, 'sopr')), - sopr24hEma: create_1m1wPattern2(client, _m(acc, 'sopr_24h_ema')), - upperPriceBand: createCentsSatsUsdPattern(client, _m(acc, 'upper_price_band')), - valueCreated: createMetricPattern1(client, _m(acc, 'value_created')), - valueCreatedSum: create_1m1w1y24hPattern(client, _m(acc, 'value_created')), - valueDestroyed: createMetricPattern1(client, _m(acc, 'value_destroyed')), - valueDestroyedSum: create_1m1w1y24hPattern(client, _m(acc, 'value_destroyed')), - }; -} - /** * @typedef {Object} CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern * @property {MetricPattern18} capRaw @@ -2124,61 +2132,6 @@ function create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client }; } -/** - * @typedef {Object} BpsRatioPattern2 - * @property {MetricPattern1} bps - * @property {MetricPattern1} ratio - * @property {BpsRatioPattern} ratioPct1 - * @property {CentsSatsUsdPattern} ratioPct1Price - * @property {BpsRatioPattern} ratioPct2 - * @property {CentsSatsUsdPattern} ratioPct2Price - * @property {BpsRatioPattern} ratioPct5 - * @property {CentsSatsUsdPattern} ratioPct5Price - * @property {BpsRatioPattern} ratioPct95 - * @property {CentsSatsUsdPattern} ratioPct95Price - * @property {BpsRatioPattern} ratioPct98 - * @property {CentsSatsUsdPattern} ratioPct98Price - * @property {BpsRatioPattern} ratioPct99 - * @property {CentsSatsUsdPattern} ratioPct99Price - * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd - * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd1y - * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd2y - * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd4y - * @property {BpsRatioPattern} ratioSma1m - * @property {BpsRatioPattern} ratioSma1w - */ - -/** - * Create a BpsRatioPattern2 pattern node - * @param {BrkClientBase} client - * @param {string} acc - Accumulated metric name - * @returns {BpsRatioPattern2} - */ -function createBpsRatioPattern2(client, acc) { - return { - bps: createMetricPattern1(client, _m(acc, 'bps')), - ratio: createMetricPattern1(client, acc), - ratioPct1: createBpsRatioPattern(client, _m(acc, 'pct1')), - ratioPct1Price: createCentsSatsUsdPattern(client, _m(acc, 'pct1')), - ratioPct2: createBpsRatioPattern(client, _m(acc, 'pct2')), - ratioPct2Price: createCentsSatsUsdPattern(client, _m(acc, 'pct2')), - ratioPct5: createBpsRatioPattern(client, _m(acc, 'pct5')), - ratioPct5Price: createCentsSatsUsdPattern(client, _m(acc, 'pct5')), - ratioPct95: createBpsRatioPattern(client, _m(acc, 'pct95')), - ratioPct95Price: createCentsSatsUsdPattern(client, _m(acc, 'pct95')), - ratioPct98: createBpsRatioPattern(client, _m(acc, 'pct98')), - ratioPct98Price: createCentsSatsUsdPattern(client, _m(acc, 'pct98')), - ratioPct99: createBpsRatioPattern(client, _m(acc, 'pct99')), - ratioPct99Price: createCentsSatsUsdPattern(client, _m(acc, 'pct99')), - ratioSd: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), - ratioSd1y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), - ratioSd2y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), - ratioSd4y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), - ratioSma1m: createBpsRatioPattern(client, _m(acc, 'sma_1m')), - ratioSma1w: createBpsRatioPattern(client, _m(acc, 'sma_1w')), - }; -} - /** * @typedef {Object} InvestedNegNetNuplSupplyUnrealizedPattern2 * @property {BpsPercentRatioPattern} investedCapitalInLossRelToRealizedCap @@ -2288,7 +2241,9 @@ function createPct05Pct10Pct15Pct20Pct25Pct30Pct35Pct40Pct45Pct50Pct55Pct60Pct65 } /** - * @typedef {Object} RatioPattern + * @typedef {Object} BpsRatioPattern2 + * @property {MetricPattern1} bps + * @property {MetricPattern1} ratio * @property {BpsRatioPattern} ratioPct1 * @property {CentsSatsUsdPattern} ratioPct1Price * @property {BpsRatioPattern} ratioPct2 @@ -2301,22 +2256,20 @@ function createPct05Pct10Pct15Pct20Pct25Pct30Pct35Pct40Pct45Pct50Pct55Pct60Pct65 * @property {CentsSatsUsdPattern} ratioPct98Price * @property {BpsRatioPattern} ratioPct99 * @property {CentsSatsUsdPattern} ratioPct99Price - * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd - * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd1y - * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd2y - * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd4y * @property {BpsRatioPattern} ratioSma1m * @property {BpsRatioPattern} ratioSma1w */ /** - * Create a RatioPattern pattern node + * Create a BpsRatioPattern2 pattern node * @param {BrkClientBase} client * @param {string} acc - Accumulated metric name - * @returns {RatioPattern} + * @returns {BpsRatioPattern2} */ -function createRatioPattern(client, acc) { +function createBpsRatioPattern2(client, acc) { return { + bps: createMetricPattern1(client, _m(acc, 'bps')), + ratio: createMetricPattern1(client, acc), ratioPct1: createBpsRatioPattern(client, _m(acc, 'pct1')), ratioPct1Price: createCentsSatsUsdPattern(client, _m(acc, 'pct1')), ratioPct2: createBpsRatioPattern(client, _m(acc, 'pct2')), @@ -2329,10 +2282,6 @@ function createRatioPattern(client, acc) { ratioPct98Price: createCentsSatsUsdPattern(client, _m(acc, 'pct98')), ratioPct99: createBpsRatioPattern(client, _m(acc, 'pct99')), ratioPct99Price: createCentsSatsUsdPattern(client, _m(acc, 'pct99')), - ratioSd: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), - ratioSd1y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), - ratioSd2y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), - ratioSd4y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), ratioSma1m: createBpsRatioPattern(client, _m(acc, 'sma_1m')), ratioSma1w: createBpsRatioPattern(client, _m(acc, 'sma_1w')), }; @@ -2385,6 +2334,49 @@ function createGreedGrossInvestedInvestorNegNetPainSupplyUnrealizedPattern(clien }; } +/** + * @typedef {Object} RatioPattern + * @property {BpsRatioPattern} ratioPct1 + * @property {CentsSatsUsdPattern} ratioPct1Price + * @property {BpsRatioPattern} ratioPct2 + * @property {CentsSatsUsdPattern} ratioPct2Price + * @property {BpsRatioPattern} ratioPct5 + * @property {CentsSatsUsdPattern} ratioPct5Price + * @property {BpsRatioPattern} ratioPct95 + * @property {CentsSatsUsdPattern} ratioPct95Price + * @property {BpsRatioPattern} ratioPct98 + * @property {CentsSatsUsdPattern} ratioPct98Price + * @property {BpsRatioPattern} ratioPct99 + * @property {CentsSatsUsdPattern} ratioPct99Price + * @property {BpsRatioPattern} ratioSma1m + * @property {BpsRatioPattern} ratioSma1w + */ + +/** + * Create a RatioPattern pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {RatioPattern} + */ +function createRatioPattern(client, acc) { + return { + ratioPct1: createBpsRatioPattern(client, _m(acc, 'pct1')), + ratioPct1Price: createCentsSatsUsdPattern(client, _m(acc, 'pct1')), + ratioPct2: createBpsRatioPattern(client, _m(acc, 'pct2')), + ratioPct2Price: createCentsSatsUsdPattern(client, _m(acc, 'pct2')), + ratioPct5: createBpsRatioPattern(client, _m(acc, 'pct5')), + ratioPct5Price: createCentsSatsUsdPattern(client, _m(acc, 'pct5')), + ratioPct95: createBpsRatioPattern(client, _m(acc, 'pct95')), + ratioPct95Price: createCentsSatsUsdPattern(client, _m(acc, 'pct95')), + ratioPct98: createBpsRatioPattern(client, _m(acc, 'pct98')), + ratioPct98Price: createCentsSatsUsdPattern(client, _m(acc, 'pct98')), + ratioPct99: createBpsRatioPattern(client, _m(acc, 'pct99')), + ratioPct99Price: createCentsSatsUsdPattern(client, _m(acc, 'pct99')), + ratioSma1m: createBpsRatioPattern(client, _m(acc, 'sma_1m')), + ratioSma1w: createBpsRatioPattern(client, _m(acc, 'sma_1w')), + }; +} + /** * @typedef {Object} _10y1m1w1y2y3m3y4y5y6m6y8yPattern2 * @property {BpsPercentRatioPattern} _10y @@ -3175,6 +3167,29 @@ function createInvestedMaxMinPercentilesPattern(client, acc) { }; } +/** + * @typedef {Object} RatioPattern2 + * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd + * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd1y + * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd2y + * @property {_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern} ratioSd4y + */ + +/** + * Create a RatioPattern2 pattern node + * @param {BrkClientBase} client + * @param {string} acc - Accumulated metric name + * @returns {RatioPattern2} + */ +function createRatioPattern2(client, acc) { + return { + ratioSd: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), + ratioSd1y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), + ratioSd2y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), + ratioSd4y: create_0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc), + }; +} + /** * @template T * @typedef {Object} _1m1w1y24hPattern diff --git a/packages/brk_client/brk_client/__init__.py b/packages/brk_client/brk_client/__init__.py index 1f566f9eb..53a3df203 100644 --- a/packages/brk_client/brk_client/__init__.py +++ b/packages/brk_client/brk_client/__init__.py @@ -2082,7 +2082,8 @@ class AdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedS self.investor_cap_raw: MetricPattern18[CentsSquaredSats] = MetricPattern18(client, _m(acc, 'investor_cap_raw')) self.investor_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'investor_price')) self.investor_price_ratio: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'investor_price_ratio')) - self.investor_price_ratio_ext: RatioPattern = RatioPattern(client, _m(acc, 'investor_price_ratio')) + self.investor_price_ratio_percentiles: RatioPattern = RatioPattern(client, _m(acc, 'investor_price_ratio')) + self.investor_price_ratio_std_dev: RatioPattern2 = RatioPattern2(client, _m(acc, 'investor_price_ratio')) self.loss_value_created: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'loss_value_created')) self.loss_value_destroyed: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'loss_value_destroyed')) self.lower_price_band: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'lower_price_band')) @@ -2109,7 +2110,69 @@ class AdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedS self.realized_loss_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'realized_loss')) self.realized_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'realized_price')) self.realized_price_ratio: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'realized_price_ratio')) - self.realized_price_ratio_ext: RatioPattern = RatioPattern(client, _m(acc, 'realized_price_ratio')) + self.realized_price_ratio_percentiles: RatioPattern = RatioPattern(client, _m(acc, 'realized_price_ratio')) + self.realized_price_ratio_std_dev: RatioPattern2 = RatioPattern2(client, _m(acc, 'realized_price_ratio')) + self.realized_profit: CumulativeHeightPattern[Cents] = CumulativeHeightPattern(client, _m(acc, 'realized_profit')) + self.realized_profit_ema_1w: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'realized_profit_ema_1w')) + self.realized_profit_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_realized_cap')) + self.realized_profit_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'realized_profit')) + self.realized_profit_to_loss_ratio: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, _m(acc, 'realized_profit_to_loss_ratio')) + self.sell_side_risk_ratio: _1m1w1y24hPattern2 = _1m1w1y24hPattern2(client, _m(acc, 'sell_side_risk_ratio')) + self.sell_side_risk_ratio_24h_ema: _1m1wPattern = _1m1wPattern(client, _m(acc, 'sell_side_risk_ratio_24h_ema')) + self.sent_in_loss: BaseCumulativePattern = BaseCumulativePattern(client, _m(acc, 'sent_in_loss')) + self.sent_in_loss_ema: _2wPattern = _2wPattern(client, _m(acc, 'sent_in_loss_ema_2w')) + self.sent_in_profit: BaseCumulativePattern = BaseCumulativePattern(client, _m(acc, 'sent_in_profit')) + self.sent_in_profit_ema: _2wPattern = _2wPattern(client, _m(acc, 'sent_in_profit_ema_2w')) + self.sopr: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, _m(acc, 'sopr')) + self.sopr_24h_ema: _1m1wPattern2 = _1m1wPattern2(client, _m(acc, 'sopr_24h_ema')) + self.upper_price_band: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'upper_price_band')) + self.value_created: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'value_created')) + self.value_created_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'value_created')) + self.value_destroyed: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'value_destroyed')) + self.value_destroyed_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'value_destroyed')) + +class CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.cap_raw: MetricPattern18[CentsSats] = MetricPattern18(client, _m(acc, 'cap_raw')) + self.capitulation_flow: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'capitulation_flow')) + self.gross_pnl: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'realized_gross_pnl')) + self.gross_pnl_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'gross_pnl_sum')) + self.investor_cap_raw: MetricPattern18[CentsSquaredSats] = MetricPattern18(client, _m(acc, 'investor_cap_raw')) + self.investor_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'investor_price')) + self.investor_price_ratio: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'investor_price_ratio')) + self.investor_price_ratio_percentiles: RatioPattern = RatioPattern(client, _m(acc, 'investor_price_ratio')) + self.investor_price_ratio_std_dev: RatioPattern2 = RatioPattern2(client, _m(acc, 'investor_price_ratio')) + self.loss_value_created: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'loss_value_created')) + self.loss_value_destroyed: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'loss_value_destroyed')) + self.lower_price_band: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'lower_price_band')) + self.mvrv: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'mvrv')) + self.neg_realized_loss: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_realized_loss')) + self.net_pnl_change_1m: MetricPattern1[CentsSigned] = MetricPattern1(client, _m(acc, 'net_pnl_change_1m')) + self.net_pnl_change_1m_rel_to_market_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'net_pnl_change_1m_rel_to_market_cap')) + self.net_pnl_change_1m_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'net_pnl_change_1m_rel_to_realized_cap')) + self.net_realized_pnl: CumulativeHeightPattern[CentsSigned] = CumulativeHeightPattern(client, _m(acc, 'net_realized_pnl')) + self.net_realized_pnl_ema_1w: MetricPattern1[CentsSigned] = MetricPattern1(client, _m(acc, 'net_realized_pnl_ema_1w')) + self.net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'net_realized_pnl_rel_to_realized_cap')) + self.peak_regret: CumulativeHeightPattern[Cents] = CumulativeHeightPattern(client, _m(acc, 'realized_peak_regret')) + self.peak_regret_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_peak_regret_rel_to_realized_cap')) + self.profit_flow: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'profit_flow')) + self.profit_value_created: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'profit_value_created')) + self.profit_value_destroyed: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'profit_value_destroyed')) + self.realized_cap: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'realized_cap')) + self.realized_cap_cents: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'realized_cap_cents')) + self.realized_cap_change_1m: MetricPattern1[CentsSigned] = MetricPattern1(client, _m(acc, 'realized_cap_change_1m')) + self.realized_cap_rel_to_own_market_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_cap_rel_to_own_market_cap')) + self.realized_loss: CumulativeHeightPattern[Cents] = CumulativeHeightPattern(client, _m(acc, 'realized_loss')) + self.realized_loss_ema_1w: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'realized_loss_ema_1w')) + self.realized_loss_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_loss_rel_to_realized_cap')) + self.realized_loss_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'realized_loss')) + self.realized_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'realized_price')) + self.realized_price_ratio: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'realized_price_ratio')) + self.realized_price_ratio_percentiles: RatioPattern = RatioPattern(client, _m(acc, 'realized_price_ratio')) + self.realized_price_ratio_std_dev: RatioPattern2 = RatioPattern2(client, _m(acc, 'realized_price_ratio')) self.realized_profit: CumulativeHeightPattern[Cents] = CumulativeHeightPattern(client, _m(acc, 'realized_profit')) self.realized_profit_ema_1w: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'realized_profit_ema_1w')) self.realized_profit_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_realized_cap')) @@ -2188,65 +2251,6 @@ class AdjustedCapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedS self.value_destroyed: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'value_destroyed')) self.value_destroyed_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'value_destroyed')) -class CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern2: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.cap_raw: MetricPattern18[CentsSats] = MetricPattern18(client, _m(acc, 'cap_raw')) - self.capitulation_flow: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'capitulation_flow')) - self.gross_pnl: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'realized_gross_pnl')) - self.gross_pnl_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'gross_pnl_sum')) - self.investor_cap_raw: MetricPattern18[CentsSquaredSats] = MetricPattern18(client, _m(acc, 'investor_cap_raw')) - self.investor_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'investor_price')) - self.investor_price_ratio: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'investor_price_ratio')) - self.investor_price_ratio_ext: RatioPattern = RatioPattern(client, _m(acc, 'investor_price_ratio')) - self.loss_value_created: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'loss_value_created')) - self.loss_value_destroyed: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'loss_value_destroyed')) - self.lower_price_band: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'lower_price_band')) - self.mvrv: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'mvrv')) - self.neg_realized_loss: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'neg_realized_loss')) - self.net_pnl_change_1m: MetricPattern1[CentsSigned] = MetricPattern1(client, _m(acc, 'net_pnl_change_1m')) - self.net_pnl_change_1m_rel_to_market_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'net_pnl_change_1m_rel_to_market_cap')) - self.net_pnl_change_1m_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'net_pnl_change_1m_rel_to_realized_cap')) - self.net_realized_pnl: CumulativeHeightPattern[CentsSigned] = CumulativeHeightPattern(client, _m(acc, 'net_realized_pnl')) - self.net_realized_pnl_ema_1w: MetricPattern1[CentsSigned] = MetricPattern1(client, _m(acc, 'net_realized_pnl_ema_1w')) - self.net_realized_pnl_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'net_realized_pnl_rel_to_realized_cap')) - self.peak_regret: CumulativeHeightPattern[Cents] = CumulativeHeightPattern(client, _m(acc, 'realized_peak_regret')) - self.peak_regret_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_peak_regret_rel_to_realized_cap')) - self.profit_flow: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'profit_flow')) - self.profit_value_created: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'profit_value_created')) - self.profit_value_destroyed: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'profit_value_destroyed')) - self.realized_cap: MetricPattern1[Dollars] = MetricPattern1(client, _m(acc, 'realized_cap')) - self.realized_cap_cents: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'realized_cap_cents')) - self.realized_cap_change_1m: MetricPattern1[CentsSigned] = MetricPattern1(client, _m(acc, 'realized_cap_change_1m')) - self.realized_cap_rel_to_own_market_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_cap_rel_to_own_market_cap')) - self.realized_loss: CumulativeHeightPattern[Cents] = CumulativeHeightPattern(client, _m(acc, 'realized_loss')) - self.realized_loss_ema_1w: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'realized_loss_ema_1w')) - self.realized_loss_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_loss_rel_to_realized_cap')) - self.realized_loss_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'realized_loss')) - self.realized_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'realized_price')) - self.realized_price_ratio: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'realized_price_ratio')) - self.realized_price_ratio_ext: RatioPattern = RatioPattern(client, _m(acc, 'realized_price_ratio')) - self.realized_profit: CumulativeHeightPattern[Cents] = CumulativeHeightPattern(client, _m(acc, 'realized_profit')) - self.realized_profit_ema_1w: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'realized_profit_ema_1w')) - self.realized_profit_rel_to_realized_cap: BpsPercentRatioPattern = BpsPercentRatioPattern(client, _m(acc, 'realized_profit_rel_to_realized_cap')) - self.realized_profit_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'realized_profit')) - self.realized_profit_to_loss_ratio: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, _m(acc, 'realized_profit_to_loss_ratio')) - self.sell_side_risk_ratio: _1m1w1y24hPattern2 = _1m1w1y24hPattern2(client, _m(acc, 'sell_side_risk_ratio')) - self.sell_side_risk_ratio_24h_ema: _1m1wPattern = _1m1wPattern(client, _m(acc, 'sell_side_risk_ratio_24h_ema')) - self.sent_in_loss: BaseCumulativePattern = BaseCumulativePattern(client, _m(acc, 'sent_in_loss')) - self.sent_in_loss_ema: _2wPattern = _2wPattern(client, _m(acc, 'sent_in_loss_ema_2w')) - self.sent_in_profit: BaseCumulativePattern = BaseCumulativePattern(client, _m(acc, 'sent_in_profit')) - self.sent_in_profit_ema: _2wPattern = _2wPattern(client, _m(acc, 'sent_in_profit_ema_2w')) - self.sopr: _1m1w1y24hPattern[StoredF64] = _1m1w1y24hPattern(client, _m(acc, 'sopr')) - self.sopr_24h_ema: _1m1wPattern2 = _1m1wPattern2(client, _m(acc, 'sopr_24h_ema')) - self.upper_price_band: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'upper_price_band')) - self.value_created: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'value_created')) - self.value_created_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'value_created')) - self.value_destroyed: MetricPattern1[Cents] = MetricPattern1(client, _m(acc, 'value_destroyed')) - self.value_destroyed_sum: _1m1w1y24hPattern[Cents] = _1m1w1y24hPattern(client, _m(acc, 'value_destroyed')) - class CapCapitulationGrossInvestorLossLowerMvrvNegNetPeakProfitRealizedSellSentSoprUpperValuePattern: """Pattern struct for repeated tree structure.""" @@ -2334,32 +2338,6 @@ class _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern: self.sma: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'sma_4y')) self.zscore: MetricPattern1[StoredF32] = MetricPattern1(client, _m(acc, 'zscore_4y')) -class BpsRatioPattern2: - """Pattern struct for repeated tree structure.""" - - def __init__(self, client: BrkClientBase, acc: str): - """Create pattern node with accumulated metric name.""" - self.bps: MetricPattern1[BasisPoints32] = MetricPattern1(client, _m(acc, 'bps')) - self.ratio: MetricPattern1[StoredF32] = MetricPattern1(client, acc) - self.ratio_pct1: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct1')) - self.ratio_pct1_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct1')) - self.ratio_pct2: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct2')) - self.ratio_pct2_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct2')) - self.ratio_pct5: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct5')) - self.ratio_pct5_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct5')) - self.ratio_pct95: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct95')) - self.ratio_pct95_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct95')) - self.ratio_pct98: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct98')) - self.ratio_pct98_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct98')) - self.ratio_pct99: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct99')) - self.ratio_pct99_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct99')) - self.ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) - self.ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) - self.ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) - self.ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) - self.ratio_sma_1m: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'sma_1m')) - self.ratio_sma_1w: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'sma_1w')) - class InvestedNegNetNuplSupplyUnrealizedPattern2: """Pattern struct for repeated tree structure.""" @@ -2411,11 +2389,13 @@ class Pct05Pct10Pct15Pct20Pct25Pct30Pct35Pct40Pct45Pct50Pct55Pct60Pct65Pct70Pct7 self.pct90: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct90')) self.pct95: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct95')) -class RatioPattern: +class BpsRatioPattern2: """Pattern struct for repeated tree structure.""" def __init__(self, client: BrkClientBase, acc: str): """Create pattern node with accumulated metric name.""" + self.bps: MetricPattern1[BasisPoints32] = MetricPattern1(client, _m(acc, 'bps')) + self.ratio: MetricPattern1[StoredF32] = MetricPattern1(client, acc) self.ratio_pct1: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct1')) self.ratio_pct1_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct1')) self.ratio_pct2: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct2')) @@ -2428,10 +2408,6 @@ class RatioPattern: self.ratio_pct98_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct98')) self.ratio_pct99: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct99')) self.ratio_pct99_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct99')) - self.ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) - self.ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) - self.ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) - self.ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) self.ratio_sma_1m: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'sma_1m')) self.ratio_sma_1w: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'sma_1w')) @@ -2457,6 +2433,26 @@ class GreedGrossInvestedInvestorNegNetPainSupplyUnrealizedPattern: self.unrealized_loss: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'unrealized_loss')) self.unrealized_profit: CentsUsdPattern = CentsUsdPattern(client, _m(acc, 'unrealized_profit')) +class RatioPattern: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.ratio_pct1: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct1')) + self.ratio_pct1_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct1')) + self.ratio_pct2: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct2')) + self.ratio_pct2_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct2')) + self.ratio_pct5: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct5')) + self.ratio_pct5_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct5')) + self.ratio_pct95: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct95')) + self.ratio_pct95_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct95')) + self.ratio_pct98: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct98')) + self.ratio_pct98_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct98')) + self.ratio_pct99: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'pct99')) + self.ratio_pct99_price: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'pct99')) + self.ratio_sma_1m: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'sma_1m')) + self.ratio_sma_1w: BpsRatioPattern = BpsRatioPattern(client, _m(acc, 'sma_1w')) + class _10y1m1w1y2y3m3y4y5y6m6y8yPattern2: """Pattern struct for repeated tree structure.""" @@ -2811,6 +2807,16 @@ class InvestedMaxMinPercentilesPattern: self.min: CentsSatsUsdPattern = CentsSatsUsdPattern(client, _m(acc, 'cost_basis_min')) self.percentiles: Pct05Pct10Pct15Pct20Pct25Pct30Pct35Pct40Pct45Pct50Pct55Pct60Pct65Pct70Pct75Pct80Pct85Pct90Pct95Pattern = Pct05Pct10Pct15Pct20Pct25Pct30Pct35Pct40Pct45Pct50Pct55Pct60Pct65Pct70Pct75Pct80Pct85Pct90Pct95Pattern(client, _m(acc, 'cost_basis')) +class RatioPattern2: + """Pattern struct for repeated tree structure.""" + + def __init__(self, client: BrkClientBase, acc: str): + """Create pattern node with accumulated metric name.""" + self.ratio_sd: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) + self.ratio_sd_1y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) + self.ratio_sd_2y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) + self.ratio_sd_4y: _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern = _0sdM0M1M1sdM2M2sdM3sdP0P1P1sdP2P2sdP3sdSdSmaZscorePattern(client, acc) + class _1m1w1y24hPattern(Generic[T]): """Pattern struct for repeated tree structure."""