global: snapshot

This commit is contained in:
nym21
2026-02-24 12:21:20 +01:00
parent 3b7aa8242a
commit cefc8cfd42
24 changed files with 3561 additions and 1073 deletions

View File

@@ -13,45 +13,17 @@
import { Unit } from "../../utils/units.js";
import { line, baseline, dotsBaseline, dots } from "../series.js";
import { satsBtcUsd, mapCohortsWithAll, flatMapCohortsWithAll } from "../shared.js";
import {
satsBtcUsd,
mapCohortsWithAll,
flatMapCohortsWithAll,
} from "../shared.js";
import { colors } from "../../utils/colors.js";
// ============================================================================
// Shared Helpers
// ============================================================================
/**
* Create SOPR series from realized pattern (30d > 7d > raw order)
* @param {{ sopr: AnyMetricPattern, sopr7dEma: AnyMetricPattern, sopr30dEma: AnyMetricPattern }} realized
* @param {string} rawName - Name for the raw SOPR series
* @returns {AnyFetchedSeriesBlueprint[]}
*/
function soprSeries(realized, rawName = "SOPR") {
return [
baseline({
metric: realized.sopr30dEma,
name: "30d EMA",
color: colors.bi.p3,
unit: Unit.ratio,
base: 1,
}),
baseline({
metric: realized.sopr7dEma,
name: "7d EMA",
color: colors.bi.p2,
unit: Unit.ratio,
base: 1,
}),
dotsBaseline({
metric: realized.sopr,
name: rawName,
color: colors.bi.p1,
unit: Unit.ratio,
base: 1,
}),
];
}
/**
* Create grouped SOPR chart entries (Raw, 7d EMA, 30d EMA)
* @template {{ color: Color, name: string }} T
@@ -237,18 +209,308 @@ function coinsDestroyedTree(list, all, title) {
}
// ============================================================================
// SOPR Helpers
// Rolling Helpers
// ============================================================================
/**
* Create SOPR series for single cohort (30d > 7d > raw order)
* @param {UtxoCohortObject | CohortWithoutRelative} cohort
* @returns {AnyFetchedSeriesBlueprint[]}
* Rolling SOPR tree for single cohort
* @param {Object} m
* @param {AnyMetricPattern} m.s24h
* @param {AnyMetricPattern} m.s7d
* @param {AnyMetricPattern} m.s30d
* @param {AnyMetricPattern} m.s1y
* @param {AnyMetricPattern} m.ema24h7d
* @param {AnyMetricPattern} m.ema24h30d
* @param {(metric: string) => string} title
* @param {string} prefix
* @returns {PartialOptionsTree}
*/
function createSingleSoprSeries(cohort) {
return soprSeries(cohort.tree.realized);
function singleRollingSoprTree(m, title, prefix = "") {
return [
{
name: "Compare",
title: title(`Rolling ${prefix}SOPR`),
bottom: [
baseline({ metric: m.s24h, name: "24h", color: colors.time._24h, unit: Unit.ratio, base: 1 }),
baseline({ metric: m.s7d, name: "7d", color: colors.time._1w, unit: Unit.ratio, base: 1 }),
baseline({ metric: m.s30d, name: "30d", color: colors.time._1m, unit: Unit.ratio, base: 1 }),
baseline({ metric: m.s1y, name: "1y", color: colors.time._1y, unit: Unit.ratio, base: 1 }),
],
},
{
name: "24h",
title: title(`${prefix}SOPR (24h)`),
bottom: [
baseline({ metric: m.ema24h30d, name: "30d EMA", color: colors.bi.p3, unit: Unit.ratio, base: 1 }),
baseline({ metric: m.ema24h7d, name: "7d EMA", color: colors.bi.p2, unit: Unit.ratio, base: 1 }),
dotsBaseline({ metric: m.s24h, name: "24h", color: colors.bi.p1, unit: Unit.ratio, base: 1 }),
],
},
{
name: "7d",
title: title(`${prefix}SOPR (7d)`),
bottom: [baseline({ metric: m.s7d, name: "SOPR", unit: Unit.ratio, base: 1 })],
},
{
name: "30d",
title: title(`${prefix}SOPR (30d)`),
bottom: [baseline({ metric: m.s30d, name: "SOPR", unit: Unit.ratio, base: 1 })],
},
{
name: "1y",
title: title(`${prefix}SOPR (1y)`),
bottom: [baseline({ metric: m.s1y, name: "SOPR", unit: Unit.ratio, base: 1 })],
},
];
}
/**
* Rolling sell side risk tree for single cohort
* @param {AnyRealizedPattern} r
* @param {(metric: string) => string} title
* @returns {PartialOptionsTree}
*/
function singleRollingSellSideRiskTree(r, title) {
return [
{
name: "Compare",
title: title("Rolling Sell Side Risk"),
bottom: [
line({ metric: r.sellSideRiskRatio24h, name: "24h", color: colors.time._24h, unit: Unit.ratio }),
line({ metric: r.sellSideRiskRatio7d, name: "7d", color: colors.time._1w, unit: Unit.ratio }),
line({ metric: r.sellSideRiskRatio30d, name: "30d", color: colors.time._1m, unit: Unit.ratio }),
line({ metric: r.sellSideRiskRatio1y, name: "1y", color: colors.time._1y, unit: Unit.ratio }),
],
},
{
name: "24h",
title: title("Sell Side Risk (24h)"),
bottom: [
line({ metric: r.sellSideRiskRatio24h30dEma, name: "30d EMA", color: colors.time._1m, unit: Unit.ratio }),
line({ metric: r.sellSideRiskRatio24h7dEma, name: "7d EMA", color: colors.time._1w, unit: Unit.ratio }),
dots({ metric: r.sellSideRiskRatio24h, name: "Raw", color: colors.bitcoin, unit: Unit.ratio }),
],
},
{
name: "7d",
title: title("Sell Side Risk (7d)"),
bottom: [line({ metric: r.sellSideRiskRatio7d, name: "Risk", unit: Unit.ratio })],
},
{
name: "30d",
title: title("Sell Side Risk (30d)"),
bottom: [line({ metric: r.sellSideRiskRatio30d, name: "Risk", unit: Unit.ratio })],
},
{
name: "1y",
title: title("Sell Side Risk (1y)"),
bottom: [line({ metric: r.sellSideRiskRatio1y, name: "Risk", unit: Unit.ratio })],
},
];
}
/**
* Rolling value created/destroyed tree for single cohort
* @param {Object} m
* @param {AnyMetricPattern} m.created24h
* @param {AnyMetricPattern} m.created7d
* @param {AnyMetricPattern} m.created30d
* @param {AnyMetricPattern} m.created1y
* @param {AnyMetricPattern} m.destroyed24h
* @param {AnyMetricPattern} m.destroyed7d
* @param {AnyMetricPattern} m.destroyed30d
* @param {AnyMetricPattern} m.destroyed1y
* @param {(metric: string) => string} title
* @param {string} prefix
* @returns {PartialOptionsTree}
*/
function singleRollingValueTree(m, title, prefix = "") {
return [
{
name: "Compare",
tree: [
{
name: "Created",
title: title(`Rolling ${prefix}Value Created`),
bottom: [
line({ metric: m.created24h, name: "24h", color: colors.time._24h, unit: Unit.usd }),
line({ metric: m.created7d, name: "7d", color: colors.time._1w, unit: Unit.usd }),
line({ metric: m.created30d, name: "30d", color: colors.time._1m, unit: Unit.usd }),
line({ metric: m.created1y, name: "1y", color: colors.time._1y, unit: Unit.usd }),
],
},
{
name: "Destroyed",
title: title(`Rolling ${prefix}Value Destroyed`),
bottom: [
line({ metric: m.destroyed24h, name: "24h", color: colors.time._24h, unit: Unit.usd }),
line({ metric: m.destroyed7d, name: "7d", color: colors.time._1w, unit: Unit.usd }),
line({ metric: m.destroyed30d, name: "30d", color: colors.time._1m, unit: Unit.usd }),
line({ metric: m.destroyed1y, name: "1y", color: colors.time._1y, unit: Unit.usd }),
],
},
],
},
{
name: "24h",
title: title(`${prefix}Value Created & Destroyed (24h)`),
bottom: [
line({ metric: m.created24h, name: "Created", color: colors.usd, unit: Unit.usd }),
line({ metric: m.destroyed24h, name: "Destroyed", color: colors.loss, unit: Unit.usd }),
],
},
{
name: "7d",
title: title(`${prefix}Value Created & Destroyed (7d)`),
bottom: [
line({ metric: m.created7d, name: "Created", color: colors.usd, unit: Unit.usd }),
line({ metric: m.destroyed7d, name: "Destroyed", color: colors.loss, unit: Unit.usd }),
],
},
{
name: "30d",
title: title(`${prefix}Value Created & Destroyed (30d)`),
bottom: [
line({ metric: m.created30d, name: "Created", color: colors.usd, unit: Unit.usd }),
line({ metric: m.destroyed30d, name: "Destroyed", color: colors.loss, unit: Unit.usd }),
],
},
{
name: "1y",
title: title(`${prefix}Value Created & Destroyed (1y)`),
bottom: [
line({ metric: m.created1y, name: "Created", color: colors.usd, unit: Unit.usd }),
line({ metric: m.destroyed1y, name: "Destroyed", color: colors.loss, unit: Unit.usd }),
],
},
];
}
/**
* Rolling SOPR charts for grouped cohorts
* @template {{ color: Color, name: string }} T
* @param {readonly T[]} list
* @param {T} all
* @param {(item: T) => AnyMetricPattern} get24h
* @param {(item: T) => AnyMetricPattern} get7d
* @param {(item: T) => AnyMetricPattern} get30d
* @param {(item: T) => AnyMetricPattern} get1y
* @param {(metric: string) => string} title
* @param {string} prefix
* @returns {PartialOptionsTree}
*/
function groupedRollingSoprCharts(list, all, get24h, get7d, get30d, get1y, title, prefix = "") {
return [
{
name: "24h",
title: title(`${prefix}SOPR (24h)`),
bottom: mapCohortsWithAll(list, all, (c) =>
baseline({ metric: get24h(c), name: c.name, color: c.color, unit: Unit.ratio, base: 1 }),
),
},
{
name: "7d",
title: title(`${prefix}SOPR (7d)`),
bottom: mapCohortsWithAll(list, all, (c) =>
baseline({ metric: get7d(c), name: c.name, color: c.color, unit: Unit.ratio, base: 1 }),
),
},
{
name: "30d",
title: title(`${prefix}SOPR (30d)`),
bottom: mapCohortsWithAll(list, all, (c) =>
baseline({ metric: get30d(c), name: c.name, color: c.color, unit: Unit.ratio, base: 1 }),
),
},
{
name: "1y",
title: title(`${prefix}SOPR (1y)`),
bottom: mapCohortsWithAll(list, all, (c) =>
baseline({ metric: get1y(c), name: c.name, color: c.color, unit: Unit.ratio, base: 1 }),
),
},
];
}
/**
* Rolling sell side risk charts for grouped cohorts
* @param {readonly CohortObject[]} list
* @param {CohortObject} all
* @param {(metric: string) => string} title
* @returns {PartialOptionsTree}
*/
function groupedRollingSellSideRiskCharts(list, all, title) {
return [
{
name: "24h",
title: title("Sell Side Risk (24h)"),
bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) =>
line({ metric: tree.realized.sellSideRiskRatio24h, name, color, unit: Unit.ratio }),
),
},
{
name: "7d",
title: title("Sell Side Risk (7d)"),
bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) =>
line({ metric: tree.realized.sellSideRiskRatio7d, name, color, unit: Unit.ratio }),
),
},
{
name: "30d",
title: title("Sell Side Risk (30d)"),
bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) =>
line({ metric: tree.realized.sellSideRiskRatio30d, name, color, unit: Unit.ratio }),
),
},
{
name: "1y",
title: title("Sell Side Risk (1y)"),
bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) =>
line({ metric: tree.realized.sellSideRiskRatio1y, name, color, unit: Unit.ratio }),
),
},
];
}
/**
* Rolling value created/destroyed charts for grouped cohorts
* @template {{ color: Color, name: string }} T
* @param {readonly T[]} list
* @param {T} all
* @param {readonly { name: string, getCreated: (item: T) => AnyMetricPattern, getDestroyed: (item: T) => AnyMetricPattern }[]} windows
* @param {(metric: string) => string} title
* @param {string} prefix
* @returns {PartialOptionsTree}
*/
function groupedRollingValueCharts(list, all, windows, title, prefix = "") {
return [
{
name: "Created",
tree: windows.map((w) => ({
name: w.name,
title: title(`${prefix}Value Created (${w.name})`),
bottom: mapCohortsWithAll(list, all, (item) =>
line({ metric: w.getCreated(item), name: item.name, color: item.color, unit: Unit.usd }),
),
})),
},
{
name: "Destroyed",
tree: windows.map((w) => ({
name: w.name,
title: title(`${prefix}Value Destroyed (${w.name})`),
bottom: mapCohortsWithAll(list, all, (item) =>
line({ metric: w.getDestroyed(item), name: item.name, color: item.color, unit: Unit.usd }),
),
})),
},
];
}
// ============================================================================
// SOPR Helpers
// ============================================================================
/**
* Create SOPR tree with normal and adjusted sub-sections
* @param {CohortAll | CohortFull | CohortWithAdjusted} cohort
@@ -256,23 +518,21 @@ function createSingleSoprSeries(cohort) {
* @returns {PartialOptionsTree}
*/
function createSingleSoprTreeWithAdjusted(cohort, title) {
const { realized } = cohort.tree;
const r = cohort.tree.realized;
return [
{
name: "Normal",
title: title("SOPR"),
bottom: soprSeries(realized),
tree: singleRollingSoprTree(
{ s24h: r.sopr24h, s7d: r.sopr7d, s30d: r.sopr30d, s1y: r.sopr1y, ema24h7d: r.sopr24h7dEma, ema24h30d: r.sopr24h30dEma },
title,
),
},
{
name: "Adjusted",
title: title("Adjusted SOPR"),
bottom: soprSeries(
{
sopr: realized.adjustedSopr,
sopr7dEma: realized.adjustedSopr7dEma,
sopr30dEma: realized.adjustedSopr30dEma,
},
"Adjusted SOPR",
tree: singleRollingSoprTree(
{ s24h: r.adjustedSopr24h, s7d: r.adjustedSopr7d, s30d: r.adjustedSopr30d, s1y: r.adjustedSopr1y, ema24h7d: r.adjustedSopr24h7dEma, ema24h30d: r.adjustedSopr24h30dEma },
title,
"Adjusted ",
),
},
];
@@ -308,27 +568,56 @@ function createGroupedSoprTreeWithAdjusted(list, all, title) {
return [
{
name: "Normal",
tree: groupedSoprCharts(
list,
all,
(c) => c.tree.realized.sopr,
(c) => c.tree.realized.sopr7dEma,
(c) => c.tree.realized.sopr30dEma,
title,
"",
),
tree: [
...groupedSoprCharts(
list,
all,
(c) => c.tree.realized.sopr,
(c) => c.tree.realized.sopr7dEma,
(c) => c.tree.realized.sopr30dEma,
title,
"",
),
{
name: "Rolling",
tree: groupedRollingSoprCharts(
list,
all,
(c) => c.tree.realized.sopr24h,
(c) => c.tree.realized.sopr7d,
(c) => c.tree.realized.sopr30d,
(c) => c.tree.realized.sopr1y,
title,
),
},
],
},
{
name: "Adjusted",
tree: groupedSoprCharts(
list,
all,
(c) => c.tree.realized.adjustedSopr,
(c) => c.tree.realized.adjustedSopr7dEma,
(c) => c.tree.realized.adjustedSopr30dEma,
title,
"Adjusted ",
),
tree: [
...groupedSoprCharts(
list,
all,
(c) => c.tree.realized.adjustedSopr,
(c) => c.tree.realized.adjustedSopr7dEma,
(c) => c.tree.realized.adjustedSopr30dEma,
title,
"Adjusted ",
),
{
name: "Rolling",
tree: groupedRollingSoprCharts(
list,
all,
(c) => c.tree.realized.adjustedSopr24h,
(c) => c.tree.realized.adjustedSopr7d,
(c) => c.tree.realized.adjustedSopr30d,
(c) => c.tree.realized.adjustedSopr1y,
title,
"Adjusted ",
),
},
],
},
];
}
@@ -344,6 +633,7 @@ function createGroupedSoprTreeWithAdjusted(list, all, title) {
* @param {(metric: string) => string} args.title
* @param {AnyFetchedSeriesBlueprint[]} [args.valueMetrics] - Optional additional value metrics
* @param {PartialOptionsTree} [args.soprTree] - Optional SOPR tree override
* @param {PartialOptionsTree} [args.valueRollingTree] - Optional value rolling tree override
* @returns {PartialOptionsGroup}
*/
export function createActivitySection({
@@ -351,6 +641,7 @@ export function createActivitySection({
title,
valueMetrics = [],
soprTree,
valueRollingTree,
}) {
const { tree, color } = cohort;
@@ -431,17 +722,18 @@ export function createActivitySection({
},
],
},
soprTree
? { name: "SOPR", tree: soprTree }
: {
name: "SOPR",
title: title("SOPR"),
bottom: createSingleSoprSeries(cohort),
},
{
name: "SOPR",
tree:
soprTree ??
singleRollingSoprTree(
{ s24h: tree.realized.sopr24h, s7d: tree.realized.sopr7d, s30d: tree.realized.sopr30d, s1y: tree.realized.sopr1y, ema24h7d: tree.realized.sopr24h7dEma, ema24h30d: tree.realized.sopr24h30dEma },
title,
),
},
{
name: "Sell Side Risk",
title: title("Sell Side Risk Ratio"),
bottom: createSingleSellSideRiskSeries(tree),
tree: singleRollingSellSideRiskTree(tree.realized, title),
},
{
name: "Value",
@@ -500,6 +792,20 @@ export function createActivitySection({
},
],
},
{
name: "Rolling",
tree:
valueRollingTree ??
singleRollingValueTree(
{
created24h: tree.realized.valueCreated24h, created7d: tree.realized.valueCreated7d,
created30d: tree.realized.valueCreated30d, created1y: tree.realized.valueCreated1y,
destroyed24h: tree.realized.valueDestroyed24h, destroyed7d: tree.realized.valueDestroyed7d,
destroyed30d: tree.realized.valueDestroyed30d, destroyed1y: tree.realized.valueDestroyed1y,
},
title,
),
},
],
},
{
@@ -574,6 +880,33 @@ export function createActivitySectionWithAdjusted({ cohort, title }) {
defaultActive: false,
}),
],
valueRollingTree: [
{
name: "Normal",
tree: singleRollingValueTree(
{
created24h: tree.realized.valueCreated24h, created7d: tree.realized.valueCreated7d,
created30d: tree.realized.valueCreated30d, created1y: tree.realized.valueCreated1y,
destroyed24h: tree.realized.valueDestroyed24h, destroyed7d: tree.realized.valueDestroyed7d,
destroyed30d: tree.realized.valueDestroyed30d, destroyed1y: tree.realized.valueDestroyed1y,
},
title,
),
},
{
name: "Adjusted",
tree: singleRollingValueTree(
{
created24h: tree.realized.adjustedValueCreated24h, created7d: tree.realized.adjustedValueCreated7d,
created30d: tree.realized.adjustedValueCreated30d, created1y: tree.realized.adjustedValueCreated1y,
destroyed24h: tree.realized.adjustedValueDestroyed24h, destroyed7d: tree.realized.adjustedValueDestroyed7d,
destroyed30d: tree.realized.adjustedValueDestroyed30d, destroyed1y: tree.realized.adjustedValueDestroyed1y,
},
title,
"Adjusted ",
),
},
],
});
}
@@ -701,16 +1034,45 @@ export function createGroupedActivitySection({
},
{
name: "SOPR",
tree: soprTree ?? createGroupedSoprTree(list, all, title),
tree: soprTree ?? [
...createGroupedSoprTree(list, all, title),
{
name: "Rolling",
tree: groupedRollingSoprCharts(
list,
all,
(c) => c.tree.realized.sopr24h,
(c) => c.tree.realized.sopr7d,
(c) => c.tree.realized.sopr30d,
(c) => c.tree.realized.sopr1y,
title,
),
},
],
},
{
name: "Sell Side Risk",
title: title("Sell Side Risk Ratio"),
bottom: createGroupedSellSideRiskSeries(list, all),
tree: groupedRollingSellSideRiskCharts(list, all, title),
},
{
name: "Value",
tree: valueTree ?? createGroupedValueTree(list, all, title),
tree: valueTree ?? [
...createGroupedValueTree(list, all, title),
{
name: "Rolling",
tree: groupedRollingValueCharts(
list,
all,
[
{ name: "24h", getCreated: (c) => c.tree.realized.valueCreated24h, getDestroyed: (c) => c.tree.realized.valueDestroyed24h },
{ name: "7d", getCreated: (c) => c.tree.realized.valueCreated7d, getDestroyed: (c) => c.tree.realized.valueDestroyed7d },
{ name: "30d", getCreated: (c) => c.tree.realized.valueCreated30d, getDestroyed: (c) => c.tree.realized.valueDestroyed30d },
{ name: "1y", getCreated: (c) => c.tree.realized.valueCreated1y, getDestroyed: (c) => c.tree.realized.valueDestroyed1y },
],
title,
),
},
],
},
{ name: "Coins Destroyed", tree: coinsDestroyedTree(list, all, title) },
],
@@ -786,6 +1148,40 @@ function createGroupedValueTreeWithAdjusted(list, all, title) {
],
},
{ name: "Breakdown", tree: valueBreakdownTree(list, all, title) },
{
name: "Rolling",
tree: [
{
name: "Normal",
tree: groupedRollingValueCharts(
list,
all,
[
{ name: "24h", getCreated: (c) => c.tree.realized.valueCreated24h, getDestroyed: (c) => c.tree.realized.valueDestroyed24h },
{ name: "7d", getCreated: (c) => c.tree.realized.valueCreated7d, getDestroyed: (c) => c.tree.realized.valueDestroyed7d },
{ name: "30d", getCreated: (c) => c.tree.realized.valueCreated30d, getDestroyed: (c) => c.tree.realized.valueDestroyed30d },
{ name: "1y", getCreated: (c) => c.tree.realized.valueCreated1y, getDestroyed: (c) => c.tree.realized.valueDestroyed1y },
],
title,
),
},
{
name: "Adjusted",
tree: groupedRollingValueCharts(
list,
all,
[
{ name: "24h", getCreated: (c) => c.tree.realized.adjustedValueCreated24h, getDestroyed: (c) => c.tree.realized.adjustedValueDestroyed24h },
{ name: "7d", getCreated: (c) => c.tree.realized.adjustedValueCreated7d, getDestroyed: (c) => c.tree.realized.adjustedValueDestroyed7d },
{ name: "30d", getCreated: (c) => c.tree.realized.adjustedValueCreated30d, getDestroyed: (c) => c.tree.realized.adjustedValueDestroyed30d },
{ name: "1y", getCreated: (c) => c.tree.realized.adjustedValueCreated1y, getDestroyed: (c) => c.tree.realized.adjustedValueDestroyed1y },
],
title,
"Adjusted ",
),
},
],
},
];
}
@@ -804,50 +1200,6 @@ export function createGroupedActivitySectionWithAdjusted({ list, all, title }) {
});
}
/**
* Create sell side risk ratio series for single cohort
* @param {{ realized: AnyRealizedPattern }} tree
* @returns {AnyFetchedSeriesBlueprint[]}
*/
function createSingleSellSideRiskSeries(tree) {
return [
line({
metric: tree.realized.sellSideRiskRatio30dEma,
name: "30d EMA",
color: colors.time._1m,
unit: Unit.ratio,
}),
line({
metric: tree.realized.sellSideRiskRatio7dEma,
name: "7d EMA",
color: colors.time._1w,
unit: Unit.ratio,
}),
dots({
metric: tree.realized.sellSideRiskRatio,
name: "Raw",
color: colors.bitcoin,
unit: Unit.ratio,
}),
];
}
/**
* Create sell side risk ratio series for grouped cohorts
* @param {readonly CohortObject[]} list
* @param {CohortObject} all
* @returns {AnyFetchedSeriesBlueprint[]}
*/
function createGroupedSellSideRiskSeries(list, all) {
return flatMapCohortsWithAll(list, all, ({ name, color, tree }) => [
line({
metric: tree.realized.sellSideRiskRatio,
name,
color,
unit: Unit.ratio,
}),
]);
}
/**
* Create value created & destroyed series for single cohort

View File

@@ -238,7 +238,11 @@ export function createGroupedCostBasisSection({ list, all, title }) {
* @param {{ list: readonly (CohortAll | CohortFull | CohortWithPercentiles)[], all: CohortAll, title: (metric: string) => string }} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCostBasisSectionWithPercentiles({ list, all, title }) {
export function createGroupedCostBasisSectionWithPercentiles({
list,
all,
title,
}) {
return {
name: "Cost Basis",
tree: [

View File

@@ -89,17 +89,15 @@ export function buildCohortData() {
});
// Age range cohorts
const dateRange = entries(utxoCohorts.ageRange).map(
([key, tree], i, arr) => {
const names = AGE_RANGE_NAMES[key];
return {
name: names.short,
title: `UTXOs ${names.long}`,
color: colors.at(i, arr.length),
tree,
};
},
);
const dateRange = entries(utxoCohorts.ageRange).map(([key, tree], i, arr) => {
const names = AGE_RANGE_NAMES[key];
return {
name: names.short,
title: `UTXOs ${names.long}`,
color: colors.at(i, arr.length),
tree,
};
});
// Epoch cohorts
const epoch = entries(utxoCohorts.epoch).map(([key, tree], i, arr) => {

View File

@@ -15,7 +15,13 @@
import { Unit } from "../../utils/units.js";
import { line, baseline } from "../series.js";
import { satsBtcUsd, satsBtcUsdBaseline, mapCohorts, mapCohortsWithAll, flatMapCohortsWithAll } from "../shared.js";
import {
satsBtcUsd,
satsBtcUsdBaseline,
mapCohorts,
mapCohortsWithAll,
flatMapCohortsWithAll,
} from "../shared.js";
import { colors } from "../../utils/colors.js";
import { priceLines } from "../constants.js";
@@ -26,10 +32,27 @@ import { priceLines } from "../constants.js";
*/
function baseSupplySeries(tree) {
return [
...satsBtcUsd({ pattern: tree.supply.total, name: "Total", color: colors.default }),
...satsBtcUsd({ pattern: tree.unrealized.supplyInProfit, name: "In Profit", color: colors.profit }),
...satsBtcUsd({ pattern: tree.unrealized.supplyInLoss, name: "In Loss", color: colors.loss }),
...satsBtcUsd({ pattern: tree.supply.halved, name: "Halved", color: colors.gray, style: 4 }),
...satsBtcUsd({
pattern: tree.supply.total,
name: "Total",
color: colors.default,
}),
...satsBtcUsd({
pattern: tree.unrealized.supplyInProfit,
name: "In Profit",
color: colors.profit,
}),
...satsBtcUsd({
pattern: tree.unrealized.supplyInLoss,
name: "In Loss",
color: colors.loss,
}),
...satsBtcUsd({
pattern: tree.supply.halved,
name: "Halved",
color: colors.gray,
style: 4,
}),
];
}
@@ -40,8 +63,18 @@ function baseSupplySeries(tree) {
*/
function ownSupplyPctSeries(tree) {
return [
line({ metric: tree.relative.supplyInProfitRelToOwnSupply, name: "In Profit", color: colors.profit, unit: Unit.pctOwn }),
line({ metric: tree.relative.supplyInLossRelToOwnSupply, name: "In Loss", color: colors.loss, unit: Unit.pctOwn }),
line({
metric: tree.relative.supplyInProfitRelToOwnSupply,
name: "In Profit",
color: colors.profit,
unit: Unit.pctOwn,
}),
line({
metric: tree.relative.supplyInLossRelToOwnSupply,
name: "In Loss",
color: colors.loss,
unit: Unit.pctOwn,
}),
...priceLines({ numbers: [100, 50, 0], unit: Unit.pctOwn }),
];
}
@@ -53,9 +86,24 @@ function ownSupplyPctSeries(tree) {
*/
function circulatingSupplyPctSeries(tree) {
return [
line({ metric: tree.relative.supplyRelToCirculatingSupply, name: "Total", color: colors.default, unit: Unit.pctSupply }),
line({ metric: tree.relative.supplyInProfitRelToCirculatingSupply, name: "In Profit", color: colors.profit, unit: Unit.pctSupply }),
line({ metric: tree.relative.supplyInLossRelToCirculatingSupply, name: "In Loss", color: colors.loss, unit: Unit.pctSupply }),
line({
metric: tree.relative.supplyRelToCirculatingSupply,
name: "Total",
color: colors.default,
unit: Unit.pctSupply,
}),
line({
metric: tree.relative.supplyInProfitRelToCirculatingSupply,
name: "In Profit",
color: colors.profit,
unit: Unit.pctSupply,
}),
line({
metric: tree.relative.supplyInLossRelToCirculatingSupply,
name: "In Loss",
color: colors.loss,
unit: Unit.pctSupply,
}),
];
}
@@ -99,7 +147,12 @@ function grouped30dUtxoCountChangeChart(list, all, title) {
name: "UTXO Count",
title: title("UTXO Count 30d Change"),
bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) =>
baseline({ metric: tree.outputs.utxoCount30dChange, name, unit: Unit.count, color }),
baseline({
metric: tree.outputs.utxoCount30dChange,
name,
unit: Unit.count,
color,
}),
),
};
}
@@ -157,7 +210,12 @@ function singleAddressCountChart(cohort, title) {
name: "Address Count",
title: title("Address Count"),
bottom: [
line({ metric: cohort.addrCount.count, name: "Address Count", color: cohort.color, unit: Unit.count }),
line({
metric: cohort.addrCount.count,
name: "Address Count",
color: cohort.color,
unit: Unit.count,
}),
],
};
}
@@ -271,10 +329,27 @@ function createSingleSupplySeriesWithRelative(cohort) {
function createSingleSupplySeriesWithOwnSupply(cohort) {
const { tree } = cohort;
return [
...satsBtcUsd({ pattern: tree.unrealized.supplyInProfit, name: "In Profit", color: colors.profit }),
...satsBtcUsd({ pattern: tree.unrealized.supplyInLoss, name: "In Loss", color: colors.loss }),
...satsBtcUsd({ pattern: tree.supply.total, name: "Total", color: colors.default }),
...satsBtcUsd({ pattern: tree.supply.halved, name: "Halved", color: colors.gray, style: 4 }),
...satsBtcUsd({
pattern: tree.unrealized.supplyInProfit,
name: "In Profit",
color: colors.profit,
}),
...satsBtcUsd({
pattern: tree.unrealized.supplyInLoss,
name: "In Loss",
color: colors.loss,
}),
...satsBtcUsd({
pattern: tree.supply.total,
name: "Total",
color: colors.default,
}),
...satsBtcUsd({
pattern: tree.supply.halved,
name: "Halved",
color: colors.gray,
style: 4,
}),
...ownSupplyPctSeries(tree),
];
}
@@ -518,7 +593,12 @@ export function createGroupedHoldingsSectionAddress({ list, all, title }) {
name: "Address Count",
title: title("Address Count 30d Change"),
bottom: mapCohortsWithAll(list, all, ({ name, color, addrCount }) =>
baseline({ metric: addrCount._30dChange, name, unit: Unit.count, color }),
baseline({
metric: addrCount._30dChange,
name,
unit: Unit.count,
color,
}),
),
},
],
@@ -532,7 +612,11 @@ export function createGroupedHoldingsSectionAddress({ list, all, title }) {
* @param {{ list: readonly AddressCohortObject[], all: CohortAll, title: (metric: string) => string }} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedHoldingsSectionAddressAmount({ list, all, title }) {
export function createGroupedHoldingsSectionAddressAmount({
list,
all,
title,
}) {
return {
name: "Holdings",
tree: [
@@ -635,7 +719,12 @@ export function createGroupedHoldingsSectionAddressAmount({ list, all, title })
name: "Address Count",
title: title("Address Count 30d Change"),
bottom: mapCohortsWithAll(list, all, ({ name, color, addrCount }) =>
baseline({ metric: addrCount._30dChange, name, unit: Unit.count, color }),
baseline({
metric: addrCount._30dChange,
name,
unit: Unit.count,
color,
}),
),
},
],
@@ -703,7 +792,11 @@ export function createGroupedHoldingsSection({ list, all, title }) {
* @param {{ list: readonly (CohortAgeRange | CohortBasicWithoutMarketCap)[], all: CohortAll, title: (metric: string) => string }} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedHoldingsSectionWithOwnSupply({ list, all, title }) {
export function createGroupedHoldingsSectionWithOwnSupply({
list,
all,
title,
}) {
return {
name: "Holdings",
tree: [

View File

@@ -321,7 +321,12 @@ export function createAddressCohortFolder(cohort) {
* @param {CohortGroupFull} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderFull({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderFull({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -340,7 +345,12 @@ export function createGroupedCohortFolderFull({ name, title: groupTitle, list, a
* @param {CohortGroupWithAdjusted} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderWithAdjusted({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderWithAdjusted({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -359,7 +369,12 @@ export function createGroupedCohortFolderWithAdjusted({ name, title: groupTitle,
* @param {CohortGroupWithNuplPercentiles} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderWithNupl({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderWithNupl({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -378,7 +393,12 @@ export function createGroupedCohortFolderWithNupl({ name, title: groupTitle, lis
* @param {CohortGroupLongTerm} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderLongTerm({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderLongTerm({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -397,7 +417,12 @@ export function createGroupedCohortFolderLongTerm({ name, title: groupTitle, lis
* @param {CohortGroupAgeRange} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderAgeRange({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderAgeRange({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -406,7 +431,11 @@ export function createGroupedCohortFolderAgeRange({ name, title: groupTitle, lis
createGroupedValuationSectionWithOwnMarketCap({ list, all, title }),
createGroupedPricesSection({ list, all, title }),
createGroupedCostBasisSectionWithPercentiles({ list, all, title }),
createGroupedProfitabilitySectionWithInvestedCapitalPct({ list, all, title }),
createGroupedProfitabilitySectionWithInvestedCapitalPct({
list,
all,
title,
}),
createGroupedActivitySection({ list, all, title }),
],
};
@@ -416,7 +445,12 @@ export function createGroupedCohortFolderAgeRange({ name, title: groupTitle, lis
* @param {CohortGroupMinAge} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderMinAge({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderMinAge({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -435,7 +469,12 @@ export function createGroupedCohortFolderMinAge({ name, title: groupTitle, list,
* @param {CohortGroupBasicWithMarketCap} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderBasicWithMarketCap({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderBasicWithMarketCap({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -454,7 +493,12 @@ export function createGroupedCohortFolderBasicWithMarketCap({ name, title: group
* @param {CohortGroupBasicWithoutMarketCap} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderBasicWithoutMarketCap({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderBasicWithoutMarketCap({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -463,7 +507,11 @@ export function createGroupedCohortFolderBasicWithoutMarketCap({ name, title: gr
createGroupedValuationSection({ list, all, title }),
createGroupedPricesSection({ list, all, title }),
createGroupedCostBasisSection({ list, all, title }),
createGroupedProfitabilitySectionBasicWithInvestedCapitalPct({ list, all, title }),
createGroupedProfitabilitySectionBasicWithInvestedCapitalPct({
list,
all,
title,
}),
createGroupedActivitySection({ list, all, title }),
],
};
@@ -473,7 +521,12 @@ export function createGroupedCohortFolderBasicWithoutMarketCap({ name, title: gr
* @param {CohortGroupAddress} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderAddress({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderAddress({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -482,7 +535,11 @@ export function createGroupedCohortFolderAddress({ name, title: groupTitle, list
createGroupedValuationSection({ list, all, title }),
createGroupedPricesSection({ list, all, title }),
createGroupedCostBasisSection({ list, all, title }),
createGroupedProfitabilitySectionBasicWithInvestedCapitalPct({ list, all, title }),
createGroupedProfitabilitySectionBasicWithInvestedCapitalPct({
list,
all,
title,
}),
createGroupedActivitySection({ list, all, title }),
],
};
@@ -492,7 +549,12 @@ export function createGroupedCohortFolderAddress({ name, title: groupTitle, list
* @param {CohortGroupWithoutRelative} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedCohortFolderWithoutRelative({ name, title: groupTitle, list, all }) {
export function createGroupedCohortFolderWithoutRelative({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",
@@ -511,7 +573,12 @@ export function createGroupedCohortFolderWithoutRelative({ name, title: groupTit
* @param {AddressCohortGroupObject} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedAddressCohortFolder({ name, title: groupTitle, list, all }) {
export function createGroupedAddressCohortFolder({
name,
title: groupTitle,
list,
all,
}) {
const title = formatCohortTitle(groupTitle);
return {
name: name || "all",

View File

@@ -28,10 +28,30 @@ function createCompareChart(tree, title) {
name: "Compare",
title: title("Prices"),
top: [
price({ metric: tree.realized.realizedPrice, name: "Realized", color: colors.realized }),
price({ metric: tree.realized.investorPrice, name: "Investor", color: colors.investor }),
price({ metric: tree.realized.upperPriceBand, name: "I²/R", color: colors.stat.max, style: 2, defaultActive: false }),
price({ metric: tree.realized.lowerPriceBand, name: "R²/I", color: colors.stat.min, style: 2, defaultActive: false }),
price({
metric: tree.realized.realizedPrice,
name: "Realized",
color: colors.realized,
}),
price({
metric: tree.realized.investorPrice,
name: "Investor",
color: colors.investor,
}),
price({
metric: tree.realized.upperPriceBand,
name: "I²/R",
color: colors.stat.max,
style: 2,
defaultActive: false,
}),
price({
metric: tree.realized.lowerPriceBand,
name: "R²/I",
color: colors.stat.min,
style: 2,
defaultActive: false,
}),
],
};
}

View File

@@ -6,7 +6,13 @@ import { Unit } from "../../utils/units.js";
import { line, baseline, dots, dotsBaseline } from "../series.js";
import { colors } from "../../utils/colors.js";
import { priceLine, priceLines } from "../constants.js";
import { satsBtcUsd, satsBtcUsdFrom, mapCohorts, mapCohortsWithAll, flatMapCohortsWithAll } from "../shared.js";
import {
satsBtcUsd,
satsBtcUsdFrom,
mapCohorts,
mapCohortsWithAll,
flatMapCohortsWithAll,
} from "../shared.js";
// ============================================================================
// Core Series Builders (Composable Primitives)
@@ -28,13 +34,33 @@ import { satsBtcUsd, satsBtcUsdFrom, mapCohorts, mapCohortsWithAll, flatMapCohor
*/
function pnlLines(metrics, unit) {
const series = [
line({ metric: metrics.profit, name: "Profit", color: colors.profit, unit }),
line({
metric: metrics.profit,
name: "Profit",
color: colors.profit,
unit,
}),
line({ metric: metrics.loss, name: "Loss", color: colors.loss, unit }),
];
if (metrics.total) {
series.push(line({ metric: metrics.total, name: "Total", color: colors.default, unit }));
series.push(
line({
metric: metrics.total,
name: "Total",
color: colors.default,
unit,
}),
);
}
series.push(line({ metric: metrics.negLoss, name: "Negative Loss", color: colors.loss, unit, defaultActive: false }));
series.push(
line({
metric: metrics.negLoss,
name: "Negative Loss",
color: colors.loss,
unit,
defaultActive: false,
}),
);
return series;
}
@@ -83,7 +109,10 @@ function getUnrealizedMetrics(tree) {
*/
function unrealizedUsd(m) {
return [
...pnlLines({ profit: m.profit, loss: m.loss, negLoss: m.negLoss, total: m.total }, Unit.usd),
...pnlLines(
{ profit: m.profit, loss: m.loss, negLoss: m.negLoss, total: m.total },
Unit.usd,
),
priceLine({ unit: Unit.usd, defaultActive: false }),
];
}
@@ -708,6 +737,166 @@ function sentInPnlTree(tree, title) {
];
}
// ============================================================================
// Rolling Realized Helpers
// ============================================================================
/**
* Rolling realized value tree for single cohort (available on all realized patterns)
* @param {AnyRealizedPattern} r
* @param {(metric: string) => string} title
* @returns {PartialOptionsTree}
*/
function singleRollingRealizedValueTree(r, title) {
return [
{
name: "Compare",
title: title("Rolling Realized Value"),
bottom: [
line({ metric: r.realizedValue24h, name: "24h", color: colors.time._24h, unit: Unit.usd }),
line({ metric: r.realizedValue7d, name: "7d", color: colors.time._1w, unit: Unit.usd }),
line({ metric: r.realizedValue30d, name: "30d", color: colors.time._1m, unit: Unit.usd }),
line({ metric: r.realizedValue1y, name: "1y", color: colors.time._1y, unit: Unit.usd }),
],
},
{ name: "24h", title: title("Realized Value (24h)"), bottom: [line({ metric: r.realizedValue24h, name: "Value", unit: Unit.usd })] },
{ name: "7d", title: title("Realized Value (7d)"), bottom: [line({ metric: r.realizedValue7d, name: "Value", unit: Unit.usd })] },
{ name: "30d", title: title("Realized Value (30d)"), bottom: [line({ metric: r.realizedValue30d, name: "Value", unit: Unit.usd })] },
{ name: "1y", title: title("Realized Value (1y)"), bottom: [line({ metric: r.realizedValue1y, name: "Value", unit: Unit.usd })] },
];
}
/**
* Rolling realized tree with P/L for single cohort (for RealizedWithExtras patterns)
* @param {RealizedWithExtras} r
* @param {(metric: string) => string} title
* @returns {PartialOptionsTree}
*/
function singleRollingRealizedTreeWithExtras(r, title) {
return [
{
name: "Value",
tree: singleRollingRealizedValueTree(r, title),
},
{
name: "Profit",
tree: [
{
name: "Compare",
title: title("Rolling Realized Profit"),
bottom: [
line({ metric: r.realizedProfit24h, name: "24h", color: colors.time._24h, unit: Unit.usd }),
line({ metric: r.realizedProfit7d, name: "7d", color: colors.time._1w, unit: Unit.usd }),
line({ metric: r.realizedProfit30d, name: "30d", color: colors.time._1m, unit: Unit.usd }),
line({ metric: r.realizedProfit1y, name: "1y", color: colors.time._1y, unit: Unit.usd }),
],
},
{ name: "24h", title: title("Realized Profit (24h)"), bottom: [line({ metric: r.realizedProfit24h, name: "Profit", color: colors.profit, unit: Unit.usd })] },
{ name: "7d", title: title("Realized Profit (7d)"), bottom: [line({ metric: r.realizedProfit7d, name: "Profit", color: colors.profit, unit: Unit.usd })] },
{ name: "30d", title: title("Realized Profit (30d)"), bottom: [line({ metric: r.realizedProfit30d, name: "Profit", color: colors.profit, unit: Unit.usd })] },
{ name: "1y", title: title("Realized Profit (1y)"), bottom: [line({ metric: r.realizedProfit1y, name: "Profit", color: colors.profit, unit: Unit.usd })] },
],
},
{
name: "Loss",
tree: [
{
name: "Compare",
title: title("Rolling Realized Loss"),
bottom: [
line({ metric: r.realizedLoss24h, name: "24h", color: colors.time._24h, unit: Unit.usd }),
line({ metric: r.realizedLoss7d, name: "7d", color: colors.time._1w, unit: Unit.usd }),
line({ metric: r.realizedLoss30d, name: "30d", color: colors.time._1m, unit: Unit.usd }),
line({ metric: r.realizedLoss1y, name: "1y", color: colors.time._1y, unit: Unit.usd }),
],
},
{ name: "24h", title: title("Realized Loss (24h)"), bottom: [line({ metric: r.realizedLoss24h, name: "Loss", color: colors.loss, unit: Unit.usd })] },
{ name: "7d", title: title("Realized Loss (7d)"), bottom: [line({ metric: r.realizedLoss7d, name: "Loss", color: colors.loss, unit: Unit.usd })] },
{ name: "30d", title: title("Realized Loss (30d)"), bottom: [line({ metric: r.realizedLoss30d, name: "Loss", color: colors.loss, unit: Unit.usd })] },
{ name: "1y", title: title("Realized Loss (1y)"), bottom: [line({ metric: r.realizedLoss1y, name: "Loss", color: colors.loss, unit: Unit.usd })] },
],
},
{
name: "P/L Ratio",
tree: [
{
name: "Compare",
title: title("Rolling Realized P/L Ratio"),
bottom: [
baseline({ metric: r.realizedProfitToLossRatio24h, name: "24h", color: colors.time._24h, unit: Unit.ratio }),
baseline({ metric: r.realizedProfitToLossRatio7d, name: "7d", color: colors.time._1w, unit: Unit.ratio }),
baseline({ metric: r.realizedProfitToLossRatio30d, name: "30d", color: colors.time._1m, unit: Unit.ratio }),
baseline({ metric: r.realizedProfitToLossRatio1y, name: "1y", color: colors.time._1y, unit: Unit.ratio }),
],
},
{ name: "24h", title: title("Realized P/L Ratio (24h)"), bottom: [baseline({ metric: r.realizedProfitToLossRatio24h, name: "P/L Ratio", unit: Unit.ratio })] },
{ name: "7d", title: title("Realized P/L Ratio (7d)"), bottom: [baseline({ metric: r.realizedProfitToLossRatio7d, name: "P/L Ratio", unit: Unit.ratio })] },
{ name: "30d", title: title("Realized P/L Ratio (30d)"), bottom: [baseline({ metric: r.realizedProfitToLossRatio30d, name: "P/L Ratio", unit: Unit.ratio })] },
{ name: "1y", title: title("Realized P/L Ratio (1y)"), bottom: [baseline({ metric: r.realizedProfitToLossRatio1y, name: "P/L Ratio", unit: Unit.ratio })] },
],
},
];
}
/**
* Grouped rolling realized value charts (available on all realized patterns)
* @param {readonly CohortObject[]} list
* @param {CohortObject} all
* @param {(metric: string) => string} title
* @returns {PartialOptionsTree}
*/
function groupedRollingRealizedValueCharts(list, all, title) {
return [
{ name: "24h", title: title("Realized Value (24h)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedValue24h, name, color, unit: Unit.usd })) },
{ name: "7d", title: title("Realized Value (7d)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedValue7d, name, color, unit: Unit.usd })) },
{ name: "30d", title: title("Realized Value (30d)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedValue30d, name, color, unit: Unit.usd })) },
{ name: "1y", title: title("Realized Value (1y)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedValue1y, name, color, unit: Unit.usd })) },
];
}
/**
* Grouped rolling realized charts with P/L (for RealizedWithExtras cohorts)
* @param {readonly (CohortAgeRange | CohortLongTerm | CohortAll | CohortFull)[]} list
* @param {CohortAll} all
* @param {(metric: string) => string} title
* @returns {PartialOptionsTree}
*/
function groupedRollingRealizedChartsWithExtras(list, all, title) {
return [
{
name: "Value",
tree: groupedRollingRealizedValueCharts(list, all, title),
},
{
name: "Profit",
tree: [
{ name: "24h", title: title("Realized Profit (24h)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedProfit24h, name, color, unit: Unit.usd })) },
{ name: "7d", title: title("Realized Profit (7d)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedProfit7d, name, color, unit: Unit.usd })) },
{ name: "30d", title: title("Realized Profit (30d)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedProfit30d, name, color, unit: Unit.usd })) },
{ name: "1y", title: title("Realized Profit (1y)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedProfit1y, name, color, unit: Unit.usd })) },
],
},
{
name: "Loss",
tree: [
{ name: "24h", title: title("Realized Loss (24h)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedLoss24h, name, color, unit: Unit.usd })) },
{ name: "7d", title: title("Realized Loss (7d)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedLoss7d, name, color, unit: Unit.usd })) },
{ name: "30d", title: title("Realized Loss (30d)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedLoss30d, name, color, unit: Unit.usd })) },
{ name: "1y", title: title("Realized Loss (1y)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => line({ metric: tree.realized.realizedLoss1y, name, color, unit: Unit.usd })) },
],
},
{
name: "P/L Ratio",
tree: [
{ name: "24h", title: title("Realized P/L Ratio (24h)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => baseline({ metric: tree.realized.realizedProfitToLossRatio24h, name, color, unit: Unit.ratio })) },
{ name: "7d", title: title("Realized P/L Ratio (7d)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => baseline({ metric: tree.realized.realizedProfitToLossRatio7d, name, color, unit: Unit.ratio })) },
{ name: "30d", title: title("Realized P/L Ratio (30d)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => baseline({ metric: tree.realized.realizedProfitToLossRatio30d, name, color, unit: Unit.ratio })) },
{ name: "1y", title: title("Realized P/L Ratio (1y)"), bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) => baseline({ metric: tree.realized.realizedProfitToLossRatio1y, name, color, unit: Unit.ratio })) },
],
},
];
}
// ============================================================================
// Realized Subfolder Builders
// ============================================================================
@@ -716,9 +905,10 @@ function sentInPnlTree(tree, title) {
* Base realized subfolder (no P/L ratio)
* @param {{ realized: AnyRealizedPattern }} tree
* @param {(metric: string) => string} title
* @param {PartialOptionsTree} [rollingTree]
* @returns {PartialOptionsGroup}
*/
function realizedSubfolder(tree, title) {
function realizedSubfolder(tree, title, rollingTree) {
const r = tree.realized;
return {
name: "Realized",
@@ -761,6 +951,10 @@ function realizedSubfolder(tree, title) {
}),
],
},
{
name: "Rolling",
tree: rollingTree ?? singleRollingRealizedValueTree(r, title),
},
{
name: "Cumulative",
tree: [
@@ -797,21 +991,21 @@ function realizedSubfolder(tree, title) {
}
/**
* Realized subfolder with P/L ratio
* Realized subfolder with P/L ratio and rolling P/L
* @param {{ realized: RealizedWithExtras }} tree
* @param {(metric: string) => string} title
* @returns {PartialOptionsGroup}
*/
function realizedSubfolderWithExtras(tree, title) {
const base = realizedSubfolder(tree, title);
const r = tree.realized;
const base = realizedSubfolder(tree, title, singleRollingRealizedTreeWithExtras(r, title));
// Insert P/L Ratio after Total (index 3)
base.tree.splice(4, 0, {
name: "P/L Ratio",
title: title("Realized Profit/Loss Ratio"),
bottom: [
baseline({
metric: r.realizedProfitToLossRatio,
metric: r.realizedProfitToLossRatio1y,
name: "P/L Ratio",
unit: Unit.ratio,
}),
@@ -1706,7 +1900,7 @@ function groupedRealizedPnlSumWithExtras(list, all, title) {
title: title("Realized Profit/Loss Ratio"),
bottom: mapCohortsWithAll(list, all, ({ name, color, tree }) =>
baseline({
metric: tree.realized.realizedProfitToLossRatio,
metric: tree.realized.realizedProfitToLossRatio1y,
name,
color,
unit: Unit.ratio,
@@ -1929,6 +2123,10 @@ function groupedRealizedSubfolder(list, all, title) {
}),
),
},
{
name: "Rolling",
tree: groupedRollingRealizedValueCharts(list, all, title),
},
{
name: "Cumulative",
tree: [
@@ -1987,6 +2185,10 @@ function groupedRealizedSubfolderWithExtras(list, all, title) {
}),
),
},
{
name: "Rolling",
tree: groupedRollingRealizedChartsWithExtras(list, all, title),
},
{
name: "Cumulative",
tree: [
@@ -2050,7 +2252,10 @@ export function createGroupedProfitabilitySectionBasicWithInvestedCapitalPct({
{ name: "Unrealized", tree: groupedPnlCharts(list, all, title) },
groupedRealizedSubfolder(list, all, title),
{ name: "Volume", tree: groupedSentInPnl(list, all, title) },
{ name: "Invested Capital", tree: groupedInvestedCapital(list, all, title) },
{
name: "Invested Capital",
tree: groupedInvestedCapital(list, all, title),
},
groupedSentiment(list, all, title),
],
};
@@ -2089,7 +2294,10 @@ export function createGroupedProfitabilitySectionWithInvestedCapitalPct({
},
groupedRealizedSubfolderWithExtras(list, all, title),
{ name: "Volume", tree: groupedSentInPnl(list, all, title) },
{ name: "Invested Capital", tree: groupedInvestedCapital(list, all, title) },
{
name: "Invested Capital",
tree: groupedInvestedCapital(list, all, title),
},
groupedSentiment(list, all, title),
],
};
@@ -2100,7 +2308,11 @@ export function createGroupedProfitabilitySectionWithInvestedCapitalPct({
* @param {{ list: readonly (CohortFull | CohortBasicWithMarketCap)[], all: CohortAll, title: (metric: string) => string }} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedProfitabilitySectionWithNupl({ list, all, title }) {
export function createGroupedProfitabilitySectionWithNupl({
list,
all,
title,
}) {
return {
name: "Profitability",
tree: [
@@ -2124,7 +2336,10 @@ export function createGroupedProfitabilitySectionWithNupl({ list, all, title })
},
groupedRealizedSubfolder(list, all, title),
{ name: "Volume", tree: groupedSentInPnl(list, all, title) },
{ name: "Invested Capital", tree: groupedInvestedCapital(list, all, title) },
{
name: "Invested Capital",
tree: groupedInvestedCapital(list, all, title),
},
groupedSentiment(list, all, title),
],
};
@@ -2135,7 +2350,11 @@ export function createGroupedProfitabilitySectionWithNupl({ list, all, title })
* @param {{ list: readonly CohortLongTerm[], all: CohortAll, title: (metric: string) => string }} args
* @returns {PartialOptionsGroup}
*/
export function createGroupedProfitabilitySectionLongTerm({ list, all, title }) {
export function createGroupedProfitabilitySectionLongTerm({
list,
all,
title,
}) {
return {
name: "Profitability",
tree: [
@@ -2181,7 +2400,10 @@ export function createGroupedProfitabilitySectionLongTerm({ list, all, title })
},
groupedRealizedSubfolderWithExtras(list, all, title),
{ name: "Volume", tree: groupedSentInPnl(list, all, title) },
{ name: "Invested Capital", tree: groupedInvestedCapital(list, all, title) },
{
name: "Invested Capital",
tree: groupedInvestedCapital(list, all, title),
},
groupedSentiment(list, all, title),
],
};
@@ -2242,7 +2464,10 @@ export function createGroupedProfitabilitySectionWithPeakRegret({
},
groupedRealizedSubfolder(list, all, title),
{ name: "Volume", tree: groupedSentInPnl(list, all, title) },
{ name: "Invested Capital", tree: groupedInvestedCapital(list, all, title) },
{
name: "Invested Capital",
tree: groupedInvestedCapital(list, all, title),
},
groupedSentiment(list, all, title),
],
};