mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-16 09:49:44 -07:00
global: added unrealized relative datasets
This commit is contained in:
@@ -79,6 +79,8 @@ 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_profit_plus_loss: Option<EagerVec<Height, Dollars>>,
|
||||
pub indexes_to_unrealized_profit_plus_loss: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
pub indexes_to_min_price_paid: Option<ComputedVecsFromHeight<Dollars>>,
|
||||
pub indexes_to_max_price_paid: Option<ComputedVecsFromHeight<Dollars>>,
|
||||
pub height_to_halved_supply_value: ComputedHeightValueVecs,
|
||||
@@ -101,6 +103,36 @@ pub struct Vecs {
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_net_unrealized_profit_and_loss_relative_to_market_cap:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub height_to_unrealized_profit_relative_to_own_market_cap: Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_unrealized_loss_relative_to_own_market_cap: Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_negative_unrealized_loss_relative_to_own_market_cap:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_net_unrealized_profit_and_loss_relative_to_own_market_cap:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub indexes_to_unrealized_profit_relative_to_own_market_cap:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_unrealized_loss_relative_to_own_market_cap:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_negative_unrealized_loss_relative_to_own_market_cap:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_net_unrealized_profit_and_loss_relative_to_own_market_cap:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub height_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss:
|
||||
Option<EagerVec<Height, StoredF32>>,
|
||||
pub indexes_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss:
|
||||
Option<ComputedVecsFromDateIndex<StoredF32>>,
|
||||
pub indexes_to_realized_profit_relative_to_realized_cap:
|
||||
Option<ComputedVecsFromHeight<StoredF32>>,
|
||||
pub indexes_to_realized_loss_relative_to_realized_cap:
|
||||
@@ -336,6 +368,25 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
height_to_unrealized_profit_plus_loss: compute_dollars.then(|| {
|
||||
EagerVec::forced_import_compressed(
|
||||
db,
|
||||
&suffix("unrealized_profit_plus_loss"),
|
||||
version + VERSION + Version::ZERO,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_unrealized_profit_plus_loss: compute_dollars.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_profit_plus_loss"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_unrealized_loss,
|
||||
height_to_realized_cap: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
@@ -842,6 +893,198 @@ impl Vecs {
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
height_to_unrealized_profit_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then(
|
||||
|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_profit_relative_to_own_market_cap"),
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
height_to_unrealized_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then(
|
||||
|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_loss_relative_to_own_market_cap"),
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
height_to_negative_unrealized_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then(
|
||||
|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("negative_unrealized_loss_relative_to_own_market_cap"),
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
height_to_net_unrealized_profit_and_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then(
|
||||
|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("net_unrealized_profit_and_loss_relative_to_own_market_cap"),
|
||||
version + VERSION + Version::TWO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_unrealized_profit_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then(
|
||||
|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_profit_relative_to_own_market_cap"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::TWO,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_unrealized_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then(
|
||||
|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_loss_relative_to_own_market_cap"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::TWO,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_negative_unrealized_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then(
|
||||
|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("negative_unrealized_loss_relative_to_own_market_cap"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::TWO,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_net_unrealized_profit_and_loss_relative_to_own_market_cap: (compute_dollars && extended && compute_relative_to_all).then(
|
||||
|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("net_unrealized_profit_and_loss_relative_to_own_market_cap"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::TWO,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then(
|
||||
|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_profit_relative_to_own_unrealized_profit_plus_loss"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
height_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then(
|
||||
|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_loss_relative_to_own_unrealized_profit_plus_loss"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
height_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then(
|
||||
|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
height_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then(
|
||||
|| {
|
||||
EagerVec::forced_import(
|
||||
db,
|
||||
&suffix("net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss"),
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then(
|
||||
|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_profit_relative_to_own_unrealized_profit_plus_loss"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then(
|
||||
|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("unrealized_loss_relative_to_own_unrealized_profit_plus_loss"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then(
|
||||
|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss: (compute_dollars && extended).then(
|
||||
|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
db,
|
||||
&suffix("net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss"),
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
),
|
||||
indexes_to_realized_profit_relative_to_realized_cap: compute_dollars.then(|| {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
@@ -2429,6 +2672,33 @@ impl Vecs {
|
||||
exit,
|
||||
Some(self.dateindex_to_unrealized_loss.as_ref().unwrap()),
|
||||
)?;
|
||||
self.height_to_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_add(
|
||||
starting_indexes.height,
|
||||
self.height_to_unrealized_profit.as_ref().unwrap(),
|
||||
self.height_to_unrealized_loss.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.indexes_to_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_add(
|
||||
starting_indexes.dateindex,
|
||||
self.dateindex_to_unrealized_profit.as_ref().unwrap(),
|
||||
self.dateindex_to_unrealized_loss.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_min_price_paid
|
||||
.as_mut()
|
||||
@@ -2625,6 +2895,302 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
if self
|
||||
.height_to_unrealized_profit_relative_to_own_market_cap
|
||||
.is_some()
|
||||
{
|
||||
self.height_to_unrealized_profit_relative_to_own_market_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_unrealized_profit.as_ref().unwrap(),
|
||||
self.height_to_supply_value.dollars.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_unrealized_loss_relative_to_own_market_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_unrealized_loss.as_ref().unwrap(),
|
||||
self.height_to_supply_value.dollars.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_negative_unrealized_loss_relative_to_own_market_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_negative_unrealized_loss.as_ref().unwrap(),
|
||||
self.height_to_supply_value.dollars.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_net_unrealized_profit_and_loss_relative_to_own_market_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_net_unrealized_profit_and_loss
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
self.height_to_supply_value.dollars.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.indexes_to_unrealized_profit_relative_to_own_market_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.dateindex_to_unrealized_profit.as_ref().unwrap(),
|
||||
self.indexes_to_supply
|
||||
.dollars
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_unrealized_loss_relative_to_own_market_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.dateindex_to_unrealized_loss.as_ref().unwrap(),
|
||||
self.indexes_to_supply
|
||||
.dollars
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_negative_unrealized_loss_relative_to_own_market_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_negative_unrealized_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
self.indexes_to_supply
|
||||
.dollars
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_net_unrealized_profit_and_loss_relative_to_own_market_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_net_unrealized_profit_and_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
self.indexes_to_supply
|
||||
.dollars
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
||||
if self
|
||||
.height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss
|
||||
.is_some()
|
||||
{
|
||||
self.height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_unrealized_profit.as_ref().unwrap(),
|
||||
self.height_to_unrealized_profit_plus_loss.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_unrealized_loss.as_ref().unwrap(),
|
||||
self.height_to_unrealized_profit_plus_loss.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_negative_unrealized_loss.as_ref().unwrap(),
|
||||
self.height_to_unrealized_profit_plus_loss.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.height_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.height_to_net_unrealized_profit_and_loss
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
self.height_to_unrealized_profit_plus_loss.as_ref().unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
self.indexes_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.dateindex_to_unrealized_profit.as_ref().unwrap(),
|
||||
self.indexes_to_unrealized_profit_plus_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.dateindex_to_unrealized_loss.as_ref().unwrap(),
|
||||
self.indexes_to_unrealized_profit_plus_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_negative_unrealized_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
self.indexes_to_unrealized_profit_plus_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
self.indexes_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_net_unrealized_profit_and_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
self.indexes_to_unrealized_profit_plus_loss
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.as_ref()
|
||||
.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
||||
self.indexes_to_realized_profit_relative_to_realized_cap
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@@ -3211,6 +3777,12 @@ impl Vecs {
|
||||
self.indexes_to_unrealized_loss
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.height_to_unrealized_profit_plus_loss
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.indexes_to_unrealized_profit_plus_loss
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_min_price_paid
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
@@ -3218,6 +3790,38 @@ impl Vecs {
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_halved_supply.vecs(),
|
||||
self.height_to_unrealized_profit_relative_to_own_market_cap.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_unrealized_loss_relative_to_own_market_cap.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_negative_unrealized_loss_relative_to_own_market_cap.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_net_unrealized_profit_and_loss_relative_to_own_market_cap.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.indexes_to_unrealized_profit_relative_to_own_market_cap.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_unrealized_loss_relative_to_own_market_cap.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_negative_unrealized_loss_relative_to_own_market_cap.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_net_unrealized_profit_and_loss_relative_to_own_market_cap.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.height_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.height_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
self.indexes_to_unrealized_profit_relative_to_own_unrealized_profit_plus_loss.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_unrealized_loss_relative_to_own_unrealized_profit_plus_loss.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.height_to_negative_unrealized_loss
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| vec![v]),
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
* "Bool" |
|
||||
* "Days" |
|
||||
* "%mcap" |
|
||||
* "%cmcap" |
|
||||
* "%cp+l" |
|
||||
* "%rcap" |
|
||||
* "%self" |
|
||||
* "%all" |
|
||||
@@ -919,6 +921,20 @@ function createUtils() {
|
||||
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
|
||||
unit = "%mcap";
|
||||
}
|
||||
if (
|
||||
(!unit || thoroughUnitCheck) &&
|
||||
id.endsWith("relative_to_own_market_cap")
|
||||
) {
|
||||
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
|
||||
unit = "%cmcap";
|
||||
}
|
||||
if (
|
||||
(!unit || thoroughUnitCheck) &&
|
||||
id.endsWith("relative_to_own_unrealized_profit_plus_loss")
|
||||
) {
|
||||
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
|
||||
unit = "%cp+l";
|
||||
}
|
||||
if (
|
||||
(!unit || thoroughUnitCheck) &&
|
||||
id.endsWith("relative_to_realized_cap")
|
||||
|
||||
@@ -1068,17 +1068,26 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) {
|
||||
* @param {number} [args.number]
|
||||
* @param {string} [args.name]
|
||||
* @param {boolean} [args.defaultActive]
|
||||
* @param {number} [args.lineStyle]
|
||||
* @param {Color} [args.color]
|
||||
* @param {Unit} args.unit
|
||||
*/
|
||||
function createPriceLine({ number = 0, unit, defaultActive, name }) {
|
||||
function createPriceLine({
|
||||
number = 0,
|
||||
unit,
|
||||
defaultActive,
|
||||
color,
|
||||
name,
|
||||
lineStyle,
|
||||
}) {
|
||||
return /** @satisfies {FetchedLineSeriesBlueprint} */ ({
|
||||
key: `constant_${number >= 0 ? number : `minus_${Math.abs(number)}`}`,
|
||||
title: name ?? `${number}`,
|
||||
unit,
|
||||
defaultActive,
|
||||
color: colors.gray,
|
||||
color: color ?? colors.gray,
|
||||
options: {
|
||||
lineStyle: 4,
|
||||
lineStyle: lineStyle ?? 4,
|
||||
lastValueVisible: false,
|
||||
crosshairMarkerVisible: false,
|
||||
},
|
||||
@@ -1833,6 +1842,16 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) {
|
||||
name: "Even",
|
||||
color: colors.yellow,
|
||||
}),
|
||||
createPriceLine({
|
||||
unit: "%self",
|
||||
number: 100,
|
||||
lineStyle: 0,
|
||||
color: colors.default,
|
||||
}),
|
||||
createPriceLine({
|
||||
unit: "%self",
|
||||
number: 50,
|
||||
}),
|
||||
]);
|
||||
}),
|
||||
}
|
||||
@@ -2644,6 +2663,11 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) {
|
||||
name: "pnl",
|
||||
title: `Unrealized Profit And Loss ${title}`,
|
||||
bottom: [
|
||||
createBaseSeries({
|
||||
key: `${fixKey(args.key)}unrealized_profit_plus_loss`,
|
||||
name: "profit+loss",
|
||||
color: colors.default,
|
||||
}),
|
||||
createBaseSeries({
|
||||
key: `${fixKey(args.key)}unrealized_profit`,
|
||||
name: "Profit",
|
||||
@@ -2676,6 +2700,62 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) {
|
||||
name: "Negative Loss",
|
||||
color: colors.red,
|
||||
}),
|
||||
...(`${fixKey(args.key)}unrealized_profit_relative_to_own_market_cap` in
|
||||
vecIdToIndexes
|
||||
? [
|
||||
createBaseSeries({
|
||||
key: `${fixKey(args.key)}unrealized_profit_relative_to_own_market_cap`,
|
||||
name: "Profit",
|
||||
color: colors.green,
|
||||
}),
|
||||
createBaseSeries({
|
||||
key: `${fixKey(args.key)}unrealized_loss_relative_to_own_market_cap`,
|
||||
name: "Loss",
|
||||
color: colors.red,
|
||||
defaultActive: false,
|
||||
}),
|
||||
createBaseSeries({
|
||||
key: `${fixKey(args.key)}negative_unrealized_loss_relative_to_own_market_cap`,
|
||||
name: "Negative Loss",
|
||||
color: colors.red,
|
||||
}),
|
||||
createPriceLine({
|
||||
unit: "%cmcap",
|
||||
number: 100,
|
||||
}),
|
||||
createPriceLine({
|
||||
unit: "%cmcap",
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
...(`${fixKey(args.key)}unrealized_profit_relative_to_own_unrealized_profit_plus_loss` in
|
||||
vecIdToIndexes
|
||||
? [
|
||||
createBaseSeries({
|
||||
key: `${fixKey(args.key)}unrealized_profit_relative_to_own_unrealized_profit_plus_loss`,
|
||||
name: "Profit",
|
||||
color: colors.green,
|
||||
}),
|
||||
createBaseSeries({
|
||||
key: `${fixKey(args.key)}unrealized_loss_relative_to_own_unrealized_profit_plus_loss`,
|
||||
name: "Loss",
|
||||
color: colors.red,
|
||||
defaultActive: false,
|
||||
}),
|
||||
createBaseSeries({
|
||||
key: `${fixKey(args.key)}negative_unrealized_loss_relative_to_own_unrealized_profit_plus_loss`,
|
||||
name: "Negative Loss",
|
||||
color: colors.red,
|
||||
}),
|
||||
createPriceLine({
|
||||
unit: "%cp+l",
|
||||
number: 100,
|
||||
}),
|
||||
createPriceLine({
|
||||
unit: "%cp+l",
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
createPriceLine({
|
||||
unit: "USD",
|
||||
defaultActive: false,
|
||||
@@ -2736,6 +2816,38 @@ function createPartialOptions({ env, colors, vecIdToIndexes }) {
|
||||
title: useGroupName ? name : "Net",
|
||||
color: useGroupName ? color : undefined,
|
||||
}),
|
||||
...(`${fixKey(key)}net_unrealized_profit_and_loss_relative_to_own_market_cap` in
|
||||
vecIdToIndexes
|
||||
? [
|
||||
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
|
||||
type: "Baseline",
|
||||
key: `${fixKey(
|
||||
key,
|
||||
)}net_unrealized_profit_and_loss_relative_to_own_market_cap`,
|
||||
title: useGroupName ? name : "Net",
|
||||
color: useGroupName ? color : undefined,
|
||||
}),
|
||||
createPriceLine({
|
||||
unit: "%cmcap",
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
...(`${fixKey(key)}net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss` in
|
||||
vecIdToIndexes
|
||||
? [
|
||||
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
|
||||
type: "Baseline",
|
||||
key: `${fixKey(
|
||||
key,
|
||||
)}net_unrealized_profit_and_loss_relative_to_own_unrealized_profit_plus_loss`,
|
||||
title: useGroupName ? name : "Net",
|
||||
color: useGroupName ? color : undefined,
|
||||
}),
|
||||
createPriceLine({
|
||||
unit: "%cp+l",
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
]),
|
||||
createPriceLine({
|
||||
unit: "USD",
|
||||
|
||||
Reference in New Issue
Block a user