mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-27 16:19:59 -07:00
server: mcp + global: refactor
This commit is contained in:
@@ -163,7 +163,7 @@ where
|
||||
self.height.compute(
|
||||
starting_indexes.height,
|
||||
txindex,
|
||||
&indexer.vecs().height_to_first_txindex,
|
||||
&indexer.vecs.height_to_first_txindex,
|
||||
&indexes.height_to_txindex_count,
|
||||
exit,
|
||||
)?;
|
||||
@@ -173,7 +173,7 @@ where
|
||||
self.height.compute(
|
||||
starting_indexes.height,
|
||||
txindex,
|
||||
&indexer.vecs().height_to_first_txindex,
|
||||
&indexer.vecs.height_to_first_txindex,
|
||||
&indexes.height_to_txindex_count,
|
||||
exit,
|
||||
)?;
|
||||
@@ -289,7 +289,7 @@ impl ComputedVecsFromTxindex<Bitcoin> {
|
||||
|
||||
let starting_index = self.height.starting_index(starting_indexes.height);
|
||||
|
||||
(starting_index.unwrap_to_usize()..indexer.vecs().height_to_weight.len())
|
||||
(starting_index.unwrap_to_usize()..indexer.vecs.height_to_weight.len())
|
||||
.map(Height::from)
|
||||
.try_for_each(|height| -> Result<()> {
|
||||
if let Some(first) = self.height.first.as_mut() {
|
||||
@@ -470,7 +470,7 @@ impl ComputedVecsFromTxindex<Dollars> {
|
||||
|
||||
let mut close_iter = fetched.chainindexes_to_close.height.into_iter();
|
||||
|
||||
(starting_index.unwrap_to_usize()..indexer.vecs().height_to_weight.len())
|
||||
(starting_index.unwrap_to_usize()..indexer.vecs.height_to_weight.len())
|
||||
.map(Height::from)
|
||||
.try_for_each(|height| -> Result<()> {
|
||||
let price = *close_iter.unwrap_get_inner(height);
|
||||
|
||||
@@ -28,6 +28,7 @@ pub struct ComputedRatioVecsFromDateIndex {
|
||||
pub ratio_1y_sma_momentum_oscillator: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_4y_sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_1y_sd: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_p99_9: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_p99_5: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_p99: ComputedVecsFromDateIndex<StoredF32>,
|
||||
@@ -54,6 +55,7 @@ pub struct ComputedRatioVecsFromDateIndex {
|
||||
pub ratio_m3sd_as_price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub ratio_zscore: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_4y_zscore: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_1y_zscore: ComputedVecsFromDateIndex<StoredF32>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
@@ -152,6 +154,14 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
format,
|
||||
options,
|
||||
)?,
|
||||
ratio_1y_sd: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&format!("{name}_ratio_1y_sd"),
|
||||
true,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
)?,
|
||||
ratio_p99_9: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&format!("{name}_ratio_p99_9"),
|
||||
@@ -360,6 +370,14 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
format,
|
||||
options,
|
||||
)?,
|
||||
ratio_1y_zscore: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&format!("{name}_ratio_1y_zscore"),
|
||||
true,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -571,8 +589,8 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
// }
|
||||
|
||||
let mut sma_iter = self.ratio_sma.dateindex.as_ref().unwrap().into_iter();
|
||||
|
||||
let mut _4y_sma_iter = self.ratio_4y_sma.dateindex.as_ref().unwrap().into_iter();
|
||||
let mut _1y_sma_iter = self.ratio_1y_sma.dateindex.as_ref().unwrap().into_iter();
|
||||
|
||||
let nan = StoredF32::from(f32::NAN);
|
||||
self.ratio
|
||||
@@ -622,6 +640,11 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, nan, exit)?;
|
||||
self.ratio_1y_sd
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, nan, exit)?;
|
||||
|
||||
self.ratio_p1sd
|
||||
.dateindex
|
||||
@@ -716,6 +739,20 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
.unwrap()
|
||||
.forced_push_at(index, _4y_sd, exit)?;
|
||||
|
||||
let _1y_avg = _1y_sma_iter.unwrap_get_inner(index);
|
||||
|
||||
let _1y_sd = StoredF32::from(
|
||||
(sorted.iter().map(|v| (**v - *_1y_avg).powi(2)).sum::<f32>()
|
||||
/ (index.unwrap_to_usize() + 1) as f32)
|
||||
.sqrt(),
|
||||
);
|
||||
|
||||
self.ratio_1y_sd
|
||||
.dateindex
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.forced_push_at(index, _1y_sd, exit)?;
|
||||
|
||||
self.ratio_p1sd.dateindex.as_mut().unwrap().forced_push_at(
|
||||
index,
|
||||
avg + sd,
|
||||
@@ -803,6 +840,12 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
exit,
|
||||
None as Option<&EagerVec<_, _>>,
|
||||
)?;
|
||||
self.ratio_1y_sd.compute_rest(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
None as Option<&EagerVec<_, _>>,
|
||||
)?;
|
||||
self.ratio_p1sd.compute_rest(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
@@ -1104,6 +1147,22 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
},
|
||||
)?;
|
||||
|
||||
self.ratio_1y_zscore.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_zscore(
|
||||
starting_indexes.dateindex,
|
||||
self.ratio.dateindex.as_ref().unwrap(),
|
||||
self.ratio_1y_sma.dateindex.as_ref().unwrap(),
|
||||
self.ratio_1y_sd.dateindex.as_ref().unwrap(),
|
||||
exit,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1111,6 +1170,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
vec![
|
||||
self.ratio_sd.dateindex.as_mut().unwrap(),
|
||||
self.ratio_4y_sd.dateindex.as_mut().unwrap(),
|
||||
self.ratio_1y_sd.dateindex.as_mut().unwrap(),
|
||||
self.ratio_p99_9.dateindex.as_mut().unwrap(),
|
||||
self.ratio_p99_5.dateindex.as_mut().unwrap(),
|
||||
self.ratio_p99.dateindex.as_mut().unwrap(),
|
||||
@@ -1137,6 +1197,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
self.ratio_4y_sma.vecs(),
|
||||
self.ratio_1y_sma_momentum_oscillator.vecs(),
|
||||
self.ratio_sd.vecs(),
|
||||
self.ratio_1y_sd.vecs(),
|
||||
self.ratio_4y_sd.vecs(),
|
||||
self.ratio_p99_9.vecs(),
|
||||
self.ratio_p99_5.vecs(),
|
||||
@@ -1163,6 +1224,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
self.ratio_m2sd_as_price.vecs(),
|
||||
self.ratio_m3sd_as_price.vecs(),
|
||||
self.ratio_zscore.vecs(),
|
||||
self.ratio_1y_zscore.vecs(),
|
||||
self.ratio_4y_zscore.vecs(),
|
||||
]
|
||||
.into_iter()
|
||||
|
||||
@@ -205,7 +205,7 @@ impl ComputedValueVecsFromTxindex {
|
||||
|
||||
dollars_txindex.compute_if_necessary(
|
||||
starting_indexes.txindex,
|
||||
&indexer.vecs().txindex_to_txid,
|
||||
&indexer.vecs.txindex_to_txid,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user