Skip to content

Instantly share code, notes, and snippets.

name: Deploy to GitHub pages
on:
  push:
    branches: [ main ]
  pull_request:
    branches: ["main"]
  schedule:
    - cron: "30 */2 * * *"
theme toc
dashboard
false

Relative performance

import {plotBreakdownChange, plotValueChange} from "./components/plots.js";
import {createClubbedStack, convertDates, getTopPerformer} from "./components/helpers.js";
export function getTopPerformer(breakdown, num_days) {
    const changeArray = []
    for (let i = 0; i < names.length; i++) {
        const changeObj = {
            name: names[i],
            change: (breakdown[breakdown.length - 1][names[i]] -
                    breakdown[breakdown.length - 1 - num_days][names[i]])
                    / breakdown[breakdown.length - 1- num_days][names[i]]
export function plotValueChange(breakdown, date, {width} = {}) {
    const bisector = d3.bisector((i) => breakdown[i].time);
    const basis = (I, Y) => Y[I[bisector.center(I, date)]];
    return Plot.plot({
    style: "overflow: visible;",
    y: {
        //type: "log",
export function plotBreakdownChange(stackArray, date, {width} = {}) {
    const bisector = d3.bisector((i) => stackArray[i].time);
    const basis = (I, Y) => Y[I[bisector.center(I, date)]];
    return Plot.plot({
    style: "overflow: visible;",
    y: {
        //type: "log",
theme toc
dashboard
false

Total value

import {plotValue, plotBreakdownBar, plotBreakdownArea} from "./components/plots.js";
import {createStack, getPertChange} from "./components/helpers.js";
export function getPertChange(breakdown, num_days) {
    const change = (breakdown[breakdown.length - 1].value -
                    breakdown[breakdown.length - 1 - num_days].value)
                    / breakdown[breakdown.length - 1- num_days].value
   
    // Change %
    const pert_change = change * 100;
    // Round off to first digit after decimal
export function plotBreakdownArea(stackArray, {width} = {}) {
  return Plot.plot({
    width,
    //title: "Portfolio breakdown",
    x: {label: "Time [days]"},
    y: {grid: true, label: "Value [euros]", domain: [0, domain_max]},
    color: {legend: true},
    marks: [
      Plot.areaY(stackArray, {
export function plotBreakdownBar(stackArray, {width} = {}) {
    return Plot.plot({
      width,
      //title: "Portfolio breakdown",
      x: {label: "Time [days]"},
      y: {grid: true, label: "Value [euros]", domain: [0, domain_max]},
      color: {legend: true},
      marks: [
        Plot.rectY(stackArray, {
import * as Plot from "npm:@observablehq/plot";
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
const domain_max = 30000
export function plotValue(breakdown, {width} = {}) {
    return Plot.plot({
      width,
      //title: "Total portfolio value",