mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot part 12
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -24,19 +24,8 @@ use crate::distribution::metrics::ImportConfig;
|
|||||||
|
|
||||||
use super::RealizedCore;
|
use super::RealizedCore;
|
||||||
|
|
||||||
#[derive(Traversable)]
|
|
||||||
pub struct RealizedProfitFull<M: StorageMode = Rw> {
|
|
||||||
pub to_rcap: PercentPerBlock<BasisPoints32, M>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Traversable)]
|
|
||||||
pub struct RealizedLossFull<M: StorageMode = Rw> {
|
|
||||||
pub to_rcap: PercentPerBlock<BasisPoints32, M>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
pub struct RealizedNetPnl<M: StorageMode = Rw> {
|
pub struct RealizedNetPnl<M: StorageMode = Rw> {
|
||||||
pub to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
|
||||||
#[traversable(wrap = "change_1m", rename = "to_rcap")]
|
#[traversable(wrap = "change_1m", rename = "to_rcap")]
|
||||||
pub change_1m_to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
pub change_1m_to_rcap: PercentPerBlock<BasisPointsSigned32, M>,
|
||||||
#[traversable(wrap = "change_1m", rename = "to_mcap")]
|
#[traversable(wrap = "change_1m", rename = "to_mcap")]
|
||||||
@@ -53,7 +42,6 @@ pub struct RealizedSopr<M: StorageMode = Rw> {
|
|||||||
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub value: FiatPerBlockCumulativeWithSums<Cents, M>,
|
pub value: FiatPerBlockCumulativeWithSums<Cents, M>,
|
||||||
pub to_rcap: PercentPerBlock<BasisPoints32, M>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Traversable)]
|
#[derive(Traversable)]
|
||||||
@@ -70,8 +58,6 @@ pub struct RealizedFull<M: StorageMode = Rw> {
|
|||||||
#[traversable(flatten)]
|
#[traversable(flatten)]
|
||||||
pub core: RealizedCore<M>,
|
pub core: RealizedCore<M>,
|
||||||
|
|
||||||
pub profit: RealizedProfitFull<M>,
|
|
||||||
pub loss: RealizedLossFull<M>,
|
|
||||||
pub gross_pnl: FiatPerBlockCumulativeWithSums<Cents, M>,
|
pub gross_pnl: FiatPerBlockCumulativeWithSums<Cents, M>,
|
||||||
pub sell_side_risk_ratio: PercentRollingWindows<BasisPoints32, M>,
|
pub sell_side_risk_ratio: PercentRollingWindows<BasisPoints32, M>,
|
||||||
pub net_pnl: RealizedNetPnl<M>,
|
pub net_pnl: RealizedNetPnl<M>,
|
||||||
@@ -101,13 +87,6 @@ impl RealizedFull {
|
|||||||
|
|
||||||
let core = RealizedCore::forced_import(cfg)?;
|
let core = RealizedCore::forced_import(cfg)?;
|
||||||
|
|
||||||
let profit = RealizedProfitFull {
|
|
||||||
to_rcap: cfg.import("realized_profit_to_rcap", Version::new(2))?,
|
|
||||||
};
|
|
||||||
let loss = RealizedLossFull {
|
|
||||||
to_rcap: cfg.import("realized_loss_to_rcap", Version::new(2))?,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Gross PnL
|
// Gross PnL
|
||||||
let gross_pnl: FiatPerBlockCumulativeWithSums<Cents> =
|
let gross_pnl: FiatPerBlockCumulativeWithSums<Cents> =
|
||||||
cfg.import("realized_gross_pnl", v1)?;
|
cfg.import("realized_gross_pnl", v1)?;
|
||||||
@@ -115,7 +94,6 @@ impl RealizedFull {
|
|||||||
|
|
||||||
// Net PnL
|
// Net PnL
|
||||||
let net_pnl = RealizedNetPnl {
|
let net_pnl = RealizedNetPnl {
|
||||||
to_rcap: cfg.import("net_realized_pnl_to_rcap", Version::new(2))?,
|
|
||||||
change_1m_to_rcap: cfg.import("net_pnl_change_1m_to_rcap", Version::new(4))?,
|
change_1m_to_rcap: cfg.import("net_pnl_change_1m_to_rcap", Version::new(4))?,
|
||||||
change_1m_to_mcap: cfg.import("net_pnl_change_1m_to_mcap", Version::new(4))?,
|
change_1m_to_mcap: cfg.import("net_pnl_change_1m_to_mcap", Version::new(4))?,
|
||||||
};
|
};
|
||||||
@@ -128,7 +106,6 @@ impl RealizedFull {
|
|||||||
// Peak regret
|
// Peak regret
|
||||||
let peak_regret = RealizedPeakRegret {
|
let peak_regret = RealizedPeakRegret {
|
||||||
value: cfg.import("realized_peak_regret", Version::new(3))?,
|
value: cfg.import("realized_peak_regret", Version::new(3))?,
|
||||||
to_rcap: cfg.import("realized_peak_regret_to_rcap", Version::new(2))?,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Investor
|
// Investor
|
||||||
@@ -143,8 +120,6 @@ impl RealizedFull {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
core,
|
core,
|
||||||
profit,
|
|
||||||
loss,
|
|
||||||
gross_pnl,
|
gross_pnl,
|
||||||
sell_side_risk_ratio,
|
sell_side_risk_ratio,
|
||||||
net_pnl,
|
net_pnl,
|
||||||
@@ -298,32 +273,6 @@ impl RealizedFull {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Profit/loss/net_pnl rel to realized cap
|
|
||||||
self.profit
|
|
||||||
.to_rcap
|
|
||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.core.minimal.profit.block.cents,
|
|
||||||
&self.core.minimal.cap.cents.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.loss
|
|
||||||
.to_rcap
|
|
||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.core.minimal.loss.block.cents,
|
|
||||||
&self.core.minimal.cap.cents.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
self.net_pnl
|
|
||||||
.to_rcap
|
|
||||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.core.net_pnl.block.cents,
|
|
||||||
&self.core.minimal.cap.cents.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Gross PnL
|
// Gross PnL
|
||||||
self.gross_pnl.block.cents.compute_add(
|
self.gross_pnl.block.cents.compute_add(
|
||||||
starting_indexes.height,
|
starting_indexes.height,
|
||||||
@@ -351,16 +300,6 @@ impl RealizedFull {
|
|||||||
exit,
|
exit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Peak regret rel to rcap
|
|
||||||
self.peak_regret
|
|
||||||
.to_rcap
|
|
||||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
|
||||||
starting_indexes.height,
|
|
||||||
&self.peak_regret.value.block.cents,
|
|
||||||
&self.core.minimal.cap.cents.height,
|
|
||||||
exit,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Investor price ratio, percentiles and bands
|
// Investor price ratio, percentiles and bands
|
||||||
self.investor
|
self.investor
|
||||||
.price
|
.price
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -41,7 +41,7 @@ import {
|
|||||||
* @returns {AnyFetchedSeriesBlueprint}
|
* @returns {AnyFetchedSeriesBlueprint}
|
||||||
*/
|
*/
|
||||||
function netBaseline(s, unit) {
|
function netBaseline(s, unit) {
|
||||||
return baseline({ series: s, name: "Net P&L", unit });
|
return baseline({ series: s, name: "Net", unit });
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -61,7 +61,7 @@ function unrealizedOverview(profit, loss, netPnlUsd, title) {
|
|||||||
name: "Overview",
|
name: "Overview",
|
||||||
title: title("Unrealized P&L"),
|
title: title("Unrealized P&L"),
|
||||||
bottom: [
|
bottom: [
|
||||||
baseline({ series: netPnlUsd, name: "Net P&L", unit: Unit.usd }),
|
baseline({ series: netPnlUsd, name: "Net", unit: Unit.usd }),
|
||||||
dotted({
|
dotted({
|
||||||
series: profit.usd,
|
series: profit.usd,
|
||||||
name: "Profit",
|
name: "Profit",
|
||||||
@@ -119,7 +119,7 @@ function unrealizedBase(u, title) {
|
|||||||
return [
|
return [
|
||||||
unrealizedOverview(u.profit, u.loss, u.netPnl.usd, title),
|
unrealizedOverview(u.profit, u.loss, u.netPnl.usd, title),
|
||||||
{
|
{
|
||||||
name: "Net P&L",
|
name: "Net",
|
||||||
title: title("Net Unrealized P&L"),
|
title: title("Net Unrealized P&L"),
|
||||||
bottom: [netBaseline(u.netPnl.usd, Unit.usd)],
|
bottom: [netBaseline(u.netPnl.usd, Unit.usd)],
|
||||||
},
|
},
|
||||||
@@ -227,7 +227,7 @@ function unrealizedTreeMid(u, title) {
|
|||||||
return [
|
return [
|
||||||
unrealizedOverview(u.profit, u.loss, u.netPnl.usd, title),
|
unrealizedOverview(u.profit, u.loss, u.netPnl.usd, title),
|
||||||
{
|
{
|
||||||
name: "Net P&L",
|
name: "Net",
|
||||||
title: title("Net Unrealized P&L"),
|
title: title("Net Unrealized P&L"),
|
||||||
bottom: [netBaseline(u.netPnl.usd, Unit.usd)],
|
bottom: [netBaseline(u.netPnl.usd, Unit.usd)],
|
||||||
},
|
},
|
||||||
@@ -312,10 +312,9 @@ function nuplSeries(nupl) {
|
|||||||
* @param {string} args.metricTitle
|
* @param {string} args.metricTitle
|
||||||
* @param {Color} args.color
|
* @param {Color} args.color
|
||||||
* @param {(name: string) => string} args.title
|
* @param {(name: string) => string} args.title
|
||||||
* @param {{ percent: AnySeriesPattern, ratio: AnySeriesPattern }} [args.toRcap]
|
|
||||||
* @returns {PartialOptionsTree}
|
* @returns {PartialOptionsTree}
|
||||||
*/
|
*/
|
||||||
function realizedMetricFolder({ pattern, metricTitle, color, title, toRcap }) {
|
function realizedMetricFolder({ pattern, metricTitle, color, title }) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: "Compare",
|
name: "Compare",
|
||||||
@@ -353,19 +352,6 @@ function realizedMetricFolder({ pattern, metricTitle, color, title, toRcap }) {
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
...(toRcap
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
name: "% of Realized Cap",
|
|
||||||
title: title(`Realized ${metricTitle} (% of Realized Cap)`),
|
|
||||||
bottom: percentRatioBaseline({
|
|
||||||
pattern: toRcap,
|
|
||||||
name: metricTitle,
|
|
||||||
color,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,13 +360,12 @@ function realizedMetricFolder({ pattern, metricTitle, color, title, toRcap }) {
|
|||||||
* @param {Object} args
|
* @param {Object} args
|
||||||
* @param {NetPnlFullPattern | NetPnlBasicPattern} args.netPnl
|
* @param {NetPnlFullPattern | NetPnlBasicPattern} args.netPnl
|
||||||
* @param {(name: string) => string} args.title
|
* @param {(name: string) => string} args.title
|
||||||
* @param {{ percent: AnySeriesPattern, ratio: AnySeriesPattern }} [args.toRcap]
|
|
||||||
* @param {PartialOptionsTree} [args.extraChange] - Additional change items (% of Mcap, % of Rcap)
|
* @param {PartialOptionsTree} [args.extraChange] - Additional change items (% of Mcap, % of Rcap)
|
||||||
* @returns {PartialOptionsGroup}
|
* @returns {PartialOptionsGroup}
|
||||||
*/
|
*/
|
||||||
function realizedNetFolder({ netPnl, title, toRcap, extraChange = [] }) {
|
function realizedNetFolder({ netPnl, title, extraChange = [] }) {
|
||||||
return {
|
return {
|
||||||
name: "Net P&L",
|
name: "Net",
|
||||||
tree: [
|
tree: [
|
||||||
{
|
{
|
||||||
name: "Compare",
|
name: "Compare",
|
||||||
@@ -416,15 +401,6 @@ function realizedNetFolder({ netPnl, title, toRcap, extraChange = [] }) {
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
...(toRcap
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
name: "% of Realized Cap",
|
|
||||||
title: title("Net Realized P&L (% of Realized Cap)"),
|
|
||||||
bottom: percentRatioBaseline({ pattern: toRcap, name: "Net" }),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
{ ...sumsTreeBaseline({ windows: mapWindows(netPnl.delta.absolute, (c) => c.usd), title: title("Net Realized P&L Change"), unit: Unit.usd }), name: "Change" },
|
{ ...sumsTreeBaseline({ windows: mapWindows(netPnl.delta.absolute, (c) => c.usd), title: title("Net Realized P&L Change"), unit: Unit.usd }), name: "Change" },
|
||||||
{
|
{
|
||||||
name: "Growth Rate",
|
name: "Growth Rate",
|
||||||
@@ -464,7 +440,7 @@ function realizedOverviewFolder({
|
|||||||
bottom: [
|
bottom: [
|
||||||
baseline({
|
baseline({
|
||||||
series: netPnl.sum[w.key].usd,
|
series: netPnl.sum[w.key].usd,
|
||||||
name: "Net P&L",
|
name: "Net",
|
||||||
unit: Unit.usd,
|
unit: Unit.usd,
|
||||||
}),
|
}),
|
||||||
dotted({
|
dotted({
|
||||||
@@ -491,7 +467,7 @@ function realizedOverviewFolder({
|
|||||||
dotted({
|
dotted({
|
||||||
series: grossPnl.sum[w.key].usd,
|
series: grossPnl.sum[w.key].usd,
|
||||||
name: "Gross",
|
name: "Gross",
|
||||||
color: colors.bitcoin,
|
color: colors.gross,
|
||||||
unit: Unit.usd,
|
unit: Unit.usd,
|
||||||
defaultActive: false,
|
defaultActive: false,
|
||||||
}),
|
}),
|
||||||
@@ -502,7 +478,7 @@ function realizedOverviewFolder({
|
|||||||
dotted({
|
dotted({
|
||||||
series: peakRegret.sum[w.key].usd,
|
series: peakRegret.sum[w.key].usd,
|
||||||
name: "Peak Regret",
|
name: "Peak Regret",
|
||||||
color: colors.default,
|
color: colors.regret,
|
||||||
unit: Unit.usd,
|
unit: Unit.usd,
|
||||||
defaultActive: false,
|
defaultActive: false,
|
||||||
}),
|
}),
|
||||||
@@ -539,7 +515,6 @@ function realizedSubfolderFull(r, title) {
|
|||||||
realizedNetFolder({
|
realizedNetFolder({
|
||||||
netPnl: r.netPnl,
|
netPnl: r.netPnl,
|
||||||
title,
|
title,
|
||||||
toRcap: r.netPnl.toRcap,
|
|
||||||
extraChange: [
|
extraChange: [
|
||||||
{
|
{
|
||||||
name: "% of Market Cap",
|
name: "% of Market Cap",
|
||||||
@@ -566,7 +541,6 @@ function realizedSubfolderFull(r, title) {
|
|||||||
metricTitle: "Profit",
|
metricTitle: "Profit",
|
||||||
color: colors.profit,
|
color: colors.profit,
|
||||||
title,
|
title,
|
||||||
toRcap: r.profit.toRcap,
|
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -576,15 +550,14 @@ function realizedSubfolderFull(r, title) {
|
|||||||
metricTitle: "Loss",
|
metricTitle: "Loss",
|
||||||
color: colors.loss,
|
color: colors.loss,
|
||||||
title,
|
title,
|
||||||
toRcap: r.loss.toRcap,
|
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Gross P&L",
|
name: "Gross",
|
||||||
tree: realizedMetricFolder({
|
tree: realizedMetricFolder({
|
||||||
pattern: r.grossPnl,
|
pattern: r.grossPnl,
|
||||||
metricTitle: "Gross P&L",
|
metricTitle: "Gross P&L",
|
||||||
color: colors.bitcoin,
|
color: colors.gross,
|
||||||
title,
|
title,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@@ -655,14 +628,6 @@ function realizedSubfolderFull(r, title) {
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "% of Realized Cap",
|
|
||||||
title: title("Peak Regret (% of Realized Cap)"),
|
|
||||||
bottom: percentRatioBaseline({
|
|
||||||
pattern: r.peakRegret.toRcap,
|
|
||||||
name: "Peak Regret",
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -1102,7 +1067,7 @@ function groupedRealizedSubfolderFull(list, all, title) {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Gross P&L",
|
name: "Gross",
|
||||||
tree: groupedWindowsCumulativeUsd({
|
tree: groupedWindowsCumulativeUsd({
|
||||||
list,
|
list,
|
||||||
all,
|
all,
|
||||||
@@ -1177,7 +1142,7 @@ function groupedNuplCharts(list, all, title) {
|
|||||||
function groupedUnrealizedMid(list, all, title) {
|
function groupedUnrealizedMid(list, all, title) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: "Net P&L",
|
name: "Net",
|
||||||
title: title("Net Unrealized P&L"),
|
title: title("Net Unrealized P&L"),
|
||||||
bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) =>
|
bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) =>
|
||||||
baseline({
|
baseline({
|
||||||
|
|||||||
@@ -173,6 +173,10 @@ export const colors = {
|
|||||||
adjustedCreated: palette.lime,
|
adjustedCreated: palette.lime,
|
||||||
adjustedDestroyed: palette.pink,
|
adjustedDestroyed: palette.pink,
|
||||||
|
|
||||||
|
// Realized P&L
|
||||||
|
gross: palette.yellow,
|
||||||
|
regret: palette.pink,
|
||||||
|
|
||||||
// Ratios
|
// Ratios
|
||||||
plRatio: palette.yellow,
|
plRatio: palette.yellow,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user