mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
computer: renames
This commit is contained in:
@@ -52,7 +52,7 @@ impl Vecs {
|
||||
}
|
||||
|
||||
// DCA by period - stack (rolling sum via _start vecs)
|
||||
for (stack, days) in self.period.stack.iter_mut_with_days() {
|
||||
for (stack, days) in self.period.dca_stack.iter_mut_with_days() {
|
||||
let window_starts = blocks.lookback.start_vec(days as usize);
|
||||
stack.sats.height.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
@@ -63,14 +63,16 @@ impl Vecs {
|
||||
}
|
||||
|
||||
// DCA by period - stack cents (sats × price)
|
||||
for stack in self.period.stack.iter_mut() {
|
||||
for stack in self.period.dca_stack.iter_mut() {
|
||||
stack.compute(prices, starting_indexes.height, exit)?;
|
||||
}
|
||||
|
||||
// DCA by period - average price (derived from stack)
|
||||
let starting_height = starting_indexes.height.to_usize();
|
||||
for (average_price, stack, days) in
|
||||
self.period.cost_basis.zip_mut_with_days(&self.period.stack)
|
||||
for (average_price, stack, days) in self
|
||||
.period
|
||||
.dca_cost_basis
|
||||
.zip_mut_with_days(&self.period.dca_stack)
|
||||
{
|
||||
let days = days as usize;
|
||||
average_price.cents.height.compute_transform2(
|
||||
@@ -94,9 +96,9 @@ impl Vecs {
|
||||
// DCA by period - returns (compute from average price)
|
||||
for (returns, (average_price, _)) in self
|
||||
.period
|
||||
.r#return
|
||||
.dca_return
|
||||
.iter_mut()
|
||||
.zip(self.period.cost_basis.iter_with_days())
|
||||
.zip(self.period.dca_cost_basis.iter_with_days())
|
||||
{
|
||||
returns.compute_binary::<Cents, Cents, RatioDiffCentsBps32>(
|
||||
starting_indexes.height,
|
||||
@@ -107,7 +109,11 @@ impl Vecs {
|
||||
}
|
||||
|
||||
// DCA by period - CAGR (computed from returns at height level)
|
||||
for (cagr, returns, days) in self.period.cagr.zip_mut_with_period(&self.period.r#return) {
|
||||
for (cagr, returns, days) in self
|
||||
.period
|
||||
.dca_cagr
|
||||
.zip_mut_with_period(&self.period.dca_return)
|
||||
{
|
||||
let years = days as f64 / 365.0;
|
||||
cagr.bps.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
@@ -165,11 +171,15 @@ impl Vecs {
|
||||
|
||||
// DCA by year class - stack (cumulative sum from class start date)
|
||||
let start_days = super::ByDcaClass::<()>::start_days();
|
||||
for (stack, day1) in self.class.stack.iter_mut().zip(start_days) {
|
||||
for (stack, day1) in self.class.dca_stack.iter_mut().zip(start_days) {
|
||||
let mut last_di: Option<Day1> = None;
|
||||
let cls_start = stack.sats.height.len().min(starting_height);
|
||||
let mut prev_value = if cls_start > 0 {
|
||||
stack.sats.height.collect_one_at(cls_start - 1).unwrap_or_default()
|
||||
stack
|
||||
.sats
|
||||
.height
|
||||
.collect_one_at(cls_start - 1)
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
Sats::ZERO
|
||||
};
|
||||
@@ -216,7 +226,7 @@ impl Vecs {
|
||||
}
|
||||
|
||||
// DCA by year class - stack cents (sats × price)
|
||||
for stack in self.class.stack.iter_mut() {
|
||||
for stack in self.class.dca_stack.iter_mut() {
|
||||
stack.compute(prices, starting_indexes.height, exit)?;
|
||||
}
|
||||
|
||||
@@ -224,9 +234,9 @@ impl Vecs {
|
||||
let start_days = super::ByDcaClass::<()>::start_days();
|
||||
for ((average_price, stack), from) in self
|
||||
.class
|
||||
.cost_basis
|
||||
.dca_cost_basis
|
||||
.iter_mut()
|
||||
.zip(self.class.stack.iter())
|
||||
.zip(self.class.dca_stack.iter())
|
||||
.zip(start_days)
|
||||
{
|
||||
let from_usize = from.to_usize();
|
||||
@@ -250,9 +260,9 @@ impl Vecs {
|
||||
// DCA by year class - returns (compute from average price)
|
||||
for (returns, average_price) in self
|
||||
.class
|
||||
.r#return
|
||||
.dca_return
|
||||
.iter_mut()
|
||||
.zip(self.class.cost_basis.iter())
|
||||
.zip(self.class.dca_cost_basis.iter())
|
||||
{
|
||||
returns.compute_binary::<Cents, Cents, RatioDiffCentsBps32>(
|
||||
starting_indexes.height,
|
||||
|
||||
@@ -4,13 +4,13 @@ use brk_error::Result;
|
||||
use brk_types::Version;
|
||||
use vecdb::ImportableVec;
|
||||
|
||||
use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod, Vecs};
|
||||
use super::vecs::{ClassVecs, PeriodVecs};
|
||||
use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod, Vecs};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
db_utils::{finalize_db, open_db},
|
||||
AmountPerBlock, PercentPerBlock, Price,
|
||||
db_utils::{finalize_db, open_db},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -66,17 +66,17 @@ impl Vecs {
|
||||
let this = Self {
|
||||
sats_per_day: ImportableVec::forced_import(&db, "dca_sats_per_day", version)?,
|
||||
period: PeriodVecs {
|
||||
stack,
|
||||
cost_basis,
|
||||
r#return,
|
||||
cagr,
|
||||
dca_stack: stack,
|
||||
dca_cost_basis: cost_basis,
|
||||
dca_return: r#return,
|
||||
dca_cagr: cagr,
|
||||
lump_sum_stack,
|
||||
lump_sum_return,
|
||||
},
|
||||
class: ClassVecs {
|
||||
stack: class_stack,
|
||||
cost_basis: class_cost_basis,
|
||||
r#return: class_return,
|
||||
dca_stack: class_stack,
|
||||
dca_cost_basis: class_cost_basis,
|
||||
dca_return: class_return,
|
||||
},
|
||||
db,
|
||||
};
|
||||
|
||||
@@ -7,19 +7,19 @@ use crate::internal::{AmountPerBlock, PerBlock, PercentPerBlock, Price};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct PeriodVecs<M: StorageMode = Rw> {
|
||||
pub stack: ByDcaPeriod<AmountPerBlock<M>>,
|
||||
pub cost_basis: ByDcaPeriod<Price<PerBlock<Cents, M>>>,
|
||||
pub r#return: ByDcaPeriod<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||
pub cagr: ByDcaCagr<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||
pub dca_stack: ByDcaPeriod<AmountPerBlock<M>>,
|
||||
pub dca_cost_basis: ByDcaPeriod<Price<PerBlock<Cents, M>>>,
|
||||
pub dca_return: ByDcaPeriod<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||
pub dca_cagr: ByDcaCagr<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||
pub lump_sum_stack: ByDcaPeriod<AmountPerBlock<M>>,
|
||||
pub lump_sum_return: ByDcaPeriod<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ClassVecs<M: StorageMode = Rw> {
|
||||
pub stack: ByDcaClass<AmountPerBlock<M>>,
|
||||
pub cost_basis: ByDcaClass<Price<PerBlock<Cents, M>>>,
|
||||
pub r#return: ByDcaClass<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||
pub dca_stack: ByDcaClass<AmountPerBlock<M>>,
|
||||
pub dca_cost_basis: ByDcaClass<Price<PerBlock<Cents, M>>>,
|
||||
pub dca_return: ByDcaClass<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||
}
|
||||
|
||||
#[derive(Traversable)]
|
||||
|
||||
Reference in New Issue
Block a user