From 88a0c9ea03eaeabe69953c38a89f8e03c9686bfa Mon Sep 17 00:00:00 2001 From: nym21 Date: Tue, 13 May 2025 01:27:21 +0200 Subject: [PATCH] global: returns (lump sum vs dca) --- crates/brk_cli/src/run.rs | 2 +- .../vecs/grouped/ratio_from_dateindex.rs | 2 +- .../brk_computer/src/storage/vecs/market.rs | 1258 +++++++++++++---- crates/brk_core/src/structs/bitcoin.rs | 8 +- crates/brk_core/src/structs/cents.rs | 7 + crates/brk_core/src/structs/dollars.rs | 38 +- crates/brk_core/src/structs/stored_f32.rs | 8 +- crates/brk_core/src/structs/stored_f64.rs | 15 +- crates/brk_vec/src/variants/eager.rs | 269 +++- websites/kibo.money/index.html | 8 +- .../packages/lightweight-charts/wrapper.js | 23 +- websites/kibo.money/scripts/chart.js | 6 +- websites/kibo.money/scripts/main.js | 29 +- websites/kibo.money/scripts/options.js | 112 ++ websites/kibo.money/scripts/simulation.js | 2 +- .../kibo.money/scripts/vecid-to-indexes.js | 76 + 16 files changed, 1575 insertions(+), 288 deletions(-) diff --git a/crates/brk_cli/src/run.rs b/crates/brk_cli/src/run.rs index d7313b75e..d8c2cf4a5 100644 --- a/crates/brk_cli/src/run.rs +++ b/crates/brk_cli/src/run.rs @@ -108,7 +108,7 @@ pub fn run(config: RunConfig) -> color_eyre::Result<()> { }; thread::Builder::new() - .stack_size(64 * 1024 * 1024) + .stack_size(128 * 1024 * 1024) .spawn(f)? .join() .unwrap() diff --git a/crates/brk_computer/src/storage/vecs/grouped/ratio_from_dateindex.rs b/crates/brk_computer/src/storage/vecs/grouped/ratio_from_dateindex.rs index 63767fbb7..9b40d7989 100644 --- a/crates/brk_computer/src/storage/vecs/grouped/ratio_from_dateindex.rs +++ b/crates/brk_computer/src/storage/vecs/grouped/ratio_from_dateindex.rs @@ -333,7 +333,7 @@ impl ComputedRatioVecsFromDateIndex { if price == Dollars::ZERO { (i, StoredF32::from(1.0)) } else { - (i, *close / price) + (i, StoredF32::from(*close / price)) } }, exit, diff --git a/crates/brk_computer/src/storage/vecs/market.rs b/crates/brk_computer/src/storage/vecs/market.rs index 76da27a96..dc2206f7a 100644 --- a/crates/brk_computer/src/storage/vecs/market.rs +++ b/crates/brk_computer/src/storage/vecs/market.rs @@ -1,6 +1,6 @@ use std::{fs, path::Path, thread}; -use brk_core::{Dollars, StoredF64, StoredUsize}; +use brk_core::{Dollars, Sats, StoredF32, StoredUsize}; use brk_exit::Exit; use brk_indexer::Indexer; use brk_vec::{AnyCollectableVec, Compressed, Computation, StoredIndex, VecIterator, Version}; @@ -13,14 +13,16 @@ use super::{ indexes, transactions, }; +const VERSION: Version = Version::new(10); + #[derive(Clone)] pub struct Vecs { pub indexes_to_marketcap: ComputedVecsFromDateIndex, pub indexes_to_ath: ComputedVecsFromDateIndex, - pub indexes_to_drawdown: ComputedVecsFromDateIndex, + pub indexes_to_drawdown: ComputedVecsFromDateIndex, pub indexes_to_days_since_ath: ComputedVecsFromDateIndex, pub indexes_to_max_days_between_ath: ComputedVecsFromDateIndex, - pub indexes_to_max_years_between_ath: ComputedVecsFromDateIndex, + pub indexes_to_max_years_between_ath: ComputedVecsFromDateIndex, pub indexes_to_1w_sma: ComputedRatioVecsFromDateIndex, pub indexes_to_8d_sma: ComputedRatioVecsFromDateIndex, @@ -35,6 +37,85 @@ pub struct Vecs { pub indexes_to_2y_sma: ComputedRatioVecsFromDateIndex, pub indexes_to_200w_sma: ComputedRatioVecsFromDateIndex, pub indexes_to_4y_sma: ComputedRatioVecsFromDateIndex, + + pub price_1d_ago: ComputedVecsFromDateIndex, + pub price_1w_ago: ComputedVecsFromDateIndex, + pub price_1m_ago: ComputedVecsFromDateIndex, + pub price_3m_ago: ComputedVecsFromDateIndex, + pub price_6m_ago: ComputedVecsFromDateIndex, + pub price_1y_ago: ComputedVecsFromDateIndex, + pub price_2y_ago: ComputedVecsFromDateIndex, + pub price_3y_ago: ComputedVecsFromDateIndex, + pub price_4y_ago: ComputedVecsFromDateIndex, + pub price_5y_ago: ComputedVecsFromDateIndex, + pub price_6y_ago: ComputedVecsFromDateIndex, + pub price_8y_ago: ComputedVecsFromDateIndex, + pub price_10y_ago: ComputedVecsFromDateIndex, + + pub _1d_returns: ComputedVecsFromDateIndex, + pub _1w_returns: ComputedVecsFromDateIndex, + pub _1m_returns: ComputedVecsFromDateIndex, + pub _3m_returns: ComputedVecsFromDateIndex, + pub _6m_returns: ComputedVecsFromDateIndex, + pub _1y_returns: ComputedVecsFromDateIndex, + pub _2y_returns: ComputedVecsFromDateIndex, + pub _3y_returns: ComputedVecsFromDateIndex, + pub _4y_returns: ComputedVecsFromDateIndex, + pub _5y_returns: ComputedVecsFromDateIndex, + pub _6y_returns: ComputedVecsFromDateIndex, + pub _8y_returns: ComputedVecsFromDateIndex, + pub _10y_returns: ComputedVecsFromDateIndex, + pub _2y_cagr: ComputedVecsFromDateIndex, + pub _3y_cagr: ComputedVecsFromDateIndex, + pub _4y_cagr: ComputedVecsFromDateIndex, + pub _5y_cagr: ComputedVecsFromDateIndex, + pub _6y_cagr: ComputedVecsFromDateIndex, + pub _8y_cagr: ComputedVecsFromDateIndex, + pub _10y_cagr: ComputedVecsFromDateIndex, + + pub _1w_dca_stack: ComputedVecsFromDateIndex, + pub _1m_dca_stack: ComputedVecsFromDateIndex, + pub _3m_dca_stack: ComputedVecsFromDateIndex, + pub _6m_dca_stack: ComputedVecsFromDateIndex, + pub _1y_dca_stack: ComputedVecsFromDateIndex, + pub _2y_dca_stack: ComputedVecsFromDateIndex, + pub _3y_dca_stack: ComputedVecsFromDateIndex, + pub _4y_dca_stack: ComputedVecsFromDateIndex, + pub _5y_dca_stack: ComputedVecsFromDateIndex, + pub _6y_dca_stack: ComputedVecsFromDateIndex, + pub _8y_dca_stack: ComputedVecsFromDateIndex, + pub _10y_dca_stack: ComputedVecsFromDateIndex, + pub _1w_dca_avg_price: ComputedVecsFromDateIndex, + pub _1m_dca_avg_price: ComputedVecsFromDateIndex, + pub _3m_dca_avg_price: ComputedVecsFromDateIndex, + pub _6m_dca_avg_price: ComputedVecsFromDateIndex, + pub _1y_dca_avg_price: ComputedVecsFromDateIndex, + pub _2y_dca_avg_price: ComputedVecsFromDateIndex, + pub _3y_dca_avg_price: ComputedVecsFromDateIndex, + pub _4y_dca_avg_price: ComputedVecsFromDateIndex, + pub _5y_dca_avg_price: ComputedVecsFromDateIndex, + pub _6y_dca_avg_price: ComputedVecsFromDateIndex, + pub _8y_dca_avg_price: ComputedVecsFromDateIndex, + pub _10y_dca_avg_price: ComputedVecsFromDateIndex, + pub _1w_dca_returns: ComputedVecsFromDateIndex, + pub _1m_dca_returns: ComputedVecsFromDateIndex, + pub _3m_dca_returns: ComputedVecsFromDateIndex, + pub _6m_dca_returns: ComputedVecsFromDateIndex, + pub _1y_dca_returns: ComputedVecsFromDateIndex, + pub _2y_dca_returns: ComputedVecsFromDateIndex, + pub _3y_dca_returns: ComputedVecsFromDateIndex, + pub _4y_dca_returns: ComputedVecsFromDateIndex, + pub _5y_dca_returns: ComputedVecsFromDateIndex, + pub _6y_dca_returns: ComputedVecsFromDateIndex, + pub _8y_dca_returns: ComputedVecsFromDateIndex, + pub _10y_dca_returns: ComputedVecsFromDateIndex, + pub _2y_dca_cagr: ComputedVecsFromDateIndex, + pub _3y_dca_cagr: ComputedVecsFromDateIndex, + pub _4y_dca_cagr: ComputedVecsFromDateIndex, + pub _5y_dca_cagr: ComputedVecsFromDateIndex, + pub _6y_dca_cagr: ComputedVecsFromDateIndex, + pub _8y_dca_cagr: ComputedVecsFromDateIndex, + pub _10y_dca_cagr: ComputedVecsFromDateIndex, } impl Vecs { @@ -49,14 +130,14 @@ impl Vecs { indexes_to_marketcap: ComputedVecsFromDateIndex::forced_import( path, "marketcap", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_ath: ComputedVecsFromDateIndex::forced_import( path, "ath", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, @@ -70,21 +151,21 @@ impl Vecs { indexes_to_days_since_ath: ComputedVecsFromDateIndex::forced_import( path, "days_since_ath", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_max_days_between_ath: ComputedVecsFromDateIndex::forced_import( path, "max_days_between_ath", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_max_years_between_ath: ComputedVecsFromDateIndex::forced_import( path, "max_years_between_ath", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, @@ -92,91 +173,625 @@ impl Vecs { indexes_to_1w_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "1w_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_8d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "8d_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_13d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "13d_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_21d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "21d_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_1m_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "1m_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_34d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "34d_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_55d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "55d_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_89d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "89d_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_144d_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "144d_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_1y_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "1y_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_2y_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "2y_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_200w_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "200w_sma", - Version::ZERO, + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, indexes_to_4y_sma: ComputedRatioVecsFromDateIndex::forced_import( path, "4y_sma", - Version::ZERO, + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + + _1d_returns: ComputedVecsFromDateIndex::forced_import( + path, + "1d_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1w_returns: ComputedVecsFromDateIndex::forced_import( + path, + "1w_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1m_returns: ComputedVecsFromDateIndex::forced_import( + path, + "1m_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3m_returns: ComputedVecsFromDateIndex::forced_import( + path, + "3m_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6m_returns: ComputedVecsFromDateIndex::forced_import( + path, + "6m_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1y_returns: ComputedVecsFromDateIndex::forced_import( + path, + "1y_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _2y_returns: ComputedVecsFromDateIndex::forced_import( + path, + "2y_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3y_returns: ComputedVecsFromDateIndex::forced_import( + path, + "3y_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _4y_returns: ComputedVecsFromDateIndex::forced_import( + path, + "4y_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _5y_returns: ComputedVecsFromDateIndex::forced_import( + path, + "5y_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6y_returns: ComputedVecsFromDateIndex::forced_import( + path, + "6y_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _8y_returns: ComputedVecsFromDateIndex::forced_import( + path, + "8y_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _10y_returns: ComputedVecsFromDateIndex::forced_import( + path, + "10y_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _2y_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "2y_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3y_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "3y_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _4y_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "4y_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _5y_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "5y_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6y_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "6y_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _8y_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "8y_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _10y_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "10y_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + + _1w_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "1w_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1m_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "1m_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3m_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "3m_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6m_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "6m_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1y_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "1y_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _2y_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "2y_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3y_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "3y_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _4y_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "4y_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _5y_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "5y_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6y_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "6y_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _8y_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "8y_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _10y_dca_returns: ComputedVecsFromDateIndex::forced_import( + path, + "10y_dca_returns", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _2y_dca_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "2y_dca_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3y_dca_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "3y_dca_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _4y_dca_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "4y_dca_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _5y_dca_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "5y_dca_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6y_dca_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "6y_dca_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _8y_dca_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "8y_dca_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _10y_dca_cagr: ComputedVecsFromDateIndex::forced_import( + path, + "10y_dca_cagr", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1w_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "1w_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1m_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "1m_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3m_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "3m_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6m_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "6m_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "1y_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _2y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "2y_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "3y_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _4y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "4y_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _5y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "5y_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "6y_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _8y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "8y_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _10y_dca_avg_price: ComputedVecsFromDateIndex::forced_import( + path, + "10y_dca_avg_price", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_1d_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_1d_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_1w_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_1w_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_1m_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_1m_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_3m_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_3m_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_6m_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_6m_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_1y_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_1y_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_2y_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_2y_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_3y_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_3y_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_4y_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_4y_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_5y_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_5y_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_6y_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_6y_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_8y_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_8y_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + price_10y_ago: ComputedVecsFromDateIndex::forced_import( + path, + "price_10y_ago", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1w_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "1w_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1m_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "1m_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3m_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "3m_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6m_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "6m_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _1y_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "1y_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _2y_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "2y_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _3y_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "3y_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _4y_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "4y_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _5y_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "5y_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _6y_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "6y_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _8y_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "8y_dca_stack", + VERSION + Version::ZERO, + compressed, + StorableVecGeneatorOptions::default().add_last(), + )?, + _10y_dca_stack: ComputedVecsFromDateIndex::forced_import( + path, + "10y_dca_stack", + VERSION + Version::ZERO, compressed, StorableVecGeneatorOptions::default().add_last(), )?, @@ -257,10 +872,10 @@ impl Vecs { &self.indexes_to_ath.dateindex, |(i, ath, ..)| { if ath == Dollars::ZERO { - return (i, StoredF64::default()); + return (i, StoredF32::default()); } let close = *close_iter.unwrap_get_inner(i); - let drawdown = StoredF64::from((*ath - *close) / *ath * -100.0); + let drawdown = StoredF32::from((*ath - *close) / *ath * -100.0); (i, drawdown) }, exit, @@ -338,247 +953,300 @@ impl Vecs { v.compute_transform( starting_indexes.dateindex, &self.indexes_to_max_days_between_ath.dateindex, - |(i, max, ..)| (i, StoredF64::from(*max as f64 / 365.0)), + |(i, max, ..)| (i, StoredF32::from(*max as f64 / 365.0)), exit, ) }, )?; + [ + (1, &mut self.price_1d_ago, &mut self._1d_returns, None), + (7, &mut self.price_1w_ago, &mut self._1w_returns, None), + (30, &mut self.price_1m_ago, &mut self._1m_returns, None), + (3 * 30, &mut self.price_3m_ago, &mut self._3m_returns, None), + (6 * 30, &mut self.price_6m_ago, &mut self._6m_returns, None), + (365, &mut self.price_1y_ago, &mut self._1y_returns, None), + ( + 2 * 365, + &mut self.price_2y_ago, + &mut self._2y_returns, + Some(&mut self._2y_cagr), + ), + ( + 3 * 365, + &mut self.price_3y_ago, + &mut self._3y_returns, + Some(&mut self._3y_cagr), + ), + ( + 4 * 365, + &mut self.price_4y_ago, + &mut self._4y_returns, + Some(&mut self._4y_cagr), + ), + ( + 5 * 365, + &mut self.price_5y_ago, + &mut self._5y_returns, + Some(&mut self._5y_cagr), + ), + ( + 6 * 365, + &mut self.price_6y_ago, + &mut self._6y_returns, + Some(&mut self._6y_cagr), + ), + ( + 8 * 365, + &mut self.price_8y_ago, + &mut self._8y_returns, + Some(&mut self._8y_cagr), + ), + ( + 10 * 365, + &mut self.price_10y_ago, + &mut self._10y_returns, + Some(&mut self._10y_cagr), + ), + ] + .into_iter() + .try_for_each(|(days, ago, returns, cagr)| -> color_eyre::Result<()> { + ago.compute( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_previous_value( + starting_indexes.dateindex, + &fetched.timeindexes_to_close.dateindex, + days, + exit, + ) + }, + )?; + + returns.compute( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_percentage_change( + starting_indexes.dateindex, + &fetched.timeindexes_to_close.dateindex, + days, + exit, + ) + }, + )?; + + if let Some(cagr) = cagr { + cagr.compute( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_cagr(starting_indexes.dateindex, &returns.dateindex, days, exit) + }, + )?; + } + + Ok(()) + })?; + + [ + ( + 7, + &mut self._1w_dca_stack, + &mut self._1w_dca_avg_price, + &mut self._1w_dca_returns, + None, + ), + ( + 30, + &mut self._1m_dca_stack, + &mut self._1m_dca_avg_price, + &mut self._1m_dca_returns, + None, + ), + ( + 3 * 30, + &mut self._3m_dca_stack, + &mut self._3m_dca_avg_price, + &mut self._3m_dca_returns, + None, + ), + ( + 6 * 30, + &mut self._6m_dca_stack, + &mut self._6m_dca_avg_price, + &mut self._6m_dca_returns, + None, + ), + ( + 365, + &mut self._1y_dca_stack, + &mut self._1y_dca_avg_price, + &mut self._1y_dca_returns, + None, + ), + ( + 2 * 365, + &mut self._2y_dca_stack, + &mut self._2y_dca_avg_price, + &mut self._2y_dca_returns, + Some(&mut self._2y_dca_cagr), + ), + ( + 3 * 365, + &mut self._3y_dca_stack, + &mut self._3y_dca_avg_price, + &mut self._3y_dca_returns, + Some(&mut self._3y_dca_cagr), + ), + ( + 4 * 365, + &mut self._4y_dca_stack, + &mut self._4y_dca_avg_price, + &mut self._4y_dca_returns, + Some(&mut self._4y_dca_cagr), + ), + ( + 5 * 365, + &mut self._5y_dca_stack, + &mut self._5y_dca_avg_price, + &mut self._5y_dca_returns, + Some(&mut self._5y_dca_cagr), + ), + ( + 6 * 365, + &mut self._6y_dca_stack, + &mut self._6y_dca_avg_price, + &mut self._6y_dca_returns, + Some(&mut self._6y_dca_cagr), + ), + ( + 8 * 365, + &mut self._8y_dca_stack, + &mut self._8y_dca_avg_price, + &mut self._8y_dca_returns, + Some(&mut self._8y_dca_cagr), + ), + ( + 10 * 365, + &mut self._10y_dca_stack, + &mut self._10y_dca_avg_price, + &mut self._10y_dca_returns, + Some(&mut self._10y_dca_cagr), + ), + ] + .into_iter() + .try_for_each( + |(days, dca_stack, dca_avg_price, dca_returns, dca_cagr)| -> color_eyre::Result<()> { + dca_stack.compute( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_dca_stack( + starting_indexes.dateindex, + &fetched.timeindexes_to_close.dateindex, + days, + exit, + ) + }, + )?; + + dca_avg_price.compute( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_dca_avg_price( + starting_indexes.dateindex, + &dca_stack.dateindex, + days, + exit, + ) + }, + )?; + + dca_returns.compute( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_percentage_difference( + starting_indexes.dateindex, + &fetched.timeindexes_to_close.dateindex, + &dca_avg_price.dateindex, + exit, + ) + }, + )?; + + if let Some(dca_cagr) = dca_cagr { + dca_cagr.compute( + indexer, + indexes, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_cagr( + starting_indexes.dateindex, + &dca_returns.dateindex, + days, + exit, + ) + }, + )?; + } + + Ok(()) + }, + )?; + thread::scope(|s| -> color_eyre::Result<()> { - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_1w_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 7, - exit, - ) - }, - ) + [ + (&mut self.indexes_to_1w_sma, 7), + (&mut self.indexes_to_8d_sma, 8), + (&mut self.indexes_to_13d_sma, 13), + (&mut self.indexes_to_21d_sma, 21), + (&mut self.indexes_to_1m_sma, 30), + (&mut self.indexes_to_34d_sma, 34), + (&mut self.indexes_to_55d_sma, 55), + (&mut self.indexes_to_89d_sma, 89), + (&mut self.indexes_to_144d_sma, 144), + (&mut self.indexes_to_1y_sma, 365), + (&mut self.indexes_to_2y_sma, 2 * 365), + (&mut self.indexes_to_200w_sma, 200 * 7), + (&mut self.indexes_to_4y_sma, 4 * 365), + ] + .into_iter() + .for_each(|(vecs, sma)| { + s.spawn(move || -> color_eyre::Result<()> { + vecs.compute( + indexer, + indexes, + fetched, + starting_indexes, + exit, + |v, _, _, starting_indexes, exit| { + v.compute_sma( + starting_indexes.dateindex, + &fetched.timeindexes_to_close.dateindex, + sma, + exit, + ) + }, + ) + }); }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_8d_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 8, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_13d_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 13, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_21d_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 21, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_1m_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 30, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_34d_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 34, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_55d_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 55, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_89d_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 89, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_144d_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 144, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_1y_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 365, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_2y_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 2 * 365, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_200w_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 200 * 7, - exit, - ) - }, - ) - }); - - s.spawn(|| -> color_eyre::Result<()> { - self.indexes_to_4y_sma.compute( - indexer, - indexes, - fetched, - starting_indexes, - exit, - |v, _, _, starting_indexes, exit| { - v.compute_sma( - starting_indexes.dateindex, - &fetched.timeindexes_to_close.dateindex, - 4 * 365, - exit, - ) - }, - ) - }); - Ok(()) }) } @@ -604,6 +1272,82 @@ impl Vecs { self.indexes_to_2y_sma.vecs(), self.indexes_to_200w_sma.vecs(), self.indexes_to_4y_sma.vecs(), + self.price_1d_ago.vecs(), + self.price_1w_ago.vecs(), + self.price_1m_ago.vecs(), + self.price_3m_ago.vecs(), + self.price_6m_ago.vecs(), + self.price_1y_ago.vecs(), + self.price_2y_ago.vecs(), + self.price_3y_ago.vecs(), + self.price_4y_ago.vecs(), + self.price_5y_ago.vecs(), + self.price_6y_ago.vecs(), + self.price_8y_ago.vecs(), + self.price_10y_ago.vecs(), + self._1d_returns.vecs(), + self._1w_returns.vecs(), + self._1m_returns.vecs(), + self._3m_returns.vecs(), + self._6m_returns.vecs(), + self._1y_returns.vecs(), + self._2y_returns.vecs(), + self._3y_returns.vecs(), + self._4y_returns.vecs(), + self._5y_returns.vecs(), + self._6y_returns.vecs(), + self._8y_returns.vecs(), + self._10y_returns.vecs(), + self._2y_cagr.vecs(), + self._3y_cagr.vecs(), + self._4y_cagr.vecs(), + self._5y_cagr.vecs(), + self._6y_cagr.vecs(), + self._8y_cagr.vecs(), + self._10y_cagr.vecs(), + self._1w_dca_returns.vecs(), + self._1m_dca_returns.vecs(), + self._3m_dca_returns.vecs(), + self._6m_dca_returns.vecs(), + self._1y_dca_returns.vecs(), + self._2y_dca_returns.vecs(), + self._3y_dca_returns.vecs(), + self._4y_dca_returns.vecs(), + self._5y_dca_returns.vecs(), + self._6y_dca_returns.vecs(), + self._8y_dca_returns.vecs(), + self._10y_dca_returns.vecs(), + self._2y_dca_cagr.vecs(), + self._3y_dca_cagr.vecs(), + self._4y_dca_cagr.vecs(), + self._5y_dca_cagr.vecs(), + self._6y_dca_cagr.vecs(), + self._8y_dca_cagr.vecs(), + self._10y_dca_cagr.vecs(), + self._1w_dca_avg_price.vecs(), + self._1m_dca_avg_price.vecs(), + self._3m_dca_avg_price.vecs(), + self._6m_dca_avg_price.vecs(), + self._1y_dca_avg_price.vecs(), + self._2y_dca_avg_price.vecs(), + self._3y_dca_avg_price.vecs(), + self._4y_dca_avg_price.vecs(), + self._5y_dca_avg_price.vecs(), + self._6y_dca_avg_price.vecs(), + self._8y_dca_avg_price.vecs(), + self._10y_dca_avg_price.vecs(), + self._1w_dca_stack.vecs(), + self._1m_dca_stack.vecs(), + self._3m_dca_stack.vecs(), + self._6m_dca_stack.vecs(), + self._1y_dca_stack.vecs(), + self._2y_dca_stack.vecs(), + self._3y_dca_stack.vecs(), + self._4y_dca_stack.vecs(), + self._5y_dca_stack.vecs(), + self._6y_dca_stack.vecs(), + self._8y_dca_stack.vecs(), + self._10y_dca_stack.vecs(), ] .concat() } diff --git a/crates/brk_core/src/structs/bitcoin.rs b/crates/brk_core/src/structs/bitcoin.rs index 9dff9e90c..b61812e8f 100644 --- a/crates/brk_core/src/structs/bitcoin.rs +++ b/crates/brk_core/src/structs/bitcoin.rs @@ -3,7 +3,7 @@ use std::ops::{Add, Div, Mul}; use serde::Serialize; use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; -use super::Sats; +use super::{Sats, StoredF64}; #[derive( Debug, @@ -53,6 +53,12 @@ impl From for Bitcoin { } } +impl From for Bitcoin { + fn from(value: StoredF64) -> Self { + Self(*value) + } +} + impl From for f64 { fn from(value: Bitcoin) -> Self { value.0 diff --git a/crates/brk_core/src/structs/cents.rs b/crates/brk_core/src/structs/cents.rs index 1fa11b77f..718262310 100644 --- a/crates/brk_core/src/structs/cents.rs +++ b/crates/brk_core/src/structs/cents.rs @@ -81,3 +81,10 @@ impl Mul for Cents { Self(self.0 * rhs.0) } } + +impl Mul for Cents { + type Output = Cents; + fn mul(self, rhs: usize) -> Self::Output { + Self(self.0 * rhs as u64) + } +} diff --git a/crates/brk_core/src/structs/dollars.rs b/crates/brk_core/src/structs/dollars.rs index 2490ca7a2..724769571 100644 --- a/crates/brk_core/src/structs/dollars.rs +++ b/crates/brk_core/src/structs/dollars.rs @@ -7,7 +7,7 @@ use derive_deref::Deref; use serde::Serialize; use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; -use super::{Bitcoin, Cents, Close, Sats, StoredF32}; +use super::{Bitcoin, Cents, Close, Sats, StoredF32, StoredF64}; #[derive( Debug, @@ -27,6 +27,10 @@ pub struct Dollars(f64); impl Dollars { pub const ZERO: Self = Self(0.0); + + pub const fn mint(dollars: f64) -> Self { + Self(dollars) + } } impl From for Dollars { @@ -79,9 +83,23 @@ impl Add for Dollars { } impl Div for Dollars { - type Output = StoredF32; + type Output = StoredF64; fn div(self, rhs: Dollars) -> Self::Output { - StoredF32::from((self.0 / rhs.0) as f32) + StoredF64::from(self.0 / rhs.0) + } +} + +impl Div> for Dollars { + type Output = StoredF64; + fn div(self, rhs: Close) -> Self::Output { + StoredF64::from(self.0 / rhs.0) + } +} + +impl Div for Close { + type Output = StoredF64; + fn div(self, rhs: Dollars) -> Self::Output { + StoredF64::from(self.0 / rhs.0) } } @@ -92,6 +110,13 @@ impl Div for Dollars { } } +impl Div for Dollars { + type Output = Self; + fn div(self, rhs: Bitcoin) -> Self::Output { + Self(f64::from(self) / f64::from(rhs)) + } +} + impl Eq for Dollars {} #[allow(clippy::derive_ord_xor_partial_ord)] @@ -121,6 +146,13 @@ impl Mul for Dollars { } } +impl Mul for Dollars { + type Output = Self; + fn mul(self, rhs: usize) -> Self::Output { + Self::from(Cents::from(self) * rhs) + } +} + impl From for Dollars { fn from(value: u128) -> Self { Self::from(Cents::from(value)) diff --git a/crates/brk_core/src/structs/stored_f32.rs b/crates/brk_core/src/structs/stored_f32.rs index 3dfdac93c..005f1bdb1 100644 --- a/crates/brk_core/src/structs/stored_f32.rs +++ b/crates/brk_core/src/structs/stored_f32.rs @@ -6,7 +6,7 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::CheckedSub; -use super::Dollars; +use super::{Dollars, StoredF64}; #[derive( Debug, @@ -36,6 +36,12 @@ impl From for StoredF32 { } } +impl From for StoredF32 { + fn from(value: StoredF64) -> Self { + Self(*value as f32) + } +} + impl From for StoredF32 { fn from(value: usize) -> Self { Self(value as f32) diff --git a/crates/brk_core/src/structs/stored_f64.rs b/crates/brk_core/src/structs/stored_f64.rs index 42b63c755..e81da2ccb 100644 --- a/crates/brk_core/src/structs/stored_f64.rs +++ b/crates/brk_core/src/structs/stored_f64.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, Div}; +use std::ops::{Add, Div, Mul}; use derive_deref::Deref; use serde::Serialize; @@ -40,6 +40,13 @@ impl CheckedSub for StoredF64 { } } +impl Mul for StoredF64 { + type Output = Self; + fn mul(self, rhs: usize) -> Self::Output { + Self(self.0 * rhs as f64) + } +} + impl Div for StoredF64 { type Output = Self; fn div(self, rhs: usize) -> Self::Output { @@ -68,3 +75,9 @@ impl Ord for StoredF64 { self.0.partial_cmp(&other.0).unwrap() } } + +impl CheckedSub for StoredF64 { + fn checked_sub(self, rhs: usize) -> Option { + Some(Self(self.0 - rhs as f64)) + } +} diff --git a/crates/brk_vec/src/variants/eager.rs b/crates/brk_vec/src/variants/eager.rs index e3a1703ed..8eb130457 100644 --- a/crates/brk_vec/src/variants/eager.rs +++ b/crates/brk_vec/src/variants/eager.rs @@ -3,12 +3,14 @@ use std::{ cmp::Ordering, f32, fmt::Debug, - ops::{Add, Div}, + ops::{Add, Div, Mul}, path::{Path, PathBuf}, time::Duration, }; -use brk_core::{Bitcoin, CheckedSub, Close, Dollars, Height, Sats, StoredUsize, TxIndex}; +use brk_core::{ + Bitcoin, CheckedSub, Close, DateIndex, Dollars, Height, Sats, StoredUsize, TxIndex, +}; use brk_exit::Exit; use log::info; @@ -21,6 +23,7 @@ use crate::{ const ONE_KIB: usize = 1024; const ONE_MIB: usize = ONE_KIB * ONE_KIB; const MAX_CACHE_SIZE: usize = 210 * ONE_MIB; +const DCA_AMOUNT: Dollars = Dollars::mint(100.0); #[derive(Debug, Clone)] pub struct EagerVec { @@ -176,6 +179,88 @@ where self.safe_flush(exit) } + pub fn compute_divide( + &mut self, + max_from: I, + divided: &impl AnyIterableVec, + divider: &impl AnyIterableVec, + exit: &Exit, + ) -> Result<()> + where + T2: StoredType + Div, + T3: StoredType, + T4: Mul + CheckedSub, + T: From, + { + self.compute_divide_(max_from, divided, divider, exit, false, false) + } + + pub fn compute_percentage( + &mut self, + max_from: I, + divided: &impl AnyIterableVec, + divider: &impl AnyIterableVec, + exit: &Exit, + ) -> Result<()> + where + T2: StoredType + Div, + T3: StoredType, + T4: Mul + CheckedSub, + T: From, + { + self.compute_divide_(max_from, divided, divider, exit, true, false) + } + + pub fn compute_percentage_difference( + &mut self, + max_from: I, + divided: &impl AnyIterableVec, + divider: &impl AnyIterableVec, + exit: &Exit, + ) -> Result<()> + where + T2: StoredType + Div, + T3: StoredType, + T4: Mul + CheckedSub, + T: From, + { + self.compute_divide_(max_from, divided, divider, exit, true, true) + } + + pub fn compute_divide_( + &mut self, + max_from: I, + divided: &impl AnyIterableVec, + divider: &impl AnyIterableVec, + exit: &Exit, + as_percentage: bool, + as_difference: bool, + ) -> Result<()> + where + T2: StoredType + Div, + T3: StoredType, + T4: Mul + CheckedSub, + T: From, + { + self.validate_computed_version_or_reset_file( + Version::ZERO + self.inner.version() + divided.version() + divider.version(), + )?; + + let index = max_from.min(I::from(self.len())); + let multiplier = if as_percentage { 100 } else { 1 }; + let subtract = if as_difference { multiplier } else { 0 }; + + let mut divider_iter = divider.iter(); + divided.iter_at(index).try_for_each(|(i, divided)| { + let v = (divided.into_inner() / divider_iter.unwrap_get_inner(i) * multiplier) + .checked_sub(subtract) + .unwrap(); + self.forced_push_at(i, T::from(v), exit) + })?; + + self.safe_flush(exit) + } + pub fn compute_inverse_more_to_less( &mut self, max_from: T, @@ -474,6 +559,186 @@ where self.safe_flush(exit) } + + pub fn compute_previous_value( + &mut self, + max_from: I, + source: &impl AnyIterableVec, + len: usize, + exit: &Exit, + ) -> Result<()> + where + I: CheckedSub, + T2: StoredType + Default, + f32: From, + T: From, + { + self.validate_computed_version_or_reset_file( + Version::ZERO + self.inner.version() + source.version(), + )?; + + let index = max_from.min(I::from(self.len())); + let mut source_iter = source.iter(); + (index.to_usize()?..source.len()).try_for_each(|i| { + let i = I::from(i); + + let previous_value = i + .checked_sub(I::from(len)) + .map(|prev_i| f32::from(source_iter.unwrap_get_inner(prev_i))) + .unwrap_or(f32::NAN); + + self.forced_push_at(i, T::from(previous_value), exit) + })?; + + self.safe_flush(exit) + } + + pub fn compute_percentage_change( + &mut self, + max_from: I, + source: &impl AnyIterableVec, + len: usize, + exit: &Exit, + ) -> Result<()> + where + I: CheckedSub, + T2: StoredType + Default, + f32: From, + T: From, + { + self.validate_computed_version_or_reset_file( + Version::ZERO + self.inner.version() + source.version(), + )?; + + let index = max_from.min(I::from(self.len())); + let mut source_iter = source.iter(); + source.iter_at(index).try_for_each(|(i, b)| { + let previous_value = f32::from( + i.checked_sub(I::from(len)) + .map(|prev_i| source_iter.unwrap_get_inner(prev_i)) + .unwrap_or_default(), + ); + + let last_value = f32::from(b.into_inner()); + + let percentage_change = ((last_value / previous_value) - 1.0) * 100.0; + + self.forced_push_at(i, T::from(percentage_change), exit) + })?; + + self.safe_flush(exit) + } + + pub fn compute_cagr( + &mut self, + max_from: I, + percentage_returns: &impl AnyIterableVec, + days: usize, + exit: &Exit, + ) -> Result<()> + where + I: CheckedSub, + T2: StoredType + Default, + f32: From, + T: From, + { + self.validate_computed_version_or_reset_file( + Version::ZERO + self.inner.version() + percentage_returns.version(), + )?; + + if days % 365 != 0 { + panic!("bad days"); + } + + let years = days / 365; + let index = max_from.min(I::from(self.len())); + percentage_returns + .iter_at(index) + .try_for_each(|(i, percentage)| { + let percentage = percentage.into_inner(); + + let cagr = (((f32::from(percentage) / 100.0 + 1.0).powf(1.0 / years as f32)) - 1.0) + * 100.0; + + self.forced_push_at(i, T::from(cagr), exit) + })?; + + self.safe_flush(exit) + } +} + +impl EagerVec { + pub fn compute_dca_stack( + &mut self, + max_from: DateIndex, + closes: &impl AnyIterableVec>, + len: usize, + exit: &Exit, + ) -> Result<()> { + self.validate_computed_version_or_reset_file( + Version::ZERO + self.inner.version() + closes.version(), + )?; + + let mut other_iter = closes.iter(); + let mut prev = None; + + let index = max_from.min(DateIndex::from(self.len())); + closes.iter_at(index).try_for_each(|(i, closes)| { + let price = *closes.into_inner(); + let i_usize = i.unwrap_to_usize(); + if prev.is_none() { + if i_usize == 0 { + prev.replace(Sats::ZERO); + } else { + prev.replace(self.into_iter().unwrap_get_inner_(i_usize - 1)); + } + } + + let mut stack = Sats::ZERO; + + if price != Dollars::ZERO { + stack = prev.unwrap() + Sats::from(Bitcoin::from(DCA_AMOUNT / price)); + if i_usize >= len { + let prev_price = *other_iter.unwrap_get_inner_(i_usize - len); + if prev_price != Dollars::ZERO { + stack = stack + .checked_sub(Sats::from(Bitcoin::from(DCA_AMOUNT / prev_price))) + .unwrap(); + } + } + } + + prev.replace(stack); + + self.forced_push_at(i, stack, exit) + })?; + + self.safe_flush(exit) + } +} + +impl EagerVec { + pub fn compute_dca_avg_price( + &mut self, + max_from: DateIndex, + stacks: &impl AnyIterableVec, + len: usize, + exit: &Exit, + ) -> Result<()> { + self.validate_computed_version_or_reset_file( + Version::ONE + self.inner.version() + stacks.version(), + )?; + + let index = max_from.min(DateIndex::from(self.len())); + + stacks.iter_at(index).try_for_each(|(i, stack)| { + let stack = stack.into_inner(); + let avg_price = DCA_AMOUNT * len.min(i.unwrap_to_usize() + 1) / Bitcoin::from(stack); + self.forced_push_at(i, avg_price, exit) + })?; + + self.safe_flush(exit) + } } impl EagerVec diff --git a/websites/kibo.money/index.html b/websites/kibo.money/index.html index ebe4b5fd1..864443336 100644 --- a/websites/kibo.money/index.html +++ b/websites/kibo.money/index.html @@ -990,12 +990,8 @@ display: flex; align-items: center; gap: 1.5rem; - margin-left: var(--negative-main-padding); - margin-right: var(--negative-main-padding); - padding-left: var(--main-padding); - padding-right: var(--main-padding); - padding-top: 0.5rem; - padding-bottom: 0.5rem; + margin: -0.5rem var(--negative-main-padding); + padding: 1rem var(--main-padding); overflow-x: auto; min-width: 0; font-size: var(--font-size-sm); diff --git a/websites/kibo.money/packages/lightweight-charts/wrapper.js b/websites/kibo.money/packages/lightweight-charts/wrapper.js index 821568e40..19e34ad32 100644 --- a/websites/kibo.money/packages/lightweight-charts/wrapper.js +++ b/websites/kibo.money/packages/lightweight-charts/wrapper.js @@ -1,6 +1,6 @@ // @ts-check -/** @import {IChartApi, ISeriesApi, SeriesDefinition, SingleValueData as _SingleValueData, CandlestickData as _CandlestickData, BaselineData, SeriesType, IPaneApi, LineSeriesOptions} from './v5.0.6-treeshaked/types' */ +/** @import {IChartApi, ISeriesApi, SeriesDefinition, SingleValueData as _SingleValueData, CandlestickData as _CandlestickData, BaselineData, SeriesType, IPaneApi, LineSeriesOptions, BaselineStyleOptions} from './v5.0.6-treeshaked/types' */ /** * @typedef {[number, number, number, number]} OHLCTuple @@ -485,7 +485,7 @@ export default import("./v5.0.6-treeshaked/script.js").then((lc) => { * @param {VecId} [args.vecId] * @param {number} [args.paneIndex] * @param {boolean} [args.defaultActive] - * @param {DeepPartial} [args.options] + * @param {DeepPartial} [args.options] */ addBaselineSeries({ vecId, @@ -507,18 +507,18 @@ export default import("./v5.0.6-treeshaked/script.js").then((lc) => { { lineWidth: /** @type {any} */ (1.5), visible: defaultActive !== false, - topLineColor: colors.green(), - bottomLineColor: colors.red(), + ...options, + topLineColor: options?.topLineColor ?? colors.green(), + bottomLineColor: options?.bottomLineColor ?? colors.red(), priceLineVisible: false, - // bottomFillColor1: "transparent", - // bottomFillColor2: "transparent", - // topFillColor1: "transparent", - // topFillColor2: "transparent", + bottomFillColor1: "transparent", + bottomFillColor2: "transparent", + topFillColor1: "transparent", + topFillColor2: "transparent", baseValue: { price: 0, }, lineVisible: true, - ...options, }, paneIndex, ); @@ -545,7 +545,10 @@ export default import("./v5.0.6-treeshaked/script.js").then((lc) => { (paneIndex ? legendBottom : legendTop).add({ series, - colors: [colors.green, colors.red], + colors: [ + () => options?.topLineColor ?? colors.green(), + () => options?.bottomLineColor ?? colors.red(), + ], name, defaultActive, url, diff --git a/websites/kibo.money/scripts/chart.js b/websites/kibo.money/scripts/chart.js index a7a913d8c..abb31d166 100644 --- a/websites/kibo.money/scripts/chart.js +++ b/websites/kibo.money/scripts/chart.js @@ -238,7 +238,11 @@ export function init({ unit, defaultActive: blueprint.defaultActive, paneIndex, - options: blueprint.options, + options: { + ...blueprint.options, + topLineColor: blueprint.colors?.[0](), + bottomLineColor: blueprint.colors?.[1](), + }, }); break; } diff --git a/websites/kibo.money/scripts/main.js b/websites/kibo.money/scripts/main.js index 56e813afd..0cc6010ec 100644 --- a/websites/kibo.money/scripts/main.js +++ b/websites/kibo.money/scripts/main.js @@ -41,7 +41,9 @@ * "Years" | * "Locktime" | * "sat/vB" | - * "vB" + * "cagr" | + * "vB" | + * "performance" | * } Unit */ @@ -686,6 +688,10 @@ function createUtils() { let unit; if (id.includes("index") || id.includes("height") || id.includes("epoch")) { unit = "Index"; + } else if (id.endsWith("cagr")) { + unit = "cagr"; + } else if (id.endsWith("returns")) { + unit = "performance"; } else if (id === "drawdown" || id.endsWith("oscillator")) { unit = "percentage"; } else if (id.endsWith("-as-price")) { @@ -726,7 +732,8 @@ function createUtils() { id.includes("output-value") || id.includes("fee") || id.includes("coinbase") || - id.includes("subsidy") + id.includes("subsidy") || + id.endsWith("stack") ) { unit = "Sats"; } else if ( @@ -737,7 +744,9 @@ function createUtils() { id.includes("ohlc") || id.includes("marketcap") || id.includes("ath") || - id.includes("-sma") + id.includes("-sma") || + id.endsWith("-price") || + id.startsWith("price-") ) { unit = "USD"; } else if (id.includes("count") || id.match(/v[1-3]/g)) { @@ -1619,6 +1628,20 @@ function createColors(dark, elements) { _4y: purple, _10y: fuchsia, + // r1d: pink, + // r1w: red, + // r1m: amber, + // r3m: yellow, + // r6m: lime, + // r1y: green, + // r2y: emerald, + // r3y: teal, + // r4y: blue, + // r5y: indigo, + // r6y: violet, + // r8y: purple, + // r10y: fuchsia, + p2pk: lime, p2pkh: violet, p2sh: emerald, diff --git a/websites/kibo.money/scripts/options.js b/websites/kibo.money/scripts/options.js index 4b19601e3..2e41dec60 100644 --- a/websites/kibo.money/scripts/options.js +++ b/websites/kibo.money/scripts/options.js @@ -19,6 +19,7 @@ * @typedef {Object} BaselineSeriesBlueprintSpecific * @property {"Baseline"} type * @property {Color} [color] + * @property {[Color, Color]} [colors] * @property {DeepPartial} [options] * @property {Accessor} [data] * @typedef {BaseSeriesBlueprint & BaselineSeriesBlueprintSpecific} BaselineSeriesBlueprint @@ -1093,6 +1094,117 @@ function createPartialOptions(colors) { })), ], }, + { + name: "Returns", + tree: [ + { + name: "1 Day", + title: `1 Day Returns`, + top: [ + createBaseSeries({ + key: `price-1d-ago`, + name: `Price 1d ago`, + }), + ], + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `1d-returns`, + title: "1d", + type: "Baseline", + }), + ], + }, + .../** @type {const} */ ([ + { name: "1 Week", key: "1w" }, + { name: "1 Month", key: "1m" }, + { name: "3 Months", key: "3m" }, + { name: "6 Months", key: "6m" }, + { name: "1 Year", key: "1y" }, + ]).map( + ({ name, key }) => + /** @satisfies {PartialChartOption} */ ({ + name, + title: `${name} Returns`, + top: [ + createBaseSeries({ + key: `price-${key}-ago`, + name: `lump sum`, + color: colors.cyan, + }), + createBaseSeries({ + key: `${key}-dca-avg-price`, + name: `dca`, + color: colors.orange, + }), + ], + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}-returns`, + title: "lump sum", + type: "Baseline", + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}-dca-returns`, + title: "dca", + type: "Baseline", + colors: [colors.yellow, colors.pink], + }), + ], + }), + ), + .../** @type {const} */ ([ + { name: "2 Year", key: "2y" }, + { name: "3 Year", key: "3y" }, + { name: "4 Year", key: "4y" }, + { name: "5 Year", key: "5y" }, + { name: "6 Year", key: "6y" }, + { name: "8 Year", key: "8y" }, + { name: "10 Year", key: "10y" }, + ]).map( + ({ name, key }) => + /** @satisfies {PartialChartOption} */ ({ + name, + title: `${name} Returns`, + top: [ + createBaseSeries({ + key: `price-${key}-ago`, + name: `lump sum`, + color: colors.cyan, + }), + createBaseSeries({ + key: `${key}-dca-avg-price`, + name: `dca`, + color: colors.orange, + }), + ], + bottom: [ + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}-returns`, + title: "lump sum", + type: "Baseline", + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}-cagr`, + title: "lump sum", + type: "Baseline", + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}-dca-returns`, + title: "dca", + type: "Baseline", + colors: [colors.yellow, colors.pink], + }), + /** @satisfies {FetchedBaselineSeriesBlueprint} */ ({ + key: `${key}-dca-cagr`, + title: "dca", + type: "Baseline", + colors: [colors.yellow, colors.pink], + }), + ], + }), + ), + ], + }, ], }, ], diff --git a/websites/kibo.money/scripts/simulation.js b/websites/kibo.money/scripts/simulation.js index 18b3351ad..913c58138 100644 --- a/websites/kibo.money/scripts/simulation.js +++ b/websites/kibo.money/scripts/simulation.js @@ -832,7 +832,7 @@ export function init({ owner, config: [ { - unit: "%", + unit: "percentage", blueprints: [ { title: "Profitable Days Ratio", diff --git a/websites/kibo.money/scripts/vecid-to-indexes.js b/websites/kibo.money/scripts/vecid-to-indexes.js index d85329672..628f239ba 100644 --- a/websites/kibo.money/scripts/vecid-to-indexes.js +++ b/websites/kibo.money/scripts/vecid-to-indexes.js @@ -56,6 +56,12 @@ export function createVecIdToIndexes() { const YearIndex = /** @satisfies {YearIndex} */ (23); return /** @type {const} */ ({ + "10y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "10y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "10y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "10y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "10y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "10y-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "13d-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "13d-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "13d-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -120,6 +126,11 @@ export function createVecIdToIndexes() { "144d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "144d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "144d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1d-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1m-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1m-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1m-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1m-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -152,6 +163,10 @@ export function createVecIdToIndexes() { "1m-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1m-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1w-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1w-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1w-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1w-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -184,6 +199,10 @@ export function createVecIdToIndexes() { "1w-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1w-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "1y-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1y-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1y-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "1y-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -280,6 +299,12 @@ export function createVecIdToIndexes() { "21d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "21d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "21d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "2y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "2y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "2y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "2y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "2y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "2y-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "2y-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "2y-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "2y-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -344,6 +369,22 @@ export function createVecIdToIndexes() { "34d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "34d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "34d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3m-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3m-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3m-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3m-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "3y-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "4y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "4y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "4y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "4y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "4y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "4y-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "4y-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "4y-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "4y-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -408,6 +449,22 @@ export function createVecIdToIndexes() { "55d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "55d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "55d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "5y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "5y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "5y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "5y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "5y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "5y-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6m-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6m-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6m-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6m-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "6y-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "89d-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "89d-sma-ratio": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "89d-sma-ratio-1m-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], @@ -472,6 +529,12 @@ export function createVecIdToIndexes() { "8d-sma-ratio-p99-as-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8d-sma-ratio-sma": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "8d-sma-ratio-standard-deviation": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "8y-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "8y-dca-avg-price": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "8y-dca-cagr": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "8y-dca-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "8y-dca-stack": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "8y-returns": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], ath: [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], "base-size": [TxIndex], "block-count": [Height], @@ -764,6 +827,19 @@ export function createVecIdToIndexes() { "p2wsh-count-sum": [DateIndex, DecadeIndex, DifficultyEpoch, MonthIndex, QuarterIndex, WeekIndex, YearIndex], p2wshbytes: [P2WSHIndex], p2wshindex: [P2WSHIndex], + "price-10y-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-1d-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-1m-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-1w-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-1y-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-2y-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-3m-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-3y-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-4y-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-5y-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-6m-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-6y-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], + "price-8y-ago": [DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex], quarterindex: [MonthIndex, QuarterIndex], rawlocktime: [TxIndex], subsidy: [Height],