mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-03 10:57:56 -07:00
global: snapshot
This commit is contained in:
@@ -144,7 +144,7 @@ where
|
||||
Box::new(
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("cum"),
|
||||
&suffix("cumulative"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
|
||||
@@ -197,7 +197,7 @@ where
|
||||
}),
|
||||
cumulative: options.cumulative.then(|| {
|
||||
Box::new(LazyVecFrom2::init(
|
||||
&suffix("cum"),
|
||||
&suffix("cumulative"),
|
||||
version + VERSION + Version::ZERO,
|
||||
source_extra.cumulative.as_ref().unwrap().boxed_clone(),
|
||||
len_source.clone(),
|
||||
|
||||
@@ -447,7 +447,7 @@ impl ComputedVecsFromTxindex<Dollars> {
|
||||
|
||||
let starting_index = self.height.starting_index(starting_indexes.height);
|
||||
|
||||
let mut close_iter = price.chainindexes_to_close.height.into_iter();
|
||||
let mut close_iter = price.chainindexes_to_price_close.height.into_iter();
|
||||
|
||||
(starting_index.unwrap_to_usize()..indexer.vecs.height_to_weight.len())
|
||||
.map(Height::from)
|
||||
|
||||
@@ -22,18 +22,18 @@ pub struct ComputedRatioVecsFromDateIndex {
|
||||
pub ratio: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_1w_sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_1m_sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_p99: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_p98: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_p95: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_p5: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_p2: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_p1: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_p99_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_p98_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_p95_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_p5_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_p2_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_p1_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_pct99: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_pct98: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_pct95: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_pct5: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_pct2: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_pct1: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub ratio_pct99_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_pct98_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_pct95_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_pct5_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_pct2_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub ratio_pct1_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
|
||||
pub ratio_sd: Option<ComputedStandardDeviationVecsFromDateIndex>,
|
||||
pub ratio_4y_sd: Option<ComputedStandardDeviationVecsFromDateIndex>,
|
||||
@@ -141,10 +141,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p99: extended.then(|| {
|
||||
ratio_pct99: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p99"),
|
||||
&format!("{name}_ratio_pct99"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -152,10 +152,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p98: extended.then(|| {
|
||||
ratio_pct98: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p98"),
|
||||
&format!("{name}_ratio_pct98"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -163,10 +163,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p95: extended.then(|| {
|
||||
ratio_pct95: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p95"),
|
||||
&format!("{name}_ratio_pct95"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -174,10 +174,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p5: extended.then(|| {
|
||||
ratio_pct5: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p5"),
|
||||
&format!("{name}_ratio_pct5"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -185,10 +185,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p2: extended.then(|| {
|
||||
ratio_pct2: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p2"),
|
||||
&format!("{name}_ratio_pct2"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -196,10 +196,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p1: extended.then(|| {
|
||||
ratio_pct1: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p1"),
|
||||
&format!("{name}_ratio_pct1"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -207,10 +207,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p99_as_price: extended.then(|| {
|
||||
ratio_pct99_in_usd: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p99_as_price"),
|
||||
&format!("{name}_ratio_pct99_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -218,10 +218,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p98_as_price: extended.then(|| {
|
||||
ratio_pct98_in_usd: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p98_as_price"),
|
||||
&format!("{name}_ratio_pct98_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -229,10 +229,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p95_as_price: extended.then(|| {
|
||||
ratio_pct95_in_usd: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p95_as_price"),
|
||||
&format!("{name}_ratio_pct95_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -240,10 +240,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p5_as_price: extended.then(|| {
|
||||
ratio_pct5_in_usd: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p5_as_price"),
|
||||
&format!("{name}_ratio_pct5_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -251,10 +251,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p2_as_price: extended.then(|| {
|
||||
ratio_pct2_in_usd: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p2_as_price"),
|
||||
&format!("{name}_ratio_pct2_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -262,10 +262,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio_p1_as_price: extended.then(|| {
|
||||
ratio_pct1_in_usd: extended.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_ratio_p1_as_price"),
|
||||
&format!("{name}_ratio_pct1_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -322,7 +322,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
exit: &Exit,
|
||||
price_opt: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
|
||||
) -> Result<()> {
|
||||
let closes = price.timeindexes_to_close.dateindex.as_ref().unwrap();
|
||||
let closes = price.timeindexes_to_price_close.dateindex.as_ref().unwrap();
|
||||
|
||||
let price = price_opt.unwrap_or_else(|| unsafe {
|
||||
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
|
||||
@@ -423,42 +423,42 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
.iter_at(starting_dateindex)
|
||||
.try_for_each(|(index, ratio)| -> Result<()> {
|
||||
if index < min_ratio_date {
|
||||
self.ratio_p5
|
||||
self.ratio_pct5
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, StoredF32::NAN, exit)?;
|
||||
self.ratio_p2
|
||||
self.ratio_pct2
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, StoredF32::NAN, exit)?;
|
||||
self.ratio_p1
|
||||
self.ratio_pct1
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, StoredF32::NAN, exit)?;
|
||||
self.ratio_p95
|
||||
self.ratio_pct95
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, StoredF32::NAN, exit)?;
|
||||
self.ratio_p98
|
||||
self.ratio_pct98
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, StoredF32::NAN, exit)?;
|
||||
self.ratio_p99
|
||||
self.ratio_pct99
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
@@ -470,42 +470,42 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos);
|
||||
sorted.insert(pos, ratio);
|
||||
|
||||
self.ratio_p1
|
||||
self.ratio_pct1
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, get_percentile(&sorted, 0.01), exit)?;
|
||||
self.ratio_p2
|
||||
self.ratio_pct2
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, get_percentile(&sorted, 0.02), exit)?;
|
||||
self.ratio_p5
|
||||
self.ratio_pct5
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, get_percentile(&sorted, 0.05), exit)?;
|
||||
self.ratio_p95
|
||||
self.ratio_pct95
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, get_percentile(&sorted, 0.95), exit)?;
|
||||
self.ratio_p98
|
||||
self.ratio_pct98
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, get_percentile(&sorted, 0.98), exit)?;
|
||||
self.ratio_p99
|
||||
self.ratio_pct99
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
@@ -521,32 +521,32 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
.into_iter()
|
||||
.try_for_each(|v| v.safe_flush(exit))?;
|
||||
|
||||
self.ratio_p1.as_mut().unwrap().compute_rest(
|
||||
self.ratio_pct1.as_mut().unwrap().compute_rest(
|
||||
starting_indexes,
|
||||
exit,
|
||||
None as Option<&EagerVec<_, _>>,
|
||||
)?;
|
||||
self.ratio_p2.as_mut().unwrap().compute_rest(
|
||||
self.ratio_pct2.as_mut().unwrap().compute_rest(
|
||||
starting_indexes,
|
||||
exit,
|
||||
None as Option<&EagerVec<_, _>>,
|
||||
)?;
|
||||
self.ratio_p5.as_mut().unwrap().compute_rest(
|
||||
self.ratio_pct5.as_mut().unwrap().compute_rest(
|
||||
starting_indexes,
|
||||
exit,
|
||||
None as Option<&EagerVec<_, _>>,
|
||||
)?;
|
||||
self.ratio_p95.as_mut().unwrap().compute_rest(
|
||||
self.ratio_pct95.as_mut().unwrap().compute_rest(
|
||||
starting_indexes,
|
||||
exit,
|
||||
None as Option<&EagerVec<_, _>>,
|
||||
)?;
|
||||
self.ratio_p98.as_mut().unwrap().compute_rest(
|
||||
self.ratio_pct98.as_mut().unwrap().compute_rest(
|
||||
starting_indexes,
|
||||
exit,
|
||||
None as Option<&EagerVec<_, _>>,
|
||||
)?;
|
||||
self.ratio_p99.as_mut().unwrap().compute_rest(
|
||||
self.ratio_pct99.as_mut().unwrap().compute_rest(
|
||||
starting_indexes,
|
||||
exit,
|
||||
None as Option<&EagerVec<_, _>>,
|
||||
@@ -556,14 +556,14 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
|
||||
});
|
||||
|
||||
self.ratio_p99_as_price.as_mut().unwrap().compute_all(
|
||||
self.ratio_pct99_in_usd.as_mut().unwrap().compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
let mut iter = self
|
||||
.ratio_p99
|
||||
.ratio_pct99
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
@@ -583,10 +583,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
},
|
||||
)?;
|
||||
|
||||
let compute_as_price =
|
||||
|as_price: Option<&mut ComputedVecsFromDateIndex<Dollars>>,
|
||||
let compute_in_usd =
|
||||
|in_usd: Option<&mut ComputedVecsFromDateIndex<Dollars>>,
|
||||
source: Option<&ComputedVecsFromDateIndex<StoredF32>>| {
|
||||
as_price.unwrap().compute_all(
|
||||
in_usd.unwrap().compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
@@ -607,12 +607,12 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
)
|
||||
};
|
||||
|
||||
compute_as_price(self.ratio_p1_as_price.as_mut(), self.ratio_p1.as_ref())?;
|
||||
compute_as_price(self.ratio_p2_as_price.as_mut(), self.ratio_p2.as_ref())?;
|
||||
compute_as_price(self.ratio_p5_as_price.as_mut(), self.ratio_p5.as_ref())?;
|
||||
compute_as_price(self.ratio_p95_as_price.as_mut(), self.ratio_p95.as_ref())?;
|
||||
compute_as_price(self.ratio_p98_as_price.as_mut(), self.ratio_p98.as_ref())?;
|
||||
compute_as_price(self.ratio_p99_as_price.as_mut(), self.ratio_p99.as_ref())?;
|
||||
compute_in_usd(self.ratio_pct1_in_usd.as_mut(), self.ratio_pct1.as_ref())?;
|
||||
compute_in_usd(self.ratio_pct2_in_usd.as_mut(), self.ratio_pct2.as_ref())?;
|
||||
compute_in_usd(self.ratio_pct5_in_usd.as_mut(), self.ratio_pct5.as_ref())?;
|
||||
compute_in_usd(self.ratio_pct95_in_usd.as_mut(), self.ratio_pct95.as_ref())?;
|
||||
compute_in_usd(self.ratio_pct98_in_usd.as_mut(), self.ratio_pct98.as_ref())?;
|
||||
compute_in_usd(self.ratio_pct99_in_usd.as_mut(), self.ratio_pct99.as_ref())?;
|
||||
|
||||
self.ratio_sd.as_mut().unwrap().compute_all(
|
||||
indexer,
|
||||
@@ -652,22 +652,22 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
|
||||
fn mut_ratio_vecs(&mut self) -> Vec<&mut EagerVec<DateIndex, StoredF32>> {
|
||||
[
|
||||
self.ratio_p1
|
||||
self.ratio_pct1
|
||||
.as_mut()
|
||||
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
|
||||
self.ratio_p2
|
||||
self.ratio_pct2
|
||||
.as_mut()
|
||||
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
|
||||
self.ratio_p5
|
||||
self.ratio_pct5
|
||||
.as_mut()
|
||||
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
|
||||
self.ratio_p95
|
||||
self.ratio_pct95
|
||||
.as_mut()
|
||||
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
|
||||
self.ratio_p98
|
||||
self.ratio_pct98
|
||||
.as_mut()
|
||||
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
|
||||
self.ratio_p99
|
||||
self.ratio_pct99
|
||||
.as_mut()
|
||||
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
|
||||
]
|
||||
@@ -686,22 +686,22 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
self.ratio_1y_sd.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_2y_sd.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_4y_sd.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p1.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p2.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p5.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p95.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p98.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p99.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p1_as_price.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p2_as_price.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p5_as_price.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p95_as_price
|
||||
self.ratio_pct1.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct2.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct5.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct95.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct98.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct99.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct1_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct2_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct5_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_pct95_in_usd
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p98_as_price
|
||||
self.ratio_pct98_in_usd
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.ratio_p99_as_price
|
||||
self.ratio_pct99_in_usd
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
]
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct ComputedStandardDeviationVecsFromDateIndex {
|
||||
|
||||
pub sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub _0sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub _0sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p0_5sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub p1sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub p1_5sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
@@ -29,18 +29,18 @@ pub struct ComputedStandardDeviationVecsFromDateIndex {
|
||||
pub m2sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub m2_5sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub m3sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub p0_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p1sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p1_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p2sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p2_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p3sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m0_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m1sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m1_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m2sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m2_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m3sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p0_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p1sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p1_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p2sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p2_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub p3sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m0_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m1sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m1_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m2sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m2_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub m3sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub zscore: ComputedVecsFromDateIndex<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -175,105 +175,105 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
_0sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
_0sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_0sd_as_price"),
|
||||
&format!("{name}_0sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
p0_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
p0_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_p0_5sd_as_price"),
|
||||
&format!("{name}_p0_5sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
p1sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
p1sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_p1sd_as_price"),
|
||||
&format!("{name}_p1sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
p1_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
p1_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_p1_5sd_as_price"),
|
||||
&format!("{name}_p1_5sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
p2sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
p2sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_p2sd_as_price"),
|
||||
&format!("{name}_p2sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
p2_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
p2_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_p2_5sd_as_price"),
|
||||
&format!("{name}_p2_5sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
p3sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
p3sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_p3sd_as_price"),
|
||||
&format!("{name}_p3sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
m0_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
m0_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_m0_5sd_as_price"),
|
||||
&format!("{name}_m0_5sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
m1sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
m1sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_m1sd_as_price"),
|
||||
&format!("{name}_m1sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
m1_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
m1_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_m1_5sd_as_price"),
|
||||
&format!("{name}_m1_5sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
m2sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
m2sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_m2sd_as_price"),
|
||||
&format!("{name}_m2sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
m2_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
m2_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_m2_5sd_as_price"),
|
||||
&format!("{name}_m2_5sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
m3sd_as_price: ComputedVecsFromDateIndex::forced_import(
|
||||
m3sd_in_usd: ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&format!("{name}_m3sd_as_price"),
|
||||
&format!("{name}_m3sd_in_usd"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -297,7 +297,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
source: &impl CollectableVec<DateIndex, StoredF32>,
|
||||
source_as_price: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
|
||||
source_in_usd: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
|
||||
) -> Result<()> {
|
||||
let min_date = DateIndex::try_from(Date::MIN_RATIO).unwrap();
|
||||
|
||||
@@ -326,7 +326,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
exit,
|
||||
sma_opt,
|
||||
source,
|
||||
source_as_price,
|
||||
source_in_usd,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
exit: &Exit,
|
||||
sma_opt: Option<&impl AnyIterableVec<DateIndex, StoredF32>>,
|
||||
source: &impl CollectableVec<DateIndex, StoredF32>,
|
||||
source_as_price: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
|
||||
source_in_usd: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
|
||||
) -> Result<()> {
|
||||
let sma = sma_opt.unwrap_or_else(|| unsafe {
|
||||
std::mem::transmute(&self.sma.as_ref().unwrap().dateindex)
|
||||
@@ -571,14 +571,14 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
},
|
||||
)?;
|
||||
|
||||
let Some(price) = source_as_price else {
|
||||
let Some(price) = source_in_usd else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let compute_as_price =
|
||||
|as_price: &mut ComputedVecsFromDateIndex<Dollars>,
|
||||
let compute_in_usd =
|
||||
|in_usd: &mut ComputedVecsFromDateIndex<Dollars>,
|
||||
mut iter: BoxedVecIterator<DateIndex, StoredF32>| {
|
||||
as_price.compute_all(
|
||||
in_usd.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
@@ -598,53 +598,53 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
)
|
||||
};
|
||||
|
||||
compute_as_price(&mut self._0sd_as_price, sma.iter())?;
|
||||
compute_as_price(
|
||||
&mut self.p0_5sd_as_price,
|
||||
compute_in_usd(&mut self._0sd_in_usd, sma.iter())?;
|
||||
compute_in_usd(
|
||||
&mut self.p0_5sd_in_usd,
|
||||
self.p0_5sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.p1sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.p1sd_in_usd,
|
||||
self.p1sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.p1_5sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.p1_5sd_in_usd,
|
||||
self.p1_5sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.p2sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.p2sd_in_usd,
|
||||
self.p2sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.p2_5sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.p2_5sd_in_usd,
|
||||
self.p2_5sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.p3sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.p3sd_in_usd,
|
||||
self.p3sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.m0_5sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.m0_5sd_in_usd,
|
||||
self.m0_5sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.m1sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.m1sd_in_usd,
|
||||
self.m1sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.m1_5sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.m1_5sd_in_usd,
|
||||
self.m1_5sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.m2sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.m2sd_in_usd,
|
||||
self.m2sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.m2_5sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.m2_5sd_in_usd,
|
||||
self.m2_5sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
compute_as_price(
|
||||
&mut self.m3sd_as_price,
|
||||
compute_in_usd(
|
||||
&mut self.m3sd_in_usd,
|
||||
self.m3sd.dateindex.as_ref().unwrap().iter(),
|
||||
)?;
|
||||
|
||||
@@ -685,19 +685,19 @@ impl ComputedStandardDeviationVecsFromDateIndex {
|
||||
self.m2sd.vecs(),
|
||||
self.m2_5sd.vecs(),
|
||||
self.m3sd.vecs(),
|
||||
self._0sd_as_price.vecs(),
|
||||
self.p0_5sd_as_price.vecs(),
|
||||
self.p1sd_as_price.vecs(),
|
||||
self.p1_5sd_as_price.vecs(),
|
||||
self.p2sd_as_price.vecs(),
|
||||
self.p2_5sd_as_price.vecs(),
|
||||
self.p3sd_as_price.vecs(),
|
||||
self.m0_5sd_as_price.vecs(),
|
||||
self.m1sd_as_price.vecs(),
|
||||
self.m1_5sd_as_price.vecs(),
|
||||
self.m2sd_as_price.vecs(),
|
||||
self.m2_5sd_as_price.vecs(),
|
||||
self.m3sd_as_price.vecs(),
|
||||
self._0sd_in_usd.vecs(),
|
||||
self.p0_5sd_in_usd.vecs(),
|
||||
self.p1sd_in_usd.vecs(),
|
||||
self.p1_5sd_in_usd.vecs(),
|
||||
self.p2sd_in_usd.vecs(),
|
||||
self.p2_5sd_in_usd.vecs(),
|
||||
self.p3sd_in_usd.vecs(),
|
||||
self.m0_5sd_in_usd.vecs(),
|
||||
self.m1sd_in_usd.vecs(),
|
||||
self.m1_5sd_in_usd.vecs(),
|
||||
self.m2sd_in_usd.vecs(),
|
||||
self.m2_5sd_in_usd.vecs(),
|
||||
self.m3sd_in_usd.vecs(),
|
||||
self.zscore.vecs(),
|
||||
]
|
||||
.into_iter()
|
||||
|
||||
@@ -138,10 +138,10 @@ impl ComputedValueVecsFromDateIndex {
|
||||
}
|
||||
|
||||
let dateindex_to_bitcoin = self.bitcoin.dateindex.as_ref().unwrap();
|
||||
let dateindex_to_close = price
|
||||
let dateindex_to_price_close = price
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.timeindexes_to_close
|
||||
.timeindexes_to_price_close
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
@@ -156,7 +156,7 @@ impl ComputedValueVecsFromDateIndex {
|
||||
v.compute_from_bitcoin(
|
||||
starting_indexes.dateindex,
|
||||
dateindex_to_bitcoin,
|
||||
dateindex_to_close,
|
||||
dateindex_to_price_close,
|
||||
exit,
|
||||
)
|
||||
},
|
||||
|
||||
@@ -139,7 +139,7 @@ impl ComputedValueVecsFromHeight {
|
||||
}
|
||||
|
||||
let height_to_bitcoin = self.bitcoin.height.as_ref().unwrap();
|
||||
let height_to_close = &price.as_ref().unwrap().chainindexes_to_close.height;
|
||||
let height_to_price_close = &price.as_ref().unwrap().chainindexes_to_price_close.height;
|
||||
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.compute_all(
|
||||
@@ -151,7 +151,7 @@ impl ComputedValueVecsFromHeight {
|
||||
v.compute_from_bitcoin(
|
||||
starting_indexes.height,
|
||||
height_to_bitcoin,
|
||||
height_to_close,
|
||||
height_to_price_close,
|
||||
exit,
|
||||
)
|
||||
},
|
||||
|
||||
@@ -78,23 +78,25 @@ impl ComputedValueVecsFromTxindex {
|
||||
version + VERSION,
|
||||
bitcoin_txindex.boxed_clone(),
|
||||
indexes.txindex_to_height.boxed_clone(),
|
||||
price.chainindexes_to_close.height.boxed_clone(),
|
||||
price.chainindexes_to_price_close.height.boxed_clone(),
|
||||
|txindex: TxIndex,
|
||||
txindex_to_btc_iter,
|
||||
txindex_to_in_btc_iter,
|
||||
txindex_to_height_iter,
|
||||
height_to_close_iter| {
|
||||
height_to_price_close_iter| {
|
||||
let txindex = txindex.unwrap_to_usize();
|
||||
txindex_to_btc_iter.next_at(txindex).and_then(|(_, value)| {
|
||||
let btc = value.into_owned();
|
||||
txindex_to_height_iter
|
||||
.next_at(txindex)
|
||||
.and_then(|(_, value)| {
|
||||
let height = value.into_owned();
|
||||
height_to_close_iter
|
||||
.next_at(height.unwrap_to_usize())
|
||||
.map(|(_, close)| *close.into_owned() * btc)
|
||||
})
|
||||
})
|
||||
txindex_to_in_btc_iter
|
||||
.next_at(txindex)
|
||||
.and_then(|(_, value)| {
|
||||
let btc = value.into_owned();
|
||||
txindex_to_height_iter
|
||||
.next_at(txindex)
|
||||
.and_then(|(_, value)| {
|
||||
let height = value.into_owned();
|
||||
height_to_price_close_iter
|
||||
.next_at(height.unwrap_to_usize())
|
||||
.map(|(_, close)| *close.into_owned() * btc)
|
||||
})
|
||||
})
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
@@ -102,13 +102,13 @@ impl ComputedHeightValueVecs {
|
||||
}
|
||||
|
||||
let height_to_bitcoin = &self.bitcoin;
|
||||
let height_to_close = &price.as_ref().unwrap().chainindexes_to_close.height;
|
||||
let height_to_price_close = &price.as_ref().unwrap().chainindexes_to_price_close.height;
|
||||
|
||||
if let Some(dollars) = self.dollars.as_mut() {
|
||||
dollars.compute_from_bitcoin(
|
||||
starting_indexes.height,
|
||||
height_to_bitcoin,
|
||||
height_to_close,
|
||||
height_to_price_close,
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user