refactor: reduce verbosity and use vecdb cumulative function

- Remove verbose inline comments from compute.rs
- Update vecdb to 0.6.1
- Refactor HODL Bank to use compute_cumulative_transformed_binary
This commit is contained in:
Brandon Collins
2026-01-21 12:20:53 -05:00
parent 9dda513f84
commit 581a800612
3 changed files with 16 additions and 49 deletions
Generated
+6 -6
View File
@@ -2482,9 +2482,9 @@ dependencies = [
[[package]]
name = "rawdb"
version = "0.6.0"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdd8290a282cf2ea860ee2e787b3229731db7dac73a16c9240c545e20e91b302"
checksum = "39ebb540a243e937d5ec268361bbf7b83e05e6c4ad8de21ac9ee64c4f72e9001"
dependencies = [
"libc",
"log",
@@ -3365,9 +3365,9 @@ checksum = "8f54a172d0620933a27a4360d3db3e2ae0dd6cceae9730751a036bbf182c4b23"
[[package]]
name = "vecdb"
version = "0.6.0"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81910b96a48ea197d1871259164b957c05f3e94d94cd107c4b87cf24e7f2968f"
checksum = "d64486e34d56d63797295aa928288542226b6f28f96a3b58f661b1efd9f54cde"
dependencies = [
"ctrlc",
"log",
@@ -3386,9 +3386,9 @@ dependencies = [
[[package]]
name = "vecdb_derive"
version = "0.6.0"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab7250822f3caf8795728690804d39ab5c72c51f5558b90788a79bc99776d55"
checksum = "3c1f863f6687e9ff90962a51a0f6c9646a14dc0ccfd9ea2ea79e288d88187bef"
dependencies = [
"quote",
"syn",
+1 -2
View File
@@ -81,8 +81,7 @@ tokio = { version = "1.49.0", features = ["rt-multi-thread"] }
tracing = { version = "0.1", default-features = false, features = ["std"] }
tower-http = { version = "0.6.8", features = ["catch-panic", "compression-br", "compression-gzip", "compression-zstd", "cors", "normalize-path", "timeout", "trace"] }
tower-layer = "0.3"
# vecdb = { version = "0.5.11", features = ["derive", "serde_json", "pco", "schemars"] }
vecdb = { path = "../anydb/crates/vecdb", features = ["derive", "serde_json", "pco", "schemars"] }
vecdb = { version = "0.6.1", features = ["derive", "serde_json", "pco", "schemars"] }
[workspace.metadata.release]
shared-version = true
@@ -1,6 +1,6 @@
use brk_error::Result;
use brk_types::{DateIndex, StoredF64};
use vecdb::{AnyStoredVec, AnyVec, Exit, GenericStoredVec, IterableVec, VecIndex};
use brk_types::{Close, Dollars, StoredF64};
use vecdb::Exit;
use super::{super::value, Vecs};
use crate::{price, ComputeIndexes};
@@ -13,11 +13,8 @@ impl Vecs {
value: &value::Vecs,
exit: &Exit,
) -> Result<()> {
// Get VOCDD dateindex sum data (from cointime/value module)
// The dateindex.sum.0 contains daily VOCDD values as EagerVec
let vocdd_dateindex_sum = &value.vocdd.dateindex.sum.0;
// Compute 365-day SMA of VOCDD
self.vocdd_365d_sma.compute_sma(
starting_indexes.dateindex,
vocdd_dateindex_sum,
@@ -27,43 +24,14 @@ impl Vecs {
let price_close = &price.usd.split.close.dateindex;
// Compute HODL Bank = cumulative sum of (price - vocdd_sma)
// Start from where we left off and maintain cumulative state
let starting_dateindex = starting_indexes
.dateindex
.to_usize()
.min(self.hodl_bank.len());
let target_len = price_close.len().min(self.vocdd_365d_sma.len());
self.hodl_bank.compute_cumulative_transformed_binary(
starting_indexes.dateindex,
price_close,
&self.vocdd_365d_sma,
|price: Close<Dollars>, sma: StoredF64| StoredF64::from(f64::from(price) - f64::from(sma)),
exit,
)?;
if target_len > starting_dateindex {
let mut price_iter = price_close.iter();
let mut vocdd_sma_iter = self.vocdd_365d_sma.iter();
// Get previous cumulative value, or start at 0
let mut cumulative: f64 = if starting_dateindex > 0 {
let prev_dateindex = DateIndex::from(starting_dateindex - 1);
f64::from(*self.hodl_bank.iter().get_unwrap(prev_dateindex))
} else {
0.0
};
for i in starting_dateindex..target_len {
let dateindex = DateIndex::from(i);
let price_val = f64::from(*price_iter.get_unwrap(dateindex));
let vocdd_sma = f64::from(*vocdd_sma_iter.get_unwrap(dateindex));
// HODL Bank contribution: price - smoothed VOCDD
// Accumulate over time
cumulative += price_val - vocdd_sma;
self.hodl_bank
.truncate_push_at(i, StoredF64::from(cumulative))?;
}
let _lock = exit.lock();
self.hodl_bank.write()?;
}
// Compute Reserve Risk = price / hodl_bank (if enabled)
if let Some(reserve_risk) = self.reserve_risk.as_mut() {
reserve_risk.compute_all(starting_indexes, exit, |v| {
v.compute_divide(