mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-24 09:28:11 -07:00
global: snapshot
This commit is contained in:
@@ -4994,7 +4994,7 @@ pub struct SeriesTree_Market {
|
|||||||
pub ath: SeriesTree_Market_Ath,
|
pub ath: SeriesTree_Market_Ath,
|
||||||
pub lookback: SeriesTree_Market_Lookback,
|
pub lookback: SeriesTree_Market_Lookback,
|
||||||
pub returns: SeriesTree_Market_Returns,
|
pub returns: SeriesTree_Market_Returns,
|
||||||
pub volatility: SeriesTree_Market_Volatility,
|
pub volatility: _1m1w1y24hPattern<StoredF32>,
|
||||||
pub range: SeriesTree_Market_Range,
|
pub range: SeriesTree_Market_Range,
|
||||||
pub moving_average: SeriesTree_Market_MovingAverage,
|
pub moving_average: SeriesTree_Market_MovingAverage,
|
||||||
pub dca: SeriesTree_Market_Dca,
|
pub dca: SeriesTree_Market_Dca,
|
||||||
@@ -5007,7 +5007,7 @@ impl SeriesTree_Market {
|
|||||||
ath: SeriesTree_Market_Ath::new(client.clone(), format!("{base_path}_ath")),
|
ath: SeriesTree_Market_Ath::new(client.clone(), format!("{base_path}_ath")),
|
||||||
lookback: SeriesTree_Market_Lookback::new(client.clone(), format!("{base_path}_lookback")),
|
lookback: SeriesTree_Market_Lookback::new(client.clone(), format!("{base_path}_lookback")),
|
||||||
returns: SeriesTree_Market_Returns::new(client.clone(), format!("{base_path}_returns")),
|
returns: SeriesTree_Market_Returns::new(client.clone(), format!("{base_path}_returns")),
|
||||||
volatility: SeriesTree_Market_Volatility::new(client.clone(), format!("{base_path}_volatility")),
|
volatility: _1m1w1y24hPattern::new(client.clone(), "price_volatility".to_string()),
|
||||||
range: SeriesTree_Market_Range::new(client.clone(), format!("{base_path}_range")),
|
range: SeriesTree_Market_Range::new(client.clone(), format!("{base_path}_range")),
|
||||||
moving_average: SeriesTree_Market_MovingAverage::new(client.clone(), format!("{base_path}_moving_average")),
|
moving_average: SeriesTree_Market_MovingAverage::new(client.clone(), format!("{base_path}_moving_average")),
|
||||||
dca: SeriesTree_Market_Dca::new(client.clone(), format!("{base_path}_dca")),
|
dca: SeriesTree_Market_Dca::new(client.clone(), format!("{base_path}_dca")),
|
||||||
@@ -5132,6 +5132,7 @@ impl SeriesTree_Market_Returns_Periods {
|
|||||||
|
|
||||||
/// Series tree node.
|
/// Series tree node.
|
||||||
pub struct SeriesTree_Market_Returns_Sd24h {
|
pub struct SeriesTree_Market_Returns_Sd24h {
|
||||||
|
pub _24h: SeriesTree_Market_Returns_Sd24h_24h,
|
||||||
pub _1w: SeriesTree_Market_Returns_Sd24h_1w,
|
pub _1w: SeriesTree_Market_Returns_Sd24h_1w,
|
||||||
pub _1m: SeriesTree_Market_Returns_Sd24h_1m,
|
pub _1m: SeriesTree_Market_Returns_Sd24h_1m,
|
||||||
pub _1y: SeriesTree_Market_Returns_Sd24h_1y,
|
pub _1y: SeriesTree_Market_Returns_Sd24h_1y,
|
||||||
@@ -5140,6 +5141,7 @@ pub struct SeriesTree_Market_Returns_Sd24h {
|
|||||||
impl SeriesTree_Market_Returns_Sd24h {
|
impl SeriesTree_Market_Returns_Sd24h {
|
||||||
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
|
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
_24h: SeriesTree_Market_Returns_Sd24h_24h::new(client.clone(), format!("{base_path}_24h")),
|
||||||
_1w: SeriesTree_Market_Returns_Sd24h_1w::new(client.clone(), format!("{base_path}_1w")),
|
_1w: SeriesTree_Market_Returns_Sd24h_1w::new(client.clone(), format!("{base_path}_1w")),
|
||||||
_1m: SeriesTree_Market_Returns_Sd24h_1m::new(client.clone(), format!("{base_path}_1m")),
|
_1m: SeriesTree_Market_Returns_Sd24h_1m::new(client.clone(), format!("{base_path}_1m")),
|
||||||
_1y: SeriesTree_Market_Returns_Sd24h_1y::new(client.clone(), format!("{base_path}_1y")),
|
_1y: SeriesTree_Market_Returns_Sd24h_1y::new(client.clone(), format!("{base_path}_1y")),
|
||||||
@@ -5147,6 +5149,21 @@ impl SeriesTree_Market_Returns_Sd24h {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Series tree node.
|
||||||
|
pub struct SeriesTree_Market_Returns_Sd24h_24h {
|
||||||
|
pub sma: SeriesPattern1<StoredF32>,
|
||||||
|
pub sd: SeriesPattern1<StoredF32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SeriesTree_Market_Returns_Sd24h_24h {
|
||||||
|
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
|
||||||
|
Self {
|
||||||
|
sma: SeriesPattern1::new(client.clone(), "price_return_24h_sma_24h".to_string()),
|
||||||
|
sd: SeriesPattern1::new(client.clone(), "price_return_24h_sd_24h".to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Series tree node.
|
/// Series tree node.
|
||||||
pub struct SeriesTree_Market_Returns_Sd24h_1w {
|
pub struct SeriesTree_Market_Returns_Sd24h_1w {
|
||||||
pub sma: SeriesPattern1<StoredF32>,
|
pub sma: SeriesPattern1<StoredF32>,
|
||||||
@@ -5192,23 +5209,6 @@ impl SeriesTree_Market_Returns_Sd24h_1y {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Series tree node.
|
|
||||||
pub struct SeriesTree_Market_Volatility {
|
|
||||||
pub _1w: SeriesPattern1<StoredF32>,
|
|
||||||
pub _1m: SeriesPattern1<StoredF32>,
|
|
||||||
pub _1y: SeriesPattern1<StoredF32>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SeriesTree_Market_Volatility {
|
|
||||||
pub fn new(client: Arc<BrkClientBase>, base_path: String) -> Self {
|
|
||||||
Self {
|
|
||||||
_1w: SeriesPattern1::new(client.clone(), "price_volatility_1w".to_string()),
|
|
||||||
_1m: SeriesPattern1::new(client.clone(), "price_volatility_1m".to_string()),
|
|
||||||
_1y: SeriesPattern1::new(client.clone(), "price_volatility_1y".to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Series tree node.
|
/// Series tree node.
|
||||||
pub struct SeriesTree_Market_Range {
|
pub struct SeriesTree_Market_Range {
|
||||||
pub min: _1m1w1y2wPattern,
|
pub min: _1m1w1y2wPattern,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ impl Vecs {
|
|||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.spent
|
self.spent
|
||||||
.compute(&self.db, indexer, starting_indexes, exit)?;
|
.compute(indexer, starting_indexes, exit)?;
|
||||||
self.count
|
self.count
|
||||||
.compute(indexer, indexes, blocks, starting_indexes, exit)?;
|
.compute(indexer, indexes, blocks, starting_indexes, exit)?;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use brk_error::Result;
|
|||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{Indexes, Sats, TxIndex, TxOutIndex, Vout};
|
use brk_types::{Indexes, Sats, TxIndex, TxOutIndex, Vout};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, VecIndex, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, VecIndex, WritableVec};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
|
|
||||||
@@ -11,7 +11,6 @@ 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,
|
&mut self,
|
||||||
db: &Database,
|
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
starting_indexes: &Indexes,
|
starting_indexes: &Indexes,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
@@ -105,14 +104,13 @@ impl Vecs {
|
|||||||
self.value.push(out_value[i]);
|
self.value.push(out_value[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if batch_end < target {
|
|
||||||
info!("TxIns: {:.2}%", batch_end as f64 / target as f64 * 100.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
let _lock = exit.lock();
|
let _lock = exit.lock();
|
||||||
self.txout_index.write()?;
|
self.txout_index.write()?;
|
||||||
self.value.write()?;
|
self.value.write()?;
|
||||||
db.flush()?;
|
|
||||||
|
if batch_end < target {
|
||||||
|
info!("TxIns: {:.2}%", batch_end as f64 / target as f64 * 100.0);
|
||||||
|
}
|
||||||
|
|
||||||
batch_start = batch_end;
|
batch_start = batch_end;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ pub struct Windows<A> {
|
|||||||
|
|
||||||
impl<A> Windows<A> {
|
impl<A> Windows<A> {
|
||||||
pub const SUFFIXES: [&'static str; 4] = ["24h", "1w", "1m", "1y"];
|
pub const SUFFIXES: [&'static str; 4] = ["24h", "1w", "1m", "1y"];
|
||||||
|
pub const DAYS: [usize; 4] = [1, 7, 30, 365];
|
||||||
|
|
||||||
pub fn try_from_fn<E>(
|
pub fn try_from_fn<E>(
|
||||||
mut f: impl FnMut(&str) -> std::result::Result<A, E>,
|
mut f: impl FnMut(&str) -> std::result::Result<A, E>,
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ impl RatioPerBlockPercentiles {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let _lock = exit.lock();
|
let _lock = exit.lock();
|
||||||
self.mut_pct_vecs().try_for_each(|v| v.flush())?;
|
self.mut_pct_vecs().try_for_each(|v| v.write().map(|_| ()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cents bands
|
// Cents bands
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ impl StdDevPerBlockExtended {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let _lock = exit.lock();
|
let _lock = exit.lock();
|
||||||
self.mut_band_height_vecs().try_for_each(|v| v.flush())?;
|
self.mut_band_height_vecs().try_for_each(|v| v.write().map(|_| ()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.zscore.height.compute_zscore(
|
self.zscore.height.compute_zscore(
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ pub trait SqrtDays {
|
|||||||
const FACTOR: f32;
|
const FACTOR: f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Days1;
|
||||||
|
impl SqrtDays for Days1 {
|
||||||
|
const FACTOR: f32 = 1.0; // 1.0_f32.sqrt()
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Days7;
|
pub struct Days7;
|
||||||
impl SqrtDays for Days7 {
|
impl SqrtDays for Days7 {
|
||||||
const FACTOR: f32 = 2.6457513; // 7.0_f32.sqrt()
|
const FACTOR: f32 = 2.6457513; // 7.0_f32.sqrt()
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub use currency::{
|
|||||||
SatsToBitcoin, SatsToCents,
|
SatsToBitcoin, SatsToCents,
|
||||||
};
|
};
|
||||||
pub use derived::{
|
pub use derived::{
|
||||||
Days7, Days30, Days365, DaysToYears, PerSec, PriceTimesRatioBp32Cents, PriceTimesRatioCents,
|
Days1, Days7, Days30, Days365, DaysToYears, PerSec, PriceTimesRatioBp32Cents, PriceTimesRatioCents,
|
||||||
RatioCents64, TimesSqrt,
|
RatioCents64, TimesSqrt,
|
||||||
};
|
};
|
||||||
pub use ratio::{
|
pub use ratio::{
|
||||||
|
|||||||
@@ -46,11 +46,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 [
|
for sd in self.sd_24h.as_mut_array() {
|
||||||
&mut self.sd_24h._1w,
|
|
||||||
&mut self.sd_24h._1m,
|
|
||||||
&mut self.sd_24h._1y,
|
|
||||||
] {
|
|
||||||
sd.compute_all(blocks, starting_indexes, exit, _24h_price_return_ratio)?;
|
sd.compute_all(blocks, starting_indexes, exit, _24h_price_return_ratio)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ use brk_types::Version;
|
|||||||
use vecdb::Database;
|
use vecdb::Database;
|
||||||
|
|
||||||
use super::super::lookback::ByLookbackPeriod;
|
use super::super::lookback::ByLookbackPeriod;
|
||||||
use super::{vecs::PriceReturn24hSdVecs, Vecs};
|
use super::Vecs;
|
||||||
use crate::{
|
use crate::{
|
||||||
indexes,
|
indexes,
|
||||||
internal::{StdDevPerBlock, PercentPerBlock},
|
internal::{StdDevPerBlock, PercentPerBlock, Windows},
|
||||||
market::dca::ByDcaCagr,
|
market::dca::ByDcaCagr,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -18,46 +18,27 @@ impl Vecs {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let v1 = Version::ONE;
|
let v1 = Version::ONE;
|
||||||
|
|
||||||
let price_return = ByLookbackPeriod::try_new(|name, _days| {
|
let periods = ByLookbackPeriod::try_new(|name, _days| {
|
||||||
PercentPerBlock::forced_import(db, &format!("price_return_{name}"), version, indexes)
|
PercentPerBlock::forced_import(db, &format!("price_return_{name}"), version, indexes)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// CAGR (computed, 2y+ only)
|
let cagr = ByDcaCagr::try_new(|name, _days| {
|
||||||
let price_cagr = ByDcaCagr::try_new(|name, _days| {
|
|
||||||
PercentPerBlock::forced_import(db, &format!("price_cagr_{name}"), version, indexes)
|
PercentPerBlock::forced_import(db, &format!("price_cagr_{name}"), version, indexes)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let price_return_24h_sd = PriceReturn24hSdVecs {
|
let mut days_iter = Windows::<()>::DAYS.iter();
|
||||||
_1w: StdDevPerBlock::forced_import(
|
let sd_24h = Windows::try_from_fn(|suffix| {
|
||||||
|
let days = *days_iter.next().unwrap();
|
||||||
|
StdDevPerBlock::forced_import(
|
||||||
db,
|
db,
|
||||||
"price_return_24h",
|
"price_return_24h",
|
||||||
"1w",
|
suffix,
|
||||||
7,
|
days,
|
||||||
version + v1,
|
version + v1,
|
||||||
indexes,
|
indexes,
|
||||||
)?,
|
)
|
||||||
_1m: StdDevPerBlock::forced_import(
|
})?;
|
||||||
db,
|
|
||||||
"price_return_24h",
|
|
||||||
"1m",
|
|
||||||
30,
|
|
||||||
version + v1,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
_1y: StdDevPerBlock::forced_import(
|
|
||||||
db,
|
|
||||||
"price_return_24h",
|
|
||||||
"1y",
|
|
||||||
365,
|
|
||||||
version + v1,
|
|
||||||
indexes,
|
|
||||||
)?,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self { periods, cagr, sd_24h })
|
||||||
periods: price_return,
|
|
||||||
cagr: price_cagr,
|
|
||||||
sd_24h: price_return_24h_sd,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,13 @@ use brk_types::BasisPointsSigned32;
|
|||||||
use vecdb::{Rw, StorageMode};
|
use vecdb::{Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
internal::{PercentPerBlock, StdDevPerBlock},
|
internal::{PercentPerBlock, StdDevPerBlock, Windows},
|
||||||
market::{dca::ByDcaCagr, lookback::ByLookbackPeriod},
|
market::{dca::ByDcaCagr, lookback::ByLookbackPeriod},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Traversable)]
|
|
||||||
pub struct PriceReturn24hSdVecs<M: StorageMode = Rw> {
|
|
||||||
pub _1w: StdDevPerBlock<M>,
|
|
||||||
pub _1m: StdDevPerBlock<M>,
|
|
||||||
pub _1y: StdDevPerBlock<M>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct Vecs<M: StorageMode = Rw> {
|
pub struct Vecs<M: StorageMode = Rw> {
|
||||||
pub periods: ByLookbackPeriod<PercentPerBlock<BasisPointsSigned32, M>>,
|
pub periods: ByLookbackPeriod<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||||
pub cagr: ByDcaCagr<PercentPerBlock<BasisPointsSigned32, M>>,
|
pub cagr: ByDcaCagr<PercentPerBlock<BasisPointsSigned32, M>>,
|
||||||
pub sd_24h: PriceReturn24hSdVecs<M>,
|
pub sd_24h: Windows<StdDevPerBlock<M>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,54 +22,43 @@ impl Vecs {
|
|||||||
starting_indexes: &Indexes,
|
starting_indexes: &Indexes,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Stochastic Oscillator: K = (close - low_2w) / (high_2w - low_2w), stored as ratio (0-1)
|
self.stoch_k.bps.height.compute_transform3(
|
||||||
{
|
starting_indexes.height,
|
||||||
let price = &prices.spot.usd.height;
|
&prices.spot.usd.height,
|
||||||
self.stoch_k.bps.height.compute_transform3(
|
&range.min._2w.usd.height,
|
||||||
starting_indexes.height,
|
&range.max._2w.usd.height,
|
||||||
price,
|
|(h, close, low, high, ..)| {
|
||||||
&range.min._2w.usd.height,
|
let range = *high - *low;
|
||||||
&range.max._2w.usd.height,
|
let stoch = if range == 0.0 {
|
||||||
|(h, close, low, high, ..)| {
|
BasisPoints16::ZERO
|
||||||
let range = *high - *low;
|
} else {
|
||||||
let stoch = if range == 0.0 {
|
BasisPoints16::from((*close - *low) / range)
|
||||||
BasisPoints16::ZERO
|
};
|
||||||
} else {
|
(h, stoch)
|
||||||
BasisPoints16::from((*close - *low) / range)
|
},
|
||||||
};
|
exit,
|
||||||
(h, stoch)
|
)?;
|
||||||
},
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.stoch_d.bps.height.compute_rolling_average(
|
self.stoch_d.bps.height.compute_rolling_average(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
&blocks.lookback._3d,
|
&blocks.lookback._3d,
|
||||||
&self.stoch_k.bps.height,
|
&self.stoch_k.bps.height,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
|
||||||
|
|
||||||
// RSI per timeframe
|
let daily_returns = &returns.periods._24h.ratio.height;
|
||||||
let return_sources = [
|
for (rsi_chain, &m) in self.rsi.as_mut_array().into_iter().zip(&TF_MULTIPLIERS) {
|
||||||
&returns.periods._24h.ratio.height,
|
|
||||||
&returns.periods._1w.ratio.height,
|
|
||||||
&returns.periods._1m.ratio.height,
|
|
||||||
&returns.periods._1y.ratio.height,
|
|
||||||
];
|
|
||||||
for (rsi_chain, ret) in self.rsi.as_mut_array().into_iter().zip(return_sources) {
|
|
||||||
rsi::compute(
|
rsi::compute(
|
||||||
rsi_chain,
|
rsi_chain,
|
||||||
blocks,
|
blocks,
|
||||||
ret,
|
daily_returns,
|
||||||
14,
|
14 * m,
|
||||||
3,
|
3 * m,
|
||||||
starting_indexes,
|
starting_indexes,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MACD per timeframe
|
|
||||||
for (macd_chain, &m) in self.macd.as_mut_array().into_iter().zip(&TF_MULTIPLIERS) {
|
for (macd_chain, &m) in self.macd.as_mut_array().into_iter().zip(&TF_MULTIPLIERS) {
|
||||||
macd::compute(
|
macd::compute(
|
||||||
macd_chain,
|
macd_chain,
|
||||||
@@ -83,7 +72,6 @@ impl Vecs {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pi Cycle: sma_111d / sma_350d_x2
|
|
||||||
self.pi_cycle
|
self.pi_cycle
|
||||||
.bps
|
.bps
|
||||||
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
.compute_binary::<Dollars, Dollars, RatioDollarsBp32>(
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ impl Vecs {
|
|||||||
let v = version + VERSION;
|
let v = version + VERSION;
|
||||||
|
|
||||||
let rsi =
|
let rsi =
|
||||||
Windows::try_from_fn(|tf| RsiChain::forced_import(db, tf, v + Version::ONE, indexes))?;
|
Windows::try_from_fn(|tf| RsiChain::forced_import(db, tf, v + Version::TWO, indexes))?;
|
||||||
let macd = Windows::try_from_fn(|tf| MacdChain::forced_import(db, tf, v, indexes))?;
|
let macd = Windows::try_from_fn(|tf| MacdChain::forced_import(db, tf, v, indexes))?;
|
||||||
|
|
||||||
let stoch_k = PercentPerBlock::forced_import(db, "stoch_k", v, indexes)?;
|
let stoch_k = PercentPerBlock::forced_import(db, "stoch_k", v, indexes)?;
|
||||||
|
|||||||
@@ -4,48 +4,40 @@ use vecdb::ReadableCloneableVec;
|
|||||||
|
|
||||||
use super::super::returns;
|
use super::super::returns;
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::internal::{Days30, Days365, Days7, LazyPerBlock, TimesSqrt};
|
use crate::internal::{Days1, Days7, Days30, Days365, LazyPerBlock, TimesSqrt, Windows};
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn forced_import(version: Version, returns: &returns::Vecs) -> Result<Self> {
|
pub(crate) fn forced_import(version: Version, returns: &returns::Vecs) -> Result<Self> {
|
||||||
let v2 = Version::TWO;
|
let v2 = Version::TWO;
|
||||||
|
|
||||||
|
let _24h = LazyPerBlock::from_computed::<TimesSqrt<Days1>>(
|
||||||
|
"price_volatility_24h",
|
||||||
|
version + v2,
|
||||||
|
returns.sd_24h._24h.sd.height.read_only_boxed_clone(),
|
||||||
|
&returns.sd_24h._24h.sd,
|
||||||
|
);
|
||||||
|
|
||||||
let _1w = LazyPerBlock::from_computed::<TimesSqrt<Days7>>(
|
let _1w = LazyPerBlock::from_computed::<TimesSqrt<Days7>>(
|
||||||
"price_volatility_1w",
|
"price_volatility_1w",
|
||||||
version + v2,
|
version + v2,
|
||||||
returns
|
returns.sd_24h._1w.sd.height.read_only_boxed_clone(),
|
||||||
.sd_24h
|
|
||||||
._1w
|
|
||||||
.sd
|
|
||||||
.height
|
|
||||||
.read_only_boxed_clone(),
|
|
||||||
&returns.sd_24h._1w.sd,
|
&returns.sd_24h._1w.sd,
|
||||||
);
|
);
|
||||||
|
|
||||||
let _1m = LazyPerBlock::from_computed::<TimesSqrt<Days30>>(
|
let _1m = LazyPerBlock::from_computed::<TimesSqrt<Days30>>(
|
||||||
"price_volatility_1m",
|
"price_volatility_1m",
|
||||||
version + v2,
|
version + v2,
|
||||||
returns
|
returns.sd_24h._1m.sd.height.read_only_boxed_clone(),
|
||||||
.sd_24h
|
|
||||||
._1m
|
|
||||||
.sd
|
|
||||||
.height
|
|
||||||
.read_only_boxed_clone(),
|
|
||||||
&returns.sd_24h._1m.sd,
|
&returns.sd_24h._1m.sd,
|
||||||
);
|
);
|
||||||
|
|
||||||
let _1y = LazyPerBlock::from_computed::<TimesSqrt<Days365>>(
|
let _1y = LazyPerBlock::from_computed::<TimesSqrt<Days365>>(
|
||||||
"price_volatility_1y",
|
"price_volatility_1y",
|
||||||
version + v2,
|
version + v2,
|
||||||
returns
|
returns.sd_24h._1y.sd.height.read_only_boxed_clone(),
|
||||||
.sd_24h
|
|
||||||
._1y
|
|
||||||
.sd
|
|
||||||
.height
|
|
||||||
.read_only_boxed_clone(),
|
|
||||||
&returns.sd_24h._1y.sd,
|
&returns.sd_24h._1y.sd,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(Self { _1w, _1m, _1y })
|
Ok(Windows { _24h, _1w, _1m, _1y })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
use brk_traversable::Traversable;
|
|
||||||
|
|
||||||
use crate::internal::LazyPerBlock;
|
|
||||||
|
|
||||||
use brk_types::StoredF32;
|
use brk_types::StoredF32;
|
||||||
#[derive(Clone, Traversable)]
|
|
||||||
pub struct Vecs {
|
use crate::internal::{LazyPerBlock, Windows};
|
||||||
pub _1w: LazyPerBlock<StoredF32>,
|
|
||||||
pub _1m: LazyPerBlock<StoredF32>,
|
pub type Vecs = Windows<LazyPerBlock<StoredF32>>;
|
||||||
pub _1y: LazyPerBlock<StoredF32>,
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ impl Vecs {
|
|||||||
starting_indexes: &Indexes,
|
starting_indexes: &Indexes,
|
||||||
exit: &Exit,
|
exit: &Exit,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.spent
|
|
||||||
.compute(&self.db, indexer, inputs, starting_indexes, exit)?;
|
|
||||||
self.count.compute(
|
self.count.compute(
|
||||||
indexer,
|
indexer,
|
||||||
indexes,
|
indexes,
|
||||||
@@ -29,8 +27,9 @@ impl Vecs {
|
|||||||
starting_indexes,
|
starting_indexes,
|
||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
let _lock = self
|
||||||
let _lock = exit.lock();
|
.spent
|
||||||
|
.compute(indexer, inputs, starting_indexes, exit)?;
|
||||||
self.db.compact()?;
|
self.db.compact()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use brk_error::Result;
|
|||||||
use brk_indexer::Indexer;
|
use brk_indexer::Indexer;
|
||||||
use brk_types::{Height, Indexes, TxInIndex, TxOutIndex};
|
use brk_types::{Height, Indexes, TxInIndex, TxOutIndex};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use vecdb::{AnyStoredVec, AnyVec, Database, Exit, ReadableVec, Stamp, VecIndex, WritableVec};
|
use vecdb::{AnyStoredVec, AnyVec, Exit, ExitGuard, ReadableVec, Stamp, VecIndex, WritableVec};
|
||||||
|
|
||||||
use super::Vecs;
|
use super::Vecs;
|
||||||
use crate::inputs;
|
use crate::inputs;
|
||||||
@@ -10,17 +10,16 @@ use crate::inputs;
|
|||||||
const HEIGHT_BATCH: u32 = 10_000;
|
const HEIGHT_BATCH: u32 = 10_000;
|
||||||
|
|
||||||
impl Vecs {
|
impl Vecs {
|
||||||
pub(crate) fn compute(
|
pub(crate) fn compute<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &Database,
|
|
||||||
indexer: &Indexer,
|
indexer: &Indexer,
|
||||||
inputs: &inputs::Vecs,
|
inputs: &inputs::Vecs,
|
||||||
starting_indexes: &Indexes,
|
starting_indexes: &Indexes,
|
||||||
exit: &Exit,
|
exit: &'a Exit,
|
||||||
) -> Result<()> {
|
) -> Result<ExitGuard<'a>> {
|
||||||
let target_height = indexer.vecs.blocks.blockhash.len();
|
let target_height = indexer.vecs.blocks.blockhash.len();
|
||||||
if target_height == 0 {
|
if target_height == 0 {
|
||||||
return Ok(());
|
return Ok(exit.lock());
|
||||||
}
|
}
|
||||||
let target_height = Height::from(target_height - 1);
|
let target_height = Height::from(target_height - 1);
|
||||||
|
|
||||||
@@ -125,17 +124,15 @@ impl Vecs {
|
|||||||
"TxOuts: {:.2}%",
|
"TxOuts: {:.2}%",
|
||||||
batch_end_height.to_usize() as f64 / target_height.to_usize() as f64 * 100.0
|
batch_end_height.to_usize() as f64 / target_height.to_usize() as f64 * 100.0
|
||||||
);
|
);
|
||||||
db.flush()?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
batch_start_height = batch_end_height + 1_u32;
|
batch_start_height = batch_end_height + 1_u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _lock = exit.lock();
|
let lock = exit.lock();
|
||||||
self.txin_index
|
self.txin_index
|
||||||
.stamped_write_with_changes(Stamp::from(target_height))?;
|
.stamped_write_with_changes(Stamp::from(target_height))?;
|
||||||
db.flush()?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(lock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,16 +128,16 @@ impl Vecs {
|
|||||||
|
|
||||||
if *block.height() % 1_000 == 0 {
|
if *block.height() % 1_000 == 0 {
|
||||||
let _lock = exit.lock();
|
let _lock = exit.lock();
|
||||||
self.block.flush()?;
|
self.block.write()?;
|
||||||
self.tx.flush()?;
|
self.tx.write()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let _lock = exit.lock();
|
let _lock = exit.lock();
|
||||||
self.block.flush()?;
|
self.block.write()?;
|
||||||
self.tx.flush()?;
|
self.tx.write()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn clear_caches(&mut self) {
|
pub fn clear_caches(&mut self) {
|
||||||
for cache in &mut self.caches {
|
for cache in &mut self.caches {
|
||||||
cache.clear();
|
*cache = FxHashMap::default();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,9 +336,6 @@ where
|
|||||||
|
|
||||||
Self::ingest(&self.keyspace, puts.iter(), dels.iter())?;
|
Self::ingest(&self.keyspace, puts.iter(), dels.iter())?;
|
||||||
|
|
||||||
// Pre-allocate for next batch based on current batch size
|
|
||||||
self.puts.reserve(puts.len());
|
|
||||||
|
|
||||||
if !self.caches.is_empty() {
|
if !self.caches.is_empty() {
|
||||||
self.caches.pop();
|
self.caches.pop();
|
||||||
self.caches.insert(0, puts);
|
self.caches.insert(0, puts);
|
||||||
@@ -349,10 +346,10 @@ where
|
|||||||
|
|
||||||
fn reset(&mut self) -> Result<()> {
|
fn reset(&mut self) -> Result<()> {
|
||||||
self.meta.reset()?;
|
self.meta.reset()?;
|
||||||
self.puts.clear();
|
self.puts = FxHashMap::default();
|
||||||
self.dels.clear();
|
self.dels = FxHashSet::default();
|
||||||
for cache in &mut self.caches {
|
for cache in &mut self.caches {
|
||||||
cache.clear();
|
*cache = FxHashMap::default();
|
||||||
}
|
}
|
||||||
self.keyspace.clear()?;
|
self.keyspace.clear()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
+13
-13
@@ -4772,7 +4772,7 @@ function createUnspentPattern(client, acc) {
|
|||||||
* @property {SeriesTree_Market_Ath} ath
|
* @property {SeriesTree_Market_Ath} ath
|
||||||
* @property {SeriesTree_Market_Lookback} lookback
|
* @property {SeriesTree_Market_Lookback} lookback
|
||||||
* @property {SeriesTree_Market_Returns} returns
|
* @property {SeriesTree_Market_Returns} returns
|
||||||
* @property {SeriesTree_Market_Volatility} volatility
|
* @property {_1m1w1y24hPattern<StoredF32>} volatility
|
||||||
* @property {SeriesTree_Market_Range} range
|
* @property {SeriesTree_Market_Range} range
|
||||||
* @property {SeriesTree_Market_MovingAverage} movingAverage
|
* @property {SeriesTree_Market_MovingAverage} movingAverage
|
||||||
* @property {SeriesTree_Market_Dca} dca
|
* @property {SeriesTree_Market_Dca} dca
|
||||||
@@ -4832,11 +4832,18 @@ function createUnspentPattern(client, acc) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} SeriesTree_Market_Returns_Sd24h
|
* @typedef {Object} SeriesTree_Market_Returns_Sd24h
|
||||||
|
* @property {SeriesTree_Market_Returns_Sd24h_24h} _24h
|
||||||
* @property {SeriesTree_Market_Returns_Sd24h_1w} _1w
|
* @property {SeriesTree_Market_Returns_Sd24h_1w} _1w
|
||||||
* @property {SeriesTree_Market_Returns_Sd24h_1m} _1m
|
* @property {SeriesTree_Market_Returns_Sd24h_1m} _1m
|
||||||
* @property {SeriesTree_Market_Returns_Sd24h_1y} _1y
|
* @property {SeriesTree_Market_Returns_Sd24h_1y} _1y
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} SeriesTree_Market_Returns_Sd24h_24h
|
||||||
|
* @property {SeriesPattern1<StoredF32>} sma
|
||||||
|
* @property {SeriesPattern1<StoredF32>} sd
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} SeriesTree_Market_Returns_Sd24h_1w
|
* @typedef {Object} SeriesTree_Market_Returns_Sd24h_1w
|
||||||
* @property {SeriesPattern1<StoredF32>} sma
|
* @property {SeriesPattern1<StoredF32>} sma
|
||||||
@@ -4855,13 +4862,6 @@ function createUnspentPattern(client, acc) {
|
|||||||
* @property {SeriesPattern1<StoredF32>} sd
|
* @property {SeriesPattern1<StoredF32>} sd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} SeriesTree_Market_Volatility
|
|
||||||
* @property {SeriesPattern1<StoredF32>} _1w
|
|
||||||
* @property {SeriesPattern1<StoredF32>} _1m
|
|
||||||
* @property {SeriesPattern1<StoredF32>} _1y
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} SeriesTree_Market_Range
|
* @typedef {Object} SeriesTree_Market_Range
|
||||||
* @property {_1m1w1y2wPattern} min
|
* @property {_1m1w1y2wPattern} min
|
||||||
@@ -8087,6 +8087,10 @@ class BrkClient extends BrkClientBase {
|
|||||||
},
|
},
|
||||||
cagr: create_10y2y3y4y5y6y8yPattern(this, 'price_cagr'),
|
cagr: create_10y2y3y4y5y6y8yPattern(this, 'price_cagr'),
|
||||||
sd24h: {
|
sd24h: {
|
||||||
|
_24h: {
|
||||||
|
sma: createSeriesPattern1(this, 'price_return_24h_sma_24h'),
|
||||||
|
sd: createSeriesPattern1(this, 'price_return_24h_sd_24h'),
|
||||||
|
},
|
||||||
_1w: {
|
_1w: {
|
||||||
sma: createSeriesPattern1(this, 'price_return_24h_sma_1w'),
|
sma: createSeriesPattern1(this, 'price_return_24h_sma_1w'),
|
||||||
sd: createSeriesPattern1(this, 'price_return_24h_sd_1w'),
|
sd: createSeriesPattern1(this, 'price_return_24h_sd_1w'),
|
||||||
@@ -8101,11 +8105,7 @@ class BrkClient extends BrkClientBase {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
volatility: {
|
volatility: create_1m1w1y24hPattern(this, 'price_volatility'),
|
||||||
_1w: createSeriesPattern1(this, 'price_volatility_1w'),
|
|
||||||
_1m: createSeriesPattern1(this, 'price_volatility_1m'),
|
|
||||||
_1y: createSeriesPattern1(this, 'price_volatility_1y'),
|
|
||||||
},
|
|
||||||
range: {
|
range: {
|
||||||
min: create_1m1w1y2wPattern(this, 'price_min'),
|
min: create_1m1w1y2wPattern(this, 'price_min'),
|
||||||
max: create_1m1w1y2wPattern(this, 'price_max'),
|
max: create_1m1w1y2wPattern(this, 'price_max'),
|
||||||
|
|||||||
@@ -4139,6 +4139,13 @@ class SeriesTree_Market_Returns_Periods:
|
|||||||
self._8y: BpsPercentRatioPattern = BpsPercentRatioPattern(client, 'price_return_8y')
|
self._8y: BpsPercentRatioPattern = BpsPercentRatioPattern(client, 'price_return_8y')
|
||||||
self._10y: BpsPercentRatioPattern = BpsPercentRatioPattern(client, 'price_return_10y')
|
self._10y: BpsPercentRatioPattern = BpsPercentRatioPattern(client, 'price_return_10y')
|
||||||
|
|
||||||
|
class SeriesTree_Market_Returns_Sd24h_24h:
|
||||||
|
"""Series tree node."""
|
||||||
|
|
||||||
|
def __init__(self, client: BrkClientBase, base_path: str = ''):
|
||||||
|
self.sma: SeriesPattern1[StoredF32] = SeriesPattern1(client, 'price_return_24h_sma_24h')
|
||||||
|
self.sd: SeriesPattern1[StoredF32] = SeriesPattern1(client, 'price_return_24h_sd_24h')
|
||||||
|
|
||||||
class SeriesTree_Market_Returns_Sd24h_1w:
|
class SeriesTree_Market_Returns_Sd24h_1w:
|
||||||
"""Series tree node."""
|
"""Series tree node."""
|
||||||
|
|
||||||
@@ -4164,6 +4171,7 @@ class SeriesTree_Market_Returns_Sd24h:
|
|||||||
"""Series tree node."""
|
"""Series tree node."""
|
||||||
|
|
||||||
def __init__(self, client: BrkClientBase, base_path: str = ''):
|
def __init__(self, client: BrkClientBase, base_path: str = ''):
|
||||||
|
self._24h: SeriesTree_Market_Returns_Sd24h_24h = SeriesTree_Market_Returns_Sd24h_24h(client)
|
||||||
self._1w: SeriesTree_Market_Returns_Sd24h_1w = SeriesTree_Market_Returns_Sd24h_1w(client)
|
self._1w: SeriesTree_Market_Returns_Sd24h_1w = SeriesTree_Market_Returns_Sd24h_1w(client)
|
||||||
self._1m: SeriesTree_Market_Returns_Sd24h_1m = SeriesTree_Market_Returns_Sd24h_1m(client)
|
self._1m: SeriesTree_Market_Returns_Sd24h_1m = SeriesTree_Market_Returns_Sd24h_1m(client)
|
||||||
self._1y: SeriesTree_Market_Returns_Sd24h_1y = SeriesTree_Market_Returns_Sd24h_1y(client)
|
self._1y: SeriesTree_Market_Returns_Sd24h_1y = SeriesTree_Market_Returns_Sd24h_1y(client)
|
||||||
@@ -4176,14 +4184,6 @@ class SeriesTree_Market_Returns:
|
|||||||
self.cagr: _10y2y3y4y5y6y8yPattern = _10y2y3y4y5y6y8yPattern(client, 'price_cagr')
|
self.cagr: _10y2y3y4y5y6y8yPattern = _10y2y3y4y5y6y8yPattern(client, 'price_cagr')
|
||||||
self.sd_24h: SeriesTree_Market_Returns_Sd24h = SeriesTree_Market_Returns_Sd24h(client)
|
self.sd_24h: SeriesTree_Market_Returns_Sd24h = SeriesTree_Market_Returns_Sd24h(client)
|
||||||
|
|
||||||
class SeriesTree_Market_Volatility:
|
|
||||||
"""Series tree node."""
|
|
||||||
|
|
||||||
def __init__(self, client: BrkClientBase, base_path: str = ''):
|
|
||||||
self._1w: SeriesPattern1[StoredF32] = SeriesPattern1(client, 'price_volatility_1w')
|
|
||||||
self._1m: SeriesPattern1[StoredF32] = SeriesPattern1(client, 'price_volatility_1m')
|
|
||||||
self._1y: SeriesPattern1[StoredF32] = SeriesPattern1(client, 'price_volatility_1y')
|
|
||||||
|
|
||||||
class SeriesTree_Market_Range:
|
class SeriesTree_Market_Range:
|
||||||
"""Series tree node."""
|
"""Series tree node."""
|
||||||
|
|
||||||
@@ -4436,7 +4436,7 @@ class SeriesTree_Market:
|
|||||||
self.ath: SeriesTree_Market_Ath = SeriesTree_Market_Ath(client)
|
self.ath: SeriesTree_Market_Ath = SeriesTree_Market_Ath(client)
|
||||||
self.lookback: SeriesTree_Market_Lookback = SeriesTree_Market_Lookback(client)
|
self.lookback: SeriesTree_Market_Lookback = SeriesTree_Market_Lookback(client)
|
||||||
self.returns: SeriesTree_Market_Returns = SeriesTree_Market_Returns(client)
|
self.returns: SeriesTree_Market_Returns = SeriesTree_Market_Returns(client)
|
||||||
self.volatility: SeriesTree_Market_Volatility = SeriesTree_Market_Volatility(client)
|
self.volatility: _1m1w1y24hPattern[StoredF32] = _1m1w1y24hPattern(client, 'price_volatility')
|
||||||
self.range: SeriesTree_Market_Range = SeriesTree_Market_Range(client)
|
self.range: SeriesTree_Market_Range = SeriesTree_Market_Range(client)
|
||||||
self.moving_average: SeriesTree_Market_MovingAverage = SeriesTree_Market_MovingAverage(client)
|
self.moving_average: SeriesTree_Market_MovingAverage = SeriesTree_Market_MovingAverage(client)
|
||||||
self.dca: SeriesTree_Market_Dca = SeriesTree_Market_Dca(client)
|
self.dca: SeriesTree_Market_Dca = SeriesTree_Market_Dca(client)
|
||||||
|
|||||||
+602
-601
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user