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