mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-22 16:38:11 -07:00
computer: snapshot
This commit is contained in:
@@ -104,14 +104,14 @@ impl Vecs {
|
||||
self.nvt.compute_binary::<Dollars, Dollars, Ratio32>(
|
||||
starting_indexes.height,
|
||||
&distribution.utxo_cohorts.all.metrics.supply.total.usd.height,
|
||||
&transactions.volume.sent_sum.usd.height,
|
||||
&transactions.volume.sent_sum.usd,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Pi Cycle: sma_111d / sma_350d_x2
|
||||
self.pi_cycle.compute_binary::<Dollars, Dollars, Ratio32>(
|
||||
starting_indexes.height,
|
||||
&moving_average.price_111d_sma.price.as_ref().unwrap().usd.height,
|
||||
&moving_average.price_111d_sma.price.usd.height,
|
||||
&moving_average.price_350d_sma_x2.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightRatio, DollarsTimesTenths, Price},
|
||||
internal::{ComputedFromHeightPriceWithRatioExtended, DollarsTimesTenths, Price},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -14,265 +14,21 @@ impl Vecs {
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let price_1w_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_1w_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_8d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_8d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_13d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_13d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_21d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_21d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_1m_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_1m_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_34d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_34d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_55d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_55d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_89d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_89d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_111d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_111d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_144d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_144d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_200d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_200d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_350d_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_350d_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_1y_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_1y_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_2y_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_2y_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_200w_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_200w_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_4y_sma = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_4y_sma",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
macro_rules! import {
|
||||
($name:expr) => {
|
||||
ComputedFromHeightPriceWithRatioExtended::forced_import(
|
||||
db,
|
||||
$name,
|
||||
version,
|
||||
indexes,
|
||||
)?
|
||||
};
|
||||
}
|
||||
|
||||
let price_1w_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_1w_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_8d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_8d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_12d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_12d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_13d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_13d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_21d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_21d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_26d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_26d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_1m_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_1m_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_34d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_34d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_55d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_55d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_89d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_89d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_144d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_144d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_200d_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_200d_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_1y_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_1y_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_2y_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_2y_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_200w_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_200w_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_4y_ema = ComputedFromHeightRatio::forced_import(
|
||||
db,
|
||||
"price_4y_ema",
|
||||
None,
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
)?;
|
||||
let price_200d_sma = import!("price_200d_sma");
|
||||
let price_350d_sma = import!("price_350d_sma");
|
||||
|
||||
let price_200d_sma_source = &price_200d_sma.price.as_ref().unwrap().usd;
|
||||
let price_200d_sma_source = &price_200d_sma.price.usd;
|
||||
let price_200d_sma_x2_4 = Price::from_computed::<DollarsTimesTenths<24>>(
|
||||
"price_200d_sma_x2_4",
|
||||
version,
|
||||
@@ -284,7 +40,7 @@ impl Vecs {
|
||||
price_200d_sma_source,
|
||||
);
|
||||
|
||||
let price_350d_sma_source = &price_350d_sma.price.as_ref().unwrap().usd;
|
||||
let price_350d_sma_source = &price_350d_sma.price.usd;
|
||||
let price_350d_sma_x2 = Price::from_computed::<DollarsTimesTenths<20>>(
|
||||
"price_350d_sma_x2",
|
||||
version,
|
||||
@@ -292,39 +48,39 @@ impl Vecs {
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
price_1w_sma,
|
||||
price_8d_sma,
|
||||
price_13d_sma,
|
||||
price_21d_sma,
|
||||
price_1m_sma,
|
||||
price_34d_sma,
|
||||
price_55d_sma,
|
||||
price_89d_sma,
|
||||
price_111d_sma,
|
||||
price_144d_sma,
|
||||
price_1w_sma: import!("price_1w_sma"),
|
||||
price_8d_sma: import!("price_8d_sma"),
|
||||
price_13d_sma: import!("price_13d_sma"),
|
||||
price_21d_sma: import!("price_21d_sma"),
|
||||
price_1m_sma: import!("price_1m_sma"),
|
||||
price_34d_sma: import!("price_34d_sma"),
|
||||
price_55d_sma: import!("price_55d_sma"),
|
||||
price_89d_sma: import!("price_89d_sma"),
|
||||
price_111d_sma: import!("price_111d_sma"),
|
||||
price_144d_sma: import!("price_144d_sma"),
|
||||
price_200d_sma,
|
||||
price_350d_sma,
|
||||
price_1y_sma,
|
||||
price_2y_sma,
|
||||
price_200w_sma,
|
||||
price_4y_sma,
|
||||
price_1y_sma: import!("price_1y_sma"),
|
||||
price_2y_sma: import!("price_2y_sma"),
|
||||
price_200w_sma: import!("price_200w_sma"),
|
||||
price_4y_sma: import!("price_4y_sma"),
|
||||
|
||||
price_1w_ema,
|
||||
price_8d_ema,
|
||||
price_12d_ema,
|
||||
price_13d_ema,
|
||||
price_21d_ema,
|
||||
price_26d_ema,
|
||||
price_1m_ema,
|
||||
price_34d_ema,
|
||||
price_55d_ema,
|
||||
price_89d_ema,
|
||||
price_144d_ema,
|
||||
price_200d_ema,
|
||||
price_1y_ema,
|
||||
price_2y_ema,
|
||||
price_200w_ema,
|
||||
price_4y_ema,
|
||||
price_1w_ema: import!("price_1w_ema"),
|
||||
price_8d_ema: import!("price_8d_ema"),
|
||||
price_12d_ema: import!("price_12d_ema"),
|
||||
price_13d_ema: import!("price_13d_ema"),
|
||||
price_21d_ema: import!("price_21d_ema"),
|
||||
price_26d_ema: import!("price_26d_ema"),
|
||||
price_1m_ema: import!("price_1m_ema"),
|
||||
price_34d_ema: import!("price_34d_ema"),
|
||||
price_55d_ema: import!("price_55d_ema"),
|
||||
price_89d_ema: import!("price_89d_ema"),
|
||||
price_144d_ema: import!("price_144d_ema"),
|
||||
price_200d_ema: import!("price_200d_ema"),
|
||||
price_1y_ema: import!("price_1y_ema"),
|
||||
price_2y_ema: import!("price_2y_ema"),
|
||||
price_200w_ema: import!("price_200w_ema"),
|
||||
price_4y_ema: import!("price_4y_ema"),
|
||||
|
||||
price_200d_sma_x2_4,
|
||||
price_200d_sma_x0_8,
|
||||
|
||||
@@ -2,44 +2,44 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Dollars;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightRatio, LazyFromHeightLast, Price};
|
||||
use crate::internal::{ComputedFromHeightPriceWithRatioExtended, LazyFromHeightLast, Price};
|
||||
|
||||
/// Simple and exponential moving average metrics
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub price_1w_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_8d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_13d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_21d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_1m_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_34d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_55d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_89d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_111d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_144d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_200d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_350d_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_1y_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_2y_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_200w_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_4y_sma: ComputedFromHeightRatio<M>,
|
||||
pub price_1w_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_8d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_13d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_21d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_1m_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_34d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_55d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_89d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_111d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_144d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_200d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_350d_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_1y_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_2y_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_200w_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_4y_sma: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
|
||||
pub price_1w_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_8d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_12d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_13d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_21d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_26d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_1m_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_34d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_55d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_89d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_144d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_200d_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_1y_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_2y_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_200w_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_4y_ema: ComputedFromHeightRatio<M>,
|
||||
pub price_1w_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_8d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_12d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_13d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_21d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_26d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_1m_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_34d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_55d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_89d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_144d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_200d_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_1y_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_2y_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_200w_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
pub price_4y_ema: ComputedFromHeightPriceWithRatioExtended<M>,
|
||||
|
||||
pub price_200d_sma_x2_4: Price<LazyFromHeightLast<Dollars, Dollars>>,
|
||||
pub price_200d_sma_x0_8: Price<LazyFromHeightLast<Dollars, Dollars>>,
|
||||
|
||||
@@ -6,10 +6,8 @@ use super::super::lookback::ByLookbackPeriod;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromHeightLast, ComputedFromHeightStdDev,
|
||||
StandardDeviationVecsOptions,
|
||||
},
|
||||
internal::ComputedFromHeightLast,
|
||||
internal::ComputedFromHeightStdDev,
|
||||
market::dca::ByDcaCagr,
|
||||
};
|
||||
|
||||
@@ -41,7 +39,6 @@ impl Vecs {
|
||||
7,
|
||||
version + v1,
|
||||
indexes,
|
||||
StandardDeviationVecsOptions::default(),
|
||||
)?;
|
||||
let _1d_returns_1m_sd = ComputedFromHeightStdDev::forced_import(
|
||||
db,
|
||||
@@ -49,7 +46,6 @@ impl Vecs {
|
||||
30,
|
||||
version + v1,
|
||||
indexes,
|
||||
StandardDeviationVecsOptions::default(),
|
||||
)?;
|
||||
let _1d_returns_1y_sd = ComputedFromHeightStdDev::forced_import(
|
||||
db,
|
||||
@@ -57,7 +53,6 @@ impl Vecs {
|
||||
365,
|
||||
version + v1,
|
||||
indexes,
|
||||
StandardDeviationVecsOptions::default(),
|
||||
)?;
|
||||
|
||||
let downside_returns = EagerVec::forced_import(db, "downside_returns", version)?;
|
||||
@@ -67,7 +62,6 @@ impl Vecs {
|
||||
7,
|
||||
version + v1,
|
||||
indexes,
|
||||
StandardDeviationVecsOptions::default(),
|
||||
)?;
|
||||
let downside_1m_sd = ComputedFromHeightStdDev::forced_import(
|
||||
db,
|
||||
@@ -75,7 +69,6 @@ impl Vecs {
|
||||
30,
|
||||
version + v1,
|
||||
indexes,
|
||||
StandardDeviationVecsOptions::default(),
|
||||
)?;
|
||||
let downside_1y_sd = ComputedFromHeightStdDev::forced_import(
|
||||
db,
|
||||
@@ -83,7 +76,6 @@ impl Vecs {
|
||||
365,
|
||||
version + v1,
|
||||
indexes,
|
||||
StandardDeviationVecsOptions::default(),
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
|
||||
Reference in New Issue
Block a user