mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-19 14:24:47 -07:00
global: adding support for safe lengths
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -483,7 +483,6 @@ dependencies = [
|
|||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"smallvec",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
"vecdb",
|
"vecdb",
|
||||||
]
|
]
|
||||||
@@ -2388,8 +2387,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rawdb"
|
name = "rawdb"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "78ec6d90b48955942ae9aa12b8630c8100798bf79e73dbdffd8115a3e71e4915"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
@@ -3281,8 +3278,6 @@ checksum = "8f54a172d0620933a27a4360d3db3e2ae0dd6cceae9730751a036bbf182c4b23"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "vecdb"
|
name = "vecdb"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2ca57cedd42c0c7d8a343c06ab9c311be28a731e5d1e4101ef671d9a9af409a8"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -3304,8 +3299,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "vecdb_derive"
|
name = "vecdb_derive"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8840b74c96d5888e1a5846adcd2ec8355778052a07dd5f6d30d67ef0fbc33b7e"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ tower-http = { version = "0.6.9", features = ["catch-panic", "compression-br", "
|
|||||||
tower-layer = "0.3"
|
tower-layer = "0.3"
|
||||||
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
tracing = { version = "0.1", default-features = false, features = ["std"] }
|
||||||
ureq = { version = "3.3.0", features = ["json"] }
|
ureq = { version = "3.3.0", features = ["json"] }
|
||||||
vecdb = { version = "0.10.2", features = ["derive", "serde_json", "pco", "schemars"] }
|
# vecdb = { version = "=0.10.2", features = ["derive", "serde_json", "pco", "schemars"] }
|
||||||
# vecdb = { path = "../anydb/crates/vecdb", features = ["derive", "serde_json", "pco", "schemars"] }
|
vecdb = { path = "../anydb/crates/vecdb", features = ["derive", "serde_json", "pco", "schemars"] }
|
||||||
|
|
||||||
[workspace.metadata.release]
|
[workspace.metadata.release]
|
||||||
shared-version = true
|
shared-version = true
|
||||||
|
|||||||
@@ -270,9 +270,7 @@ fn extract_response_kind(operation: &Operation, spec: &Spec) -> ResponseKind {
|
|||||||
|
|
||||||
fn schema_name_from_content(content: &oas3::spec::MediaType) -> Option<String> {
|
fn schema_name_from_content(content: &oas3::spec::MediaType) -> Option<String> {
|
||||||
match content.schema.as_ref()? {
|
match content.schema.as_ref()? {
|
||||||
ObjectOrReference::Ref { ref_path, .. } => {
|
ObjectOrReference::Ref { ref_path, .. } => Some(ref_to_type_name(ref_path)?.to_string()),
|
||||||
Some(ref_to_type_name(ref_path)?.to_string())
|
|
||||||
}
|
|
||||||
ObjectOrReference::Object(schema) => schema_to_type_name(schema),
|
ObjectOrReference::Object(schema) => schema_to_type_name(schema),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,7 +286,9 @@ fn is_numeric_schema(spec: &Spec, name: &str) -> bool {
|
|||||||
};
|
};
|
||||||
matches!(
|
matches!(
|
||||||
schema.schema_type.as_ref(),
|
schema.schema_type.as_ref(),
|
||||||
Some(SchemaTypeSet::Single(SchemaType::Integer | SchemaType::Number))
|
Some(SchemaTypeSet::Single(
|
||||||
|
SchemaType::Integer | SchemaType::Number
|
||||||
|
))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ pub fn main() -> anyhow::Result<()> {
|
|||||||
{
|
{
|
||||||
// Pre-run indexer if too far behind, then drop and reimport to reduce memory
|
// Pre-run indexer if too far behind, then drop and reimport to reduce memory
|
||||||
let chain_height = client.get_last_height()?;
|
let chain_height = client.get_last_height()?;
|
||||||
let indexed_height = indexer.vecs.starting_height();
|
let indexed_height = indexer.vecs.next_height();
|
||||||
let blocks_behind = chain_height.saturating_sub(*indexed_height);
|
let blocks_behind = chain_height.saturating_sub(*indexed_height);
|
||||||
if blocks_behind > 10_000 {
|
if blocks_behind > 10_000 {
|
||||||
info!("---");
|
info!("---");
|
||||||
@@ -105,15 +105,17 @@ pub fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let total_start = Instant::now();
|
let total_start = Instant::now();
|
||||||
|
|
||||||
let starting_indexes = if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
indexer.checked_index(&reader, &client, &exit)?
|
indexer.checked_index(&reader, &client, &exit)?;
|
||||||
} else {
|
} else {
|
||||||
indexer.index(&reader, &client, &exit)?
|
indexer.index(&reader, &client, &exit)?;
|
||||||
};
|
}
|
||||||
|
|
||||||
Mimalloc::collect();
|
Mimalloc::collect();
|
||||||
|
|
||||||
computer.compute(&indexer, starting_indexes, &exit)?;
|
computer.compute(&indexer, &exit)?;
|
||||||
|
|
||||||
|
indexer.advance_safe_lengths()?;
|
||||||
|
|
||||||
info!("Total time: {:?}", total_start.elapsed());
|
info!("Total time: {:?}", total_start.elapsed());
|
||||||
info!("Waiting for new blocks...");
|
info!("Waiting for new blocks...");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ pub fn dot_brk_path() -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn dot_brk_log_path() -> PathBuf {
|
pub fn dot_brk_log_path() -> PathBuf {
|
||||||
dot_brk_path().join("log")
|
dot_brk_path().join("logs")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_brk_path() -> PathBuf {
|
pub fn default_brk_path() -> PathBuf {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ Compute 1000+ on-chain metrics from indexed blockchain data: supply breakdowns,
|
|||||||
let mut computer = Computer::forced_import(&outputs_path, &indexer)?;
|
let mut computer = Computer::forced_import(&outputs_path, &indexer)?;
|
||||||
|
|
||||||
// Compute all metrics for new blocks
|
// Compute all metrics for new blocks
|
||||||
computer.compute(&indexer, starting_indexes, &reader, &exit)?;
|
computer.compute(&indexer, &exit)?;
|
||||||
|
|
||||||
// Access computed data via traversable vecs
|
// Access computed data via traversable vecs
|
||||||
let supply = computer.distribution.utxo_cohorts.all.metrics.supply.total.sats.height;
|
let supply = computer.distribution.utxo_cohorts.all.metrics.supply.total.sats.height;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ pub fn main() -> color_eyre::Result<()> {
|
|||||||
|
|
||||||
// Pre-run indexer if too far behind, then drop and reimport to reduce memory
|
// Pre-run indexer if too far behind, then drop and reimport to reduce memory
|
||||||
let chain_height = client.get_last_height()?;
|
let chain_height = client.get_last_height()?;
|
||||||
let indexed_height = indexer.vecs.starting_height();
|
let indexed_height = indexer.vecs.next_height();
|
||||||
if u32::from(chain_height).saturating_sub(u32::from(indexed_height)) > 1000 {
|
if u32::from(chain_height).saturating_sub(u32::from(indexed_height)) > 1000 {
|
||||||
indexer.checked_index(&reader, &client, &exit)?;
|
indexer.checked_index(&reader, &client, &exit)?;
|
||||||
drop(indexer);
|
drop(indexer);
|
||||||
@@ -49,11 +49,11 @@ pub fn main() -> color_eyre::Result<()> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let i = Instant::now();
|
let i = Instant::now();
|
||||||
let starting_indexes = indexer.checked_index(&reader, &client, &exit)?;
|
indexer.checked_index(&reader, &client, &exit)?;
|
||||||
|
|
||||||
Mimalloc::collect();
|
Mimalloc::collect();
|
||||||
|
|
||||||
computer.compute(&indexer, starting_indexes, &exit)?;
|
computer.compute(&indexer, &exit)?;
|
||||||
dbg!(i.elapsed());
|
dbg!(i.elapsed());
|
||||||
sleep(Duration::from_secs(10));
|
sleep(Duration::from_secs(10));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ pub fn main() -> Result<()> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let i = Instant::now();
|
let i = Instant::now();
|
||||||
let starting_indexes = indexer.index(&reader, &client, &exit)?;
|
indexer.index(&reader, &client, &exit)?;
|
||||||
info!("Done in {:?}", i.elapsed());
|
info!("Done in {:?}", i.elapsed());
|
||||||
|
|
||||||
Mimalloc::collect();
|
Mimalloc::collect();
|
||||||
|
|
||||||
let i = Instant::now();
|
let i = Instant::now();
|
||||||
computer.compute(&indexer, starting_indexes, &exit)?;
|
computer.compute(&indexer, &exit)?;
|
||||||
info!("Done in {:?}", i.elapsed());
|
info!("Done in {:?}", i.elapsed());
|
||||||
|
|
||||||
// We want to benchmark the drop too
|
// We want to benchmark the drop too
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ pub fn main() -> color_eyre::Result<()> {
|
|||||||
|
|
||||||
// Pre-run indexer if too far behind, then drop and reimport to reduce memory
|
// Pre-run indexer if too far behind, then drop and reimport to reduce memory
|
||||||
let chain_height = client.get_last_height()?;
|
let chain_height = client.get_last_height()?;
|
||||||
let indexed_height = indexer.vecs.starting_height();
|
let indexed_height = indexer.vecs.next_height();
|
||||||
if chain_height.saturating_sub(*indexed_height) > 1000 {
|
if chain_height.saturating_sub(*indexed_height) > 1000 {
|
||||||
indexer.index(&reader, &client, &exit)?;
|
indexer.index(&reader, &client, &exit)?;
|
||||||
drop(indexer);
|
drop(indexer);
|
||||||
@@ -60,13 +60,13 @@ pub fn main() -> color_eyre::Result<()> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let i = Instant::now();
|
let i = Instant::now();
|
||||||
let starting_indexes = indexer.index(&reader, &client, &exit)?;
|
indexer.index(&reader, &client, &exit)?;
|
||||||
info!("Done in {:?}", i.elapsed());
|
info!("Done in {:?}", i.elapsed());
|
||||||
|
|
||||||
Mimalloc::collect();
|
Mimalloc::collect();
|
||||||
|
|
||||||
let i = Instant::now();
|
let i = Instant::now();
|
||||||
computer.compute(&indexer, starting_indexes, &exit)?;
|
computer.compute(&indexer, &exit)?;
|
||||||
info!("Done in {:?}", i.elapsed());
|
info!("Done in {:?}", i.elapsed());
|
||||||
|
|
||||||
sleep(Duration::from_secs(60));
|
sleep(Duration::from_secs(60));
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::thread;
|
|||||||
|
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::Indexes;
|
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use crate::indexes;
|
use crate::indexes;
|
||||||
@@ -14,13 +13,12 @@ impl Vecs {
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
|
|
||||||
// lookback depends on indexes.timestamp.monotonic
|
// lookback depends on indexes.timestamp.monotonic
|
||||||
self.lookback.compute(indexes, starting_indexes, exit)?;
|
self.lookback.compute(indexer, indexes, exit)?;
|
||||||
|
|
||||||
// Parallel: remaining sub-modules are independent of each other.
|
// Parallel: remaining sub-modules are independent of each other.
|
||||||
// size depends on lookback (already computed above).
|
// size depends on lookback (already computed above).
|
||||||
@@ -35,12 +33,12 @@ impl Vecs {
|
|||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
thread::scope(|s| -> Result<()> {
|
thread::scope(|s| -> Result<()> {
|
||||||
let r1 = s.spawn(|| count.compute(indexer, starting_indexes, exit));
|
let r1 = s.spawn(|| count.compute(indexer, exit));
|
||||||
let r2 = s.spawn(|| interval.compute(indexer, starting_indexes, exit));
|
let r2 = s.spawn(|| interval.compute(indexer, exit));
|
||||||
let r3 = s.spawn(|| weight.compute(indexer, starting_indexes, exit));
|
let r3 = s.spawn(|| weight.compute(indexer, exit));
|
||||||
let r4 = s.spawn(|| difficulty.compute(indexer, indexes, starting_indexes, exit));
|
let r4 = s.spawn(|| difficulty.compute(indexer, indexes, exit));
|
||||||
let r5 = s.spawn(|| halving.compute(indexes, starting_indexes, exit));
|
let r5 = s.spawn(|| halving.compute(indexer, indexes, exit));
|
||||||
size.compute(indexer, &*lookback, starting_indexes, exit)?;
|
size.compute(indexer, &*lookback, exit)?;
|
||||||
r1.join().unwrap()?;
|
r1.join().unwrap()?;
|
||||||
r2.join().unwrap()?;
|
r2.join().unwrap()?;
|
||||||
r3.join().unwrap()?;
|
r3.join().unwrap()?;
|
||||||
|
|||||||
@@ -1,25 +1,20 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{Indexes, StoredU32};
|
use brk_types::StoredU32;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_height = indexer.safe_lengths().height;
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
// Block count raw + cumulative
|
|
||||||
self.total.block.compute_range(
|
self.total.block.compute_range(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexer.vecs.blocks.weight,
|
&indexer.vecs.blocks.weight,
|
||||||
|h| (h, StoredU32::from(1_u32)),
|
|h| (h, StoredU32::from(1_u32)),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.total.compute_rest(starting_indexes.height, exit)?;
|
self.total.compute_rest(starting_height, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{Indexes, StoredU32};
|
use brk_types::StoredU32;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -11,25 +11,25 @@ impl Vecs {
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
self.adjustment.bps.height.compute_ratio_change(
|
self.adjustment.bps.height.compute_ratio_change(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexer.vecs.blocks.difficulty,
|
&indexer.vecs.blocks.difficulty,
|
||||||
2016,
|
2016,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.epoch.height.compute_transform(
|
self.epoch.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexes.height.epoch,
|
&indexes.height.epoch,
|
||||||
|(h, epoch, ..)| (h, epoch),
|
|(h, epoch, ..)| (h, epoch),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.blocks_to_retarget.height.compute_transform(
|
self.blocks_to_retarget.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexes.height.epoch,
|
&indexes.height.epoch,
|
||||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
|
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Indexes, StoredU32};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::StoredU32;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -8,19 +9,20 @@ use crate::indexes;
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
self.epoch.height.compute_transform(
|
self.epoch.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexes.height.halving,
|
&indexes.height.halving,
|
||||||
|(h, epoch, ..)| (h, epoch),
|
|(h, epoch, ..)| (h, epoch),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.blocks_to_halving.height.compute_transform(
|
self.blocks_to_halving.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexes.height.halving,
|
&indexes.height.halving,
|
||||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_halving())),
|
|(h, ..)| (h, StoredU32::from(h.left_before_next_halving())),
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{CheckedSub, Indexes, Timestamp};
|
use brk_types::{CheckedSub, Timestamp};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_height = indexer.safe_lengths().height;
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
let mut prev_timestamp = None;
|
let mut prev_timestamp = None;
|
||||||
self.0.compute(starting_indexes.height, exit, |vec| {
|
self.0.compute(starting_height, exit, |vec| {
|
||||||
vec.compute_transform(
|
vec.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexer.vecs.blocks.timestamp,
|
&indexer.vecs.blocks.timestamp,
|
||||||
|(h, timestamp, ..)| {
|
|(h, timestamp, ..)| {
|
||||||
let interval = if let Some(prev_h) = h.decremented() {
|
let interval = if let Some(prev_h) = h.decremented() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Indexer;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Timestamp, Version};
|
use brk_types::{Height, Timestamp, Version};
|
||||||
use vecdb::{
|
use vecdb::{
|
||||||
AnyVec, CachedVec, Cursor, Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableVec, Rw,
|
AnyVec, CachedVec, Cursor, Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableVec, Rw,
|
||||||
StorageMode, VecIndex,
|
StorageMode, VecIndex,
|
||||||
@@ -219,53 +220,54 @@ impl Vecs {
|
|||||||
|
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_rolling_start_hours(indexes, starting_indexes, exit, 1, |s| &mut s._1h)?;
|
let starting_height = indexer.safe_lengths().height;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 1, |s| &mut s._24h.inner)?;
|
self.compute_rolling_start_hours(indexes, starting_height, exit, 1, |s| &mut s._1h)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 3, |s| &mut s._3d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 1, |s| &mut s._24h.inner)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 7, |s| &mut s._1w.inner)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 3, |s| &mut s._3d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 8, |s| &mut s._8d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 7, |s| &mut s._1w.inner)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 9, |s| &mut s._9d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 8, |s| &mut s._8d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 12, |s| &mut s._12d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 9, |s| &mut s._9d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 13, |s| &mut s._13d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 12, |s| &mut s._12d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 14, |s| &mut s._2w)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 13, |s| &mut s._13d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 21, |s| &mut s._21d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 14, |s| &mut s._2w)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 26, |s| &mut s._26d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 21, |s| &mut s._21d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 30, |s| &mut s._1m.inner)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 26, |s| &mut s._26d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 34, |s| &mut s._34d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 30, |s| &mut s._1m.inner)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 55, |s| &mut s._55d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 34, |s| &mut s._34d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 60, |s| &mut s._2m)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 55, |s| &mut s._55d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 63, |s| &mut s._9w)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 60, |s| &mut s._2m)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 84, |s| &mut s._12w)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 63, |s| &mut s._9w)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 89, |s| &mut s._89d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 84, |s| &mut s._12w)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 90, |s| &mut s._3m)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 89, |s| &mut s._89d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 98, |s| &mut s._14w)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 90, |s| &mut s._3m)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 111, |s| &mut s._111d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 98, |s| &mut s._14w)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 144, |s| &mut s._144d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 111, |s| &mut s._111d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 180, |s| &mut s._6m)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 144, |s| &mut s._144d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 182, |s| &mut s._26w)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 180, |s| &mut s._6m)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 200, |s| &mut s._200d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 182, |s| &mut s._26w)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 270, |s| &mut s._9m)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 200, |s| &mut s._200d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 350, |s| &mut s._350d)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 270, |s| &mut s._9m)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 360, |s| &mut s._12m)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 350, |s| &mut s._350d)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 365, |s| &mut s._1y.inner)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 360, |s| &mut s._12m)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 420, |s| &mut s._14m)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 365, |s| &mut s._1y.inner)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 730, |s| &mut s._2y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 420, |s| &mut s._14m)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 780, |s| &mut s._26m)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 730, |s| &mut s._2y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 1095, |s| &mut s._3y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 780, |s| &mut s._26m)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 1400, |s| &mut s._200w)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 1095, |s| &mut s._3y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 1460, |s| &mut s._4y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 1400, |s| &mut s._200w)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 1825, |s| &mut s._5y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 1460, |s| &mut s._4y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 2190, |s| &mut s._6y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 1825, |s| &mut s._5y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 2920, |s| &mut s._8y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 2190, |s| &mut s._6y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 3285, |s| &mut s._9y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 2920, |s| &mut s._8y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 3650, |s| &mut s._10y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 3285, |s| &mut s._9y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 4380, |s| &mut s._12y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 3650, |s| &mut s._10y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 5110, |s| &mut s._14y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 4380, |s| &mut s._12y)?;
|
||||||
self.compute_rolling_start(indexes, starting_indexes, exit, 9490, |s| &mut s._26y)?;
|
self.compute_rolling_start(indexes, starting_height, exit, 5110, |s| &mut s._14y)?;
|
||||||
|
self.compute_rolling_start(indexes, starting_height, exit, 9490, |s| &mut s._26y)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -273,7 +275,7 @@ impl Vecs {
|
|||||||
fn compute_rolling_start<F>(
|
fn compute_rolling_start<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_height: Height,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
days: usize,
|
days: usize,
|
||||||
get_field: F,
|
get_field: F,
|
||||||
@@ -281,19 +283,15 @@ impl Vecs {
|
|||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> &mut EagerVec<PcoVec<Height, Height>>,
|
F: FnOnce(&mut Self) -> &mut EagerVec<PcoVec<Height, Height>>,
|
||||||
{
|
{
|
||||||
self.compute_rolling_start_inner(
|
self.compute_rolling_start_inner(indexes, starting_height, exit, get_field, |t, prev_ts| {
|
||||||
indexes,
|
t.difference_in_days_between(prev_ts) >= days
|
||||||
starting_indexes,
|
})
|
||||||
exit,
|
|
||||||
get_field,
|
|
||||||
|t, prev_ts| t.difference_in_days_between(prev_ts) >= days,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_rolling_start_hours<F>(
|
fn compute_rolling_start_hours<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_height: Height,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
hours: usize,
|
hours: usize,
|
||||||
get_field: F,
|
get_field: F,
|
||||||
@@ -301,19 +299,15 @@ impl Vecs {
|
|||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> &mut EagerVec<PcoVec<Height, Height>>,
|
F: FnOnce(&mut Self) -> &mut EagerVec<PcoVec<Height, Height>>,
|
||||||
{
|
{
|
||||||
self.compute_rolling_start_inner(
|
self.compute_rolling_start_inner(indexes, starting_height, exit, get_field, |t, prev_ts| {
|
||||||
indexes,
|
t.difference_in_hours_between(prev_ts) >= hours
|
||||||
starting_indexes,
|
})
|
||||||
exit,
|
|
||||||
get_field,
|
|
||||||
|t, prev_ts| t.difference_in_hours_between(prev_ts) >= hours,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_rolling_start_inner<F, D>(
|
fn compute_rolling_start_inner<F, D>(
|
||||||
&mut self,
|
&mut self,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_height: Height,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
get_field: F,
|
get_field: F,
|
||||||
expired: D,
|
expired: D,
|
||||||
@@ -323,7 +317,7 @@ impl Vecs {
|
|||||||
D: Fn(Timestamp, Timestamp) -> bool,
|
D: Fn(Timestamp, Timestamp) -> bool,
|
||||||
{
|
{
|
||||||
let field = get_field(self);
|
let field = get_field(self);
|
||||||
let resume_from = field.len().min(starting_indexes.height.to_usize());
|
let resume_from = field.len().min(starting_height.to_usize());
|
||||||
let mut prev = if resume_from > 0 {
|
let mut prev = if resume_from > 0 {
|
||||||
field.collect_one_at(resume_from - 1).unwrap()
|
field.collect_one_at(resume_from - 1).unwrap()
|
||||||
} else {
|
} else {
|
||||||
@@ -333,7 +327,7 @@ impl Vecs {
|
|||||||
cursor.advance(prev.to_usize());
|
cursor.advance(prev.to_usize());
|
||||||
let mut prev_ts = cursor.next().unwrap();
|
let mut prev_ts = cursor.next().unwrap();
|
||||||
Ok(field.compute_transform(
|
Ok(field.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexes.timestamp.monotonic,
|
&indexes.timestamp.monotonic,
|
||||||
|(h, t, ..)| {
|
|(h, t, ..)| {
|
||||||
while expired(t, prev_ts) {
|
while expired(t, prev_ts) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{Indexes, StoredU64};
|
use brk_types::StoredU64;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -11,25 +11,23 @@ impl Vecs {
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
lookback: &blocks::LookbackVecs,
|
lookback: &blocks::LookbackVecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let window_starts = lookback.window_starts();
|
let window_starts = lookback.window_starts();
|
||||||
|
|
||||||
// vbytes = floor(weight / 4), stored at height level
|
|
||||||
self.vbytes
|
self.vbytes
|
||||||
.compute(starting_indexes.height, &window_starts, exit, |height| {
|
.compute(starting_height, &window_starts, exit, |height| {
|
||||||
Ok(height.compute_transform(
|
Ok(height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexer.vecs.blocks.weight,
|
&indexer.vecs.blocks.weight,
|
||||||
|(h, weight, ..)| (h, StoredU64::from(weight.to_vbytes_floor())),
|
|(h, weight, ..)| (h, StoredU64::from(weight.to_vbytes_floor())),
|
||||||
exit,
|
exit,
|
||||||
)?)
|
)?)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// size from indexer total_size
|
|
||||||
self.size.compute(
|
self.size.compute(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&window_starts,
|
&window_starts,
|
||||||
&indexer.vecs.blocks.total,
|
&indexer.vecs.blocks.total,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{BasisPoints16, Indexes};
|
use brk_types::BasisPoints16;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_height = indexer.safe_lengths().height;
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.fullness.bps.compute_transform(
|
self.fullness.bps.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexer.vecs.blocks.weight,
|
&indexer.vecs.blocks.weight,
|
||||||
|(h, weight, ..)| (h, BasisPoints16::from(weight.fullness())),
|
|(h, weight, ..)| (h, BasisPoints16::from(weight.fullness())),
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Bitcoin, Indexes, StoredF64};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{Bitcoin, StoredF64};
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -8,17 +9,18 @@ use crate::distribution;
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
distribution: &distribution::Vecs,
|
distribution: &distribution::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||||
let circulating_supply = &all_metrics.supply.total.sats.height;
|
let circulating_supply = &all_metrics.supply.total.sats.height;
|
||||||
|
|
||||||
self.coinblocks_created
|
self.coinblocks_created
|
||||||
.compute(starting_indexes.height, exit, |vec| {
|
.compute(starting_height, exit, |vec| {
|
||||||
vec.compute_transform(
|
vec.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
circulating_supply,
|
circulating_supply,
|
||||||
|(i, v, ..)| (i, StoredF64::from(Bitcoin::from(v))),
|
|(i, v, ..)| (i, StoredF64::from(Bitcoin::from(v))),
|
||||||
exit,
|
exit,
|
||||||
@@ -27,9 +29,9 @@ impl Vecs {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.coinblocks_stored
|
self.coinblocks_stored
|
||||||
.compute(starting_indexes.height, exit, |vec| {
|
.compute(starting_height, exit, |vec| {
|
||||||
vec.compute_subtract(
|
vec.compute_subtract(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.coinblocks_created.block,
|
&self.coinblocks_created.block,
|
||||||
&distribution.coinblocks_destroyed.block,
|
&distribution.coinblocks_destroyed.block,
|
||||||
exit,
|
exit,
|
||||||
@@ -38,14 +40,14 @@ impl Vecs {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.liveliness.height.compute_divide(
|
self.liveliness.height.compute_divide(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&distribution.coinblocks_destroyed.cumulative.height,
|
&distribution.coinblocks_destroyed.cumulative.height,
|
||||||
&self.coinblocks_created.cumulative.height,
|
&self.coinblocks_created.cumulative.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.ratio.height.compute_divide(
|
self.ratio.height.compute_divide(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.liveliness.height,
|
&self.liveliness.height,
|
||||||
&self.vaultedness.height,
|
&self.vaultedness.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{BasisPointsSigned32, Indexes};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::BasisPointsSigned32;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::super::activity;
|
use super::super::activity;
|
||||||
@@ -9,13 +10,15 @@ use crate::supply;
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
supply: &supply::Vecs,
|
supply: &supply::Vecs,
|
||||||
activity: &activity::Vecs,
|
activity: &activity::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
|
|
||||||
self.inflation_rate.bps.height.compute_transform2(
|
self.inflation_rate.bps.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&activity.ratio.height,
|
&activity.ratio.height,
|
||||||
&supply.inflation_rate.bps.height,
|
&supply.inflation_rate.bps.height,
|
||||||
|(h, a2vr, inflation, ..)| {
|
|(h, a2vr, inflation, ..)| {
|
||||||
@@ -28,14 +31,14 @@ impl Vecs {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.tx_velocity_native.height.compute_multiply(
|
self.tx_velocity_native.height.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&activity.ratio.height,
|
&activity.ratio.height,
|
||||||
&supply.velocity.native.height,
|
&supply.velocity.native.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.tx_velocity_fiat.height.compute_multiply(
|
self.tx_velocity_fiat.height.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&activity.ratio.height,
|
&activity.ratio.height,
|
||||||
&supply.velocity.fiat.height,
|
&supply.velocity.fiat.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Dollars, Indexes};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::Dollars;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::super::{activity, value};
|
use super::super::{activity, value};
|
||||||
@@ -10,40 +11,41 @@ impl Vecs {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
mining: &mining::Vecs,
|
mining: &mining::Vecs,
|
||||||
distribution: &distribution::Vecs,
|
distribution: &distribution::Vecs,
|
||||||
activity: &activity::Vecs,
|
activity: &activity::Vecs,
|
||||||
value: &value::Vecs,
|
value: &value::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_lengths = indexer.safe_lengths();
|
||||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||||
let realized_cap_cents = &all_metrics.realized.cap.cents.height;
|
let realized_cap_cents = &all_metrics.realized.cap.cents.height;
|
||||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||||
|
|
||||||
self.thermo.cents.height.compute_transform(
|
self.thermo.cents.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&mining.rewards.subsidy.cumulative.cents.height,
|
&mining.rewards.subsidy.cumulative.cents.height,
|
||||||
|(i, v, ..)| (i, v),
|
|(i, v, ..)| (i, v),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.investor.cents.height.compute_subtract(
|
self.investor.cents.height.compute_subtract(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
realized_cap_cents,
|
realized_cap_cents,
|
||||||
&self.thermo.cents.height,
|
&self.thermo.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.vaulted.cents.height.compute_multiply(
|
self.vaulted.cents.height.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
realized_cap_cents,
|
realized_cap_cents,
|
||||||
&activity.vaultedness.height,
|
&activity.vaultedness.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.active.cents.height.compute_multiply(
|
self.active.cents.height.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
realized_cap_cents,
|
realized_cap_cents,
|
||||||
&activity.liveliness.height,
|
&activity.liveliness.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -51,7 +53,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// cointime_cap = (cointime_value_destroyed_cumulative * circulating_supply) / coinblocks_stored_cumulative
|
// cointime_cap = (cointime_value_destroyed_cumulative * circulating_supply) / coinblocks_stored_cumulative
|
||||||
self.cointime.cents.height.compute_transform3(
|
self.cointime.cents.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&value.destroyed.cumulative.height,
|
&value.destroyed.cumulative.height,
|
||||||
circulating_supply,
|
circulating_supply,
|
||||||
&activity.coinblocks_stored.cumulative.height,
|
&activity.coinblocks_stored.cumulative.height,
|
||||||
@@ -67,7 +69,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// AVIV = active_cap / investor_cap
|
// AVIV = active_cap / investor_cap
|
||||||
self.aviv.compute_ratio(
|
self.aviv.compute_ratio(
|
||||||
starting_indexes,
|
&starting_lengths,
|
||||||
&self.active.cents.height,
|
&self.active.cents.height,
|
||||||
&self.investor.cents.height,
|
&self.investor.cents.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Indexes;
|
use brk_indexer::Indexer;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -9,7 +9,7 @@ impl Vecs {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
mining: &mining::Vecs,
|
mining: &mining::Vecs,
|
||||||
@@ -20,29 +20,23 @@ impl Vecs {
|
|||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
|
|
||||||
// Activity computes first (liveliness, vaultedness, etc.)
|
// Activity computes first (liveliness, vaultedness, etc.)
|
||||||
self.activity
|
self.activity.compute(indexer, distribution, exit)?;
|
||||||
.compute(starting_indexes, distribution, exit)?;
|
|
||||||
|
|
||||||
// Phase 2: supply, adjusted, value are independent (all depend only on activity)
|
// Phase 2: supply, adjusted, value are independent (all depend only on activity)
|
||||||
let (r1, r2) = rayon::join(
|
let (r1, r2) = rayon::join(
|
||||||
|| {
|
|| {
|
||||||
self.supply
|
self.supply
|
||||||
.compute(starting_indexes, prices, distribution, &self.activity, exit)
|
.compute(indexer, prices, distribution, &self.activity, exit)
|
||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
rayon::join(
|
rayon::join(
|
||||||
|| {
|
|| {
|
||||||
self.adjusted
|
self.adjusted
|
||||||
.compute(starting_indexes, supply_vecs, &self.activity, exit)
|
.compute(indexer, supply_vecs, &self.activity, exit)
|
||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
self.value.compute(
|
self.value
|
||||||
starting_indexes,
|
.compute(indexer, prices, distribution, &self.activity, exit)
|
||||||
prices,
|
|
||||||
distribution,
|
|
||||||
&self.activity,
|
|
||||||
exit,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -53,7 +47,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// Cap depends on activity + value
|
// Cap depends on activity + value
|
||||||
self.cap.compute(
|
self.cap.compute(
|
||||||
starting_indexes,
|
indexer,
|
||||||
mining,
|
mining,
|
||||||
distribution,
|
distribution,
|
||||||
&self.activity,
|
&self.activity,
|
||||||
@@ -65,7 +59,7 @@ impl Vecs {
|
|||||||
let (r3, r4) = rayon::join(
|
let (r3, r4) = rayon::join(
|
||||||
|| {
|
|| {
|
||||||
self.prices.compute(
|
self.prices.compute(
|
||||||
starting_indexes,
|
indexer,
|
||||||
prices,
|
prices,
|
||||||
distribution,
|
distribution,
|
||||||
&self.activity,
|
&self.activity,
|
||||||
@@ -76,7 +70,7 @@ impl Vecs {
|
|||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
self.reserve_risk
|
self.reserve_risk
|
||||||
.compute(starting_indexes, blocks, prices, &self.value, exit)
|
.compute(indexer, blocks, prices, &self.value, exit)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
r3?;
|
r3?;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Cents, Indexes};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::Cents;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::super::{activity, cap, supply};
|
use super::super::{activity, cap, supply};
|
||||||
@@ -10,7 +11,7 @@ impl Vecs {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
distribution: &distribution::Vecs,
|
distribution: &distribution::Vecs,
|
||||||
activity: &activity::Vecs,
|
activity: &activity::Vecs,
|
||||||
@@ -18,14 +19,15 @@ impl Vecs {
|
|||||||
cap: &cap::Vecs,
|
cap: &cap::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_lengths = indexer.safe_lengths();
|
||||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||||
let realized_price = &all_metrics.realized.price.cents.height;
|
let realized_price = &all_metrics.realized.price.cents.height;
|
||||||
|
|
||||||
self.vaulted
|
self.vaulted
|
||||||
.compute_all(prices, starting_indexes, exit, |v| {
|
.compute_all(prices, &starting_lengths, exit, |v| {
|
||||||
Ok(v.compute_transform2(
|
Ok(v.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
realized_price,
|
realized_price,
|
||||||
&activity.vaultedness.height,
|
&activity.vaultedness.height,
|
||||||
|(i, price, vaultedness, ..)| {
|
|(i, price, vaultedness, ..)| {
|
||||||
@@ -36,9 +38,9 @@ impl Vecs {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.active
|
self.active
|
||||||
.compute_all(prices, starting_indexes, exit, |v| {
|
.compute_all(prices, &starting_lengths, exit, |v| {
|
||||||
Ok(v.compute_transform2(
|
Ok(v.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
realized_price,
|
realized_price,
|
||||||
&activity.liveliness.height,
|
&activity.liveliness.height,
|
||||||
|(i, price, liveliness, ..)| {
|
|(i, price, liveliness, ..)| {
|
||||||
@@ -49,9 +51,9 @@ impl Vecs {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.true_market_mean
|
self.true_market_mean
|
||||||
.compute_all(prices, starting_indexes, exit, |v| {
|
.compute_all(prices, &starting_lengths, exit, |v| {
|
||||||
Ok(v.compute_transform2(
|
Ok(v.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&cap.investor.cents.height,
|
&cap.investor.cents.height,
|
||||||
&supply.active.btc.height,
|
&supply.active.btc.height,
|
||||||
|(i, cap_cents, supply_btc, ..)| {
|
|(i, cap_cents, supply_btc, ..)| {
|
||||||
@@ -62,9 +64,9 @@ impl Vecs {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.cointime
|
self.cointime
|
||||||
.compute_all(prices, starting_indexes, exit, |v| {
|
.compute_all(prices, &starting_lengths, exit, |v| {
|
||||||
Ok(v.compute_transform2(
|
Ok(v.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&cap.cointime.cents.height,
|
&cap.cointime.cents.height,
|
||||||
circulating_supply,
|
circulating_supply,
|
||||||
|(i, cap_cents, supply_btc, ..)| {
|
|(i, cap_cents, supply_btc, ..)| {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Indexes, StoredF64};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::StoredF64;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::{super::value, Vecs};
|
use super::{super::value, Vecs};
|
||||||
@@ -8,21 +9,23 @@ use crate::{blocks, internal::algo::ComputeRollingMedianFromStarts, prices};
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
value: &value::Vecs,
|
value: &value::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
|
|
||||||
self.vocdd_median_1y.compute_rolling_median_from_starts(
|
self.vocdd_median_1y.compute_rolling_median_from_starts(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&blocks.lookback._1y,
|
&blocks.lookback._1y,
|
||||||
&value.vocdd.block,
|
&value.vocdd.block,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.hodl_bank.compute_cumulative_transformed_binary(
|
self.hodl_bank.compute_cumulative_transformed_binary(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&self.vocdd_median_1y,
|
&self.vocdd_median_1y,
|
||||||
|price, median| StoredF64::from(f64::from(price) - f64::from(median)),
|
|price, median| StoredF64::from(f64::from(price) - f64::from(median)),
|
||||||
@@ -30,7 +33,7 @@ impl Vecs {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.value.height.compute_divide(
|
self.value.height.compute_divide(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&self.hodl_bank,
|
&self.hodl_bank,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Indexes;
|
use brk_indexer::Indexer;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::super::activity;
|
use super::super::activity;
|
||||||
@@ -9,12 +9,13 @@ use crate::{distribution, prices};
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
distribution: &distribution::Vecs,
|
distribution: &distribution::Vecs,
|
||||||
activity: &activity::Vecs,
|
activity: &activity::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let circulating_supply = &distribution
|
let circulating_supply = &distribution
|
||||||
.utxo_cohorts
|
.utxo_cohorts
|
||||||
.all
|
.all
|
||||||
@@ -25,22 +26,21 @@ impl Vecs {
|
|||||||
.height;
|
.height;
|
||||||
|
|
||||||
self.vaulted.sats.height.compute_multiply(
|
self.vaulted.sats.height.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
circulating_supply,
|
circulating_supply,
|
||||||
&activity.vaultedness.height,
|
&activity.vaultedness.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.active.sats.height.compute_multiply(
|
self.active.sats.height.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
circulating_supply,
|
circulating_supply,
|
||||||
&activity.liveliness.height,
|
&activity.liveliness.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.vaulted
|
self.vaulted.compute(prices, starting_height, exit)?;
|
||||||
.compute(prices, starting_indexes.height, exit)?;
|
self.active.compute(prices, starting_height, exit)?;
|
||||||
self.active.compute(prices, starting_indexes.height, exit)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Bitcoin, Dollars, Indexes, StoredF64};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{Bitcoin, Dollars, StoredF64};
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::super::activity;
|
use super::super::activity;
|
||||||
@@ -9,31 +10,31 @@ use crate::{distribution, prices};
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
distribution: &distribution::Vecs,
|
distribution: &distribution::Vecs,
|
||||||
activity: &activity::Vecs,
|
activity: &activity::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||||
let coinblocks_destroyed = &distribution.coinblocks_destroyed;
|
let coinblocks_destroyed = &distribution.coinblocks_destroyed;
|
||||||
let coindays_destroyed = &all_metrics.activity.coindays_destroyed;
|
let coindays_destroyed = &all_metrics.activity.coindays_destroyed;
|
||||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||||
|
|
||||||
self.destroyed
|
self.destroyed.compute(starting_height, exit, |vec| {
|
||||||
.compute(starting_indexes.height, exit, |vec| {
|
|
||||||
vec.compute_multiply(
|
|
||||||
starting_indexes.height,
|
|
||||||
&prices.spot.usd.height,
|
|
||||||
&coinblocks_destroyed.block,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
Ok(())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
self.created.compute(starting_indexes.height, exit, |vec| {
|
|
||||||
vec.compute_multiply(
|
vec.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
|
&prices.spot.usd.height,
|
||||||
|
&coinblocks_destroyed.block,
|
||||||
|
exit,
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
|
||||||
|
self.created.compute(starting_height, exit, |vec| {
|
||||||
|
vec.compute_multiply(
|
||||||
|
starting_height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&activity.coinblocks_created.block,
|
&activity.coinblocks_created.block,
|
||||||
exit,
|
exit,
|
||||||
@@ -41,9 +42,9 @@ impl Vecs {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.stored.compute(starting_indexes.height, exit, |vec| {
|
self.stored.compute(starting_height, exit, |vec| {
|
||||||
vec.compute_multiply(
|
vec.compute_multiply(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&activity.coinblocks_stored.block,
|
&activity.coinblocks_stored.block,
|
||||||
exit,
|
exit,
|
||||||
@@ -54,9 +55,9 @@ impl Vecs {
|
|||||||
// VOCDD: Value of Coin Days Destroyed = price × (CDD / circulating_supply)
|
// VOCDD: Value of Coin Days Destroyed = price × (CDD / circulating_supply)
|
||||||
// Supply-adjusted to account for growing supply over time
|
// Supply-adjusted to account for growing supply over time
|
||||||
// This is a key input for Reserve Risk / HODL Bank calculation
|
// This is a key input for Reserve Risk / HODL Bank calculation
|
||||||
self.vocdd.compute(starting_indexes.height, exit, |vec| {
|
self.vocdd.compute(starting_height, exit, |vec| {
|
||||||
vec.compute_transform3(
|
vec.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&coindays_destroyed.block,
|
&coindays_destroyed.block,
|
||||||
circulating_supply,
|
circulating_supply,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Indexes, Version};
|
use brk_types::Version;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use vecdb::{AnyStoredVec, Database, Exit, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Database, Exit, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -70,9 +71,9 @@ impl AddrCountFundedTotalVecs {
|
|||||||
self.total.push_counts(total);
|
self.total.push_counts(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
|
pub(crate) fn compute_rest(&mut self, starting_lengths: &Lengths, exit: &Exit) -> Result<()> {
|
||||||
self.funded.compute_rest(starting_indexes, exit)?;
|
self.funded.compute_rest(starting_lengths, exit)?;
|
||||||
self.total.compute_rest(starting_indexes, exit)?;
|
self.total.compute_rest(starting_lengths, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,9 @@
|
|||||||
|
|
||||||
use brk_cohort::ByAddrType;
|
use brk_cohort::ByAddrType;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Sats, Version};
|
use brk_types::{Height, Sats, Version};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use vecdb::{AnyStoredVec, Database, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Database, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -102,17 +103,17 @@ impl ExposedAddrVecs {
|
|||||||
|
|
||||||
pub(crate) fn compute_rest(
|
pub(crate) fn compute_rest(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
type_supply_sats: &ByAddrType<&impl ReadableVec<Height, Sats>>,
|
type_supply_sats: &ByAddrType<&impl ReadableVec<Height, Sats>>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.count.compute_rest(starting_indexes, exit)?;
|
self.count.compute_rest(starting_lengths, exit)?;
|
||||||
self.supply
|
self.supply
|
||||||
.compute_rest(starting_indexes.height, prices, exit)?;
|
.compute_rest(starting_lengths.height, prices, exit)?;
|
||||||
self.supply_share.compute_rest(
|
self.supply_share.compute_rest(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.supply,
|
&self.supply,
|
||||||
all_supply_sats,
|
all_supply_sats,
|
||||||
type_supply_sats,
|
type_supply_sats,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_cohort::ByAddrType;
|
use brk_cohort::ByAddrType;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{BasisPoints16, Indexes, OutputType, StoredF32, StoredU32, StoredU64, Version};
|
use brk_types::{BasisPoints16, OutputType, StoredF32, StoredU32, StoredU64, Version};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
@@ -205,37 +206,37 @@ impl AddrEventsVecs {
|
|||||||
|
|
||||||
pub(crate) fn compute_rest(
|
pub(crate) fn compute_rest(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
outputs_by_type: &outputs::ByTypeVecs,
|
outputs_by_type: &outputs::ByTypeVecs,
|
||||||
inputs_by_type: &inputs::ByTypeVecs,
|
inputs_by_type: &inputs::ByTypeVecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.output_to_reused_addr_count
|
self.output_to_reused_addr_count
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.input_from_reused_addr_count
|
self.input_from_reused_addr_count
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.active_reused_addr_count
|
self.active_reused_addr_count
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.active_reused_addr_share
|
self.active_reused_addr_share
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
|
|
||||||
self.output_to_reused_addr_share.all.compute_count_ratio(
|
self.output_to_reused_addr_share.all.compute_count_ratio(
|
||||||
&self.output_to_reused_addr_count.all,
|
&self.output_to_reused_addr_count.all,
|
||||||
&outputs_by_type.output_count.all,
|
&outputs_by_type.output_count.all,
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.spendable_output_to_reused_addr_share
|
self.spendable_output_to_reused_addr_share
|
||||||
.compute_count_ratio(
|
.compute_count_ratio(
|
||||||
&self.output_to_reused_addr_count.all,
|
&self.output_to_reused_addr_count.all,
|
||||||
&outputs_by_type.spendable_output_count,
|
&outputs_by_type.spendable_output_count,
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.input_from_reused_addr_share.all.compute_count_ratio(
|
self.input_from_reused_addr_share.all.compute_count_ratio(
|
||||||
&self.input_from_reused_addr_count.all,
|
&self.input_from_reused_addr_count.all,
|
||||||
&inputs_by_type.input_count.all,
|
&inputs_by_type.input_count.all,
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
for otype in OutputType::ADDR_TYPES {
|
for otype in OutputType::ADDR_TYPES {
|
||||||
@@ -247,7 +248,7 @@ impl AddrEventsVecs {
|
|||||||
.by_addr_type
|
.by_addr_type
|
||||||
.get_unwrap(otype),
|
.get_unwrap(otype),
|
||||||
outputs_by_type.output_count.by_type.get(otype),
|
outputs_by_type.output_count.by_type.get(otype),
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.input_from_reused_addr_share
|
self.input_from_reused_addr_share
|
||||||
@@ -258,7 +259,7 @@ impl AddrEventsVecs {
|
|||||||
.by_addr_type
|
.by_addr_type
|
||||||
.get_unwrap(otype),
|
.get_unwrap(otype),
|
||||||
inputs_by_type.input_count.by_type.get(otype),
|
inputs_by_type.input_count.by_type.get(otype),
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,9 @@ pub use events::{AddrEventsVecs, AddrTypeToAddrEventCount};
|
|||||||
|
|
||||||
use brk_cohort::ByAddrType;
|
use brk_cohort::ByAddrType;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Sats, Version};
|
use brk_types::{Height, Sats, Version};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use vecdb::{AnyStoredVec, Database, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Database, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -108,7 +109,7 @@ impl ReusedAddrVecs {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute_rest(
|
pub(crate) fn compute_rest(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
outputs_by_type: &outputs::ByTypeVecs,
|
outputs_by_type: &outputs::ByTypeVecs,
|
||||||
inputs_by_type: &inputs::ByTypeVecs,
|
inputs_by_type: &inputs::ByTypeVecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
@@ -116,13 +117,13 @@ impl ReusedAddrVecs {
|
|||||||
type_supply_sats: &ByAddrType<&impl ReadableVec<Height, Sats>>,
|
type_supply_sats: &ByAddrType<&impl ReadableVec<Height, Sats>>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.count.compute_rest(starting_indexes, exit)?;
|
self.count.compute_rest(starting_lengths, exit)?;
|
||||||
self.events
|
self.events
|
||||||
.compute_rest(starting_indexes, outputs_by_type, inputs_by_type, exit)?;
|
.compute_rest(starting_lengths, outputs_by_type, inputs_by_type, exit)?;
|
||||||
self.supply
|
self.supply
|
||||||
.compute_rest(starting_indexes.height, prices, exit)?;
|
.compute_rest(starting_lengths.height, prices, exit)?;
|
||||||
self.supply_share.compute_rest(
|
self.supply_share.compute_rest(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.supply,
|
&self.supply,
|
||||||
all_supply_sats,
|
all_supply_sats,
|
||||||
type_supply_sats,
|
type_supply_sats,
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ use std::path::Path;
|
|||||||
|
|
||||||
use brk_cohort::{AddrGroups, AmountRange, Filter, Filtered, OverAmount, UnderAmount};
|
use brk_cohort::{AddrGroups, AmountRange, Filter, Filtered, OverAmount, UnderAmount};
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Sats, StoredU64, Version};
|
use brk_types::{Height, Sats, StoredU64, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use vecdb::{AnyStoredVec, Database, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Database, Exit, ReadableVec, Rw, StorageMode};
|
||||||
@@ -83,11 +84,11 @@ impl AddrCohorts {
|
|||||||
/// Compute overlapping cohorts from component amount_range cohorts.
|
/// Compute overlapping cohorts from component amount_range cohorts.
|
||||||
pub(crate) fn compute_overlapping_vecs(
|
pub(crate) fn compute_overlapping_vecs(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.for_each_aggregate(|vecs, sources| {
|
self.for_each_aggregate(|vecs, sources| {
|
||||||
vecs.compute_from_stateful(starting_indexes, &sources, exit)
|
vecs.compute_from_stateful(starting_lengths, &sources, exit)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,11 +96,11 @@ impl AddrCohorts {
|
|||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.par_iter_mut()
|
self.par_iter_mut()
|
||||||
.try_for_each(|v| v.compute_rest_part1(prices, starting_indexes, exit))?;
|
.try_for_each(|v| v.compute_rest_part1(prices, starting_lengths, exit))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -108,7 +109,7 @@ impl AddrCohorts {
|
|||||||
pub(crate) fn compute_rest_part2(
|
pub(crate) fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
@@ -116,7 +117,7 @@ impl AddrCohorts {
|
|||||||
self.0.par_iter_mut().try_for_each(|v| {
|
self.0.par_iter_mut().try_for_each(|v| {
|
||||||
v.compute_rest_part2(
|
v.compute_rest_part2(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
all_supply_sats,
|
all_supply_sats,
|
||||||
all_utxo_count,
|
all_utxo_count,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ use std::path::Path;
|
|||||||
|
|
||||||
use brk_cohort::{CohortContext, Filter, Filtered};
|
use brk_cohort::{CohortContext, Filter, Filtered};
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{BasisPointsSigned32, Cents, Height, Indexes, Sats, StoredI64, StoredU64, Version};
|
use brk_types::{BasisPointsSigned32, Cents, Height, Sats, StoredI64, StoredU64, Version};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
@@ -174,11 +175,11 @@ impl DynCohortVecs for AddrCohortVecs {
|
|||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.metrics
|
self.metrics
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)
|
.compute_rest_part1(prices, starting_lengths, exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
||||||
@@ -205,12 +206,12 @@ impl DynCohortVecs for AddrCohortVecs {
|
|||||||
impl CohortVecs for AddrCohortVecs {
|
impl CohortVecs for AddrCohortVecs {
|
||||||
fn compute_from_stateful(
|
fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.addr_count.height.compute_sum_of_others(
|
self.addr_count.height.compute_sum_of_others(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
others
|
others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| &v.addr_count.height)
|
.map(|v| &v.addr_count.height)
|
||||||
@@ -219,7 +220,7 @@ impl CohortVecs for AddrCohortVecs {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.metrics.compute_from_sources(
|
self.metrics.compute_from_sources(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| &v.metrics).collect::<Vec<_>>(),
|
&others.iter().map(|v| &v.metrics).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -229,14 +230,14 @@ impl CohortVecs for AddrCohortVecs {
|
|||||||
fn compute_rest_part2(
|
fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.metrics.compute_rest_part2(
|
self.metrics.compute_rest_part2(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
all_supply_sats,
|
all_supply_sats,
|
||||||
all_utxo_count,
|
all_utxo_count,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Cents, Height, Indexes, Sats, StoredU64, Version};
|
use brk_indexer::Lengths;
|
||||||
|
use brk_types::{Cents, Height, Sats, StoredU64, Version};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use crate::prices;
|
use crate::prices;
|
||||||
@@ -31,7 +32,7 @@ pub trait DynCohortVecs: Send + Sync {
|
|||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ pub trait CohortVecs: DynCohortVecs {
|
|||||||
/// Compute aggregate cohort from component cohorts.
|
/// Compute aggregate cohort from component cohorts.
|
||||||
fn compute_from_stateful(
|
fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
@@ -61,7 +62,7 @@ pub trait CohortVecs: DynCohortVecs {
|
|||||||
fn compute_rest_part2(
|
fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ use brk_cohort::{
|
|||||||
SpendableType, Term, UnderAge, UnderAmount,
|
SpendableType, Term, UnderAge, UnderAmount,
|
||||||
};
|
};
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, CentsSquaredSats, Dollars, Height, Indexes, Sats, Version};
|
use brk_types::{Cents, CentsSquaredSats, Dollars, Height, Sats, Version};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use vecdb::{
|
use vecdb::{
|
||||||
AnyStoredVec, AnyVec, Database, Exit, ReadOnlyClone, ReadableVec, Rw, StorageMode, WritableVec,
|
AnyStoredVec, AnyVec, Database, Exit, ReadOnlyClone, ReadableVec, Rw, StorageMode, WritableVec,
|
||||||
@@ -414,7 +415,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
|
|
||||||
pub(crate) fn compute_overlapping_vecs(
|
pub(crate) fn compute_overlapping_vecs(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let Self {
|
let Self {
|
||||||
@@ -432,7 +433,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
|
|
||||||
let ar = &*age_range;
|
let ar = &*age_range;
|
||||||
let amr = &*amount_range;
|
let amr = &*amount_range;
|
||||||
let si = starting_indexes;
|
let si = starting_lengths;
|
||||||
|
|
||||||
let tasks: Vec<Box<dyn FnOnce() -> Result<()> + Send + '_>> = vec![
|
let tasks: Vec<Box<dyn FnOnce() -> Result<()> + Send + '_>> = vec![
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
@@ -483,7 +484,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// 1. Compute all metrics except net_sentiment (all cohorts via DynCohortVecs)
|
// 1. Compute all metrics except net_sentiment (all cohorts via DynCohortVecs)
|
||||||
@@ -527,16 +528,16 @@ impl UTXOCohorts<Rw> {
|
|||||||
);
|
);
|
||||||
all.extend(self.type_.iter_mut().map(|x| x as &mut dyn DynCohortVecs));
|
all.extend(self.type_.iter_mut().map(|x| x as &mut dyn DynCohortVecs));
|
||||||
all.into_par_iter()
|
all.into_par_iter()
|
||||||
.try_for_each(|v| v.compute_rest_part1(prices, starting_indexes, exit))?;
|
.try_for_each(|v| v.compute_rest_part1(prices, starting_lengths, exit))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute matured cumulative + cents from sats × price
|
// Compute matured cumulative + cents from sats × price
|
||||||
self.matured
|
self.matured
|
||||||
.par_iter_mut()
|
.par_iter_mut()
|
||||||
.try_for_each(|v| v.compute_rest(starting_indexes.height, prices, exit))?;
|
.try_for_each(|v| v.compute_rest(starting_lengths.height, prices, exit))?;
|
||||||
|
|
||||||
// Compute profitability supply cents and realized price
|
// Compute profitability supply cents and realized price
|
||||||
self.profitability.compute(prices, starting_indexes, exit)?;
|
self.profitability.compute(prices, starting_lengths, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -546,7 +547,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@@ -574,7 +575,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
self.all.metrics.compute_rest_part2(
|
self.all.metrics.compute_rest_part2(
|
||||||
blocks,
|
blocks,
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
&under_1h_value_created,
|
&under_1h_value_created,
|
||||||
&under_1h_value_destroyed,
|
&under_1h_value_destroyed,
|
||||||
@@ -619,7 +620,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
sth.metrics.compute_rest_part2(
|
sth.metrics.compute_rest_part2(
|
||||||
blocks,
|
blocks,
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
vc,
|
vc,
|
||||||
vd,
|
vd,
|
||||||
@@ -632,7 +633,7 @@ impl UTXOCohorts<Rw> {
|
|||||||
lth.metrics.compute_rest_part2(
|
lth.metrics.compute_rest_part2(
|
||||||
blocks,
|
blocks,
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
ss,
|
ss,
|
||||||
au,
|
au,
|
||||||
@@ -642,55 +643,55 @@ impl UTXOCohorts<Rw> {
|
|||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
age_range.par_iter_mut().try_for_each(|v| {
|
age_range.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
under_age.par_iter_mut().try_for_each(|v| {
|
under_age.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
over_age.par_iter_mut().try_for_each(|v| {
|
over_age.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
over_amount.par_iter_mut().try_for_each(|v| {
|
over_amount.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
epoch.par_iter_mut().try_for_each(|v| {
|
epoch.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
class.par_iter_mut().try_for_each(|v| {
|
class.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
amount_range.par_iter_mut().try_for_each(|v| {
|
amount_range.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
under_amount.par_iter_mut().try_for_each(|v| {
|
under_amount.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
Box::new(|| {
|
Box::new(|| {
|
||||||
type_.par_iter_mut().try_for_each(|v| {
|
type_.par_iter_mut().try_for_each(|v| {
|
||||||
v.metrics
|
v.metrics
|
||||||
.compute_rest_part2(prices, starting_indexes, ss, au, exit)
|
.compute_rest_part2(prices, starting_lengths, ss, au, exit)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_cohort::{Filter, Filtered};
|
use brk_cohort::{Filter, Filtered};
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Cents, Height, Indexes, Version};
|
use brk_indexer::Lengths;
|
||||||
|
use brk_types::{Cents, Height, Version};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -56,11 +57,11 @@ impl DynCohortVecs for UTXOCohortVecs<CoreCohortMetrics> {
|
|||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.metrics
|
self.metrics
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)
|
.compute_rest_part1(prices, starting_lengths, exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_cohort::{Filter, Filtered};
|
use brk_cohort::{Filter, Filtered};
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Cents, Height, Indexes, Version};
|
use brk_indexer::Lengths;
|
||||||
|
use brk_types::{Cents, Height, Version};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -49,11 +50,11 @@ impl DynCohortVecs for UTXOCohortVecs<MinimalCohortMetrics> {
|
|||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.metrics
|
self.metrics
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)
|
.compute_rest_part1(prices, starting_lengths, exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
||||||
|
|||||||
@@ -44,8 +44,9 @@ mod r#type;
|
|||||||
|
|
||||||
use brk_cohort::{Filter, Filtered};
|
use brk_cohort::{Filter, Filtered};
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, Height, Indexes, Version};
|
use brk_types::{Cents, Height, Version};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -186,11 +187,11 @@ impl<M: CohortMetricsBase + Traversable> DynCohortVecs for UTXOCohortVecs<M> {
|
|||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.metrics
|
self.metrics
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)?;
|
.compute_rest_part1(prices, starting_lengths, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_cohort::{Filter, Filtered};
|
use brk_cohort::{Filter, Filtered};
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Cents, Height, Indexes, Version};
|
use brk_indexer::Lengths;
|
||||||
|
use brk_types::{Cents, Height, Version};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -55,11 +56,11 @@ impl DynCohortVecs for UTXOCohortVecs<TypeCohortMetrics> {
|
|||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.metrics
|
self.metrics
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)
|
.compute_rest_part1(prices, starting_lengths, exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
fn write_state(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Bitcoin, Indexes, StoredF64, Version};
|
use brk_types::{Bitcoin, StoredF64, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
@@ -80,17 +81,17 @@ impl ActivityCore {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let minimal_refs: Vec<&ActivityMinimal> = others.iter().map(|o| &o.minimal).collect();
|
let minimal_refs: Vec<&ActivityMinimal> = others.iter().map(|o| &o.minimal).collect();
|
||||||
self.minimal
|
self.minimal
|
||||||
.compute_from_stateful(starting_indexes, &minimal_refs, exit)?;
|
.compute_from_stateful(starting_lengths, &minimal_refs, exit)?;
|
||||||
|
|
||||||
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.block);
|
sum_others!(self, starting_lengths, others, exit; coindays_destroyed.block);
|
||||||
sum_others!(self, starting_indexes, others, exit; transfer_volume_in_profit.block.sats);
|
sum_others!(self, starting_lengths, others, exit; transfer_volume_in_profit.block.sats);
|
||||||
sum_others!(self, starting_indexes, others, exit; transfer_volume_in_loss.block.sats);
|
sum_others!(self, starting_lengths, others, exit; transfer_volume_in_loss.block.sats);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -98,17 +99,17 @@ impl ActivityCore {
|
|||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.minimal
|
self.minimal
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)?;
|
.compute_rest_part1(prices, starting_lengths, exit)?;
|
||||||
self.coindays_destroyed
|
self.coindays_destroyed
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.transfer_volume_in_profit
|
self.transfer_volume_in_profit
|
||||||
.compute_rest(starting_indexes.height, prices, exit)?;
|
.compute_rest(starting_lengths.height, prices, exit)?;
|
||||||
self.transfer_volume_in_loss
|
self.transfer_volume_in_loss
|
||||||
.compute_rest(starting_indexes.height, prices, exit)?;
|
.compute_rest(starting_lengths.height, prices, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Indexes, StoredF32, StoredF64, Version};
|
use brk_types::{StoredF32, StoredF64, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, Exit, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -78,22 +79,22 @@ impl ActivityFull {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&ActivityCore],
|
others: &[&ActivityCore],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.inner
|
self.inner
|
||||||
.compute_from_stateful(starting_indexes, others, exit)
|
.compute_from_stateful(starting_lengths, others, exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.inner
|
self.inner
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)?;
|
.compute_rest_part1(prices, starting_lengths, exit)?;
|
||||||
|
|
||||||
for ((dormancy, cdd_sum), tv_sum) in self
|
for ((dormancy, cdd_sum), tv_sum) in self
|
||||||
.dormancy
|
.dormancy
|
||||||
@@ -103,7 +104,7 @@ impl ActivityFull {
|
|||||||
.zip(self.inner.minimal.transfer_volume.sum.0.as_array())
|
.zip(self.inner.minimal.transfer_volume.sum.0.as_array())
|
||||||
{
|
{
|
||||||
dormancy.height.compute_transform2(
|
dormancy.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&cdd_sum.height,
|
&cdd_sum.height,
|
||||||
&tv_sum.btc.height,
|
&tv_sum.btc.height,
|
||||||
|(i, rolling_cdd, rolling_btc, ..)| {
|
|(i, rolling_cdd, rolling_btc, ..)| {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Indexes, Version};
|
use brk_types::Version;
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -44,12 +45,12 @@ impl ActivityMinimal {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.transfer_volume.block.sats.compute_sum_of_others(
|
self.transfer_volume.block.sats.compute_sum_of_others(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| &v.transfer_volume.block.sats)
|
.map(|v| &v.transfer_volume.block.sats)
|
||||||
@@ -63,11 +64,11 @@ impl ActivityMinimal {
|
|||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.transfer_volume
|
self.transfer_volume
|
||||||
.compute_rest(starting_indexes.height, prices, exit)?;
|
.compute_rest(starting_lengths.height, prices, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ pub use full::ActivityFull;
|
|||||||
pub use minimal::ActivityMinimal;
|
pub use minimal::ActivityMinimal;
|
||||||
|
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Indexes, Version};
|
use brk_indexer::Lengths;
|
||||||
|
use brk_types::Version;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -23,14 +24,14 @@ pub trait ActivityLike: Send + Sync {
|
|||||||
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()>;
|
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()>;
|
||||||
fn compute_from_stateful(
|
fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&ActivityCore],
|
others: &[&ActivityCore],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
@@ -53,19 +54,19 @@ impl ActivityLike for ActivityCore {
|
|||||||
}
|
}
|
||||||
fn compute_from_stateful(
|
fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&ActivityCore],
|
others: &[&ActivityCore],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_from_stateful(starting_indexes, others, exit)
|
self.compute_from_stateful(starting_lengths, others, exit)
|
||||||
}
|
}
|
||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_rest_part1(prices, starting_indexes, exit)
|
self.compute_rest_part1(prices, starting_lengths, exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,18 +88,18 @@ impl ActivityLike for ActivityFull {
|
|||||||
}
|
}
|
||||||
fn compute_from_stateful(
|
fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&ActivityCore],
|
others: &[&ActivityCore],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_from_stateful(starting_indexes, others, exit)
|
self.compute_from_stateful(starting_lengths, others, exit)
|
||||||
}
|
}
|
||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_rest_part1(prices, starting_indexes, exit)
|
self.compute_rest_part1(prices, starting_lengths, exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, Dollars, Height, Indexes, Version};
|
use brk_types::{Cents, Dollars, Height, Version};
|
||||||
use vecdb::{AnyStoredVec, Exit, ReadOnlyClone, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, ReadOnlyClone, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -100,7 +101,7 @@ impl AllCohortMetrics {
|
|||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
||||||
under_1h_value_created: &impl ReadableVec<Height, Cents>,
|
under_1h_value_created: &impl ReadableVec<Height, Cents>,
|
||||||
under_1h_value_destroyed: &impl ReadableVec<Height, Cents>,
|
under_1h_value_destroyed: &impl ReadableVec<Height, Cents>,
|
||||||
@@ -109,7 +110,7 @@ impl AllCohortMetrics {
|
|||||||
self.realized.compute_rest_part2(
|
self.realized.compute_rest_part2(
|
||||||
blocks,
|
blocks,
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.supply.total.btc.height,
|
&self.supply.total.btc.height,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
&self.activity.transfer_volume,
|
&self.activity.transfer_volume,
|
||||||
@@ -117,14 +118,14 @@ impl AllCohortMetrics {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.unrealized.compute(
|
self.unrealized.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.realized.price.cents.height,
|
&self.realized.price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.asopr.compute_rest_part2(
|
self.asopr.compute_rest_part2(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.activity.transfer_volume.block.cents,
|
&self.activity.transfer_volume.block.cents,
|
||||||
&self.realized.core.sopr.value_destroyed.block,
|
&self.realized.core.sopr.value_destroyed.block,
|
||||||
under_1h_value_created,
|
under_1h_value_created,
|
||||||
@@ -134,10 +135,10 @@ impl AllCohortMetrics {
|
|||||||
|
|
||||||
let all_utxo_count = self.outputs.unspent_count.height.read_only_clone();
|
let all_utxo_count = self.outputs.unspent_count.height.read_only_clone();
|
||||||
self.outputs
|
self.outputs
|
||||||
.compute_part2(starting_indexes.height, &all_utxo_count, exit)?;
|
.compute_part2(starting_lengths.height, &all_utxo_count, exit)?;
|
||||||
|
|
||||||
self.cost_basis.compute_prices(
|
self.cost_basis.compute_prices(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.unrealized.invested_capital.in_profit.cents.height,
|
&self.unrealized.invested_capital.in_profit.cents.height,
|
||||||
&self.unrealized.invested_capital.in_loss.cents.height,
|
&self.unrealized.invested_capital.in_loss.cents.height,
|
||||||
@@ -149,14 +150,14 @@ impl AllCohortMetrics {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.unrealized
|
self.unrealized
|
||||||
.compute_sentiment(starting_indexes, &prices.spot.cents.height, exit)?;
|
.compute_sentiment(starting_lengths, &prices.spot.cents.height, exit)?;
|
||||||
|
|
||||||
let own_supply_sats = self.supply.total.sats.height.read_only_clone();
|
let own_supply_sats = self.supply.total.sats.height.read_only_clone();
|
||||||
self.supply
|
self.supply
|
||||||
.compute_dominance(starting_indexes.height, &own_supply_sats, exit)?;
|
.compute_dominance(starting_lengths.height, &own_supply_sats, exit)?;
|
||||||
|
|
||||||
self.relative.compute(
|
self.relative.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.supply,
|
&self.supply,
|
||||||
&self.unrealized,
|
&self.unrealized,
|
||||||
&self.realized,
|
&self.realized,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Sats, StoredU64};
|
use brk_types::{Height, Sats, StoredU64};
|
||||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -61,31 +62,31 @@ impl BasicCohortMetrics {
|
|||||||
pub(crate) fn compute_rest_part2(
|
pub(crate) fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.realized.compute_rest_part2(
|
self.realized.compute_rest_part2(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.supply.total.btc.height,
|
&self.supply.total.btc.height,
|
||||||
&self.activity.transfer_volume.sum._24h.cents.height,
|
&self.activity.transfer_volume.sum._24h.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.unrealized.compute(
|
self.unrealized.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.realized.price.cents.height,
|
&self.realized.price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.supply
|
self.supply
|
||||||
.compute_dominance(starting_indexes.height, all_supply_sats, exit)?;
|
.compute_dominance(starting_lengths.height, all_supply_sats, exit)?;
|
||||||
|
|
||||||
self.outputs
|
self.outputs
|
||||||
.compute_part2(starting_indexes.height, all_utxo_count, exit)?;
|
.compute_part2(starting_lengths.height, all_utxo_count, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Sats, StoredU64, Version};
|
use brk_types::{Height, Sats, StoredU64, Version};
|
||||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -63,32 +64,32 @@ impl CoreCohortMetrics {
|
|||||||
/// Aggregate Core-tier fields from CohortMetricsBase sources (e.g. age_range -> under_age/over_age).
|
/// Aggregate Core-tier fields from CohortMetricsBase sources (e.g. age_range -> under_age/over_age).
|
||||||
pub(crate) fn compute_from_base_sources<T: CohortMetricsBase>(
|
pub(crate) fn compute_from_base_sources<T: CohortMetricsBase>(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&T],
|
others: &[&T],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.supply.compute_from_stateful(
|
self.supply.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.supply()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.supply()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.outputs.compute_from_stateful(
|
self.outputs.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.outputs()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.outputs()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.activity.compute_from_stateful(
|
self.activity.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.activity_core()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.activity_core()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.realized.compute_from_stateful(
|
self.realized.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.realized_core()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.realized_core()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.unrealized.compute_from_stateful(
|
self.unrealized.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.unrealized_core())
|
.map(|v| v.unrealized_core())
|
||||||
@@ -102,19 +103,19 @@ impl CoreCohortMetrics {
|
|||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.supply.compute(prices, starting_indexes.height, exit)?;
|
self.supply.compute(prices, starting_lengths.height, exit)?;
|
||||||
|
|
||||||
self.outputs.compute_rest(starting_indexes.height, exit)?;
|
self.outputs.compute_rest(starting_lengths.height, exit)?;
|
||||||
|
|
||||||
self.activity
|
self.activity
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)?;
|
.compute_rest_part1(prices, starting_lengths, exit)?;
|
||||||
|
|
||||||
self.realized.compute_rest_part1(starting_indexes, exit)?;
|
self.realized.compute_rest_part1(starting_lengths, exit)?;
|
||||||
|
|
||||||
self.unrealized.compute_rest(starting_indexes, exit)?;
|
self.unrealized.compute_rest(starting_lengths, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -122,31 +123,31 @@ impl CoreCohortMetrics {
|
|||||||
pub(crate) fn compute_rest_part2(
|
pub(crate) fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.realized.compute_rest_part2(
|
self.realized.compute_rest_part2(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.supply.total.btc.height,
|
&self.supply.total.btc.height,
|
||||||
&self.activity.transfer_volume.sum._24h.cents.height,
|
&self.activity.transfer_volume.sum._24h.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.unrealized.compute(
|
self.unrealized.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.realized.price.cents.height,
|
&self.realized.price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.supply
|
self.supply
|
||||||
.compute_dominance(starting_indexes.height, all_supply_sats, exit)?;
|
.compute_dominance(starting_lengths.height, all_supply_sats, exit)?;
|
||||||
|
|
||||||
self.outputs
|
self.outputs
|
||||||
.compute_part2(starting_indexes.height, all_utxo_count, exit)?;
|
.compute_part2(starting_lengths.height, all_utxo_count, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Dollars, Height, Indexes, Sats, StoredU64, Version};
|
use brk_types::{Dollars, Height, Sats, StoredU64, Version};
|
||||||
use vecdb::AnyStoredVec;
|
use vecdb::AnyStoredVec;
|
||||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ impl ExtendedCohortMetrics {
|
|||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
||||||
@@ -99,7 +100,7 @@ impl ExtendedCohortMetrics {
|
|||||||
self.realized.compute_rest_part2(
|
self.realized.compute_rest_part2(
|
||||||
blocks,
|
blocks,
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.supply.total.btc.height,
|
&self.supply.total.btc.height,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
&self.activity.transfer_volume,
|
&self.activity.transfer_volume,
|
||||||
@@ -107,14 +108,14 @@ impl ExtendedCohortMetrics {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.unrealized.compute(
|
self.unrealized.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.realized.price.cents.height,
|
&self.realized.price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.cost_basis.compute_prices(
|
self.cost_basis.compute_prices(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.unrealized.invested_capital.in_profit.cents.height,
|
&self.unrealized.invested_capital.in_profit.cents.height,
|
||||||
&self.unrealized.invested_capital.in_loss.cents.height,
|
&self.unrealized.invested_capital.in_loss.cents.height,
|
||||||
@@ -126,13 +127,13 @@ impl ExtendedCohortMetrics {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.unrealized
|
self.unrealized
|
||||||
.compute_sentiment(starting_indexes, &prices.spot.cents.height, exit)?;
|
.compute_sentiment(starting_lengths, &prices.spot.cents.height, exit)?;
|
||||||
|
|
||||||
self.supply
|
self.supply
|
||||||
.compute_dominance(starting_indexes.height, all_supply_sats, exit)?;
|
.compute_dominance(starting_lengths.height, all_supply_sats, exit)?;
|
||||||
|
|
||||||
self.relative.compute(
|
self.relative.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.supply,
|
&self.supply,
|
||||||
&self.unrealized,
|
&self.unrealized,
|
||||||
&self.realized,
|
&self.realized,
|
||||||
@@ -142,7 +143,7 @@ impl ExtendedCohortMetrics {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.outputs
|
self.outputs
|
||||||
.compute_part2(starting_indexes.height, all_utxo_count, exit)?;
|
.compute_part2(starting_lengths.height, all_utxo_count, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, Dollars, Height, Indexes, Sats, StoredU64, Version};
|
use brk_types::{Cents, Dollars, Height, Sats, StoredU64, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ impl ExtendedAdjustedCohortMetrics {
|
|||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
||||||
under_1h_value_created: &impl ReadableVec<Height, Cents>,
|
under_1h_value_created: &impl ReadableVec<Height, Cents>,
|
||||||
under_1h_value_destroyed: &impl ReadableVec<Height, Cents>,
|
under_1h_value_destroyed: &impl ReadableVec<Height, Cents>,
|
||||||
@@ -73,7 +74,7 @@ impl ExtendedAdjustedCohortMetrics {
|
|||||||
self.inner.compute_rest_part2(
|
self.inner.compute_rest_part2(
|
||||||
blocks,
|
blocks,
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
all_supply_sats,
|
all_supply_sats,
|
||||||
all_utxo_count,
|
all_utxo_count,
|
||||||
@@ -81,7 +82,7 @@ impl ExtendedAdjustedCohortMetrics {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.asopr.compute_rest_part2(
|
self.asopr.compute_rest_part2(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.inner.activity.transfer_volume.block.cents,
|
&self.inner.activity.transfer_volume.block.cents,
|
||||||
&self.inner.realized.core.sopr.value_destroyed.block,
|
&self.inner.realized.core.sopr.value_destroyed.block,
|
||||||
under_1h_value_created,
|
under_1h_value_created,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Sats, StoredU64};
|
use brk_types::{Height, Sats, StoredU64};
|
||||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -58,17 +59,17 @@ impl MinimalCohortMetrics {
|
|||||||
/// Aggregate Minimal-tier metrics from other MinimalCohortMetrics sources.
|
/// Aggregate Minimal-tier metrics from other MinimalCohortMetrics sources.
|
||||||
pub(crate) fn compute_from_sources(
|
pub(crate) fn compute_from_sources(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&MinimalCohortMetrics],
|
others: &[&MinimalCohortMetrics],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.supply.compute_from_stateful(
|
self.supply.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.supply.as_ref()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.supply.as_ref()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.outputs.compute_from_stateful(
|
self.outputs.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.outputs.as_ref())
|
.map(|v| v.outputs.as_ref())
|
||||||
@@ -76,7 +77,7 @@ impl MinimalCohortMetrics {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.activity.compute_from_stateful(
|
self.activity.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.activity.as_ref())
|
.map(|v| v.activity.as_ref())
|
||||||
@@ -84,7 +85,7 @@ impl MinimalCohortMetrics {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.realized.compute_from_stateful(
|
self.realized.compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.realized.as_ref())
|
.map(|v| v.realized.as_ref())
|
||||||
@@ -97,44 +98,44 @@ impl MinimalCohortMetrics {
|
|||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.supply.compute(prices, starting_indexes.height, exit)?;
|
self.supply.compute(prices, starting_lengths.height, exit)?;
|
||||||
self.outputs.compute_rest(starting_indexes.height, exit)?;
|
self.outputs.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.activity
|
self.activity
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)?;
|
.compute_rest_part1(prices, starting_lengths, exit)?;
|
||||||
self.realized.compute_rest_part1(starting_indexes, exit)?;
|
self.realized.compute_rest_part1(starting_lengths, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest_part2(
|
pub(crate) fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.realized.compute_rest_part2(
|
self.realized.compute_rest_part2(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.supply.total.btc.height,
|
&self.supply.total.btc.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.unrealized.compute(
|
self.unrealized.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.realized.price.cents.height,
|
&self.realized.price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.supply
|
self.supply
|
||||||
.compute_dominance(starting_indexes.height, all_supply_sats, exit)?;
|
.compute_dominance(starting_lengths.height, all_supply_sats, exit)?;
|
||||||
|
|
||||||
self.outputs
|
self.outputs
|
||||||
.compute_part2(starting_indexes.height, all_utxo_count, exit)?;
|
.compute_part2(starting_lengths.height, all_utxo_count, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Sats, StoredU64};
|
use brk_types::{Height, Sats, StoredU64};
|
||||||
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -59,44 +60,44 @@ impl TypeCohortMetrics {
|
|||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.supply.compute(prices, starting_indexes.height, exit)?;
|
self.supply.compute(prices, starting_lengths.height, exit)?;
|
||||||
self.outputs.compute_rest(starting_indexes.height, exit)?;
|
self.outputs.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.activity
|
self.activity
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)?;
|
.compute_rest_part1(prices, starting_lengths, exit)?;
|
||||||
self.realized.compute_rest_part1(starting_indexes, exit)?;
|
self.realized.compute_rest_part1(starting_lengths, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest_part2(
|
pub(crate) fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
all_supply_sats: &impl ReadableVec<Height, Sats>,
|
||||||
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
all_utxo_count: &impl ReadableVec<Height, StoredU64>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.realized.compute_rest_part2(
|
self.realized.compute_rest_part2(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.supply.total.btc.height,
|
&self.supply.total.btc.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.unrealized.compute(
|
self.unrealized.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.realized.price.cents.height,
|
&self.realized.price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.supply
|
self.supply
|
||||||
.compute_dominance(starting_indexes.height, all_supply_sats, exit)?;
|
.compute_dominance(starting_lengths.height, all_supply_sats, exit)?;
|
||||||
|
|
||||||
self.outputs
|
self.outputs
|
||||||
.compute_part2(starting_indexes.height, all_utxo_count, exit)?;
|
.compute_part2(starting_lengths.height, all_utxo_count, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::CentsSquaredSats;
|
use brk_types::CentsSquaredSats;
|
||||||
use brk_types::{BasisPoints16, Cents, Height, Indexes, Sats, Version};
|
use brk_types::{BasisPoints16, Cents, Height, Sats, Version};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
use crate::internal::{PERCENTILES_LEN, PerBlock, PercentPerBlock, PercentilesVecs, Price};
|
use crate::internal::{PERCENTILES_LEN, PerBlock, PercentPerBlock, PercentilesVecs, Price};
|
||||||
@@ -147,7 +148,7 @@ impl CostBasis {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute_prices(
|
pub(crate) fn compute_prices(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
spot: &impl ReadableVec<Height, Cents>,
|
spot: &impl ReadableVec<Height, Cents>,
|
||||||
invested_cap_in_profit: &impl ReadableVec<Height, Cents>,
|
invested_cap_in_profit: &impl ReadableVec<Height, Cents>,
|
||||||
invested_cap_in_loss: &impl ReadableVec<Height, Cents>,
|
invested_cap_in_loss: &impl ReadableVec<Height, Cents>,
|
||||||
@@ -158,7 +159,7 @@ impl CostBasis {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.in_profit.per_coin.cents.height.compute_transform3(
|
self.in_profit.per_coin.cents.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
invested_cap_in_profit,
|
invested_cap_in_profit,
|
||||||
supply_in_profit_sats,
|
supply_in_profit_sats,
|
||||||
spot,
|
spot,
|
||||||
@@ -175,7 +176,7 @@ impl CostBasis {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.in_loss.per_coin.cents.height.compute_transform3(
|
self.in_loss.per_coin.cents.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
invested_cap_in_loss,
|
invested_cap_in_loss,
|
||||||
supply_in_loss_sats,
|
supply_in_loss_sats,
|
||||||
spot,
|
spot,
|
||||||
@@ -192,7 +193,7 @@ impl CostBasis {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.in_profit.per_dollar.cents.height.compute_transform3(
|
self.in_profit.per_dollar.cents.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
capitalized_cap_in_profit_raw,
|
capitalized_cap_in_profit_raw,
|
||||||
invested_cap_in_profit,
|
invested_cap_in_profit,
|
||||||
spot,
|
spot,
|
||||||
@@ -209,7 +210,7 @@ impl CostBasis {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.in_loss.per_dollar.cents.height.compute_transform3(
|
self.in_loss.per_dollar.cents.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
capitalized_cap_in_loss_raw,
|
capitalized_cap_in_loss_raw,
|
||||||
invested_cap_in_loss,
|
invested_cap_in_loss,
|
||||||
spot,
|
spot,
|
||||||
|
|||||||
@@ -140,7 +140,8 @@ pub use unrealized::{
|
|||||||
|
|
||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Cents, Indexes, Version};
|
use brk_indexer::Lengths;
|
||||||
|
use brk_types::{Cents, Version};
|
||||||
use vecdb::{AnyStoredVec, Exit, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -270,23 +271,23 @@ pub trait CohortMetricsBase:
|
|||||||
fn compute_rest_part1(
|
fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.supply_mut()
|
self.supply_mut()
|
||||||
.compute(prices, starting_indexes.height, exit)?;
|
.compute(prices, starting_lengths.height, exit)?;
|
||||||
self.outputs_mut()
|
self.outputs_mut()
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.activity_mut()
|
self.activity_mut()
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)?;
|
.compute_rest_part1(prices, starting_lengths, exit)?;
|
||||||
|
|
||||||
self.realized_mut()
|
self.realized_mut()
|
||||||
.compute_rest_part1(starting_indexes, exit)?;
|
.compute_rest_part1(starting_lengths, exit)?;
|
||||||
|
|
||||||
let (supply, unrealized) = self.supply_and_unrealized_mut();
|
let (supply, unrealized) = self.supply_and_unrealized_mut();
|
||||||
unrealized.compute_rest(
|
unrealized.compute_rest(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&supply.in_profit.sats.height,
|
&supply.in_profit.sats.height,
|
||||||
&supply.in_loss.sats.height,
|
&supply.in_loss.sats.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -298,32 +299,32 @@ pub trait CohortMetricsBase:
|
|||||||
/// Compute aggregate base metrics from source cohorts.
|
/// Compute aggregate base metrics from source cohorts.
|
||||||
fn compute_base_from_others<T: CohortMetricsBase>(
|
fn compute_base_from_others<T: CohortMetricsBase>(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&T],
|
others: &[&T],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.supply_mut().compute_from_stateful(
|
self.supply_mut().compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.supply()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.supply()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.outputs_mut().compute_from_stateful(
|
self.outputs_mut().compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.outputs()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.outputs()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.activity_mut().compute_from_stateful(
|
self.activity_mut().compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.activity_core()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.activity_core()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.realized_mut().compute_from_stateful(
|
self.realized_mut().compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others.iter().map(|v| v.realized_core()).collect::<Vec<_>>(),
|
&others.iter().map(|v| v.realized_core()).collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.unrealized_core_mut().compute_from_stateful(
|
self.unrealized_core_mut().compute_from_stateful(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.unrealized_core())
|
.map(|v| v.unrealized_core())
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{BasisPointsSigned32, Height, StoredF32, StoredI64, StoredU32, StoredU64, Version};
|
||||||
BasisPointsSigned32, Height, Indexes, StoredF32, StoredI64, StoredU32, StoredU64, Version,
|
|
||||||
};
|
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -83,19 +82,19 @@ impl OutputsBase {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.unspent_count.height.compute_sum_of_others(
|
self.unspent_count.height.compute_sum_of_others(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| &v.unspent_count.height)
|
.map(|v| &v.unspent_count.height)
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
sum_others!(self, starting_indexes, others, exit; spent_count.block);
|
sum_others!(self, starting_lengths, others, exit; spent_count.block);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_cohort::{Loss, Profit, ProfitabilityRange};
|
use brk_cohort::{Loss, Profit, ProfitabilityRange};
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{BasisPointsSigned32, Bitcoin, Cents, Dollars, Indexes, Sats, Version};
|
use brk_types::{BasisPointsSigned32, Bitcoin, Cents, Dollars, Sats, Version};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -115,11 +116,11 @@ impl ProfitabilityBucket {
|
|||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
is_profit: bool,
|
is_profit: bool,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let max_from = starting_indexes.height;
|
let max_from = starting_lengths.height;
|
||||||
|
|
||||||
self.supply.all.compute(prices, max_from, exit)?;
|
self.supply.all.compute(prices, max_from, exit)?;
|
||||||
self.supply.sth.compute(prices, max_from, exit)?;
|
self.supply.sth.compute(prices, max_from, exit)?;
|
||||||
@@ -176,12 +177,12 @@ impl ProfitabilityBucket {
|
|||||||
pub(crate) fn compute_from_ranges(
|
pub(crate) fn compute_from_ranges(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
is_profit: bool,
|
is_profit: bool,
|
||||||
sources: &[&ProfitabilityBucket],
|
sources: &[&ProfitabilityBucket],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let max_from = starting_indexes.height;
|
let max_from = starting_lengths.height;
|
||||||
|
|
||||||
self.supply.all.sats.height.compute_sum_of_others(
|
self.supply.all.sats.height.compute_sum_of_others(
|
||||||
max_from,
|
max_from,
|
||||||
@@ -216,7 +217,7 @@ impl ProfitabilityBucket {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.compute(prices, starting_indexes, is_profit, exit)
|
self.compute(prices, starting_lengths, is_profit, exit)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
pub(crate) fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||||
@@ -293,20 +294,20 @@ impl ProfitabilityMetrics {
|
|||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (is_profit, bucket) in self.range.iter_mut_with_is_profit() {
|
for (is_profit, bucket) in self.range.iter_mut_with_is_profit() {
|
||||||
bucket.compute(prices, starting_indexes, is_profit, exit)?;
|
bucket.compute(prices, starting_lengths, is_profit, exit)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let range_arr = self.range.as_array();
|
let range_arr = self.range.as_array();
|
||||||
|
|
||||||
for (threshold, sources) in self.profit.iter_mut_with_growing_prefix(&range_arr) {
|
for (threshold, sources) in self.profit.iter_mut_with_growing_prefix(&range_arr) {
|
||||||
threshold.compute_from_ranges(prices, starting_indexes, true, sources, exit)?;
|
threshold.compute_from_ranges(prices, starting_lengths, true, sources, exit)?;
|
||||||
}
|
}
|
||||||
for (threshold, sources) in self.loss.iter_mut_with_growing_suffix(&range_arr) {
|
for (threshold, sources) in self.loss.iter_mut_with_growing_suffix(&range_arr) {
|
||||||
threshold.compute_from_ranges(prices, starting_indexes, false, sources, exit)?;
|
threshold.compute_from_ranges(prices, starting_lengths, false, sources, exit)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, Height, Indexes, StoredF64, Version};
|
use brk_types::{Cents, Height, StoredF64, Version};
|
||||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -27,7 +28,7 @@ impl AdjustedSopr {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute_rest_part2(
|
pub(crate) fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
base_transfer_volume: &impl ReadableVec<Height, Cents>,
|
base_transfer_volume: &impl ReadableVec<Height, Cents>,
|
||||||
base_value_destroyed: &impl ReadableVec<Height, Cents>,
|
base_value_destroyed: &impl ReadableVec<Height, Cents>,
|
||||||
under_1h_transfer_volume: &impl ReadableVec<Height, Cents>,
|
under_1h_transfer_volume: &impl ReadableVec<Height, Cents>,
|
||||||
@@ -35,22 +36,22 @@ impl AdjustedSopr {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.transfer_volume.block.compute_subtract(
|
self.transfer_volume.block.compute_subtract(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
base_transfer_volume,
|
base_transfer_volume,
|
||||||
under_1h_transfer_volume,
|
under_1h_transfer_volume,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.value_destroyed.block.compute_subtract(
|
self.value_destroyed.block.compute_subtract(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
base_value_destroyed,
|
base_value_destroyed,
|
||||||
under_1h_value_destroyed,
|
under_1h_value_destroyed,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.transfer_volume
|
self.transfer_volume
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.value_destroyed
|
self.value_destroyed
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
|
|
||||||
for ((sopr, tv), vd) in self
|
for ((sopr, tv), vd) in self
|
||||||
.ratio
|
.ratio
|
||||||
@@ -60,7 +61,7 @@ impl AdjustedSopr {
|
|||||||
.zip(self.value_destroyed.sum.as_array())
|
.zip(self.value_destroyed.sum.as_array())
|
||||||
{
|
{
|
||||||
sopr.compute_binary::<Cents, Cents, RatioCents64>(
|
sopr.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&tv.height,
|
&tv.height,
|
||||||
&vd.height,
|
&vd.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{
|
||||||
BasisPointsSigned32, Bitcoin, Cents, CentsSigned, Dollars, Height, Indexes, StoredF64, Version,
|
BasisPointsSigned32, Bitcoin, Cents, CentsSigned, Dollars, Height, StoredF64, Version,
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{
|
use vecdb::{
|
||||||
@@ -124,31 +125,31 @@ impl RealizedCore {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let minimal_refs: Vec<&RealizedMinimal> = others.iter().map(|o| &o.minimal).collect();
|
let minimal_refs: Vec<&RealizedMinimal> = others.iter().map(|o| &o.minimal).collect();
|
||||||
self.minimal
|
self.minimal
|
||||||
.compute_from_stateful(starting_indexes, &minimal_refs, exit)?;
|
.compute_from_stateful(starting_lengths, &minimal_refs, exit)?;
|
||||||
|
|
||||||
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.block);
|
sum_others!(self, starting_lengths, others, exit; sopr.value_destroyed.block);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.minimal.compute_rest_part1(starting_indexes, exit)?;
|
self.minimal.compute_rest_part1(starting_lengths, exit)?;
|
||||||
|
|
||||||
self.sopr
|
self.sopr
|
||||||
.value_destroyed
|
.value_destroyed
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
|
|
||||||
self.net_pnl.block.cents.compute_transform2(
|
self.net_pnl.block.cents.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.minimal.profit.block.cents,
|
&self.minimal.profit.block.cents,
|
||||||
&self.minimal.loss.block.cents,
|
&self.minimal.loss.block.cents,
|
||||||
|(i, profit, loss, ..)| {
|
|(i, profit, loss, ..)| {
|
||||||
@@ -166,21 +167,21 @@ impl RealizedCore {
|
|||||||
pub(crate) fn compute_rest_part2(
|
pub(crate) fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
||||||
transfer_volume_sum_24h_cents: &impl ReadableVec<Height, Cents>,
|
transfer_volume_sum_24h_cents: &impl ReadableVec<Height, Cents>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.minimal
|
self.minimal
|
||||||
.compute_rest_part2(prices, starting_indexes, height_to_supply, exit)?;
|
.compute_rest_part2(prices, starting_lengths, height_to_supply, exit)?;
|
||||||
|
|
||||||
self.net_pnl.compute_rest(starting_indexes.height, exit)?;
|
self.net_pnl.compute_rest(starting_lengths.height, exit)?;
|
||||||
|
|
||||||
self.sopr
|
self.sopr
|
||||||
.ratio
|
.ratio
|
||||||
._24h
|
._24h
|
||||||
.compute_binary::<Cents, Cents, RatioCents64>(
|
.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
transfer_volume_sum_24h_cents,
|
transfer_volume_sum_24h_cents,
|
||||||
&self.sopr.value_destroyed.sum._24h.height,
|
&self.sopr.value_destroyed.sum._24h.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{
|
||||||
BasisPoints32, BasisPointsSigned32, Bitcoin, Cents, CentsSats, CentsSigned, CentsSquaredSats,
|
BasisPoints32, BasisPointsSigned32, Bitcoin, Cents, CentsSats, CentsSigned, CentsSquaredSats,
|
||||||
Dollars, Height, Indexes, StoredF64, Version,
|
Dollars, Height, StoredF64, Version,
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, BytesVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, BytesVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||||
@@ -194,12 +195,12 @@ impl RealizedFull {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&RealizedCore],
|
others: &[&RealizedCore],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.core
|
self.core
|
||||||
.compute_from_stateful(starting_indexes, others, exit)?;
|
.compute_from_stateful(starting_lengths, others, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -224,14 +225,14 @@ impl RealizedFull {
|
|||||||
|
|
||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.core.compute_rest_part1(starting_indexes, exit)?;
|
self.core.compute_rest_part1(starting_lengths, exit)?;
|
||||||
|
|
||||||
self.peak_regret
|
self.peak_regret
|
||||||
.value
|
.value
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +241,7 @@ impl RealizedFull {
|
|||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
||||||
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
height_to_market_cap: &impl ReadableVec<Height, Dollars>,
|
||||||
activity_transfer_volume: &ValuePerBlockCumulativeRolling,
|
activity_transfer_volume: &ValuePerBlockCumulativeRolling,
|
||||||
@@ -248,7 +249,7 @@ impl RealizedFull {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.core.compute_rest_part2(
|
self.core.compute_rest_part2(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
height_to_supply,
|
height_to_supply,
|
||||||
&activity_transfer_volume.sum._24h.cents.height,
|
&activity_transfer_volume.sum._24h.cents.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -264,7 +265,7 @@ impl RealizedFull {
|
|||||||
.zip(self.core.sopr.value_destroyed.sum.as_array()[1..].iter())
|
.zip(self.core.sopr.value_destroyed.sum.as_array()[1..].iter())
|
||||||
{
|
{
|
||||||
sopr.compute_binary::<Cents, Cents, RatioCents64>(
|
sopr.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&vc.cents.height,
|
&vc.cents.height,
|
||||||
&vd.height,
|
&vd.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -273,18 +274,18 @@ impl RealizedFull {
|
|||||||
|
|
||||||
// Gross PnL
|
// Gross PnL
|
||||||
self.gross_pnl.block.cents.compute_add(
|
self.gross_pnl.block.cents.compute_add(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.core.minimal.profit.block.cents,
|
&self.core.minimal.profit.block.cents,
|
||||||
&self.core.minimal.loss.block.cents,
|
&self.core.minimal.loss.block.cents,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.gross_pnl.compute_rest(starting_indexes.height, exit)?;
|
self.gross_pnl.compute_rest(starting_lengths.height, exit)?;
|
||||||
|
|
||||||
// Net PnL 1m change relative to rcap and mcap
|
// Net PnL 1m change relative to rcap and mcap
|
||||||
self.net_pnl
|
self.net_pnl
|
||||||
.change_1m_to_rcap
|
.change_1m_to_rcap
|
||||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.core.net_pnl.delta.absolute._1m.cents.height,
|
&self.core.net_pnl.delta.absolute._1m.cents.height,
|
||||||
&self.core.minimal.cap.cents.height,
|
&self.core.minimal.cap.cents.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -292,7 +293,7 @@ impl RealizedFull {
|
|||||||
self.net_pnl
|
self.net_pnl
|
||||||
.change_1m_to_mcap
|
.change_1m_to_mcap
|
||||||
.compute_binary::<CentsSigned, Dollars, RatioCentsSignedDollarsBps32>(
|
.compute_binary::<CentsSigned, Dollars, RatioCentsSignedDollarsBps32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.core.net_pnl.delta.absolute._1m.cents.height,
|
&self.core.net_pnl.delta.absolute._1m.cents.height,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
exit,
|
exit,
|
||||||
@@ -301,7 +302,7 @@ impl RealizedFull {
|
|||||||
// Capitalized price ratio, percentiles and bands
|
// Capitalized price ratio, percentiles and bands
|
||||||
self.capitalized
|
self.capitalized
|
||||||
.price
|
.price
|
||||||
.compute_rest(prices, starting_indexes, exit)?;
|
.compute_rest(prices, starting_lengths, exit)?;
|
||||||
|
|
||||||
// Sell-side risk ratios
|
// Sell-side risk ratios
|
||||||
for (ssrr, rv) in self
|
for (ssrr, rv) in self
|
||||||
@@ -311,7 +312,7 @@ impl RealizedFull {
|
|||||||
.zip(self.gross_pnl.sum.as_array())
|
.zip(self.gross_pnl.sum.as_array())
|
||||||
{
|
{
|
||||||
ssrr.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
ssrr.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&rv.cents.height,
|
&rv.cents.height,
|
||||||
&self.core.minimal.cap.cents.height,
|
&self.core.minimal.cap.cents.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -321,7 +322,7 @@ impl RealizedFull {
|
|||||||
// Realized cap relative to own market cap
|
// Realized cap relative to own market cap
|
||||||
self.cap_to_own_mcap
|
self.cap_to_own_mcap
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.core.minimal.cap.usd.height,
|
&self.core.minimal.cap.usd.height,
|
||||||
height_to_market_cap,
|
height_to_market_cap,
|
||||||
exit,
|
exit,
|
||||||
@@ -336,7 +337,7 @@ impl RealizedFull {
|
|||||||
.zip(self.core.minimal.loss.sum.as_array())
|
.zip(self.core.minimal.loss.sum.as_array())
|
||||||
{
|
{
|
||||||
ratio.compute_binary::<Cents, Cents, RatioCents64>(
|
ratio.compute_binary::<Cents, Cents, RatioCents64>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&profit.cents.height,
|
&profit.cents.height,
|
||||||
&loss.cents.height,
|
&loss.cents.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -345,7 +346,7 @@ impl RealizedFull {
|
|||||||
|
|
||||||
// Price ratio: percentiles, sma and std dev bands
|
// Price ratio: percentiles, sma and std dev bands
|
||||||
self.price_ratio_percentiles.compute(
|
self.price_ratio_percentiles.compute(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
exit,
|
exit,
|
||||||
&self.core.minimal.price.ratio.height,
|
&self.core.minimal.price.ratio.height,
|
||||||
&self.core.minimal.price.cents.height,
|
&self.core.minimal.price.cents.height,
|
||||||
@@ -353,14 +354,14 @@ impl RealizedFull {
|
|||||||
|
|
||||||
self.price_ratio_sma.compute(
|
self.price_ratio_sma.compute(
|
||||||
blocks,
|
blocks,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
exit,
|
exit,
|
||||||
&self.core.minimal.price.ratio.height,
|
&self.core.minimal.price.ratio.height,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.price_ratio_std_dev.compute(
|
self.price_ratio_std_dev.compute(
|
||||||
blocks,
|
blocks,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
exit,
|
exit,
|
||||||
&self.core.minimal.price.ratio.height,
|
&self.core.minimal.price.ratio.height,
|
||||||
&self.core.minimal.price.cents.height,
|
&self.core.minimal.price.cents.height,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{
|
||||||
BasisPoints32, BasisPointsSigned32, Bitcoin, Cents, CentsSigned, Height, Indexes, Sats,
|
BasisPoints32, BasisPointsSigned32, Bitcoin, Cents, CentsSigned, Height, Sats, StoredF32,
|
||||||
StoredF32, Version,
|
Version,
|
||||||
};
|
};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
@@ -81,38 +82,38 @@ impl RealizedMinimal {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
sum_others!(self, starting_indexes, others, exit; cap.cents.height);
|
sum_others!(self, starting_lengths, others, exit; cap.cents.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; profit.block.cents);
|
sum_others!(self, starting_lengths, others, exit; profit.block.cents);
|
||||||
sum_others!(self, starting_indexes, others, exit; loss.block.cents);
|
sum_others!(self, starting_lengths, others, exit; loss.block.cents);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest_part1(
|
pub(crate) fn compute_rest_part1(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.profit.compute_rest(starting_indexes.height, exit)?;
|
self.profit.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.loss.compute_rest(starting_indexes.height, exit)?;
|
self.loss.compute_rest(starting_lengths.height, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest_part2(
|
pub(crate) fn compute_rest_part2(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
height_to_supply: &impl ReadableVec<Height, Bitcoin>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let cap = &self.cap.cents.height;
|
let cap = &self.cap.cents.height;
|
||||||
self.price
|
self.price
|
||||||
.compute_all(prices, starting_indexes, exit, |v| {
|
.compute_all(prices, starting_lengths, exit, |v| {
|
||||||
Ok(v.compute_transform2(
|
Ok(v.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
cap,
|
cap,
|
||||||
height_to_supply,
|
height_to_supply,
|
||||||
|(i, cap_cents, supply, ..)| {
|
|(i, cap_cents, supply, ..)| {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ pub use full::{RealizedFull, RealizedFullAccum};
|
|||||||
pub use minimal::RealizedMinimal;
|
pub use minimal::RealizedMinimal;
|
||||||
|
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Indexes;
|
use brk_indexer::Lengths;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use crate::distribution::state::{CohortState, CostBasisData, RealizedState, WithCapital};
|
use crate::distribution::state::{CohortState, CostBasisData, RealizedState, WithCapital};
|
||||||
@@ -19,10 +19,10 @@ pub trait RealizedLike: Send + Sync {
|
|||||||
fn as_core_mut(&mut self) -> &mut RealizedCore;
|
fn as_core_mut(&mut self) -> &mut RealizedCore;
|
||||||
fn min_stateful_len(&self) -> usize;
|
fn min_stateful_len(&self) -> usize;
|
||||||
fn push_state(&mut self, state: &CohortState<RealizedState, CostBasisData<WithCapital>>);
|
fn push_state(&mut self, state: &CohortState<RealizedState, CostBasisData<WithCapital>>);
|
||||||
fn compute_rest_part1(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()>;
|
fn compute_rest_part1(&mut self, starting_lengths: &Lengths, exit: &Exit) -> Result<()>;
|
||||||
fn compute_from_stateful(
|
fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&RealizedCore],
|
others: &[&RealizedCore],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
@@ -42,16 +42,16 @@ impl RealizedLike for RealizedCore {
|
|||||||
fn push_state(&mut self, state: &CohortState<RealizedState, CostBasisData<WithCapital>>) {
|
fn push_state(&mut self, state: &CohortState<RealizedState, CostBasisData<WithCapital>>) {
|
||||||
self.push_state(state)
|
self.push_state(state)
|
||||||
}
|
}
|
||||||
fn compute_rest_part1(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
|
fn compute_rest_part1(&mut self, starting_lengths: &Lengths, exit: &Exit) -> Result<()> {
|
||||||
self.compute_rest_part1(starting_indexes, exit)
|
self.compute_rest_part1(starting_lengths, exit)
|
||||||
}
|
}
|
||||||
fn compute_from_stateful(
|
fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&RealizedCore],
|
others: &[&RealizedCore],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_from_stateful(starting_indexes, others, exit)
|
self.compute_from_stateful(starting_lengths, others, exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,15 +69,15 @@ impl RealizedLike for RealizedFull {
|
|||||||
fn push_state(&mut self, state: &CohortState<RealizedState, CostBasisData<WithCapital>>) {
|
fn push_state(&mut self, state: &CohortState<RealizedState, CostBasisData<WithCapital>>) {
|
||||||
self.push_state(state)
|
self.push_state(state)
|
||||||
}
|
}
|
||||||
fn compute_rest_part1(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
|
fn compute_rest_part1(&mut self, starting_lengths: &Lengths, exit: &Exit) -> Result<()> {
|
||||||
self.compute_rest_part1(starting_indexes, exit)
|
self.compute_rest_part1(starting_lengths, exit)
|
||||||
}
|
}
|
||||||
fn compute_from_stateful(
|
fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&RealizedCore],
|
others: &[&RealizedCore],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_from_stateful(starting_indexes, others, exit)
|
self.compute_from_stateful(starting_lengths, others, exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{BasisPoints16, BasisPointsSigned32, Height, Indexes, Sats, SatsSigned, Version};
|
use brk_types::{BasisPoints16, BasisPointsSigned32, Height, Sats, SatsSigned, Version};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -86,12 +87,12 @@ impl SupplyBase {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.total.sats.height.compute_sum_of_others(
|
self.total.sats.height.compute_sum_of_others(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&others
|
&others
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| &v.total.sats.height)
|
.map(|v| &v.total.sats.height)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Version};
|
use brk_types::{Height, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
@@ -87,15 +88,15 @@ impl SupplyCore {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let base_refs: Vec<&SupplyBase> = others.iter().map(|o| &o.base).collect();
|
let base_refs: Vec<&SupplyBase> = others.iter().map(|o| &o.base).collect();
|
||||||
self.base
|
self.base
|
||||||
.compute_from_stateful(starting_indexes, &base_refs, exit)?;
|
.compute_from_stateful(starting_lengths, &base_refs, exit)?;
|
||||||
sum_others!(self, starting_indexes, others, exit; in_profit.sats.height);
|
sum_others!(self, starting_lengths, others, exit; in_profit.sats.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; in_loss.sats.height);
|
sum_others!(self, starting_lengths, others, exit; in_loss.sats.height);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, Dollars, Indexes, Version};
|
use brk_types::{Cents, Dollars, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableCloneableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableCloneableVec, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
@@ -67,12 +68,12 @@ impl UnrealizedBasic {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_sources(
|
pub(crate) fn compute_from_sources(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
sum_others!(self, starting_indexes, others, exit; profit.cents.height);
|
sum_others!(self, starting_lengths, others, exit; profit.cents.height);
|
||||||
sum_others!(self, starting_indexes, others, exit; loss.cents.height);
|
sum_others!(self, starting_lengths, others, exit; loss.cents.height);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, CentsSigned, Indexes, Version};
|
use brk_types::{Cents, CentsSigned, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, Exit, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -47,22 +48,22 @@ impl UnrealizedCore {
|
|||||||
|
|
||||||
pub(crate) fn compute_from_stateful(
|
pub(crate) fn compute_from_stateful(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
others: &[&Self],
|
others: &[&Self],
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let basic_refs: Vec<&UnrealizedBasic> = others.iter().map(|o| &o.basic).collect();
|
let basic_refs: Vec<&UnrealizedBasic> = others.iter().map(|o| &o.basic).collect();
|
||||||
self.basic
|
self.basic
|
||||||
.compute_from_sources(starting_indexes, &basic_refs, exit)?;
|
.compute_from_sources(starting_lengths, &basic_refs, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_rest(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
|
pub(crate) fn compute_rest(&mut self, starting_lengths: &Lengths, exit: &Exit) -> Result<()> {
|
||||||
self.net_pnl
|
self.net_pnl
|
||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.basic.profit.cents.height,
|
&self.basic.profit.cents.height,
|
||||||
&self.basic.loss.cents.height,
|
&self.basic.loss.cents.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, CentsSigned, CentsSquaredSats, Height, Indexes, Sats, Version};
|
use brk_types::{Cents, CentsSigned, CentsSquaredSats, Height, Sats, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, BytesVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, BytesVec, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
@@ -99,16 +100,16 @@ impl UnrealizedFull {
|
|||||||
pub(crate) fn compute_rest_all(
|
pub(crate) fn compute_rest_all(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
supply_in_profit_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
supply_in_profit_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
||||||
supply_in_loss_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
supply_in_loss_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.inner.compute_rest(starting_indexes, exit)?;
|
self.inner.compute_rest(starting_lengths, exit)?;
|
||||||
|
|
||||||
// gross_pnl = profit + loss
|
// gross_pnl = profit + loss
|
||||||
self.gross_pnl.cents.height.compute_add(
|
self.gross_pnl.cents.height.compute_add(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.inner.basic.profit.cents.height,
|
&self.inner.basic.profit.cents.height,
|
||||||
&self.inner.basic.loss.cents.height,
|
&self.inner.basic.loss.cents.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -120,7 +121,7 @@ impl UnrealizedFull {
|
|||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.compute_transform3(
|
.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
supply_in_profit_sats,
|
supply_in_profit_sats,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.inner.basic.profit.cents.height,
|
&self.inner.basic.profit.cents.height,
|
||||||
@@ -140,7 +141,7 @@ impl UnrealizedFull {
|
|||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.compute_transform3(
|
.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
supply_in_loss_sats,
|
supply_in_loss_sats,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.inner.basic.loss.cents.height,
|
&self.inner.basic.loss.cents.height,
|
||||||
@@ -158,7 +159,7 @@ impl UnrealizedFull {
|
|||||||
/// Called after cost_basis.in_profit/loss are computed at the cohort level.
|
/// Called after cost_basis.in_profit/loss are computed at the cohort level.
|
||||||
pub(crate) fn compute_sentiment(
|
pub(crate) fn compute_sentiment(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
spot: &impl ReadableVec<Height, Cents>,
|
spot: &impl ReadableVec<Height, Cents>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@@ -166,7 +167,7 @@ impl UnrealizedFull {
|
|||||||
// capitalized_price = capitalized_cap / invested_cap
|
// capitalized_price = capitalized_cap / invested_cap
|
||||||
// invested_cap is in Cents (already / ONE_BTC), multiply back for CentsSats scale
|
// invested_cap is in Cents (already / ONE_BTC), multiply back for CentsSats scale
|
||||||
self.sentiment.greed_index.cents.height.compute_transform3(
|
self.sentiment.greed_index.cents.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.capitalized_cap_in_profit_raw,
|
&self.capitalized_cap_in_profit_raw,
|
||||||
&self.invested_capital.in_profit.cents.height,
|
&self.invested_capital.in_profit.cents.height,
|
||||||
spot,
|
spot,
|
||||||
@@ -187,7 +188,7 @@ impl UnrealizedFull {
|
|||||||
|
|
||||||
// pain = capitalized_price_losers - spot
|
// pain = capitalized_price_losers - spot
|
||||||
self.sentiment.pain_index.cents.height.compute_transform3(
|
self.sentiment.pain_index.cents.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.capitalized_cap_in_loss_raw,
|
&self.capitalized_cap_in_loss_raw,
|
||||||
&self.invested_capital.in_loss.cents.height,
|
&self.invested_capital.in_loss.cents.height,
|
||||||
spot,
|
spot,
|
||||||
@@ -212,7 +213,7 @@ impl UnrealizedFull {
|
|||||||
.cents
|
.cents
|
||||||
.height
|
.height
|
||||||
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
.compute_binary::<Cents, Cents, CentsSubtractToCentsSigned>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.sentiment.greed_index.cents.height,
|
&self.sentiment.greed_index.cents.height,
|
||||||
&self.sentiment.pain_index.cents.height,
|
&self.sentiment.pain_index.cents.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ pub use full::UnrealizedFull;
|
|||||||
pub use minimal::UnrealizedMinimal;
|
pub use minimal::UnrealizedMinimal;
|
||||||
|
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Height, Indexes, Sats};
|
use brk_indexer::Lengths;
|
||||||
|
use brk_types::{Height, Sats};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use crate::{distribution::state::UnrealizedState, prices};
|
use crate::{distribution::state::UnrealizedState, prices};
|
||||||
@@ -22,7 +23,7 @@ pub trait UnrealizedLike: Send + Sync {
|
|||||||
fn compute_rest(
|
fn compute_rest(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
supply_in_profit_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
supply_in_profit_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
||||||
supply_in_loss_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
supply_in_loss_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
@@ -46,12 +47,12 @@ impl UnrealizedLike for UnrealizedCore {
|
|||||||
fn compute_rest(
|
fn compute_rest(
|
||||||
&mut self,
|
&mut self,
|
||||||
_prices: &prices::Vecs,
|
_prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
_supply_in_profit_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
_supply_in_profit_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
||||||
_supply_in_loss_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
_supply_in_loss_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_rest(starting_indexes, exit)
|
self.compute_rest(starting_lengths, exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,14 +73,14 @@ impl UnrealizedLike for UnrealizedFull {
|
|||||||
fn compute_rest(
|
fn compute_rest(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
supply_in_profit_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
supply_in_profit_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
||||||
supply_in_loss_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
supply_in_loss_sats: &(impl ReadableVec<Height, Sats> + Sync),
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.compute_rest_all(
|
self.compute_rest_all(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
supply_in_profit_sats,
|
supply_in_profit_sats,
|
||||||
supply_in_loss_sats,
|
supply_in_loss_sats,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ use brk_error::Result;
|
|||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{
|
||||||
Cents, EmptyAddrData, EmptyAddrIndex, FundedAddrData, FundedAddrIndex, Height, Indexes,
|
Cents, EmptyAddrData, EmptyAddrIndex, FundedAddrData, FundedAddrIndex, Height, StoredF64,
|
||||||
StoredF64, SupplyState, Timestamp, TxIndex, Version,
|
SupplyState, Timestamp, TxIndex, Version,
|
||||||
};
|
};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
@@ -317,18 +317,19 @@ impl Vecs {
|
|||||||
transactions: &transactions::Vecs,
|
transactions: &transactions::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &mut Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
|
|
||||||
|
let starting_lengths = indexer.safe_lengths();
|
||||||
|
|
||||||
// 1. Find minimum height we have data for across stateful vecs
|
// 1. Find minimum height we have data for across stateful vecs
|
||||||
let current_height = Height::from(self.supply_state.len());
|
let current_height = Height::from(self.supply_state.len());
|
||||||
let min_stateful = self.min_stateful_len();
|
let min_stateful = self.min_stateful_len();
|
||||||
|
|
||||||
// 2. Determine start mode and recover/reset state
|
// 2. Determine start mode and recover/reset state
|
||||||
// Clamp to starting_indexes.height to handle reorg (indexer may require earlier start)
|
// Clamp to starting_lengths.height to handle reorg (indexer may require earlier start)
|
||||||
let resume_target = current_height.min(starting_indexes.height);
|
let resume_target = current_height.min(starting_lengths.height);
|
||||||
if resume_target < current_height {
|
if resume_target < current_height {
|
||||||
info!(
|
info!(
|
||||||
"Reorg detected: rolling back from {} to {}",
|
"Reorg detected: rolling back from {} to {}",
|
||||||
@@ -451,11 +452,6 @@ impl Vecs {
|
|||||||
recovered_height
|
recovered_height
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update starting_indexes if we need to recompute from an earlier point
|
|
||||||
if starting_height < starting_indexes.height {
|
|
||||||
starting_indexes.height = starting_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2c. Validate computed versions
|
// 2c. Validate computed versions
|
||||||
debug!("validating computed versions");
|
debug!("validating computed versions");
|
||||||
let base_version = VERSION;
|
let base_version = VERSION;
|
||||||
@@ -510,11 +506,11 @@ impl Vecs {
|
|||||||
let (r1, r2) = rayon::join(
|
let (r1, r2) = rayon::join(
|
||||||
|| {
|
|| {
|
||||||
self.utxo_cohorts
|
self.utxo_cohorts
|
||||||
.compute_overlapping_vecs(starting_indexes, exit)
|
.compute_overlapping_vecs(&starting_lengths, exit)
|
||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
self.addr_cohorts
|
self.addr_cohorts
|
||||||
.compute_overlapping_vecs(starting_indexes, exit)
|
.compute_overlapping_vecs(&starting_lengths, exit)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
r1?;
|
r1?;
|
||||||
@@ -523,7 +519,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// 5b. Compute coinblocks_destroyed cumulative from raw
|
// 5b. Compute coinblocks_destroyed cumulative from raw
|
||||||
self.coinblocks_destroyed
|
self.coinblocks_destroyed
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
|
|
||||||
// 6. Compute rest part1 (day1 mappings)
|
// 6. Compute rest part1 (day1 mappings)
|
||||||
info!("Computing rest part 1...");
|
info!("Computing rest part 1...");
|
||||||
@@ -531,11 +527,11 @@ impl Vecs {
|
|||||||
let (r1, r2) = rayon::join(
|
let (r1, r2) = rayon::join(
|
||||||
|| {
|
|| {
|
||||||
self.utxo_cohorts
|
self.utxo_cohorts
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)
|
.compute_rest_part1(prices, &starting_lengths, exit)
|
||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
self.addr_cohorts
|
self.addr_cohorts
|
||||||
.compute_rest_part1(prices, starting_indexes, exit)
|
.compute_rest_part1(prices, &starting_lengths, exit)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
r1?;
|
r1?;
|
||||||
@@ -543,8 +539,8 @@ impl Vecs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 6b. Compute address count sum (by addr_type -> all)
|
// 6b. Compute address count sum (by addr_type -> all)
|
||||||
self.addrs.funded.compute_rest(starting_indexes, exit)?;
|
self.addrs.funded.compute_rest(&starting_lengths, exit)?;
|
||||||
self.addrs.empty.compute_rest(starting_indexes, exit)?;
|
self.addrs.empty.compute_rest(&starting_lengths, exit)?;
|
||||||
let t = &self.utxo_cohorts.type_;
|
let t = &self.utxo_cohorts.type_;
|
||||||
let type_supply_sats = ByAddrType::new(|filter| {
|
let type_supply_sats = ByAddrType::new(|filter| {
|
||||||
let Filter::Type(ot) = filter else {
|
let Filter::Type(ot) = filter else {
|
||||||
@@ -554,7 +550,7 @@ impl Vecs {
|
|||||||
});
|
});
|
||||||
let all_supply_sats = &self.utxo_cohorts.all.metrics.supply.total.sats.height;
|
let all_supply_sats = &self.utxo_cohorts.all.metrics.supply.total.sats.height;
|
||||||
self.addrs.reused.compute_rest(
|
self.addrs.reused.compute_rest(
|
||||||
starting_indexes,
|
&starting_lengths,
|
||||||
&outputs.by_type,
|
&outputs.by_type,
|
||||||
&inputs.by_type,
|
&inputs.by_type,
|
||||||
prices,
|
prices,
|
||||||
@@ -563,7 +559,7 @@ impl Vecs {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.addrs.respent.compute_rest(
|
self.addrs.respent.compute_rest(
|
||||||
starting_indexes,
|
&starting_lengths,
|
||||||
&outputs.by_type,
|
&outputs.by_type,
|
||||||
&inputs.by_type,
|
&inputs.by_type,
|
||||||
prices,
|
prices,
|
||||||
@@ -572,7 +568,7 @@ impl Vecs {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.addrs.exposed.compute_rest(
|
self.addrs.exposed.compute_rest(
|
||||||
starting_indexes,
|
&starting_lengths,
|
||||||
prices,
|
prices,
|
||||||
all_supply_sats,
|
all_supply_sats,
|
||||||
&type_supply_sats,
|
&type_supply_sats,
|
||||||
@@ -586,7 +582,7 @@ impl Vecs {
|
|||||||
&all_m.supply.total.sats.height,
|
&all_m.supply.total.sats.height,
|
||||||
&all_m.outputs.unspent_count.height,
|
&all_m.outputs.unspent_count.height,
|
||||||
&self.addrs.funded.all.height,
|
&self.addrs.funded.all.height,
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
for ((ot, avg), (_, funded)) in self
|
for ((ot, avg), (_, funded)) in self
|
||||||
@@ -602,14 +598,14 @@ impl Vecs {
|
|||||||
&type_m.supply.total.sats.height,
|
&type_m.supply.total.sats.height,
|
||||||
&type_m.outputs.unspent_count.height,
|
&type_m.outputs.unspent_count.height,
|
||||||
&funded.height,
|
&funded.height,
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6c. Compute total_addr_count = addr_count + empty_addr_count
|
// 6c. Compute total_addr_count = addr_count + empty_addr_count
|
||||||
self.addrs.total.compute(
|
self.addrs.total.compute(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&self.addrs.funded,
|
&self.addrs.funded,
|
||||||
&self.addrs.empty,
|
&self.addrs.empty,
|
||||||
exit,
|
exit,
|
||||||
@@ -617,10 +613,10 @@ impl Vecs {
|
|||||||
|
|
||||||
self.addrs
|
self.addrs
|
||||||
.activity
|
.activity
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.addrs
|
self.addrs
|
||||||
.new
|
.new
|
||||||
.compute(starting_indexes.height, &self.addrs.total, exit)?;
|
.compute(starting_lengths.height, &self.addrs.total, exit)?;
|
||||||
|
|
||||||
// 7. Compute rest part2 (relative metrics)
|
// 7. Compute rest part2 (relative metrics)
|
||||||
let height_to_market_cap = self
|
let height_to_market_cap = self
|
||||||
@@ -637,7 +633,7 @@ impl Vecs {
|
|||||||
self.utxo_cohorts.compute_rest_part2(
|
self.utxo_cohorts.compute_rest_part2(
|
||||||
blocks,
|
blocks,
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
&starting_lengths,
|
||||||
&height_to_market_cap,
|
&height_to_market_cap,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -661,7 +657,7 @@ impl Vecs {
|
|||||||
.read_only_clone();
|
.read_only_clone();
|
||||||
self.addr_cohorts.compute_rest_part2(
|
self.addr_cohorts.compute_rest_part2(
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
&starting_lengths,
|
||||||
&all_supply_sats,
|
&all_supply_sats,
|
||||||
&all_utxo_count,
|
&all_utxo_count,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ use brk_error::Result;
|
|||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{
|
||||||
Date, Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Indexes, Minute10, Minute30,
|
Date, Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1,
|
||||||
Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
Month3, Month6, Version, Week1, Year1, Year10,
|
||||||
};
|
};
|
||||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -141,38 +141,34 @@ impl Vecs {
|
|||||||
Ok(this)
|
Ok(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<Indexes> {
|
|
||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
|
|
||||||
self.tx_heights.update(indexer, starting_indexes.height);
|
let starting_height = indexer.safe_lengths().height;
|
||||||
|
|
||||||
|
self.tx_heights.update(indexer, starting_height);
|
||||||
|
|
||||||
// timestamp_monotonic must be computed first — other mappings read it
|
// timestamp_monotonic must be computed first — other mappings read it
|
||||||
self.timestamp
|
self.timestamp
|
||||||
.compute_monotonic(indexer, starting_indexes.height, exit)?;
|
.compute_monotonic(indexer, starting_height, exit)?;
|
||||||
|
|
||||||
self.compute_tx_indexes(indexer, &starting_indexes, exit)?;
|
self.compute_tx_indexes(indexer, exit)?;
|
||||||
self.compute_height_indexes(indexer, &starting_indexes, exit)?;
|
self.compute_height_indexes(indexer, exit)?;
|
||||||
|
|
||||||
let prev_height = starting_indexes.height.decremented().unwrap_or_default();
|
let prev_height = starting_height.decremented().unwrap_or_default();
|
||||||
|
|
||||||
self.compute_timestamp_mappings(&starting_indexes, exit)?;
|
self.compute_timestamp_mappings(indexer, exit)?;
|
||||||
|
|
||||||
let starting_day1 =
|
let starting_day1 = self.compute_calendar_mappings(indexer, prev_height, exit)?;
|
||||||
self.compute_calendar_mappings(indexer, &starting_indexes, prev_height, exit)?;
|
|
||||||
|
|
||||||
self.compute_period_vecs(&starting_indexes, prev_height, starting_day1, exit)?;
|
self.compute_period_vecs(indexer, prev_height, starting_day1, exit)?;
|
||||||
|
|
||||||
self.timestamp.compute_per_resolution(
|
self.timestamp.compute_per_resolution(
|
||||||
indexer,
|
indexer,
|
||||||
&self.height,
|
&self.height,
|
||||||
&self.halving,
|
&self.halving,
|
||||||
&self.epoch,
|
&self.epoch,
|
||||||
&starting_indexes,
|
&indexer.safe_lengths(),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -181,19 +177,15 @@ impl Vecs {
|
|||||||
let _lock = exit.lock();
|
let _lock = exit.lock();
|
||||||
db.compact_deferred_default()
|
db.compact_deferred_default()
|
||||||
});
|
});
|
||||||
Ok(starting_indexes)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_tx_indexes(
|
fn compute_tx_indexes(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_lengths = indexer.safe_lengths();
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
let (r1, r2) = rayon::join(
|
let (r1, r2) = rayon::join(
|
||||||
|| {
|
|| {
|
||||||
self.tx_index.input_count.compute_count_from_indexes(
|
self.tx_index.input_count.compute_count_from_indexes(
|
||||||
starting_indexes.tx_index,
|
starting_lengths.tx_index,
|
||||||
&indexer.vecs.transactions.first_txin_index,
|
&indexer.vecs.transactions.first_txin_index,
|
||||||
&indexer.vecs.inputs.outpoint,
|
&indexer.vecs.inputs.outpoint,
|
||||||
exit,
|
exit,
|
||||||
@@ -201,7 +193,7 @@ impl Vecs {
|
|||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
self.tx_index.output_count.compute_count_from_indexes(
|
self.tx_index.output_count.compute_count_from_indexes(
|
||||||
starting_indexes.tx_index,
|
starting_lengths.tx_index,
|
||||||
&indexer.vecs.transactions.first_txout_index,
|
&indexer.vecs.transactions.first_txout_index,
|
||||||
&indexer.vecs.outputs.value,
|
&indexer.vecs.outputs.value,
|
||||||
exit,
|
exit,
|
||||||
@@ -213,14 +205,10 @@ impl Vecs {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_height_indexes(
|
fn compute_height_indexes(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_height = indexer.safe_lengths().height;
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
self.height.tx_index_count.compute_count_from_indexes(
|
self.height.tx_index_count.compute_count_from_indexes(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexer.vecs.transactions.first_tx_index,
|
&indexer.vecs.transactions.first_tx_index,
|
||||||
&indexer.vecs.transactions.txid,
|
&indexer.vecs.transactions.txid,
|
||||||
exit,
|
exit,
|
||||||
@@ -228,15 +216,13 @@ impl Vecs {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_timestamp_mappings(
|
fn compute_timestamp_mappings(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_height = indexer.safe_lengths().height;
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
macro_rules! from_timestamp {
|
macro_rules! from_timestamp {
|
||||||
($field:ident, $period:ty) => {
|
($field:ident, $period:ty) => {
|
||||||
self.height.$field.compute_transform(
|
self.height.$field.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.timestamp.monotonic,
|
&self.timestamp.monotonic,
|
||||||
|(h, ts, _)| (h, <$period>::from_timestamp(ts)),
|
|(h, ts, _)| (h, <$period>::from_timestamp(ts)),
|
||||||
exit,
|
exit,
|
||||||
@@ -257,10 +243,11 @@ impl Vecs {
|
|||||||
fn compute_calendar_mappings(
|
fn compute_calendar_mappings(
|
||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
prev_height: Height,
|
prev_height: Height,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<Day1> {
|
) -> Result<Day1> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
|
|
||||||
let starting_day1 = self
|
let starting_day1 = self
|
||||||
.height
|
.height
|
||||||
.day1
|
.day1
|
||||||
@@ -268,7 +255,7 @@ impl Vecs {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
self.height.day1.compute_transform(
|
self.height.day1.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.timestamp.monotonic,
|
&self.timestamp.monotonic,
|
||||||
|(h, ts, ..)| (h, Day1::try_from(Date::from(ts)).unwrap()),
|
|(h, ts, ..)| (h, Day1::try_from(Date::from(ts)).unwrap()),
|
||||||
exit,
|
exit,
|
||||||
@@ -280,40 +267,40 @@ impl Vecs {
|
|||||||
starting_day1
|
starting_day1
|
||||||
};
|
};
|
||||||
|
|
||||||
self.compute_epoch(indexer, starting_indexes, exit)?;
|
self.compute_epoch(indexer, exit)?;
|
||||||
|
|
||||||
self.height.week1.compute_transform(
|
self.height.week1.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.day1,
|
&self.height.day1,
|
||||||
|(h, di, _)| (h, Week1::from(di)),
|
|(h, di, _)| (h, Week1::from(di)),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.height.month1.compute_transform(
|
self.height.month1.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.day1,
|
&self.height.day1,
|
||||||
|(h, di, _)| (h, Month1::from(di)),
|
|(h, di, _)| (h, Month1::from(di)),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.height.month3.compute_transform(
|
self.height.month3.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.month1,
|
&self.height.month1,
|
||||||
|(h, mi, _)| (h, Month3::from(mi)),
|
|(h, mi, _)| (h, Month3::from(mi)),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.height.month6.compute_transform(
|
self.height.month6.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.month1,
|
&self.height.month1,
|
||||||
|(h, mi, _)| (h, Month6::from(mi)),
|
|(h, mi, _)| (h, Month6::from(mi)),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.height.year1.compute_transform(
|
self.height.year1.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.month1,
|
&self.height.month1,
|
||||||
|(h, mi, _)| (h, Year1::from(mi)),
|
|(h, mi, _)| (h, Year1::from(mi)),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.height.year10.compute_transform(
|
self.height.year10.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.year1,
|
&self.height.year1,
|
||||||
|(h, yi, _)| (h, Year10::from(yi)),
|
|(h, yi, _)| (h, Year10::from(yi)),
|
||||||
exit,
|
exit,
|
||||||
@@ -322,30 +309,25 @@ impl Vecs {
|
|||||||
Ok(starting_day1)
|
Ok(starting_day1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_epoch(
|
fn compute_epoch(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_height = indexer.safe_lengths().height;
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: &Indexes,
|
self.height
|
||||||
exit: &Exit,
|
.epoch
|
||||||
) -> Result<()> {
|
.compute_from_index(starting_height, &indexer.vecs.blocks.weight, exit)?;
|
||||||
self.height.epoch.compute_from_index(
|
|
||||||
starting_indexes.height,
|
|
||||||
&indexer.vecs.blocks.weight,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.epoch.first_height.inner.compute_first_per_index(
|
self.epoch.first_height.inner.compute_first_per_index(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.epoch,
|
&self.height.epoch,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.height.halving.compute_from_index(
|
self.height.halving.compute_from_index(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexer.vecs.blocks.weight,
|
&indexer.vecs.blocks.weight,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.halving.first_height.inner.compute_first_per_index(
|
self.halving.first_height.inner.compute_first_per_index(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.halving,
|
&self.height.halving,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -354,15 +336,17 @@ impl Vecs {
|
|||||||
|
|
||||||
fn compute_period_vecs(
|
fn compute_period_vecs(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
prev_height: Height,
|
prev_height: Height,
|
||||||
starting_day1: Day1,
|
starting_day1: Day1,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
|
|
||||||
macro_rules! basic_period {
|
macro_rules! basic_period {
|
||||||
($period:ident) => {
|
($period:ident) => {
|
||||||
self.$period.first_height.inner.compute_first_per_index(
|
self.$period.first_height.inner.compute_first_per_index(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.$period,
|
&self.height.$period,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -376,7 +360,7 @@ impl Vecs {
|
|||||||
basic_period!(hour12);
|
basic_period!(hour12);
|
||||||
|
|
||||||
self.day1.first_height.inner.compute_first_per_index(
|
self.day1.first_height.inner.compute_first_per_index(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.day1,
|
&self.height.day1,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
@@ -391,7 +375,7 @@ impl Vecs {
|
|||||||
macro_rules! dated_period {
|
macro_rules! dated_period {
|
||||||
($period:ident) => {{
|
($period:ident) => {{
|
||||||
self.$period.first_height.inner.compute_first_per_index(
|
self.$period.first_height.inner.compute_first_per_index(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.height.$period,
|
&self.height.$period,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{
|
||||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Indexes, Minute10, Minute30, Month1,
|
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3,
|
||||||
Month3, Month6, Timestamp, Week1, Year1, Year10,
|
Month6, Timestamp, Week1, Year1, Year10,
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{
|
use vecdb::{
|
||||||
@@ -129,10 +130,10 @@ impl Timestamps {
|
|||||||
height: &super::HeightVecs,
|
height: &super::HeightVecs,
|
||||||
halving_vecs: &super::HalvingVecs,
|
halving_vecs: &super::HalvingVecs,
|
||||||
epoch_vecs: &super::EpochVecs,
|
epoch_vecs: &super::EpochVecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let prev_height = starting_indexes.height.decremented().unwrap_or_default();
|
let prev_height = starting_lengths.height.decremented().unwrap_or_default();
|
||||||
self.resolutions.halving.compute_indirect_sequential(
|
self.resolutions.halving.compute_indirect_sequential(
|
||||||
height.halving.collect_one(prev_height).unwrap_or_default(),
|
height.halving.collect_one(prev_height).unwrap_or_default(),
|
||||||
&halving_vecs.first_height,
|
&halving_vecs.first_height,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Bitcoin, Dollars, Indexes, StoredF32};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{Bitcoin, Dollars, StoredF32};
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::{Vecs, gini};
|
use super::{Vecs, gini};
|
||||||
@@ -9,33 +10,35 @@ impl Vecs {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
mining: &mining::Vecs,
|
mining: &mining::Vecs,
|
||||||
distribution: &distribution::Vecs,
|
distribution: &distribution::Vecs,
|
||||||
transactions: &transactions::Vecs,
|
transactions: &transactions::Vecs,
|
||||||
market: &market::Vecs,
|
market: &market::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
|
|
||||||
|
let starting_lengths = indexer.safe_lengths();
|
||||||
|
|
||||||
// Puell Multiple: daily_subsidy_usd / sma_365d_subsidy_usd
|
// Puell Multiple: daily_subsidy_usd / sma_365d_subsidy_usd
|
||||||
self.puell_multiple
|
self.puell_multiple
|
||||||
.bps
|
.bps
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&mining.rewards.subsidy.block.usd,
|
&mining.rewards.subsidy.block.usd,
|
||||||
&mining.rewards.subsidy.average._1y.usd.height,
|
&mining.rewards.subsidy.average._1y.usd.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Gini coefficient (UTXO distribution inequality)
|
// Gini coefficient (UTXO distribution inequality)
|
||||||
gini::compute(&mut self.gini, distribution, starting_indexes, exit)?;
|
gini::compute(&mut self.gini, distribution, indexer, exit)?;
|
||||||
|
|
||||||
// RHODL Ratio: 1d-1w realized cap / 1y-2y realized cap
|
// RHODL Ratio: 1d-1w realized cap / 1y-2y realized cap
|
||||||
self.rhodl_ratio
|
self.rhodl_ratio
|
||||||
.bps
|
.bps
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&distribution
|
&distribution
|
||||||
.utxo_cohorts
|
.utxo_cohorts
|
||||||
.age_range
|
.age_range
|
||||||
@@ -69,7 +72,7 @@ impl Vecs {
|
|||||||
self.nvt
|
self.nvt
|
||||||
.bps
|
.bps
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
market_cap,
|
market_cap,
|
||||||
&transactions.volume.transfer_volume.sum._24h.usd.height,
|
&transactions.volume.transfer_volume.sum._24h.usd.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -79,7 +82,7 @@ impl Vecs {
|
|||||||
self.thermo_cap_multiple
|
self.thermo_cap_multiple
|
||||||
.bps
|
.bps
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
market_cap,
|
market_cap,
|
||||||
&mining.rewards.subsidy.cumulative.usd.height,
|
&mining.rewards.subsidy.cumulative.usd.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -93,7 +96,7 @@ impl Vecs {
|
|||||||
self.coindays_destroyed_supply_adj
|
self.coindays_destroyed_supply_adj
|
||||||
.height
|
.height
|
||||||
.compute_transform2(
|
.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&all_activity.coindays_destroyed.sum._24h.height,
|
&all_activity.coindays_destroyed.sum._24h.height,
|
||||||
supply_total_sats,
|
supply_total_sats,
|
||||||
|(i, cdd_24h, supply_sats, ..)| {
|
|(i, cdd_24h, supply_sats, ..)| {
|
||||||
@@ -111,7 +114,7 @@ impl Vecs {
|
|||||||
self.coinyears_destroyed_supply_adj
|
self.coinyears_destroyed_supply_adj
|
||||||
.height
|
.height
|
||||||
.compute_transform2(
|
.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&all_activity.coinyears_destroyed.height,
|
&all_activity.coinyears_destroyed.height,
|
||||||
supply_total_sats,
|
supply_total_sats,
|
||||||
|(i, cyd, supply_sats, ..)| {
|
|(i, cyd, supply_sats, ..)| {
|
||||||
@@ -127,7 +130,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// Supply-Adjusted Dormancy = dormancy / circulating_supply_btc
|
// Supply-Adjusted Dormancy = dormancy / circulating_supply_btc
|
||||||
self.dormancy.supply_adj.height.compute_transform2(
|
self.dormancy.supply_adj.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&all_activity.dormancy._24h.height,
|
&all_activity.dormancy._24h.height,
|
||||||
supply_total_sats,
|
supply_total_sats,
|
||||||
|(i, dormancy, supply_sats, ..)| {
|
|(i, dormancy, supply_sats, ..)| {
|
||||||
@@ -144,7 +147,7 @@ impl Vecs {
|
|||||||
// Stock-to-Flow: supply / annual_issuance
|
// Stock-to-Flow: supply / annual_issuance
|
||||||
// annual_issuance ≈ subsidy_per_block × 52560 (blocks/year)
|
// annual_issuance ≈ subsidy_per_block × 52560 (blocks/year)
|
||||||
self.stock_to_flow.height.compute_transform2(
|
self.stock_to_flow.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
supply_total_sats,
|
supply_total_sats,
|
||||||
&mining.rewards.subsidy.block.sats,
|
&mining.rewards.subsidy.block.sats,
|
||||||
|(i, supply_sats, subsidy_sats, ..)| {
|
|(i, supply_sats, subsidy_sats, ..)| {
|
||||||
@@ -163,7 +166,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// Dormancy Flow: supply_btc / dormancy
|
// Dormancy Flow: supply_btc / dormancy
|
||||||
self.dormancy.flow.height.compute_transform2(
|
self.dormancy.flow.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
supply_total_sats,
|
supply_total_sats,
|
||||||
&all_activity.dormancy._24h.height,
|
&all_activity.dormancy._24h.height,
|
||||||
|(i, supply_sats, dormancy, ..)| {
|
|(i, supply_sats, dormancy, ..)| {
|
||||||
@@ -180,7 +183,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// Seller Exhaustion Constant: % supply_in_profit × 30d_volatility
|
// Seller Exhaustion Constant: % supply_in_profit × 30d_volatility
|
||||||
self.seller_exhaustion.height.compute_transform3(
|
self.seller_exhaustion.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&all_metrics.supply.in_profit.sats.height,
|
&all_metrics.supply.in_profit.sats.height,
|
||||||
&market.volatility._1m.height,
|
&market.volatility._1m.height,
|
||||||
supply_total_sats,
|
supply_total_sats,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{BasisPoints16, Indexes, Sats, StoredU64, Version};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{BasisPoints16, Sats, StoredU64, Version};
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
|
||||||
|
|
||||||
use crate::{distribution, internal::PercentPerBlock};
|
use crate::{distribution, internal::PercentPerBlock};
|
||||||
@@ -7,9 +8,10 @@ use crate::{distribution, internal::PercentPerBlock};
|
|||||||
pub(super) fn compute(
|
pub(super) fn compute(
|
||||||
gini: &mut PercentPerBlock<BasisPoints16>,
|
gini: &mut PercentPerBlock<BasisPoints16>,
|
||||||
distribution: &distribution::Vecs,
|
distribution: &distribution::Vecs,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let amount_range = &distribution.utxo_cohorts.amount_range;
|
let amount_range = &distribution.utxo_cohorts.amount_range;
|
||||||
|
|
||||||
let supply_vecs: Vec<&_> = amount_range
|
let supply_vecs: Vec<&_> = amount_range
|
||||||
@@ -36,11 +38,7 @@ pub(super) fn compute(
|
|||||||
.height
|
.height
|
||||||
.validate_computed_version_or_reset(source_version)?;
|
.validate_computed_version_or_reset(source_version)?;
|
||||||
|
|
||||||
let min_len = gini
|
let min_len = gini.bps.height.len().min(starting_height.to_usize());
|
||||||
.bps
|
|
||||||
.height
|
|
||||||
.len()
|
|
||||||
.min(starting_indexes.height.to_usize());
|
|
||||||
|
|
||||||
gini.bps.height.truncate_if_needed_at(min_len)?;
|
gini.bps.height.truncate_if_needed_at(min_len)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Indexer;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, Height, Indexes, StoredI8, Version};
|
use brk_types::{Cents, Height, StoredI8, Version};
|
||||||
use vecdb::{AnyVec, Database, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
use vecdb::{AnyVec, Database, Exit, ReadableVec, Rw, StorageMode, WritableVec};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -47,60 +48,61 @@ impl RarityMeterInner {
|
|||||||
&mut self,
|
&mut self,
|
||||||
models: &[&RatioPerBlockPercentiles],
|
models: &[&RatioPerBlockPercentiles],
|
||||||
spot: &impl ReadableVec<Height, Cents>,
|
spot: &impl ReadableVec<Height, Cents>,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let gather = |f: fn(&RatioPerBlockPercentiles) -> &_| -> Vec<_> {
|
let gather = |f: fn(&RatioPerBlockPercentiles) -> &_| -> Vec<_> {
|
||||||
models.iter().map(|m| f(m)).collect()
|
models.iter().map(|m| f(m)).collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Lower percentiles: max across all models (tightest lower bound)
|
// Lower percentiles: max across all models (tightest lower bound)
|
||||||
self.pct0_5.cents.height.compute_max_of_others(
|
self.pct0_5.cents.height.compute_max_of_others(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&gather(|m| &m.pct0_5.price.cents.height),
|
&gather(|m| &m.pct0_5.price.cents.height),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.pct1.cents.height.compute_max_of_others(
|
self.pct1.cents.height.compute_max_of_others(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&gather(|m| &m.pct1.price.cents.height),
|
&gather(|m| &m.pct1.price.cents.height),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.pct2.cents.height.compute_max_of_others(
|
self.pct2.cents.height.compute_max_of_others(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&gather(|m| &m.pct2.price.cents.height),
|
&gather(|m| &m.pct2.price.cents.height),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.pct5.cents.height.compute_max_of_others(
|
self.pct5.cents.height.compute_max_of_others(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&gather(|m| &m.pct5.price.cents.height),
|
&gather(|m| &m.pct5.price.cents.height),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Upper percentiles: min across all models (tightest upper bound)
|
// Upper percentiles: min across all models (tightest upper bound)
|
||||||
self.pct95.cents.height.compute_min_of_others(
|
self.pct95.cents.height.compute_min_of_others(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&gather(|m| &m.pct95.price.cents.height),
|
&gather(|m| &m.pct95.price.cents.height),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.pct98.cents.height.compute_min_of_others(
|
self.pct98.cents.height.compute_min_of_others(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&gather(|m| &m.pct98.price.cents.height),
|
&gather(|m| &m.pct98.price.cents.height),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.pct99.cents.height.compute_min_of_others(
|
self.pct99.cents.height.compute_min_of_others(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&gather(|m| &m.pct99.price.cents.height),
|
&gather(|m| &m.pct99.price.cents.height),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
self.pct99_5.cents.height.compute_min_of_others(
|
self.pct99_5.cents.height.compute_min_of_others(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&gather(|m| &m.pct99_5.price.cents.height),
|
&gather(|m| &m.pct99_5.price.cents.height),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.compute_index(spot, starting_indexes, exit)?;
|
self.compute_index(spot, indexer, exit)?;
|
||||||
|
|
||||||
self.compute_score(models, spot, starting_indexes, exit)?;
|
self.compute_score(models, spot, indexer, exit)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -108,9 +110,10 @@ impl RarityMeterInner {
|
|||||||
fn compute_index(
|
fn compute_index(
|
||||||
&mut self,
|
&mut self,
|
||||||
spot: &impl ReadableVec<Height, Cents>,
|
spot: &impl ReadableVec<Height, Cents>,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let bands = [
|
let bands = [
|
||||||
&self.pct0_5.cents.height,
|
&self.pct0_5.cents.height,
|
||||||
&self.pct1.cents.height,
|
&self.pct1.cents.height,
|
||||||
@@ -128,9 +131,7 @@ impl RarityMeterInner {
|
|||||||
self.index
|
self.index
|
||||||
.height
|
.height
|
||||||
.validate_computed_version_or_reset(dep_version)?;
|
.validate_computed_version_or_reset(dep_version)?;
|
||||||
self.index
|
self.index.height.truncate_if_needed(starting_height)?;
|
||||||
.height
|
|
||||||
.truncate_if_needed(starting_indexes.height)?;
|
|
||||||
|
|
||||||
self.index.height.repeat_until_complete(exit, |vec| {
|
self.index.height.repeat_until_complete(exit, |vec| {
|
||||||
let skip = vec.len();
|
let skip = vec.len();
|
||||||
@@ -186,9 +187,10 @@ impl RarityMeterInner {
|
|||||||
&mut self,
|
&mut self,
|
||||||
models: &[&RatioPerBlockPercentiles],
|
models: &[&RatioPerBlockPercentiles],
|
||||||
spot: &impl ReadableVec<Height, Cents>,
|
spot: &impl ReadableVec<Height, Cents>,
|
||||||
starting_indexes: &Indexes,
|
indexer: &Indexer,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let dep_version: Version = models
|
let dep_version: Version = models
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
@@ -207,9 +209,7 @@ impl RarityMeterInner {
|
|||||||
self.score
|
self.score
|
||||||
.height
|
.height
|
||||||
.validate_computed_version_or_reset(dep_version)?;
|
.validate_computed_version_or_reset(dep_version)?;
|
||||||
self.score
|
self.score.height.truncate_if_needed(starting_height)?;
|
||||||
.height
|
|
||||||
.truncate_if_needed(starting_indexes.height)?;
|
|
||||||
|
|
||||||
self.score.height.repeat_until_complete(exit, |vec| {
|
self.score.height.repeat_until_complete(exit, |vec| {
|
||||||
let skip = vec.len();
|
let skip = vec.len();
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
mod inner;
|
mod inner;
|
||||||
|
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Indexer;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Indexes, Version};
|
use brk_types::Version;
|
||||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{distribution, indexes, prices};
|
use crate::{distribution, indexes, prices};
|
||||||
@@ -34,9 +35,9 @@ impl RarityMeter {
|
|||||||
|
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
distribution: &distribution::Vecs,
|
distribution: &distribution::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let realized = &distribution.utxo_cohorts.all.metrics.realized;
|
let realized = &distribution.utxo_cohorts.all.metrics.realized;
|
||||||
@@ -55,7 +56,7 @@ impl RarityMeter {
|
|||||||
<h_realized.capitalized.price.percentiles,
|
<h_realized.capitalized.price.percentiles,
|
||||||
],
|
],
|
||||||
spot,
|
spot,
|
||||||
starting_indexes,
|
indexer,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ impl RarityMeter {
|
|||||||
&sth_realized.capitalized.price.percentiles,
|
&sth_realized.capitalized.price.percentiles,
|
||||||
],
|
],
|
||||||
spot,
|
spot,
|
||||||
starting_indexes,
|
indexer,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ impl RarityMeter {
|
|||||||
<h_realized.capitalized.price.percentiles,
|
<h_realized.capitalized.price.percentiles,
|
||||||
],
|
],
|
||||||
spot,
|
spot,
|
||||||
starting_indexes,
|
indexer,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,24 @@
|
|||||||
use brk_error::{OptionData, Result};
|
use brk_error::{OptionData, Result};
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{Indexes, StoredU64};
|
use brk_types::StoredU64;
|
||||||
use vecdb::{AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
|
use vecdb::{AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
|
||||||
|
|
||||||
use super::{Vecs, WithInputTypes};
|
use super::{Vecs, WithInputTypes};
|
||||||
use crate::internal::{CoinbasePolicy, PerBlockCumulativeRolling, walk_blocks};
|
use crate::internal::{CoinbasePolicy, PerBlockCumulativeRolling, walk_blocks};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_lengths = indexer.safe_lengths();
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
let dep_version = indexer.vecs.inputs.output_type.version()
|
let dep_version = indexer.vecs.inputs.output_type.version()
|
||||||
+ indexer.vecs.transactions.first_tx_index.version()
|
+ indexer.vecs.transactions.first_tx_index.version()
|
||||||
+ indexer.vecs.transactions.first_txin_index.version()
|
+ indexer.vecs.transactions.first_txin_index.version()
|
||||||
+ indexer.vecs.transactions.txid.version();
|
+ indexer.vecs.transactions.txid.version();
|
||||||
|
|
||||||
self.input_count
|
self.input_count
|
||||||
.validate_and_truncate(dep_version, starting_indexes.height)?;
|
.validate_and_truncate(dep_version, starting_lengths.height)?;
|
||||||
self.tx_count
|
self.tx_count
|
||||||
.validate_and_truncate(dep_version, starting_indexes.height)?;
|
.validate_and_truncate(dep_version, starting_lengths.height)?;
|
||||||
|
|
||||||
let skip = self
|
let skip = self
|
||||||
.input_count
|
.input_count
|
||||||
@@ -84,15 +81,15 @@ impl Vecs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.input_count
|
self.input_count
|
||||||
.compute_rest(starting_indexes.height, exit)?;
|
.compute_rest(starting_lengths.height, exit)?;
|
||||||
self.tx_count.compute_rest(starting_indexes.height, exit)?;
|
self.tx_count.compute_rest(starting_lengths.height, exit)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (otype, source) in self.input_count.by_type.iter_typed() {
|
for (otype, source) in self.input_count.by_type.iter_typed() {
|
||||||
self.input_share.get_mut(otype).compute_count_ratio(
|
self.input_share.get_mut(otype).compute_count_ratio(
|
||||||
source,
|
source,
|
||||||
&self.input_count.all,
|
&self.input_count.all,
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
@@ -101,7 +98,7 @@ impl Vecs {
|
|||||||
self.tx_share.get_mut(otype).compute_count_ratio(
|
self.tx_share.get_mut(otype).compute_count_ratio(
|
||||||
source,
|
source,
|
||||||
&self.tx_count.all,
|
&self.tx_count.all,
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::Indexes;
|
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -12,16 +11,16 @@ impl Vecs {
|
|||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
|
|
||||||
self.spent.compute(indexer, starting_indexes, exit)?;
|
let starting_lengths = indexer.safe_lengths();
|
||||||
self.count
|
|
||||||
.compute(indexer, indexes, blocks, starting_indexes, exit)?;
|
self.spent.compute(indexer, exit)?;
|
||||||
self.per_sec.compute(&self.count, starting_indexes, exit)?;
|
self.count.compute(indexer, indexes, blocks, exit)?;
|
||||||
self.by_type.compute(indexer, starting_indexes, exit)?;
|
self.per_sec.compute(&self.count, &starting_lengths, exit)?;
|
||||||
|
self.by_type.compute(indexer, exit)?;
|
||||||
|
|
||||||
let exit = exit.clone();
|
let exit = exit.clone();
|
||||||
self.db.run_bg(move |db| {
|
self.db.run_bg(move |db| {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::Indexes;
|
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -12,12 +11,12 @@ impl Vecs {
|
|||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let window_starts = blocks.lookback.window_starts();
|
let window_starts = blocks.lookback.window_starts();
|
||||||
self.0.compute(
|
self.0.compute(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&indexes.tx_index.input_count,
|
&indexes.tx_index.input_count,
|
||||||
&indexer.vecs.transactions.first_tx_index,
|
&indexer.vecs.transactions.first_tx_index,
|
||||||
&indexes.height.tx_index_count,
|
&indexes.height.tx_index_count,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Indexes, StoredF32};
|
use brk_indexer::Lengths;
|
||||||
|
use brk_types::StoredF32;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -9,10 +10,10 @@ impl Vecs {
|
|||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
count: &CountVecs,
|
count: &CountVecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let h = starting_indexes.height;
|
let h = starting_lengths.height;
|
||||||
let sums = count.rolling.sum.0.as_array();
|
let sums = count.rolling.sum.0.as_array();
|
||||||
let per_sec = self.0.as_mut_array();
|
let per_sec = self.0.as_mut_array();
|
||||||
for (i, &secs) in Windows::<()>::SECS.iter().enumerate() {
|
for (i, &secs) in Windows::<()>::SECS.iter().enumerate() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{Indexes, Sats, TxIndex, TxOutIndex, Vout};
|
use brk_types::{Sats, TxIndex, TxOutIndex, Vout};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
|
||||||
@@ -10,12 +10,8 @@ use super::Vecs;
|
|||||||
const BATCH_SIZE: usize = 2 * 1024 * 1024 * 1024 / size_of::<Entry>();
|
const BATCH_SIZE: usize = 2 * 1024 * 1024 * 1024 / size_of::<Entry>();
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
let starting_lengths = indexer.safe_lengths();
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
// Validate computed versions against dependencies
|
// Validate computed versions against dependencies
|
||||||
let dep_version = indexer.vecs.inputs.outpoint.version()
|
let dep_version = indexer.vecs.inputs.outpoint.version()
|
||||||
+ indexer.vecs.transactions.first_txout_index.version()
|
+ indexer.vecs.transactions.first_txout_index.version()
|
||||||
@@ -31,7 +27,7 @@ impl Vecs {
|
|||||||
|
|
||||||
let len1 = self.txout_index.len();
|
let len1 = self.txout_index.len();
|
||||||
let len2 = self.value.len();
|
let len2 = self.value.len();
|
||||||
let starting = starting_indexes.txin_index.to_usize();
|
let starting = starting_lengths.txin_index.to_usize();
|
||||||
let min = len1.min(len2).min(starting);
|
let min = len1.min(len2).min(starting);
|
||||||
|
|
||||||
if min >= target {
|
if min >= target {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
|
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{
|
use brk_types::{
|
||||||
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Indexes, Minute10, Minute30, Month1,
|
Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3,
|
||||||
Month3, Month6, Version, Week1, Year1, Year10,
|
Month6, Version, Week1, Year1, Year10,
|
||||||
};
|
};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
@@ -74,12 +75,12 @@ where
|
|||||||
|
|
||||||
pub(crate) fn compute_first(
|
pub(crate) fn compute_first(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_source: &impl ReadableVec<Height, T>,
|
height_source: &impl ReadableVec<Height, T>,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let prev_height = starting_indexes.height.decremented().unwrap_or_default();
|
let prev_height = starting_lengths.height.decremented().unwrap_or_default();
|
||||||
|
|
||||||
macro_rules! period {
|
macro_rules! period {
|
||||||
($field:ident) => {
|
($field:ident) => {
|
||||||
@@ -117,13 +118,13 @@ where
|
|||||||
|
|
||||||
pub(crate) fn compute_max(
|
pub(crate) fn compute_max(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_source: &impl ReadableVec<Height, T>,
|
height_source: &impl ReadableVec<Height, T>,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let src_len = height_source.len();
|
let src_len = height_source.len();
|
||||||
let prev_height = starting_indexes.height.decremented().unwrap_or_default();
|
let prev_height = starting_lengths.height.decremented().unwrap_or_default();
|
||||||
|
|
||||||
macro_rules! period {
|
macro_rules! period {
|
||||||
($field:ident) => {
|
($field:ident) => {
|
||||||
@@ -164,13 +165,13 @@ where
|
|||||||
|
|
||||||
pub(crate) fn compute_min(
|
pub(crate) fn compute_min(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
height_source: &impl ReadableVec<Height, T>,
|
height_source: &impl ReadableVec<Height, T>,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let src_len = height_source.len();
|
let src_len = height_source.len();
|
||||||
let prev_height = starting_indexes.height.decremented().unwrap_or_default();
|
let prev_height = starting_lengths.height.decremented().unwrap_or_default();
|
||||||
|
|
||||||
macro_rules! period {
|
macro_rules! period {
|
||||||
($field:ident) => {
|
($field:ident) => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{BasisPoints32, Cents, Height, Indexes, StoredF32, Version};
|
use brk_types::{BasisPoints32, Cents, Height, StoredF32, Version};
|
||||||
use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
use vecdb::{Database, Exit, ReadableCloneableVec, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -50,13 +51,13 @@ impl<B: BpsType> RatioPerBlock<B> {
|
|||||||
impl RatioPerBlock<BasisPoints32> {
|
impl RatioPerBlock<BasisPoints32> {
|
||||||
pub(crate) fn compute_ratio(
|
pub(crate) fn compute_ratio(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
close_price: &impl ReadableVec<Height, Cents>,
|
close_price: &impl ReadableVec<Height, Cents>,
|
||||||
series_price: &impl ReadableVec<Height, Cents>,
|
series_price: &impl ReadableVec<Height, Cents>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.bps.height.compute_transform2(
|
self.bps.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
close_price,
|
close_price,
|
||||||
series_price,
|
series_price,
|
||||||
|(i, close, price, ..)| {
|
|(i, close, price, ..)| {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{BasisPoints32, Cents, Height, Indexes, StoredF32, Version};
|
use brk_types::{BasisPoints32, Cents, Height, StoredF32, Version};
|
||||||
use vecdb::{
|
use vecdb::{
|
||||||
AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode, VecIndex,
|
AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode, VecIndex,
|
||||||
WritableVec,
|
WritableVec,
|
||||||
@@ -86,7 +87,7 @@ impl RatioPerBlockPercentiles {
|
|||||||
|
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
||||||
series_price: &impl ReadableVec<Height, Cents>,
|
series_price: &impl ReadableVec<Height, Cents>,
|
||||||
@@ -102,7 +103,7 @@ impl RatioPerBlockPercentiles {
|
|||||||
.map(|v| Height::from(v.len()))
|
.map(|v| Height::from(v.len()))
|
||||||
.min()
|
.min()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.min(starting_indexes.height);
|
.min(starting_lengths.height);
|
||||||
|
|
||||||
let start = starting_height.to_usize();
|
let start = starting_height.to_usize();
|
||||||
let ratio_len = ratio_source.len();
|
let ratio_len = ratio_source.len();
|
||||||
@@ -159,7 +160,7 @@ impl RatioPerBlockPercentiles {
|
|||||||
.price
|
.price
|
||||||
.cents
|
.cents
|
||||||
.compute_binary::<Cents, BasisPoints32, PriceTimesRatioBp32Cents>(
|
.compute_binary::<Cents, BasisPoints32, PriceTimesRatioBp32Cents>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
series_price,
|
series_price,
|
||||||
&self.$band.ratio.bps.height,
|
&self.$band.ratio.bps.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{BasisPoints32, Cents, Dollars, Height, Indexes, SatsFract, StoredF32, Version};
|
use brk_types::{BasisPoints32, Cents, Dollars, Height, SatsFract, StoredF32, Version};
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode};
|
use vecdb::{Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
@@ -39,12 +40,12 @@ impl PriceWithRatioPerBlock {
|
|||||||
/// Compute ratio from close price and this metric's price.
|
/// Compute ratio from close price and this metric's price.
|
||||||
pub(crate) fn compute_ratio(
|
pub(crate) fn compute_ratio(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
close_price: &impl ReadableVec<Height, Cents>,
|
close_price: &impl ReadableVec<Height, Cents>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.bps.height.compute_transform2(
|
self.bps.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
close_price,
|
close_price,
|
||||||
&self.cents.height,
|
&self.cents.height,
|
||||||
|(i, close, price, ..)| {
|
|(i, close, price, ..)| {
|
||||||
@@ -63,7 +64,7 @@ impl PriceWithRatioPerBlock {
|
|||||||
pub(crate) fn compute_all<F>(
|
pub(crate) fn compute_all<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
mut compute_price: F,
|
mut compute_price: F,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
@@ -71,7 +72,7 @@ impl PriceWithRatioPerBlock {
|
|||||||
F: FnMut(&mut EagerVec<PcoVec<Height, Cents>>) -> Result<()>,
|
F: FnMut(&mut EagerVec<PcoVec<Height, Cents>>) -> Result<()>,
|
||||||
{
|
{
|
||||||
compute_price(&mut self.cents.height)?;
|
compute_price(&mut self.cents.height)?;
|
||||||
self.compute_ratio(starting_indexes, &prices.spot.cents.height, exit)
|
self.compute_ratio(starting_lengths, &prices.spot.cents.height, exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,14 +102,14 @@ impl PriceWithRatioExtendedPerBlock {
|
|||||||
pub(crate) fn compute_rest(
|
pub(crate) fn compute_rest(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let close_price = &prices.spot.cents.height;
|
let close_price = &prices.spot.cents.height;
|
||||||
self.base
|
self.base
|
||||||
.compute_ratio(starting_indexes, close_price, exit)?;
|
.compute_ratio(starting_lengths, close_price, exit)?;
|
||||||
self.percentiles.compute(
|
self.percentiles.compute(
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
exit,
|
exit,
|
||||||
&self.base.ratio.height,
|
&self.base.ratio.height,
|
||||||
&self.base.cents.height,
|
&self.base.cents.height,
|
||||||
@@ -120,7 +121,7 @@ impl PriceWithRatioExtendedPerBlock {
|
|||||||
pub(crate) fn compute_all<F>(
|
pub(crate) fn compute_all<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
mut compute_price: F,
|
mut compute_price: F,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
@@ -128,6 +129,6 @@ impl PriceWithRatioExtendedPerBlock {
|
|||||||
F: FnMut(&mut EagerVec<PcoVec<Height, Cents>>) -> Result<()>,
|
F: FnMut(&mut EagerVec<PcoVec<Height, Cents>>) -> Result<()>,
|
||||||
{
|
{
|
||||||
compute_price(&mut self.base.cents.height)?;
|
compute_price(&mut self.base.cents.height)?;
|
||||||
self.compute_rest(prices, starting_indexes, exit)
|
self.compute_rest(prices, starting_lengths, exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{BasisPoints32, Height, Indexes, StoredF32, Version};
|
use brk_types::{BasisPoints32, Height, StoredF32, Version};
|
||||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{blocks, indexes};
|
use crate::{blocks, indexes};
|
||||||
@@ -52,13 +53,13 @@ impl RatioSma {
|
|||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Expanding SMA (all history)
|
// Expanding SMA (all history)
|
||||||
self.all.bps.height.compute_sma_(
|
self.all.bps.height.compute_sma_(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
ratio_source,
|
ratio_source,
|
||||||
usize::MAX,
|
usize::MAX,
|
||||||
exit,
|
exit,
|
||||||
@@ -74,7 +75,7 @@ impl RatioSma {
|
|||||||
(&mut self._4y, &blocks.lookback._4y),
|
(&mut self._4y, &blocks.lookback._4y),
|
||||||
] {
|
] {
|
||||||
sma.bps.height.compute_rolling_average(
|
sma.bps.height.compute_rolling_average(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
lookback,
|
lookback,
|
||||||
ratio_source,
|
ratio_source,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, Height, Indexes, StoredF32, Version};
|
use brk_types::{Cents, Height, StoredF32, Version};
|
||||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{blocks, indexes, internal::StdDevPerBlockExtended};
|
use crate::{blocks, indexes, internal::StdDevPerBlockExtended};
|
||||||
@@ -43,7 +44,7 @@ impl RatioPerBlockStdDevBands {
|
|||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
ratio_source: &impl ReadableVec<Height, StoredF32>,
|
||||||
series_price: &impl ReadableVec<Height, Cents>,
|
series_price: &impl ReadableVec<Height, Cents>,
|
||||||
@@ -55,8 +56,8 @@ impl RatioPerBlockStdDevBands {
|
|||||||
(&mut self._2y, &sma._2y.ratio.height),
|
(&mut self._2y, &sma._2y.ratio.height),
|
||||||
(&mut self._1y, &sma._1y.ratio.height),
|
(&mut self._1y, &sma._1y.ratio.height),
|
||||||
] {
|
] {
|
||||||
sd.compute_all(blocks, starting_indexes, exit, ratio_source, sma_ratio)?;
|
sd.compute_all(blocks, starting_lengths, exit, ratio_source, sma_ratio)?;
|
||||||
sd.compute_cents_bands(starting_indexes, series_price, sma_ratio, exit)?;
|
sd.compute_cents_bands(starting_lengths, series_price, sma_ratio, exit)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, StoredF32, Version};
|
use brk_types::{Height, StoredF32, Version};
|
||||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{blocks, indexes, internal::PerBlock};
|
use crate::{blocks, indexes, internal::PerBlock};
|
||||||
@@ -35,20 +36,20 @@ impl StdDevPerBlock {
|
|||||||
pub(crate) fn compute_all(
|
pub(crate) fn compute_all(
|
||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
source: &impl ReadableVec<Height, StoredF32>,
|
source: &impl ReadableVec<Height, StoredF32>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if self.days == usize::MAX {
|
if self.days == usize::MAX {
|
||||||
self.sma.height.compute_sma_(
|
self.sma.height.compute_sma_(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
source,
|
source,
|
||||||
usize::MAX,
|
usize::MAX,
|
||||||
exit,
|
exit,
|
||||||
None,
|
None,
|
||||||
)?;
|
)?;
|
||||||
self.sd.height.compute_expanding_sd(
|
self.sd.height.compute_expanding_sd(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
source,
|
source,
|
||||||
&self.sma.height,
|
&self.sma.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -59,14 +60,14 @@ impl StdDevPerBlock {
|
|||||||
let window_starts = blocks.lookback.start_vec(self.days);
|
let window_starts = blocks.lookback.start_vec(self.days);
|
||||||
|
|
||||||
self.sma.height.compute_rolling_average(
|
self.sma.height.compute_rolling_average(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
window_starts,
|
window_starts,
|
||||||
source,
|
source,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.sd.height.compute_rolling_sd(
|
self.sd.height.compute_rolling_sd(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
window_starts,
|
window_starts,
|
||||||
source,
|
source,
|
||||||
&self.sma.height,
|
&self.sma.height,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Cents, Height, Indexes, StoredF32, Version};
|
use brk_types::{Cents, Height, StoredF32, Version};
|
||||||
use vecdb::{
|
use vecdb::{
|
||||||
AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode, VecIndex,
|
AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, ReadableVec, Rw, StorageMode, VecIndex,
|
||||||
WritableVec,
|
WritableVec,
|
||||||
@@ -95,7 +96,7 @@ impl StdDevPerBlockExtended {
|
|||||||
pub(crate) fn compute_all(
|
pub(crate) fn compute_all(
|
||||||
&mut self,
|
&mut self,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
source: &impl ReadableVec<Height, StoredF32>,
|
source: &impl ReadableVec<Height, StoredF32>,
|
||||||
sma: &impl ReadableVec<Height, StoredF32>,
|
sma: &impl ReadableVec<Height, StoredF32>,
|
||||||
@@ -103,11 +104,11 @@ impl StdDevPerBlockExtended {
|
|||||||
if self.days == usize::MAX {
|
if self.days == usize::MAX {
|
||||||
self.sd
|
self.sd
|
||||||
.height
|
.height
|
||||||
.compute_expanding_sd(starting_indexes.height, source, sma, exit)?;
|
.compute_expanding_sd(starting_lengths.height, source, sma, exit)?;
|
||||||
} else {
|
} else {
|
||||||
let window_starts = blocks.lookback.start_vec(self.days);
|
let window_starts = blocks.lookback.start_vec(self.days);
|
||||||
self.sd.height.compute_rolling_sd(
|
self.sd.height.compute_rolling_sd(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
window_starts,
|
window_starts,
|
||||||
source,
|
source,
|
||||||
sma,
|
sma,
|
||||||
@@ -115,12 +116,12 @@ impl StdDevPerBlockExtended {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.compute_bands(starting_indexes, exit, sma, source)
|
self.compute_bands(starting_lengths, exit, sma, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_bands(
|
fn compute_bands(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
sma: &impl ReadableVec<Height, StoredF32>,
|
sma: &impl ReadableVec<Height, StoredF32>,
|
||||||
source: &impl ReadableVec<Height, StoredF32>,
|
source: &impl ReadableVec<Height, StoredF32>,
|
||||||
@@ -138,7 +139,7 @@ impl StdDevPerBlockExtended {
|
|||||||
.map(|v| Height::from(v.len()))
|
.map(|v| Height::from(v.len()))
|
||||||
.min()
|
.min()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.min(starting_indexes.height);
|
.min(starting_lengths.height);
|
||||||
|
|
||||||
let start = starting_height.to_usize();
|
let start = starting_height.to_usize();
|
||||||
|
|
||||||
@@ -167,7 +168,7 @@ impl StdDevPerBlockExtended {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.zscore.height.compute_zscore(
|
self.zscore.height.compute_zscore(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
source,
|
source,
|
||||||
sma,
|
sma,
|
||||||
&self.sd.height,
|
&self.sd.height,
|
||||||
@@ -179,7 +180,7 @@ impl StdDevPerBlockExtended {
|
|||||||
|
|
||||||
pub(crate) fn compute_cents_bands(
|
pub(crate) fn compute_cents_bands(
|
||||||
&mut self,
|
&mut self,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
series_price: &impl ReadableVec<Height, Cents>,
|
series_price: &impl ReadableVec<Height, Cents>,
|
||||||
sma: &impl ReadableVec<Height, StoredF32>,
|
sma: &impl ReadableVec<Height, StoredF32>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
@@ -189,7 +190,7 @@ impl StdDevPerBlockExtended {
|
|||||||
$price
|
$price
|
||||||
.cents
|
.cents
|
||||||
.compute_binary::<Cents, StoredF32, PriceTimesRatioCents>(
|
.compute_binary::<Cents, StoredF32, PriceTimesRatioCents>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
series_price,
|
series_price,
|
||||||
$band_source,
|
$band_source,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::{Indexer, Lengths};
|
||||||
|
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Indexes, TxIndex, VSize};
|
use brk_types::{TxIndex, VSize};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode, Version};
|
use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode, Version};
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
tx_index_source: &impl ReadableVec<TxIndex, T>,
|
tx_index_source: &impl ReadableVec<TxIndex, T>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
@@ -76,7 +76,7 @@ where
|
|||||||
T: Copy + Ord + From<f64> + Default,
|
T: Copy + Ord + From<f64> + Default,
|
||||||
f64: From<T>,
|
f64: From<T>,
|
||||||
{
|
{
|
||||||
self.derive_from_with_skip(indexer, indexes, starting_indexes, tx_index_source, exit, 0)
|
self.derive_from_with_skip(indexer, indexes, starting_lengths, tx_index_source, exit, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@@ -84,7 +84,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
tx_index_source: &impl ReadableVec<TxIndex, T>,
|
tx_index_source: &impl ReadableVec<TxIndex, T>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
skip_count: usize,
|
skip_count: usize,
|
||||||
@@ -94,7 +94,7 @@ where
|
|||||||
f64: From<T>,
|
f64: From<T>,
|
||||||
{
|
{
|
||||||
self.block.compute_with_skip(
|
self.block.compute_with_skip(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
tx_index_source,
|
tx_index_source,
|
||||||
&indexer.vecs.transactions.first_tx_index,
|
&indexer.vecs.transactions.first_tx_index,
|
||||||
&indexes.height.tx_index_count,
|
&indexes.height.tx_index_count,
|
||||||
@@ -103,7 +103,7 @@ where
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.distribution._6b.compute_from_nblocks(
|
self.distribution._6b.compute_from_nblocks(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
tx_index_source,
|
tx_index_source,
|
||||||
&indexer.vecs.transactions.first_tx_index,
|
&indexer.vecs.transactions.first_tx_index,
|
||||||
&indexes.height.tx_index_count,
|
&indexes.height.tx_index_count,
|
||||||
@@ -121,7 +121,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
tx_index_source: &impl ReadableVec<TxIndex, T>,
|
tx_index_source: &impl ReadableVec<TxIndex, T>,
|
||||||
vsize_source: &impl ReadableVec<TxIndex, VSize>,
|
vsize_source: &impl ReadableVec<TxIndex, VSize>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
@@ -132,7 +132,7 @@ where
|
|||||||
f64: From<T>,
|
f64: From<T>,
|
||||||
{
|
{
|
||||||
self.block.compute_with_skip_weighted(
|
self.block.compute_with_skip_weighted(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
tx_index_source,
|
tx_index_source,
|
||||||
vsize_source,
|
vsize_source,
|
||||||
&indexer.vecs.transactions.first_tx_index,
|
&indexer.vecs.transactions.first_tx_index,
|
||||||
@@ -142,7 +142,7 @@ where
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.distribution._6b.compute_from_nblocks(
|
self.distribution._6b.compute_from_nblocks(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
tx_index_source,
|
tx_index_source,
|
||||||
&indexer.vecs.transactions.first_tx_index,
|
&indexer.vecs.transactions.first_tx_index,
|
||||||
&indexes.height.tx_index_count,
|
&indexes.height.tx_index_count,
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
//! and stored rather than lazily derived.
|
//! and stored rather than lazily derived.
|
||||||
|
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::{Indexer, Lengths};
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Indexes, TxIndex, VSize};
|
use brk_types::{TxIndex, VSize};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use vecdb::{
|
use vecdb::{
|
||||||
Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableVec, Rw, StorageMode, Version,
|
Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableVec, Rw, StorageMode, Version,
|
||||||
@@ -50,7 +50,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
skip_count: usize,
|
skip_count: usize,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
@@ -61,7 +61,7 @@ where
|
|||||||
self.distribution.derive_from_with_skip(
|
self.distribution.derive_from_with_skip(
|
||||||
indexer,
|
indexer,
|
||||||
indexes,
|
indexes,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.tx_index,
|
&self.tx_index,
|
||||||
exit,
|
exit,
|
||||||
skip_count,
|
skip_count,
|
||||||
@@ -73,7 +73,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
vsize_source: &impl ReadableVec<TxIndex, VSize>,
|
vsize_source: &impl ReadableVec<TxIndex, VSize>,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
skip_count: usize,
|
skip_count: usize,
|
||||||
@@ -85,7 +85,7 @@ where
|
|||||||
self.distribution.derive_from_with_skip_weighted(
|
self.distribution.derive_from_with_skip_weighted(
|
||||||
indexer,
|
indexer,
|
||||||
indexes,
|
indexes,
|
||||||
starting_indexes,
|
starting_lengths,
|
||||||
&self.tx_index,
|
&self.tx_index,
|
||||||
vsize_source,
|
vsize_source,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::{Indexer, Lengths};
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Indexes, TxIndex};
|
use brk_types::TxIndex;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use vecdb::{Database, Exit, LazyVecFrom2, ReadableVec, Rw, StorageMode, Version};
|
use vecdb::{Database, Exit, LazyVecFrom2, ReadableVec, Rw, StorageMode, Version};
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_lengths: &Lengths,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
@@ -55,6 +55,6 @@ where
|
|||||||
LazyVecFrom2<TxIndex, T, TxIndex, S1, TxIndex, S2>: ReadableVec<TxIndex, T>,
|
LazyVecFrom2<TxIndex, T, TxIndex, S1, TxIndex, S2>: ReadableVec<TxIndex, T>,
|
||||||
{
|
{
|
||||||
self.distribution
|
self.distribution
|
||||||
.derive_from(indexer, indexes, starting_indexes, &self.tx_index, exit)
|
.derive_from(indexer, indexes, starting_lengths, &self.tx_index, exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
use brk_cohort::ByAddrType;
|
use brk_cohort::ByAddrType;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
use brk_indexer::Lengths;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Height, Indexes, Sats, Version};
|
use brk_types::{Height, Sats, Version};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, WritableVec};
|
||||||
@@ -83,12 +84,12 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Compute `all.height` as the per-block sum of the per-type vecs.
|
/// Compute `all.height` as the per-block sum of the per-type vecs.
|
||||||
pub(crate) fn compute_rest(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
|
pub(crate) fn compute_rest(&mut self, starting_lengths: &Lengths, exit: &Exit) -> Result<()> {
|
||||||
let sources: Vec<&EagerVec<PcoVec<Height, T>>> =
|
let sources: Vec<&EagerVec<PcoVec<Height, T>>> =
|
||||||
self.by_addr_type.values().map(|v| &v.height).collect();
|
self.by_addr_type.values().map(|v| &v.height).collect();
|
||||||
self.all
|
self.all
|
||||||
.height
|
.height
|
||||||
.compute_sum_of_others(starting_indexes.height, &sources, exit)?;
|
.compute_sum_of_others(starting_lengths.height, &sources, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{BasisPointsSigned32, Bitcoin, Cents, Date, Day1, Dollars, Indexes, Sats};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{BasisPointsSigned32, Bitcoin, Cents, Date, Day1, Dollars, Sats};
|
||||||
use vecdb::{AnyVec, Exit, ReadableOptionVec, ReadableVec, VecIndex};
|
use vecdb::{AnyVec, Exit, ReadableOptionVec, ReadableVec, VecIndex};
|
||||||
|
|
||||||
use super::{ByDcaPeriod, Vecs};
|
use super::{ByDcaPeriod, Vecs};
|
||||||
@@ -10,15 +11,16 @@ const DCA_AMOUNT: Dollars = Dollars::mint(100.0);
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
lookback: &market::lookback::Vecs,
|
lookback: &market::lookback::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
|
|
||||||
|
let starting_lengths = indexer.safe_lengths();
|
||||||
let h2d = &indexes.height.day1;
|
let h2d = &indexes.height.day1;
|
||||||
let close = &prices.split.close.usd.day1;
|
let close = &prices.split.close.usd.day1;
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ impl Vecs {
|
|||||||
{
|
{
|
||||||
let mut last_di: Option<Day1> = None;
|
let mut last_di: Option<Day1> = None;
|
||||||
self.sats_per_day.compute_transform(
|
self.sats_per_day.compute_transform(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
h2d,
|
h2d,
|
||||||
|(h, di, _)| {
|
|(h, di, _)| {
|
||||||
if last_di.is_none() && h.to_usize() > 0 {
|
if last_di.is_none() && h.to_usize() > 0 {
|
||||||
@@ -55,7 +57,7 @@ impl Vecs {
|
|||||||
for (stack, days) in self.period.dca_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);
|
let window_starts = blocks.lookback.start_vec(days as usize);
|
||||||
stack.sats.height.compute_rolling_sum(
|
stack.sats.height.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
window_starts,
|
window_starts,
|
||||||
&self.sats_per_day,
|
&self.sats_per_day,
|
||||||
exit,
|
exit,
|
||||||
@@ -64,11 +66,11 @@ impl Vecs {
|
|||||||
|
|
||||||
// DCA by period - stack cents (sats × price)
|
// DCA by period - stack cents (sats × price)
|
||||||
for stack in self.period.dca_stack.iter_mut() {
|
for stack in self.period.dca_stack.iter_mut() {
|
||||||
stack.compute(prices, starting_indexes.height, exit)?;
|
stack.compute(prices, starting_lengths.height, exit)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DCA by period - average price (derived from stack)
|
// DCA by period - average price (derived from stack)
|
||||||
let starting_height = starting_indexes.height.to_usize();
|
let starting_height_usize = starting_lengths.height.to_usize();
|
||||||
for (average_price, stack, days) in self
|
for (average_price, stack, days) in self
|
||||||
.period
|
.period
|
||||||
.dca_cost_basis
|
.dca_cost_basis
|
||||||
@@ -76,7 +78,7 @@ impl Vecs {
|
|||||||
{
|
{
|
||||||
let days = days as usize;
|
let days = days as usize;
|
||||||
average_price.cents.height.compute_transform2(
|
average_price.cents.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
h2d,
|
h2d,
|
||||||
&stack.sats.height,
|
&stack.sats.height,
|
||||||
|(h, di, stack_sats, ..)| {
|
|(h, di, stack_sats, ..)| {
|
||||||
@@ -101,7 +103,7 @@ impl Vecs {
|
|||||||
.zip(self.period.dca_cost_basis.iter_with_days())
|
.zip(self.period.dca_cost_basis.iter_with_days())
|
||||||
{
|
{
|
||||||
returns.compute_binary::<Cents, Cents, RatioDiffCentsBps32>(
|
returns.compute_binary::<Cents, Cents, RatioDiffCentsBps32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&average_price.cents.height,
|
&average_price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -116,7 +118,7 @@ impl Vecs {
|
|||||||
{
|
{
|
||||||
let years = days as f64 / 365.0;
|
let years = days as f64 / 365.0;
|
||||||
cagr.bps.height.compute_transform(
|
cagr.bps.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&returns.bps.height,
|
&returns.bps.height,
|
||||||
|(h, r, ..)| {
|
|(h, r, ..)| {
|
||||||
let ratio = f64::from(r);
|
let ratio = f64::from(r);
|
||||||
@@ -134,7 +136,7 @@ impl Vecs {
|
|||||||
{
|
{
|
||||||
let total_invested = DCA_AMOUNT * days as usize;
|
let total_invested = DCA_AMOUNT * days as usize;
|
||||||
stack.sats.height.compute_transform2(
|
stack.sats.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
h2d,
|
h2d,
|
||||||
&lookback_price.cents.height,
|
&lookback_price.cents.height,
|
||||||
|(h, _di, lp, ..)| {
|
|(h, _di, lp, ..)| {
|
||||||
@@ -151,7 +153,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// Lump sum by period - stack cents (sats × price)
|
// Lump sum by period - stack cents (sats × price)
|
||||||
for stack in self.period.lump_sum_stack.iter_mut() {
|
for stack in self.period.lump_sum_stack.iter_mut() {
|
||||||
stack.compute(prices, starting_indexes.height, exit)?;
|
stack.compute(prices, starting_lengths.height, exit)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lump sum by period - returns (compute from lookback price)
|
// Lump sum by period - returns (compute from lookback price)
|
||||||
@@ -162,7 +164,7 @@ impl Vecs {
|
|||||||
.zip(lookback_dca.iter_with_days())
|
.zip(lookback_dca.iter_with_days())
|
||||||
{
|
{
|
||||||
returns.compute_binary::<Cents, Cents, RatioDiffCentsBps32>(
|
returns.compute_binary::<Cents, Cents, RatioDiffCentsBps32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&lookback_price.cents.height,
|
&lookback_price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -173,7 +175,7 @@ impl Vecs {
|
|||||||
let start_days = super::ByDcaClass::<()>::start_days();
|
let start_days = super::ByDcaClass::<()>::start_days();
|
||||||
for (stack, day1) in self.class.dca_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 mut last_di: Option<Day1> = None;
|
||||||
let cls_start = stack.sats.height.len().min(starting_height);
|
let cls_start = stack.sats.height.len().min(starting_height_usize);
|
||||||
let mut prev_value = if cls_start > 0 {
|
let mut prev_value = if cls_start > 0 {
|
||||||
stack
|
stack
|
||||||
.sats
|
.sats
|
||||||
@@ -185,7 +187,7 @@ impl Vecs {
|
|||||||
};
|
};
|
||||||
|
|
||||||
stack.sats.height.compute_transform(
|
stack.sats.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
h2d,
|
h2d,
|
||||||
|(h, di, _)| {
|
|(h, di, _)| {
|
||||||
let hi = h.to_usize();
|
let hi = h.to_usize();
|
||||||
@@ -227,7 +229,7 @@ impl Vecs {
|
|||||||
|
|
||||||
// DCA by year class - stack cents (sats × price)
|
// DCA by year class - stack cents (sats × price)
|
||||||
for stack in self.class.dca_stack.iter_mut() {
|
for stack in self.class.dca_stack.iter_mut() {
|
||||||
stack.compute(prices, starting_indexes.height, exit)?;
|
stack.compute(prices, starting_lengths.height, exit)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DCA by year class - average price (derived from stack)
|
// DCA by year class - average price (derived from stack)
|
||||||
@@ -241,7 +243,7 @@ impl Vecs {
|
|||||||
{
|
{
|
||||||
let from_usize = from.to_usize();
|
let from_usize = from.to_usize();
|
||||||
average_price.cents.height.compute_transform2(
|
average_price.cents.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
h2d,
|
h2d,
|
||||||
&stack.sats.height,
|
&stack.sats.height,
|
||||||
|(h, di, stack_sats, ..)| {
|
|(h, di, stack_sats, ..)| {
|
||||||
@@ -265,7 +267,7 @@ impl Vecs {
|
|||||||
.zip(self.class.dca_cost_basis.iter())
|
.zip(self.class.dca_cost_basis.iter())
|
||||||
{
|
{
|
||||||
returns.compute_binary::<Cents, Cents, RatioDiffCentsBps32>(
|
returns.compute_binary::<Cents, Cents, RatioDiffCentsBps32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&average_price.cents.height,
|
&average_price.cents.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -277,42 +277,28 @@ impl Computer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compute(
|
pub fn compute(&mut self, indexer: &Indexer, exit: &Exit) -> Result<()> {
|
||||||
&mut self,
|
|
||||||
indexer: &Indexer,
|
|
||||||
starting_indexes: brk_indexer::Indexes,
|
|
||||||
exit: &Exit,
|
|
||||||
) -> Result<()> {
|
|
||||||
internal::cache_clear_all();
|
internal::cache_clear_all();
|
||||||
|
|
||||||
let compute_start = Instant::now();
|
let compute_start = Instant::now();
|
||||||
|
|
||||||
let mut starting_indexes = timed("Computed indexes", || {
|
timed("Computed indexes", || self.indexes.compute(indexer, exit))?;
|
||||||
self.indexes.compute(indexer, starting_indexes, exit)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
thread::scope(|scope| -> Result<()> {
|
thread::scope(|scope| -> Result<()> {
|
||||||
timed("Computed blocks", || {
|
timed("Computed blocks", || {
|
||||||
self.blocks
|
self.blocks.compute(indexer, &self.indexes, exit)
|
||||||
.compute(indexer, &self.indexes, &starting_indexes, exit)
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let (inputs_result, prices_result) = rayon::join(
|
let (inputs_result, prices_result) = rayon::join(
|
||||||
|| {
|
|| {
|
||||||
timed("Computed inputs", || {
|
timed("Computed inputs", || {
|
||||||
self.inputs.compute(
|
self.inputs
|
||||||
indexer,
|
.compute(indexer, &self.indexes, &self.blocks, exit)
|
||||||
&self.indexes,
|
|
||||||
&self.blocks,
|
|
||||||
&starting_indexes,
|
|
||||||
exit,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
timed("Computed prices", || {
|
timed("Computed prices", || {
|
||||||
self.prices
|
self.prices.compute(indexer, &self.indexes, exit)
|
||||||
.compute(indexer, &self.indexes, &starting_indexes, exit)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -323,13 +309,8 @@ impl Computer {
|
|||||||
// independent. Run all three in parallel.
|
// independent. Run all three in parallel.
|
||||||
let market = scope.spawn(|| {
|
let market = scope.spawn(|| {
|
||||||
timed("Computed market", || {
|
timed("Computed market", || {
|
||||||
self.market.compute(
|
self.market
|
||||||
&self.prices,
|
.compute(indexer, &self.prices, &self.indexes, &self.blocks, exit)
|
||||||
&self.indexes,
|
|
||||||
&self.blocks,
|
|
||||||
&starting_indexes,
|
|
||||||
exit,
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -341,7 +322,6 @@ impl Computer {
|
|||||||
&self.blocks,
|
&self.blocks,
|
||||||
&self.inputs,
|
&self.inputs,
|
||||||
&self.prices,
|
&self.prices,
|
||||||
&starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
@@ -352,7 +332,6 @@ impl Computer {
|
|||||||
&self.blocks,
|
&self.blocks,
|
||||||
&self.transactions,
|
&self.transactions,
|
||||||
&self.prices,
|
&self.prices,
|
||||||
&starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -365,7 +344,6 @@ impl Computer {
|
|||||||
&self.inputs,
|
&self.inputs,
|
||||||
&self.blocks,
|
&self.blocks,
|
||||||
&self.prices,
|
&self.prices,
|
||||||
&starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
@@ -375,7 +353,6 @@ impl Computer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let starting_indexes_clone = starting_indexes.clone();
|
|
||||||
thread::scope(|scope| -> Result<()> {
|
thread::scope(|scope| -> Result<()> {
|
||||||
let pools = scope.spawn(|| {
|
let pools = scope.spawn(|| {
|
||||||
timed("Computed pools", || {
|
timed("Computed pools", || {
|
||||||
@@ -385,7 +362,6 @@ impl Computer {
|
|||||||
&self.blocks,
|
&self.blocks,
|
||||||
&self.prices,
|
&self.prices,
|
||||||
&self.mining,
|
&self.mining,
|
||||||
&starting_indexes_clone,
|
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -394,11 +370,11 @@ impl Computer {
|
|||||||
let investing = scope.spawn(|| {
|
let investing = scope.spawn(|| {
|
||||||
timed("Computed investing", || {
|
timed("Computed investing", || {
|
||||||
self.investing.compute(
|
self.investing.compute(
|
||||||
|
indexer,
|
||||||
&self.indexes,
|
&self.indexes,
|
||||||
&self.prices,
|
&self.prices,
|
||||||
&self.blocks,
|
&self.blocks,
|
||||||
&self.market.lookback,
|
&self.market.lookback,
|
||||||
&starting_indexes_clone,
|
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -413,7 +389,6 @@ impl Computer {
|
|||||||
&self.transactions,
|
&self.transactions,
|
||||||
&self.blocks,
|
&self.blocks,
|
||||||
&self.prices,
|
&self.prices,
|
||||||
&mut starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
@@ -429,11 +404,11 @@ impl Computer {
|
|||||||
let indicators = scope.spawn(|| {
|
let indicators = scope.spawn(|| {
|
||||||
timed("Computed indicators", || {
|
timed("Computed indicators", || {
|
||||||
self.indicators.compute(
|
self.indicators.compute(
|
||||||
|
indexer,
|
||||||
&self.mining,
|
&self.mining,
|
||||||
&self.distribution,
|
&self.distribution,
|
||||||
&self.transactions,
|
&self.transactions,
|
||||||
&self.market,
|
&self.market,
|
||||||
&starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -441,20 +416,20 @@ impl Computer {
|
|||||||
|
|
||||||
timed("Computed supply", || {
|
timed("Computed supply", || {
|
||||||
self.supply.compute(
|
self.supply.compute(
|
||||||
|
indexer,
|
||||||
&self.outputs,
|
&self.outputs,
|
||||||
&self.blocks,
|
&self.blocks,
|
||||||
&self.mining,
|
&self.mining,
|
||||||
&self.transactions,
|
&self.transactions,
|
||||||
&self.prices,
|
&self.prices,
|
||||||
&self.distribution,
|
&self.distribution,
|
||||||
&starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
timed("Computed cointime", || {
|
timed("Computed cointime", || {
|
||||||
self.cointime.compute(
|
self.cointime.compute(
|
||||||
&starting_indexes,
|
indexer,
|
||||||
&self.prices,
|
&self.prices,
|
||||||
&self.blocks,
|
&self.blocks,
|
||||||
&self.mining,
|
&self.mining,
|
||||||
@@ -468,12 +443,9 @@ impl Computer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
self.indicators.rarity_meter.compute(
|
self.indicators
|
||||||
&self.distribution,
|
.rarity_meter
|
||||||
&self.prices,
|
.compute(indexer, &self.distribution, &self.prices, exit)?;
|
||||||
&starting_indexes,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
info!("Total compute time: {:?}", compute_start.elapsed());
|
info!("Total compute time: {:?}", compute_start.elapsed());
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -481,8 +453,9 @@ impl Computer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Computer<Ro> {
|
impl Computer<Ro> {
|
||||||
/// Last height whose computed-side state is durably stamped, derived
|
/// Live computer stamp for diagnostics. Derived from
|
||||||
/// from `distribution.supply_state`'s stamp.
|
/// `distribution.supply_state`'s stamp. For data reads use
|
||||||
|
/// `Query::height` (clamped against the safe-lengths snapshot).
|
||||||
pub fn computed_height(&self) -> Height {
|
pub fn computed_height(&self) -> Height {
|
||||||
Height::from(self.distribution.supply_state.stamp())
|
Height::from(self.distribution.supply_state.stamp())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Indexes, StoredF32, Timestamp};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{StoredF32, Timestamp};
|
||||||
use vecdb::{Exit, ReadableVec, VecIndex};
|
use vecdb::{Exit, ReadableVec, VecIndex};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -8,20 +9,22 @@ use crate::{indexes, prices};
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
|
|
||||||
self.high.cents.height.compute_all_time_high(
|
self.high.cents.height.compute_all_time_high(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut ath_ts: Option<Timestamp> = None;
|
let mut ath_ts: Option<Timestamp> = None;
|
||||||
self.days_since.height.compute_transform3(
|
self.days_since.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.high.cents.height,
|
&self.high.cents.height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&indexes.timestamp.monotonic,
|
&indexes.timestamp.monotonic,
|
||||||
@@ -48,7 +51,7 @@ impl Vecs {
|
|||||||
|
|
||||||
let mut prev = None;
|
let mut prev = None;
|
||||||
self.max_days_between.height.compute_transform(
|
self.max_days_between.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.days_since.height,
|
&self.days_since.height,
|
||||||
|(i, days, slf)| {
|
|(i, days, slf)| {
|
||||||
if prev.is_none() {
|
if prev.is_none() {
|
||||||
@@ -67,7 +70,7 @@ impl Vecs {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.drawdown.compute_drawdown(
|
self.drawdown.compute_drawdown(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&prices.spot.cents.height,
|
&prices.spot.cents.height,
|
||||||
&self.high.cents.height,
|
&self.high.cents.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Indexes;
|
use brk_indexer::Indexer;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use crate::{blocks, indexes, prices};
|
use crate::{blocks, indexes, prices};
|
||||||
@@ -9,10 +9,10 @@ use super::Vecs;
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
indexes: &indexes::Vecs,
|
indexes: &indexes::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
@@ -21,20 +21,14 @@ impl Vecs {
|
|||||||
let (r1, r2) = rayon::join(
|
let (r1, r2) = rayon::join(
|
||||||
|| {
|
|| {
|
||||||
rayon::join(
|
rayon::join(
|
||||||
|| self.ath.compute(prices, indexes, starting_indexes, exit),
|
|| self.ath.compute(indexer, prices, indexes, exit),
|
||||||
|| {
|
|| self.lookback.compute(indexer, blocks, prices, exit),
|
||||||
self.lookback
|
|
||||||
.compute(blocks, prices, starting_indexes, exit)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|| {
|
|| {
|
||||||
rayon::join(
|
rayon::join(
|
||||||
|| self.range.compute(prices, blocks, starting_indexes, exit),
|
|| self.range.compute(indexer, prices, blocks, exit),
|
||||||
|| {
|
|| self.moving_average.compute(indexer, blocks, prices, exit),
|
||||||
self.moving_average
|
|
||||||
.compute(blocks, prices, starting_indexes, exit)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -45,15 +39,15 @@ impl Vecs {
|
|||||||
|
|
||||||
// Phase 2: Depend on lookback
|
// Phase 2: Depend on lookback
|
||||||
self.returns
|
self.returns
|
||||||
.compute(prices, blocks, &self.lookback, starting_indexes, exit)?;
|
.compute(indexer, prices, blocks, &self.lookback, exit)?;
|
||||||
|
|
||||||
// Phase 3: Depends on returns, moving_average
|
// Phase 3: Depends on returns, moving_average
|
||||||
self.technical.compute(
|
self.technical.compute(
|
||||||
|
indexer,
|
||||||
&self.returns,
|
&self.returns,
|
||||||
prices,
|
prices,
|
||||||
blocks,
|
blocks,
|
||||||
&self.moving_average,
|
&self.moving_average,
|
||||||
starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Indexes;
|
use brk_indexer::Indexer;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -8,17 +8,18 @@ use crate::{blocks, prices};
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let price = &prices.spot.cents.height;
|
let price = &prices.spot.cents.height;
|
||||||
|
|
||||||
for (price_past, days) in self.price_past.iter_mut_with_days() {
|
for (price_past, days) in self.price_past.iter_mut_with_days() {
|
||||||
let window_starts = blocks.lookback.start_vec(days as usize);
|
let window_starts = blocks.lookback.start_vec(days as usize);
|
||||||
price_past.cents.height.compute_lookback(
|
price_past.cents.height.compute_lookback(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
window_starts,
|
window_starts,
|
||||||
price,
|
price,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Indexes;
|
use brk_indexer::Indexer;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -8,11 +8,12 @@ use crate::{blocks, prices};
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_lengths = indexer.safe_lengths();
|
||||||
let close = &prices.spot.cents.height;
|
let close = &prices.spot.cents.height;
|
||||||
|
|
||||||
for (sma, period) in [
|
for (sma, period) in [
|
||||||
@@ -34,8 +35,8 @@ impl Vecs {
|
|||||||
(&mut self.sma._4y, 4 * 365),
|
(&mut self.sma._4y, 4 * 365),
|
||||||
] {
|
] {
|
||||||
let window_starts = blocks.lookback.start_vec(period);
|
let window_starts = blocks.lookback.start_vec(period);
|
||||||
sma.compute_all(prices, starting_indexes, exit, |v| {
|
sma.compute_all(prices, &starting_lengths, exit, |v| {
|
||||||
v.compute_rolling_average(starting_indexes.height, window_starts, close, exit)?;
|
v.compute_rolling_average(starting_lengths.height, window_starts, close, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
@@ -59,8 +60,8 @@ impl Vecs {
|
|||||||
(&mut self.ema._4y, 4 * 365),
|
(&mut self.ema._4y, 4 * 365),
|
||||||
] {
|
] {
|
||||||
let window_starts = blocks.lookback.start_vec(period);
|
let window_starts = blocks.lookback.start_vec(period);
|
||||||
ema.compute_all(prices, starting_indexes, exit, |v| {
|
ema.compute_all(prices, &starting_lengths, exit, |v| {
|
||||||
v.compute_rolling_ema(starting_indexes.height, window_starts, close, exit)?;
|
v.compute_rolling_ema(starting_lengths.height, window_starts, close, exit)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{BasisPoints16, Indexes, StoredF32};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{BasisPoints16, StoredF32};
|
||||||
use vecdb::{Exit, ReadableVec, VecIndex};
|
use vecdb::{Exit, ReadableVec, VecIndex};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -8,11 +9,12 @@ use crate::{blocks, prices};
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let price = &prices.spot.cents.height;
|
let price = &prices.spot.cents.height;
|
||||||
|
|
||||||
for (min_vec, max_vec, starts) in [
|
for (min_vec, max_vec, starts) in [
|
||||||
@@ -37,24 +39,14 @@ impl Vecs {
|
|||||||
&blocks.lookback._1y.inner,
|
&blocks.lookback._1y.inner,
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
min_vec.compute_rolling_min_from_starts(
|
min_vec.compute_rolling_min_from_starts(starting_height, starts, price, exit)?;
|
||||||
starting_indexes.height,
|
max_vec.compute_rolling_max_from_starts(starting_height, starts, price, exit)?;
|
||||||
starts,
|
|
||||||
price,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
max_vec.compute_rolling_max_from_starts(
|
|
||||||
starting_indexes.height,
|
|
||||||
starts,
|
|
||||||
price,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// True range at block level: |price[h] - price[h-1]|
|
// True range at block level: |price[h] - price[h-1]|
|
||||||
let mut prev_price = None;
|
let mut prev_price = None;
|
||||||
self.true_range.height.compute_transform(
|
self.true_range.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
price,
|
price,
|
||||||
|(h, current, ..)| {
|
|(h, current, ..)| {
|
||||||
let prev = prev_price.unwrap_or_else(|| {
|
let prev = prev_price.unwrap_or_else(|| {
|
||||||
@@ -74,14 +66,14 @@ impl Vecs {
|
|||||||
|
|
||||||
// 2w rolling sum of true range
|
// 2w rolling sum of true range
|
||||||
self.true_range_sum_2w.height.compute_rolling_sum(
|
self.true_range_sum_2w.height.compute_rolling_sum(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&blocks.lookback._2w,
|
&blocks.lookback._2w,
|
||||||
&self.true_range.height,
|
&self.true_range.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.choppiness_index_2w.bps.height.compute_transform4(
|
self.choppiness_index_2w.bps.height.compute_transform4(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.true_range_sum_2w.height,
|
&self.true_range_sum_2w.height,
|
||||||
&self.max._2w.cents.height,
|
&self.max._2w.cents.height,
|
||||||
&self.min._2w.cents.height,
|
&self.min._2w.cents.height,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{BasisPointsSigned32, Dollars, Indexes};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{BasisPointsSigned32, Dollars};
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -10,12 +11,14 @@ use crate::{
|
|||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
lookback: &lookback::Vecs,
|
lookback: &lookback::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_lengths = indexer.safe_lengths();
|
||||||
|
|
||||||
// Compute price returns at height level
|
// Compute price returns at height level
|
||||||
for ((returns, _), (lookback_price, _)) in self
|
for ((returns, _), (lookback_price, _)) in self
|
||||||
.periods
|
.periods
|
||||||
@@ -23,7 +26,7 @@ impl Vecs {
|
|||||||
.zip(lookback.price_past.iter_with_days())
|
.zip(lookback.price_past.iter_with_days())
|
||||||
{
|
{
|
||||||
returns.compute_binary::<Dollars, Dollars, RatioDiffDollarsBps32>(
|
returns.compute_binary::<Dollars, Dollars, RatioDiffDollarsBps32>(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&prices.spot.usd.height,
|
&prices.spot.usd.height,
|
||||||
&lookback_price.usd.height,
|
&lookback_price.usd.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -35,7 +38,7 @@ impl Vecs {
|
|||||||
for (cagr, returns, days) in self.cagr.zip_mut_with_period(&price_return_dca) {
|
for (cagr, returns, days) in self.cagr.zip_mut_with_period(&price_return_dca) {
|
||||||
let years = days as f64 / 365.0;
|
let years = days as f64 / 365.0;
|
||||||
cagr.bps.height.compute_transform(
|
cagr.bps.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_lengths.height,
|
||||||
&returns.bps.height,
|
&returns.bps.height,
|
||||||
|(h, r, ..)| {
|
|(h, r, ..)| {
|
||||||
let ratio = f64::from(r);
|
let ratio = f64::from(r);
|
||||||
@@ -49,7 +52,7 @@ impl Vecs {
|
|||||||
let _24h_price_return_ratio = &self.periods._24h.ratio.height;
|
let _24h_price_return_ratio = &self.periods._24h.ratio.height;
|
||||||
|
|
||||||
for sd in self.sd_24h.as_mut_array() {
|
for sd in self.sd_24h.as_mut_array() {
|
||||||
sd.compute_all(blocks, starting_indexes, exit, _24h_price_return_ratio)?;
|
sd.compute_all(blocks, &starting_lengths, exit, _24h_price_return_ratio)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Dollars, Indexes};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::Dollars;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
@@ -16,13 +17,14 @@ impl Vecs {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
returns: &returns::Vecs,
|
returns: &returns::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
moving_average: &moving_average::Vecs,
|
moving_average: &moving_average::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let daily_returns = &returns.periods._24h.ratio.height;
|
let daily_returns = &returns.periods._24h.ratio.height;
|
||||||
for (rsi_chain, &m) in self
|
for (rsi_chain, &m) in self
|
||||||
.rsi
|
.rsi
|
||||||
@@ -32,11 +34,11 @@ impl Vecs {
|
|||||||
{
|
{
|
||||||
rsi::compute(
|
rsi::compute(
|
||||||
rsi_chain,
|
rsi_chain,
|
||||||
|
indexer,
|
||||||
blocks,
|
blocks,
|
||||||
daily_returns,
|
daily_returns,
|
||||||
14 * m,
|
14 * m,
|
||||||
3 * m,
|
3 * m,
|
||||||
starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
@@ -49,12 +51,12 @@ impl Vecs {
|
|||||||
{
|
{
|
||||||
macd::compute(
|
macd::compute(
|
||||||
macd_chain,
|
macd_chain,
|
||||||
|
indexer,
|
||||||
blocks,
|
blocks,
|
||||||
prices,
|
prices,
|
||||||
12 * m,
|
12 * m,
|
||||||
26 * m,
|
26 * m,
|
||||||
9 * m,
|
9 * m,
|
||||||
starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
@@ -62,7 +64,7 @@ impl Vecs {
|
|||||||
self.pi_cycle
|
self.pi_cycle
|
||||||
.bps
|
.bps
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&moving_average.sma._111d.usd.height,
|
&moving_average.sma._111d.usd.height,
|
||||||
&moving_average.sma._350d_x2.usd.height,
|
&moving_average.sma._350d_x2.usd.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::Indexes;
|
use brk_indexer::Indexer;
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::MacdChain;
|
use super::MacdChain;
|
||||||
@@ -8,14 +8,15 @@ use crate::{blocks, prices};
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(super) fn compute(
|
pub(super) fn compute(
|
||||||
chain: &mut MacdChain,
|
chain: &mut MacdChain,
|
||||||
|
indexer: &Indexer,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
fast_days: usize,
|
fast_days: usize,
|
||||||
slow_days: usize,
|
slow_days: usize,
|
||||||
signal_days: usize,
|
signal_days: usize,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let close = &prices.spot.usd.height;
|
let close = &prices.spot.usd.height;
|
||||||
let ws_fast = blocks.lookback.start_vec(fast_days);
|
let ws_fast = blocks.lookback.start_vec(fast_days);
|
||||||
let ws_slow = blocks.lookback.start_vec(slow_days);
|
let ws_slow = blocks.lookback.start_vec(slow_days);
|
||||||
@@ -24,29 +25,29 @@ pub(super) fn compute(
|
|||||||
chain
|
chain
|
||||||
.ema_fast
|
.ema_fast
|
||||||
.height
|
.height
|
||||||
.compute_rolling_ema(starting_indexes.height, ws_fast, close, exit)?;
|
.compute_rolling_ema(starting_height, ws_fast, close, exit)?;
|
||||||
|
|
||||||
chain
|
chain
|
||||||
.ema_slow
|
.ema_slow
|
||||||
.height
|
.height
|
||||||
.compute_rolling_ema(starting_indexes.height, ws_slow, close, exit)?;
|
.compute_rolling_ema(starting_height, ws_slow, close, exit)?;
|
||||||
|
|
||||||
chain.line.height.compute_subtract(
|
chain.line.height.compute_subtract(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&chain.ema_fast.height,
|
&chain.ema_fast.height,
|
||||||
&chain.ema_slow.height,
|
&chain.ema_slow.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.signal.height.compute_rolling_ema(
|
chain.signal.height.compute_rolling_ema(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
ws_signal,
|
ws_signal,
|
||||||
&chain.line.height,
|
&chain.line.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.histogram.height.compute_subtract(
|
chain.histogram.height.compute_subtract(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&chain.line.height,
|
&chain.line.height,
|
||||||
&chain.signal.height,
|
&chain.signal.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{BasisPoints16, Height, Indexes, StoredF32};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{BasisPoints16, Height, StoredF32};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use super::RsiChain;
|
use super::RsiChain;
|
||||||
@@ -7,46 +8,47 @@ use crate::blocks;
|
|||||||
|
|
||||||
pub(super) fn compute(
|
pub(super) fn compute(
|
||||||
chain: &mut RsiChain,
|
chain: &mut RsiChain,
|
||||||
|
indexer: &Indexer,
|
||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
returns_source: &impl ReadableVec<Height, StoredF32>,
|
returns_source: &impl ReadableVec<Height, StoredF32>,
|
||||||
rma_days: usize,
|
rma_days: usize,
|
||||||
stoch_sma_days: usize,
|
stoch_sma_days: usize,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
let ws_rma = blocks.lookback.start_vec(rma_days);
|
let ws_rma = blocks.lookback.start_vec(rma_days);
|
||||||
let ws_sma = blocks.lookback.start_vec(stoch_sma_days);
|
let ws_sma = blocks.lookback.start_vec(stoch_sma_days);
|
||||||
|
|
||||||
chain.gains.height.compute_transform(
|
chain.gains.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
returns_source,
|
returns_source,
|
||||||
|(h, r, ..)| (h, StoredF32::from((*r).max(0.0))),
|
|(h, r, ..)| (h, StoredF32::from((*r).max(0.0))),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.losses.height.compute_transform(
|
chain.losses.height.compute_transform(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
returns_source,
|
returns_source,
|
||||||
|(h, r, ..)| (h, StoredF32::from((-*r).max(0.0))),
|
|(h, r, ..)| (h, StoredF32::from((-*r).max(0.0))),
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.average_gain.height.compute_rolling_rma(
|
chain.average_gain.height.compute_rolling_rma(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
ws_rma,
|
ws_rma,
|
||||||
&chain.gains.height,
|
&chain.gains.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.average_loss.height.compute_rolling_rma(
|
chain.average_loss.height.compute_rolling_rma(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
ws_rma,
|
ws_rma,
|
||||||
&chain.losses.height,
|
&chain.losses.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.rsi.bps.height.compute_transform2(
|
chain.rsi.bps.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&chain.average_gain.height,
|
&chain.average_gain.height,
|
||||||
&chain.average_loss.height,
|
&chain.average_loss.height,
|
||||||
|(h, g, l, ..)| {
|
|(h, g, l, ..)| {
|
||||||
@@ -58,21 +60,21 @@ pub(super) fn compute(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.rsi_min.bps.height.compute_rolling_min_from_starts(
|
chain.rsi_min.bps.height.compute_rolling_min_from_starts(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
ws_rma,
|
ws_rma,
|
||||||
&chain.rsi.bps.height,
|
&chain.rsi.bps.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.rsi_max.bps.height.compute_rolling_max_from_starts(
|
chain.rsi_max.bps.height.compute_rolling_max_from_starts(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
ws_rma,
|
ws_rma,
|
||||||
&chain.rsi.bps.height,
|
&chain.rsi.bps.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.stoch_rsi.bps.height.compute_transform3(
|
chain.stoch_rsi.bps.height.compute_transform3(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&chain.rsi.bps.height,
|
&chain.rsi.bps.height,
|
||||||
&chain.rsi_min.bps.height,
|
&chain.rsi_min.bps.height,
|
||||||
&chain.rsi_max.bps.height,
|
&chain.rsi_max.bps.height,
|
||||||
@@ -89,14 +91,14 @@ pub(super) fn compute(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.stoch_rsi_k.bps.height.compute_rolling_average(
|
chain.stoch_rsi_k.bps.height.compute_rolling_average(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
ws_sma,
|
ws_sma,
|
||||||
&chain.stoch_rsi.bps.height,
|
&chain.stoch_rsi.bps.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
chain.stoch_rsi_d.bps.height.compute_rolling_average(
|
chain.stoch_rsi_d.bps.height.compute_rolling_average(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
ws_sma,
|
ws_sma,
|
||||||
&chain.stoch_rsi_k.bps.height,
|
&chain.stoch_rsi_k.bps.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::Indexes;
|
|
||||||
use vecdb::Exit;
|
use vecdb::Exit;
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -15,7 +14,6 @@ impl Vecs {
|
|||||||
blocks: &blocks::Vecs,
|
blocks: &blocks::Vecs,
|
||||||
transactions: &transactions::Vecs,
|
transactions: &transactions::Vecs,
|
||||||
prices: &prices::Vecs,
|
prices: &prices::Vecs,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.db.sync_bg_tasks()?;
|
self.db.sync_bg_tasks()?;
|
||||||
@@ -27,17 +25,16 @@ impl Vecs {
|
|||||||
&blocks.lookback,
|
&blocks.lookback,
|
||||||
transactions,
|
transactions,
|
||||||
prices,
|
prices,
|
||||||
starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.hashrate.compute(
|
self.hashrate.compute(
|
||||||
|
indexer,
|
||||||
&blocks.count,
|
&blocks.count,
|
||||||
&blocks.lookback,
|
&blocks.lookback,
|
||||||
&blocks.difficulty,
|
&blocks.difficulty,
|
||||||
&self.rewards.coinbase.sum._24h.sats.height,
|
&self.rewards.coinbase.sum._24h.sats.height,
|
||||||
&self.rewards.coinbase.sum._24h.usd.height,
|
&self.rewards.coinbase.sum._24h.usd.height,
|
||||||
starting_indexes,
|
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{Dollars, Height, Indexes, Sats, StoredF32, StoredF64};
|
use brk_indexer::Indexer;
|
||||||
|
use brk_types::{Dollars, Height, Sats, StoredF32, StoredF64};
|
||||||
use vecdb::{Exit, ReadableVec};
|
use vecdb::{Exit, ReadableVec};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
@@ -12,16 +13,18 @@ impl Vecs {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
indexer: &Indexer,
|
||||||
count_vecs: &blocks::CountVecs,
|
count_vecs: &blocks::CountVecs,
|
||||||
lookback: &blocks::LookbackVecs,
|
lookback: &blocks::LookbackVecs,
|
||||||
difficulty_vecs: &blocks::DifficultyVecs,
|
difficulty_vecs: &blocks::DifficultyVecs,
|
||||||
coinbase_sats_24h_sum: &impl ReadableVec<Height, Sats>,
|
coinbase_sats_24h_sum: &impl ReadableVec<Height, Sats>,
|
||||||
coinbase_usd_24h_sum: &impl ReadableVec<Height, Dollars>,
|
coinbase_usd_24h_sum: &impl ReadableVec<Height, Dollars>,
|
||||||
starting_indexes: &Indexes,
|
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let starting_height = indexer.safe_lengths().height;
|
||||||
|
|
||||||
self.rate.base.height.compute_transform2(
|
self.rate.base.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&count_vecs.total.sum._24h.height,
|
&count_vecs.total.sum._24h.height,
|
||||||
&difficulty_vecs.hashrate.height,
|
&difficulty_vecs.hashrate.height,
|
||||||
|(i, block_count_sum, difficulty_as_hash, ..)| {
|
|(i, block_count_sum, difficulty_as_hash, ..)| {
|
||||||
@@ -43,24 +46,24 @@ impl Vecs {
|
|||||||
(&mut self.rate.sma._2m.height, &lookback._2m),
|
(&mut self.rate.sma._2m.height, &lookback._2m),
|
||||||
(&mut self.rate.sma._1y.height, &lookback._1y.inner),
|
(&mut self.rate.sma._1y.height, &lookback._1y.inner),
|
||||||
] {
|
] {
|
||||||
sma.compute_rolling_average(starting_indexes.height, window, hash_rate, exit)?;
|
sma.compute_rolling_average(starting_height, window, hash_rate, exit)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.rate.ath.height.compute_all_time_high(
|
self.rate.ath.height.compute_all_time_high(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.rate.base.height,
|
&self.rate.base.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.rate.drawdown.compute_drawdown(
|
self.rate.drawdown.compute_drawdown(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.rate.base.height,
|
&self.rate.base.height,
|
||||||
&self.rate.ath.height,
|
&self.rate.ath.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.price.ths.height.compute_transform2(
|
self.price.ths.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
coinbase_usd_24h_sum,
|
coinbase_usd_24h_sum,
|
||||||
&self.rate.base.height,
|
&self.rate.base.height,
|
||||||
|(i, coinbase_sum, hashrate, ..)| {
|
|(i, coinbase_sum, hashrate, ..)| {
|
||||||
@@ -76,7 +79,7 @@ impl Vecs {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.value.ths.height.compute_transform2(
|
self.value.ths.height.compute_transform2(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
coinbase_sats_24h_sum,
|
coinbase_sats_24h_sum,
|
||||||
&self.rate.base.height,
|
&self.rate.base.height,
|
||||||
|(i, coinbase_sum, hashrate, ..)| {
|
|(i, coinbase_sum, hashrate, ..)| {
|
||||||
@@ -95,13 +98,13 @@ impl Vecs {
|
|||||||
(&mut self.price.ths_min.height, &self.price.ths.height),
|
(&mut self.price.ths_min.height, &self.price.ths.height),
|
||||||
(&mut self.value.ths_min.height, &self.value.ths.height),
|
(&mut self.value.ths_min.height, &self.value.ths.height),
|
||||||
] {
|
] {
|
||||||
min_vec.compute_all_time_low_(starting_indexes.height, src_vec, exit, true)?;
|
min_vec.compute_all_time_low_(starting_height, src_vec, exit, true)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.price
|
self.price
|
||||||
.rebound
|
.rebound
|
||||||
.compute_binary::<StoredF32, StoredF32, RatioDiffF32Bps32>(
|
.compute_binary::<StoredF32, StoredF32, RatioDiffF32Bps32>(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.price.phs.height,
|
&self.price.phs.height,
|
||||||
&self.price.phs_min.height,
|
&self.price.phs_min.height,
|
||||||
exit,
|
exit,
|
||||||
@@ -110,7 +113,7 @@ impl Vecs {
|
|||||||
self.value
|
self.value
|
||||||
.rebound
|
.rebound
|
||||||
.compute_binary::<StoredF32, StoredF32, RatioDiffF32Bps32>(
|
.compute_binary::<StoredF32, StoredF32, RatioDiffF32Bps32>(
|
||||||
starting_indexes.height,
|
starting_height,
|
||||||
&self.value.phs.height,
|
&self.value.phs.height,
|
||||||
&self.value.phs_min.height,
|
&self.value.phs_min.height,
|
||||||
exit,
|
exit,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user