mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-29 00:59:58 -07:00
global: add datasets and charts
This commit is contained in:
@@ -3,9 +3,10 @@ use std::path::Path;
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_structs::{
|
||||
CheckedSub, Date, DateIndex, DifficultyEpoch, Dollars, FeeRate, HalvingEpoch, Height,
|
||||
InputIndex, OutputIndex, Sats, StoredBool, StoredF32, StoredF64, StoredU32, StoredU64,
|
||||
Timestamp, TxIndex, TxVersion, Version, Weight,
|
||||
CheckedSub, Date, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, FeeRate, HalvingEpoch,
|
||||
Height, InputIndex, MonthIndex, OutputIndex, QuarterIndex, Sats, SemesterIndex, StoredBool,
|
||||
StoredF32, StoredF64, StoredU32, StoredU64, Timestamp, TxIndex, TxVersion, Version, WeekIndex,
|
||||
Weight, YearIndex,
|
||||
};
|
||||
use vecdb::{
|
||||
AnyCloneableIterableVec, AnyCollectableVec, AnyIterableVec, Database, EagerVec, Exit,
|
||||
@@ -20,12 +21,30 @@ use crate::grouped::{
|
||||
use super::{Indexes, indexes, price};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
const TARGET_BLOCKS_PER_DAY: f64 = 144.0;
|
||||
const TARGET_BLOCKS_PER_DAY_F64: f64 = 144.0;
|
||||
const TARGET_BLOCKS_PER_DAY: u64 = 144;
|
||||
const TARGET_BLOCKS_PER_WEEK: u64 = 7 * TARGET_BLOCKS_PER_DAY;
|
||||
const TARGET_BLOCKS_PER_MONTH: u64 = 30 * TARGET_BLOCKS_PER_DAY;
|
||||
const TARGET_BLOCKS_PER_QUARTER: u64 = 3 * TARGET_BLOCKS_PER_MONTH;
|
||||
const TARGET_BLOCKS_PER_SEMESTER: u64 = 2 * TARGET_BLOCKS_PER_QUARTER;
|
||||
const TARGET_BLOCKS_PER_YEAR: u64 = 2 * TARGET_BLOCKS_PER_SEMESTER;
|
||||
const TARGET_BLOCKS_PER_DECADE: u64 = 10 * TARGET_BLOCKS_PER_YEAR;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
db: Database,
|
||||
|
||||
pub dateindex_to_block_count_target: LazyVecFrom1<DateIndex, StoredU64, DateIndex, DateIndex>,
|
||||
pub weekindex_to_block_count_target: LazyVecFrom1<WeekIndex, StoredU64, WeekIndex, WeekIndex>,
|
||||
pub monthindex_to_block_count_target:
|
||||
LazyVecFrom1<MonthIndex, StoredU64, MonthIndex, MonthIndex>,
|
||||
pub quarterindex_to_block_count_target:
|
||||
LazyVecFrom1<QuarterIndex, StoredU64, QuarterIndex, QuarterIndex>,
|
||||
pub semesterindex_to_block_count_target:
|
||||
LazyVecFrom1<SemesterIndex, StoredU64, SemesterIndex, SemesterIndex>,
|
||||
pub yearindex_to_block_count_target: LazyVecFrom1<YearIndex, StoredU64, YearIndex, YearIndex>,
|
||||
pub decadeindex_to_block_count_target:
|
||||
LazyVecFrom1<DecadeIndex, StoredU64, DecadeIndex, DecadeIndex>,
|
||||
pub height_to_interval: EagerVec<Height, Timestamp>,
|
||||
pub height_to_vbytes: EagerVec<Height, StoredU64>,
|
||||
pub difficultyepoch_to_timestamp: EagerVec<DifficultyEpoch, Timestamp>,
|
||||
@@ -39,7 +58,6 @@ pub struct Vecs {
|
||||
pub indexes_to_difficulty: ComputedVecsFromHeight<StoredF64>,
|
||||
pub indexes_to_difficultyepoch: ComputedVecsFromDateIndex<DifficultyEpoch>,
|
||||
pub indexes_to_halvingepoch: ComputedVecsFromDateIndex<HalvingEpoch>,
|
||||
|
||||
pub indexes_to_coinbase: ComputedValueVecsFromHeight,
|
||||
pub indexes_to_emptyoutput_count: ComputedVecsFromHeight<StoredU64>,
|
||||
pub indexes_to_fee: ComputedValueVecsFromTxindex,
|
||||
@@ -288,7 +306,57 @@ impl Vecs {
|
||||
let txindex_to_fee_rate =
|
||||
EagerVec::forced_import_compressed(&db, "fee_rate", version + VERSION + Version::ZERO)?;
|
||||
|
||||
let dateindex_to_block_count_target = LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes.dateindex_to_dateindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DAY)),
|
||||
);
|
||||
let weekindex_to_block_count_target = LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes.weekindex_to_weekindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_WEEK)),
|
||||
);
|
||||
let monthindex_to_block_count_target = LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes.monthindex_to_monthindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_MONTH)),
|
||||
);
|
||||
let quarterindex_to_block_count_target = LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes.quarterindex_to_quarterindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_QUARTER)),
|
||||
);
|
||||
let semesterindex_to_block_count_target = LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes.semesterindex_to_semesterindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_SEMESTER)),
|
||||
);
|
||||
let yearindex_to_block_count_target = LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes.yearindex_to_yearindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_YEAR)),
|
||||
);
|
||||
let decadeindex_to_block_count_target = LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes.decadeindex_to_decadeindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DECADE)),
|
||||
);
|
||||
|
||||
let this = Self {
|
||||
dateindex_to_block_count_target,
|
||||
weekindex_to_block_count_target,
|
||||
monthindex_to_block_count_target,
|
||||
quarterindex_to_block_count_target,
|
||||
semesterindex_to_block_count_target,
|
||||
yearindex_to_block_count_target,
|
||||
decadeindex_to_block_count_target,
|
||||
height_to_interval: EagerVec::forced_import_compressed(
|
||||
&db,
|
||||
"interval",
|
||||
@@ -1538,7 +1606,7 @@ impl Vecs {
|
||||
i,
|
||||
StoredF64::from(
|
||||
(f64::from(block_count_sum)
|
||||
/ (target_multiplier * TARGET_BLOCKS_PER_DAY))
|
||||
/ (target_multiplier * TARGET_BLOCKS_PER_DAY_F64))
|
||||
* f64::from(difficulty_as_hash),
|
||||
),
|
||||
)
|
||||
@@ -1686,6 +1754,13 @@ impl Vecs {
|
||||
&self.txindex_to_weight,
|
||||
&self.dateindex_to_fee_dominance,
|
||||
&self.dateindex_to_subsidy_dominance,
|
||||
&self.dateindex_to_block_count_target,
|
||||
&self.weekindex_to_block_count_target,
|
||||
&self.monthindex_to_block_count_target,
|
||||
&self.quarterindex_to_block_count_target,
|
||||
&self.semesterindex_to_block_count_target,
|
||||
&self.yearindex_to_block_count_target,
|
||||
&self.decadeindex_to_block_count_target,
|
||||
],
|
||||
self.indexes_to_hash_rate.vecs(),
|
||||
self.indexes_to_hash_rate_1w_sma.vecs(),
|
||||
|
||||
@@ -26,7 +26,6 @@ pub struct Vecs {
|
||||
pub constant_4: ComputedVecsFromHeight<StoredU16>,
|
||||
pub constant_50: ComputedVecsFromHeight<StoredU16>,
|
||||
pub constant_100: ComputedVecsFromHeight<StoredU16>,
|
||||
pub constant_144: ComputedVecsFromHeight<StoredU16>,
|
||||
pub constant_600: ComputedVecsFromHeight<StoredU16>,
|
||||
pub constant_minus_1: ComputedVecsFromHeight<StoredI16>,
|
||||
pub constant_minus_2: ComputedVecsFromHeight<StoredI16>,
|
||||
@@ -95,14 +94,6 @@ impl Vecs {
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
constant_144: ComputedVecsFromHeight::forced_import(
|
||||
&db,
|
||||
"constant_144",
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
constant_600: ComputedVecsFromHeight::forced_import(
|
||||
&db,
|
||||
"constant_600",
|
||||
@@ -184,7 +175,6 @@ impl Vecs {
|
||||
(&mut self.constant_4, 4),
|
||||
(&mut self.constant_50, 50),
|
||||
(&mut self.constant_100, 100),
|
||||
(&mut self.constant_144, 144),
|
||||
(&mut self.constant_600, 600),
|
||||
]
|
||||
.into_iter()
|
||||
@@ -245,7 +235,6 @@ impl Vecs {
|
||||
self.constant_4.vecs(),
|
||||
self.constant_50.vecs(),
|
||||
self.constant_100.vecs(),
|
||||
self.constant_144.vecs(),
|
||||
self.constant_600.vecs(),
|
||||
self.constant_minus_1.vecs(),
|
||||
self.constant_minus_2.vecs(),
|
||||
|
||||
@@ -77,8 +77,10 @@ pub struct Vecs {
|
||||
pub indexes_to_value_destroyed: Option<ComputedVecsFromHeight<Dollars>>,
|
||||
pub indexes_to_unrealized_profit: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub indexes_to_unrealized_loss: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub height_to_unrealized_total_pnl: Option<EagerVec<Height, Dollars>>,
|
||||
pub indexes_to_unrealized_total_pnl: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub height_to_total_unrealized_pnl: Option<EagerVec<Height, Dollars>>,
|
||||
pub indexes_to_total_unrealized_pnl: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub height_to_total_realized_pnl: Option<EagerVec<Height, Dollars>>,
|
||||
pub indexes_to_total_realized_pnl: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub indexes_to_min_price_paid: Option<ComputedVecsFromHeight<Dollars>>,
|
||||
pub indexes_to_max_price_paid: Option<ComputedVecsFromHeight<Dollars>>,
|
||||
pub height_to_supply_half_value: ComputedHeightValueVecs,
|
||||
@@ -110,21 +112,21 @@ pub struct Vecs {
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_net_unrealized_pnl_rel_to_own_market_cap:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub height_to_unrealized_profit_rel_to_own_unrealized_total_pnl:
|
||||
pub height_to_unrealized_profit_rel_to_own_total_unrealized_pnl:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_unrealized_loss_rel_to_own_unrealized_total_pnl:
|
||||
pub height_to_unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl:
|
||||
pub height_to_neg_unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl:
|
||||
pub height_to_net_unrealized_pnl_rel_to_own_total_unrealized_pnl:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub indexes_to_unrealized_profit_rel_to_own_unrealized_total_pnl:
|
||||
pub indexes_to_unrealized_profit_rel_to_own_total_unrealized_pnl:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_unrealized_loss_rel_to_own_unrealized_total_pnl:
|
||||
pub indexes_to_unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl:
|
||||
pub indexes_to_neg_unrealized_loss_rel_to_own_total_unrealized_pnl:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl:
|
||||
pub indexes_to_net_unrealized_pnl_rel_to_own_total_unrealized_pnl:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_realized_cap_rel_to_own_market_cap: Option<ComputedVecsFromHeight<StoredF32>>,
|
||||
pub indexes_to_realized_profit_rel_to_realized_cap: Option<ComputedVecsFromHeight<StoredF32>>,
|
||||
@@ -370,18 +372,18 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
height_to_unrealized_total_pnl: compute_dollars.then(|| {
|
||||
height_to_total_unrealized_pnl: compute_dollars.then(|| {
|
||||
EagerVec::forced_import_compressed(
|
||||
db,
|
||||
&suffix("unrealized_total_pnl"),
|
||||
&suffix("total_unrealized_pnl"),
|
||||
version + VERSION + Version::ZERO,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_unrealized_total_pnl: compute_dollars.then(|| {
|
||||
indexes_to_total_unrealized_pnl: compute_dollars.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_total_pnl"),
|
||||
&suffix("total_unrealized_pnl"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -389,6 +391,25 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
height_to_total_realized_pnl: compute_dollars.then(|| {
|
||||
EagerVec::forced_import_compressed(
|
||||
db,
|
||||
&suffix("total_realized_pnl"),
|
||||
version + VERSION + Version::ZERO,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_total_realized_pnl: compute_dollars.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("total_realized_pnl"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_unrealized_loss,
|
||||
height_to_realized_cap: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
@@ -990,56 +1011,56 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
height_to_unrealized_profit_rel_to_own_unrealized_total_pnl: (compute_dollars
|
||||
height_to_unrealized_profit_rel_to_own_total_unrealized_pnl: (compute_dollars
|
||||
&& extended)
|
||||
.then(|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_profit_rel_to_own_unrealized_total_pnl"),
|
||||
&suffix("unrealized_profit_rel_to_own_total_unrealized_pnl"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
height_to_unrealized_loss_rel_to_own_unrealized_total_pnl: (compute_dollars
|
||||
height_to_unrealized_loss_rel_to_own_total_unrealized_pnl: (compute_dollars
|
||||
&& extended)
|
||||
.then(|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_loss_rel_to_own_unrealized_total_pnl"),
|
||||
&suffix("unrealized_loss_rel_to_own_total_unrealized_pnl"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
height_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl: (compute_dollars
|
||||
height_to_neg_unrealized_loss_rel_to_own_total_unrealized_pnl: (compute_dollars
|
||||
&& extended)
|
||||
.then(|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("neg_unrealized_loss_rel_to_own_unrealized_total_pnl"),
|
||||
&suffix("neg_unrealized_loss_rel_to_own_total_unrealized_pnl"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
height_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl: (compute_dollars
|
||||
height_to_net_unrealized_pnl_rel_to_own_total_unrealized_pnl: (compute_dollars
|
||||
&& extended)
|
||||
.then(|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("net_unrealized_pnl_rel_to_own_unrealized_total_pnl"),
|
||||
&suffix("net_unrealized_pnl_rel_to_own_total_unrealized_pnl"),
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_unrealized_profit_rel_to_own_unrealized_total_pnl: (compute_dollars
|
||||
indexes_to_unrealized_profit_rel_to_own_total_unrealized_pnl: (compute_dollars
|
||||
&& extended)
|
||||
.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_profit_rel_to_own_unrealized_total_pnl"),
|
||||
&suffix("unrealized_profit_rel_to_own_total_unrealized_pnl"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
@@ -1047,12 +1068,12 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_unrealized_loss_rel_to_own_unrealized_total_pnl: (compute_dollars
|
||||
indexes_to_unrealized_loss_rel_to_own_total_unrealized_pnl: (compute_dollars
|
||||
&& extended)
|
||||
.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_loss_rel_to_own_unrealized_total_pnl"),
|
||||
&suffix("unrealized_loss_rel_to_own_total_unrealized_pnl"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
@@ -1060,12 +1081,12 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl: (compute_dollars
|
||||
indexes_to_neg_unrealized_loss_rel_to_own_total_unrealized_pnl: (compute_dollars
|
||||
&& extended)
|
||||
.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("neg_unrealized_loss_rel_to_own_unrealized_total_pnl"),
|
||||
&suffix("neg_unrealized_loss_rel_to_own_total_unrealized_pnl"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
@@ -1073,12 +1094,12 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl: (compute_dollars
|
||||
indexes_to_net_unrealized_pnl_rel_to_own_total_unrealized_pnl: (compute_dollars
|
||||
&& extended)
|
||||
.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("net_unrealized_pnl_rel_to_own_unrealized_total_pnl"),
|
||||
&suffix("net_unrealized_pnl_rel_to_own_total_unrealized_pnl"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
@@ -2673,7 +2694,7 @@ impl Vecs {
|
||||
exit,
|
||||
Some(self.dateindex_to_unrealized_loss.as_ref().unwrap()),
|
||||
)?;
|
||||
self.height_to_unrealized_total_pnl
|
||||
self.height_to_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_add(
|
||||
@@ -2682,7 +2703,7 @@ impl Vecs {
|
||||
self.height_to_unrealized_loss.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.indexes_to_unrealized_total_pnl
|
||||
self.indexes_to_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
@@ -2700,6 +2721,41 @@ impl Vecs {
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.height_to_total_realized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_add(
|
||||
starting_indexes.height,
|
||||
self.height_to_realized_profit.as_ref().unwrap(),
|
||||
self.height_to_realized_loss.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.indexes_to_total_realized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_add(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_realized_profit
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.unwrap_sum(),
|
||||
self.indexes_to_realized_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.unwrap_sum(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_min_price_paid
|
||||
.as_mut()
|
||||
@@ -3043,46 +3099,46 @@ impl Vecs {
|
||||
}
|
||||
|
||||
if self
|
||||
.height_to_unrealized_profit_rel_to_own_unrealized_total_pnl
|
||||
.height_to_unrealized_profit_rel_to_own_total_unrealized_pnl
|
||||
.is_some()
|
||||
{
|
||||
self.height_to_unrealized_profit_rel_to_own_unrealized_total_pnl
|
||||
self.height_to_unrealized_profit_rel_to_own_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_unrealized_profit.as_ref().unwrap(),
|
||||
self.height_to_unrealized_total_pnl.as_ref().unwrap(),
|
||||
self.height_to_total_unrealized_pnl.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_unrealized_loss_rel_to_own_unrealized_total_pnl
|
||||
self.height_to_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_unrealized_loss.as_ref().unwrap(),
|
||||
self.height_to_unrealized_total_pnl.as_ref().unwrap(),
|
||||
self.height_to_total_unrealized_pnl.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl
|
||||
self.height_to_neg_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_neg_unrealized_loss.as_ref().unwrap(),
|
||||
self.height_to_unrealized_total_pnl.as_ref().unwrap(),
|
||||
self.height_to_total_unrealized_pnl.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl
|
||||
self.height_to_net_unrealized_pnl_rel_to_own_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_net_unrealized_pnl.as_ref().unwrap(),
|
||||
self.height_to_unrealized_total_pnl.as_ref().unwrap(),
|
||||
self.height_to_total_unrealized_pnl.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.indexes_to_unrealized_profit_rel_to_own_unrealized_total_pnl
|
||||
self.indexes_to_unrealized_profit_rel_to_own_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
@@ -3094,7 +3150,7 @@ impl Vecs {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.dateindex_to_unrealized_profit.as_ref().unwrap(),
|
||||
self.indexes_to_unrealized_total_pnl
|
||||
self.indexes_to_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
@@ -3105,7 +3161,7 @@ impl Vecs {
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_unrealized_loss_rel_to_own_unrealized_total_pnl
|
||||
self.indexes_to_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
@@ -3117,7 +3173,7 @@ impl Vecs {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.dateindex_to_unrealized_loss.as_ref().unwrap(),
|
||||
self.indexes_to_unrealized_total_pnl
|
||||
self.indexes_to_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
@@ -3128,7 +3184,7 @@ impl Vecs {
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl
|
||||
self.indexes_to_neg_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
@@ -3145,7 +3201,7 @@ impl Vecs {
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
self.indexes_to_unrealized_total_pnl
|
||||
self.indexes_to_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
@@ -3156,7 +3212,7 @@ impl Vecs {
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl
|
||||
self.indexes_to_net_unrealized_pnl_rel_to_own_total_unrealized_pnl
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
@@ -3173,7 +3229,7 @@ impl Vecs {
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
self.indexes_to_unrealized_total_pnl
|
||||
self.indexes_to_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
@@ -3806,10 +3862,16 @@ impl Vecs {
|
||||
self.indexes_to_unrealized_loss
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.height_to_unrealized_total_pnl
|
||||
self.height_to_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.indexes_to_unrealized_total_pnl
|
||||
self.indexes_to_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.height_to_total_realized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.indexes_to_total_realized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_min_price_paid
|
||||
@@ -3843,28 +3905,28 @@ impl Vecs {
|
||||
self.indexes_to_net_unrealized_pnl_rel_to_own_market_cap
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.height_to_unrealized_profit_rel_to_own_unrealized_total_pnl
|
||||
self.height_to_unrealized_profit_rel_to_own_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_unrealized_loss_rel_to_own_unrealized_total_pnl
|
||||
self.height_to_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl
|
||||
self.height_to_neg_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl
|
||||
self.height_to_net_unrealized_pnl_rel_to_own_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.indexes_to_unrealized_profit_rel_to_own_unrealized_total_pnl
|
||||
self.indexes_to_unrealized_profit_rel_to_own_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_unrealized_loss_rel_to_own_unrealized_total_pnl
|
||||
self.indexes_to_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_neg_unrealized_loss_rel_to_own_unrealized_total_pnl
|
||||
self.indexes_to_neg_unrealized_loss_rel_to_own_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_net_unrealized_pnl_rel_to_own_unrealized_total_pnl
|
||||
self.indexes_to_net_unrealized_pnl_rel_to_own_total_unrealized_pnl
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.height_to_neg_unrealized_loss
|
||||
|
||||
Reference in New Issue
Block a user