mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-28 19:28:11 -07:00
global: sats version of all prices
This commit is contained in:
@@ -6,8 +6,8 @@ use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromDateLast, ComputedFromHeightAndDateLast, LazyBinaryFromHeightAndDateLast, LazyFromDateLast,
|
||||
PercentageDiffCloseDollars, StoredU16ToYears,
|
||||
ComputedFromDateLast, LazyBinaryFromHeightAndDateLast, LazyFromDateLast,
|
||||
PercentageDiffCloseDollars, PriceFromHeightAndDate, StoredU16ToYears,
|
||||
},
|
||||
price,
|
||||
};
|
||||
@@ -19,7 +19,7 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
price: &price::Vecs,
|
||||
) -> Result<Self> {
|
||||
let price_ath = ComputedFromHeightAndDateLast::forced_import(db, "price_ath", version, indexes)?;
|
||||
let price_ath = PriceFromHeightAndDate::forced_import(db, "price_ath", version, indexes)?;
|
||||
|
||||
let max_days_between_price_aths =
|
||||
ComputedFromDateLast::forced_import(db, "max_days_between_price_aths", version, indexes)?;
|
||||
|
||||
@@ -2,13 +2,13 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Close, Dollars, StoredF32, StoredU16};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromDateLast, ComputedFromHeightAndDateLast, LazyBinaryFromHeightAndDateLast, LazyFromDateLast,
|
||||
ComputedFromDateLast, LazyBinaryFromHeightAndDateLast, LazyFromDateLast, PriceFromHeightAndDate,
|
||||
};
|
||||
|
||||
/// All-time high related metrics
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub price_ath: ComputedFromHeightAndDateLast<Dollars>,
|
||||
pub price_ath: PriceFromHeightAndDate,
|
||||
pub price_drawdown: LazyBinaryFromHeightAndDateLast<StoredF32, Close<Dollars>, Dollars>,
|
||||
pub days_since_price_ath: ComputedFromDateLast<StoredU16>,
|
||||
pub years_since_price_ath: LazyFromDateLast<StoredF32, StoredU16>,
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod, DCA_CLASS_NAMES, DCA_PERIOD_NAME
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedFromDateLast, LazyBinaryFromDateLast, PercentageDiffCloseDollars,
|
||||
ComputedFromDateLast, LazyBinaryFromDateLast, PercentageDiffCloseDollars, Price,
|
||||
ValueFromDateLast,
|
||||
},
|
||||
market::lookback,
|
||||
@@ -28,12 +28,7 @@ impl Vecs {
|
||||
|
||||
// DCA by period - average price
|
||||
let period_average_price = ByDcaPeriod::try_new(|name, _days| {
|
||||
ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
&format!("{name}_dca_average_price"),
|
||||
version,
|
||||
indexes,
|
||||
)
|
||||
Price::forced_import(db, &format!("{name}_dca_average_price"), version, indexes)
|
||||
})?;
|
||||
|
||||
let period_returns =
|
||||
@@ -160,7 +155,7 @@ impl Vecs {
|
||||
|
||||
// DCA by year class - average price
|
||||
let class_average_price = ByDcaClass::try_new(|name, _year, _dateindex| {
|
||||
ComputedFromDateLast::forced_import(db, &format!("{name}_average_price"), version, indexes)
|
||||
Price::forced_import(db, &format!("{name}_average_price"), version, indexes)
|
||||
})?;
|
||||
|
||||
let class_returns =
|
||||
|
||||
@@ -2,14 +2,14 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Close, Dollars, StoredF32, StoredU32};
|
||||
|
||||
use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod};
|
||||
use crate::internal::{ComputedFromDateLast, LazyBinaryFromDateLast, ValueFromDateLast};
|
||||
use crate::internal::{ComputedFromDateLast, LazyBinaryFromDateLast, Price, ValueFromDateLast};
|
||||
|
||||
/// Dollar-cost averaging metrics by time period and year class
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
// DCA by period - KISS types
|
||||
pub period_stack: ByDcaPeriod<ValueFromDateLast>,
|
||||
pub period_average_price: ByDcaPeriod<ComputedFromDateLast<Dollars>>,
|
||||
pub period_average_price: ByDcaPeriod<Price>,
|
||||
pub period_returns: ByDcaPeriod<LazyBinaryFromDateLast<StoredF32, Close<Dollars>, Dollars>>,
|
||||
pub period_cagr: ByDcaCagr<ComputedFromDateLast<StoredF32>>,
|
||||
|
||||
@@ -31,7 +31,7 @@ pub struct Vecs {
|
||||
|
||||
// DCA by year class - KISS types
|
||||
pub class_stack: ByDcaClass<ValueFromDateLast>,
|
||||
pub class_average_price: ByDcaClass<ComputedFromDateLast<Dollars>>,
|
||||
pub class_average_price: ByDcaClass<Price>,
|
||||
pub class_returns: ByDcaClass<LazyBinaryFromDateLast<StoredF32, Close<Dollars>, Dollars>>,
|
||||
|
||||
// DCA by year class - profitability
|
||||
|
||||
@@ -3,12 +3,12 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::{ByLookbackPeriod, Vecs};
|
||||
use crate::{indexes, internal::ComputedFromDateLast};
|
||||
use crate::{indexes, internal::Price};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
let price_ago = ByLookbackPeriod::try_new(|name, _days| {
|
||||
ComputedFromDateLast::forced_import(db, &format!("price_{name}_ago"), version, indexes)
|
||||
Price::forced_import(db, &format!("price_{name}_ago"), version, indexes)
|
||||
})?;
|
||||
|
||||
Ok(Self { price_ago })
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Dollars;
|
||||
|
||||
use super::ByLookbackPeriod;
|
||||
use crate::internal::ComputedFromDateLast;
|
||||
use crate::internal::Price;
|
||||
|
||||
/// Price lookback metrics
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
#[traversable(flatten)]
|
||||
pub price_ago: ByLookbackPeriod<ComputedFromDateLast<Dollars>>,
|
||||
pub price_ago: ByLookbackPeriod<Price>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromDateRatio, DollarsTimesTenths, LazyFromDateLast},
|
||||
internal::{ComputedFromDateRatio, DollarsTimesTenths, LazyPrice},
|
||||
price,
|
||||
};
|
||||
|
||||
@@ -307,19 +307,19 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
let price_200d_sma_source = price_200d_sma.price.as_ref().unwrap();
|
||||
let price_200d_sma_x2_4 = LazyFromDateLast::from_source::<DollarsTimesTenths<24>>(
|
||||
let price_200d_sma_x2_4 = LazyPrice::from_source::<DollarsTimesTenths<24>>(
|
||||
"price_200d_sma_x2_4",
|
||||
version,
|
||||
price_200d_sma_source,
|
||||
);
|
||||
let price_200d_sma_x0_8 = LazyFromDateLast::from_source::<DollarsTimesTenths<8>>(
|
||||
let price_200d_sma_x0_8 = LazyPrice::from_source::<DollarsTimesTenths<8>>(
|
||||
"price_200d_sma_x0_8",
|
||||
version,
|
||||
price_200d_sma_source,
|
||||
);
|
||||
|
||||
let price_350d_sma_source = price_350d_sma.price.as_ref().unwrap();
|
||||
let price_350d_sma_x2 = LazyFromDateLast::from_source::<DollarsTimesTenths<20>>(
|
||||
let price_350d_sma_x2 = LazyPrice::from_source::<DollarsTimesTenths<20>>(
|
||||
"price_350d_sma_x2",
|
||||
version,
|
||||
price_350d_sma_source,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Dollars;
|
||||
|
||||
use crate::internal::{ComputedFromDateRatio, LazyFromDateLast};
|
||||
use crate::internal::{ComputedFromDateRatio, LazyPrice};
|
||||
|
||||
/// Simple and exponential moving average metrics
|
||||
#[derive(Clone, Traversable)]
|
||||
@@ -40,7 +40,7 @@ pub struct Vecs {
|
||||
pub price_200w_ema: ComputedFromDateRatio,
|
||||
pub price_4y_ema: ComputedFromDateRatio,
|
||||
|
||||
pub price_200d_sma_x2_4: LazyFromDateLast<Dollars>,
|
||||
pub price_200d_sma_x0_8: LazyFromDateLast<Dollars>,
|
||||
pub price_350d_sma_x2: LazyFromDateLast<Dollars>,
|
||||
pub price_200d_sma_x2_4: LazyPrice<Dollars>,
|
||||
pub price_200d_sma_x0_8: LazyPrice<Dollars>,
|
||||
pub price_350d_sma_x2: LazyPrice<Dollars>,
|
||||
}
|
||||
|
||||
@@ -3,67 +3,23 @@ use brk_types::Version;
|
||||
use vecdb::{Database, EagerVec, ImportableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromDateLast};
|
||||
use crate::{indexes, internal::{ComputedFromDateLast, Price}};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
let v1 = Version::ONE;
|
||||
|
||||
Ok(Self {
|
||||
price_1w_min: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_1w_min",
|
||||
version + v1,
|
||||
indexes,
|
||||
)?,
|
||||
price_1w_max: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_1w_max",
|
||||
version + v1,
|
||||
indexes,
|
||||
)?,
|
||||
price_2w_min: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_2w_min",
|
||||
version + v1,
|
||||
indexes,
|
||||
)?,
|
||||
price_2w_max: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_2w_max",
|
||||
version + v1,
|
||||
indexes,
|
||||
)?,
|
||||
price_1m_min: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_1m_min",
|
||||
version + v1,
|
||||
indexes,
|
||||
)?,
|
||||
price_1m_max: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_1m_max",
|
||||
version + v1,
|
||||
indexes,
|
||||
)?,
|
||||
price_1y_min: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_1y_min",
|
||||
version + v1,
|
||||
indexes,
|
||||
)?,
|
||||
price_1y_max: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_1y_max",
|
||||
version + v1,
|
||||
indexes,
|
||||
)?,
|
||||
price_1w_min: Price::forced_import(db, "price_1w_min", version + v1, indexes)?,
|
||||
price_1w_max: Price::forced_import(db, "price_1w_max", version + v1, indexes)?,
|
||||
price_2w_min: Price::forced_import(db, "price_2w_min", version + v1, indexes)?,
|
||||
price_2w_max: Price::forced_import(db, "price_2w_max", version + v1, indexes)?,
|
||||
price_1m_min: Price::forced_import(db, "price_1m_min", version + v1, indexes)?,
|
||||
price_1m_max: Price::forced_import(db, "price_1m_max", version + v1, indexes)?,
|
||||
price_1y_min: Price::forced_import(db, "price_1y_min", version + v1, indexes)?,
|
||||
price_1y_max: Price::forced_import(db, "price_1y_max", version + v1, indexes)?,
|
||||
price_true_range: EagerVec::forced_import(db, "price_true_range", version)?,
|
||||
price_true_range_2w_sum: EagerVec::forced_import(
|
||||
db,
|
||||
"price_true_range_2w_sum",
|
||||
version,
|
||||
)?,
|
||||
price_true_range_2w_sum: EagerVec::forced_import(db, "price_true_range_2w_sum", version)?,
|
||||
price_2w_choppiness_index: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"price_2w_choppiness_index",
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{DateIndex, Dollars, StoredF32};
|
||||
use brk_types::{DateIndex, StoredF32};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::ComputedFromDateLast;
|
||||
use crate::internal::{ComputedFromDateLast, Price};
|
||||
|
||||
/// Price range and choppiness metrics
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub price_1w_min: ComputedFromDateLast<Dollars>,
|
||||
pub price_1w_max: ComputedFromDateLast<Dollars>,
|
||||
pub price_2w_min: ComputedFromDateLast<Dollars>,
|
||||
pub price_2w_max: ComputedFromDateLast<Dollars>,
|
||||
pub price_1m_min: ComputedFromDateLast<Dollars>,
|
||||
pub price_1m_max: ComputedFromDateLast<Dollars>,
|
||||
pub price_1y_min: ComputedFromDateLast<Dollars>,
|
||||
pub price_1y_max: ComputedFromDateLast<Dollars>,
|
||||
pub price_1w_min: Price,
|
||||
pub price_1w_max: Price,
|
||||
pub price_2w_min: Price,
|
||||
pub price_2w_max: Price,
|
||||
pub price_1m_min: Price,
|
||||
pub price_1m_max: Price,
|
||||
pub price_1y_min: Price,
|
||||
pub price_1y_max: Price,
|
||||
pub price_true_range: EagerVec<PcoVec<DateIndex, StoredF32>>,
|
||||
pub price_true_range_2w_sum: EagerVec<PcoVec<DateIndex, StoredF32>>,
|
||||
pub price_2w_choppiness_index: ComputedFromDateLast<StoredF32>,
|
||||
|
||||
Reference in New Issue
Block a user