Published
Edited
Jul 31, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof chart_returns = {
const hover = vl.selectPoint('hover')
.encodings('x')
.on('mouseover')
.toggle(false)
.nearest(true);

const isHovered = hover.empty(false);

const line = vl.markLine()
.title('Returns')
.encode(
vl.x().fieldT('Date'),
vl.y().fieldQ('Returns').title('Returns (%)'),
vl.color().fieldN('Symbol').scale({ domain: local_ticker_check, scheme:'category10'}),
);

const base = line.transform(vl.filter(isHovered));
const label = {align: 'left', dx: 5, dy: -5};
const white = {align: 'left', dx: 5, dy: -5, stroke: 'white', strokeWidth: 2};

return vl.data(filtered_data)
.layer(
line,
vl.markRule({color: '#000'})
.transform(vl.filter(isHovered))
.encode(vl.x().fieldT('Date')),
line.markCircle()
.params(hover)
.encode(vl.opacity().if(isHovered, vl.value(1)).value(0)),
base.markText(label, white).encode(vl.text().fieldQ('Returns').format('.000')),
base.markText(label).encode(vl.text().fieldQ('Returns').format('.000')),
)
.width(700)
.height(400)
.render();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vl
.data(filtered_data)
.title('Volatility')

.encode(
vl
.x()
.type('temporal')
.field('Date')
.axis({
title: "Time",
format: "%m/%d/%y"
}),
vl
.y()
.type('quantitative')
.scale({ zero: false, type: 'log' })
.axis({
title: "Closing Price ($)"
}),
vl
.color()
.condition({
test: "datum.Open < datum.Close",
value: "#06982d"
})
.value("#ae1325"),
vl.tooltip([
{ field: "Symbol", type: "ordinal", title: "Symbol" },
{ field: "Date", type: "temporal", title: "Date" },
{ field: "Close", type: "quantitative", title: "Close", format: ".0f" },
{ field: "Close", type: "quantitative", title: "Close", format: ".0f" },
{ field: "Open", type: "quantitative", title: "Open", format: ".0f" },
{ field: "High", type: "quantitative", title: "High", format: ".0f" },
{ field: "Low", type: "quantitative", title: "Low", format: ".0f" }
])
)
.layer(
vl
.markBar()
.select(vl.selectInterval().bind('scales'))
.encode(vl.y().field('Open'), vl.y2().field('Close')),
vl.markRule().encode(vl.y().field('Low'), vl.y2().field('High'))
)
.width(700)
.height(400)
.render()
Insert cell
Insert cell
Insert cell
md `## Global Configuration `
Insert cell
debug = true
Insert cell
W0 = 1200
Insert cell
w = width >= W0 ? Math.floor(width * 0.4) : width * 0.75 // for fullscreen
Insert cell
height_sankey = 800 * 0.6
Insert cell
colorVega = "#4C78A8"
Insert cell
// candle chart interval
interval = '1d'
Insert cell
md `## Internal Functions`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md `## Data`
Insert cell
filtered_data = temp_filter.filter(d => d.Date >= d1 && d.Date <= d2 && d.Close > 0 && d.Low > 0)
Insert cell
temp_filter_2 = temp_filter.filter(d => d.Close > 0)
Insert cell
temp_filter = local_data.filter(d => tickers2.has(d.Symbol))
Insert cell
tickers2 = new Set(local_ticker_check)
Insert cell
local_data = FileAttachment("tickers_full.csv").csv()
Insert cell
filtered_event_data = local_event_data.filter(d => d.Date >= d1 && d.Date <= d2)
Insert cell
local_event_data = FileAttachment("events@2.csv").csv()
Insert cell
symbol = 'BTCUSD_PERP'
Insert cell
candle_data = candles(symbol, interval)
Insert cell
Insert cell
factsExample = crossfilter(local_data)
Insert cell
sportDim = factsExample.dimension(d => d.Close)
Insert cell
function sampleArray(a, n, random) {
return a.slice(0, n);
}
Insert cell
tickers = ['BTC-USD','ETH-USD', 'AAPL', 'TSLA', 'MSFT', 'NVDA', 'SQ', 'PYPL', 'MSTR', 'JPM', '^IXIC', '^DJI', '^GSPC', 'GC=F', "CL=F"]
Insert cell
type = ['BTC History', 'Global', 'Elon', 'Financial']
Insert cell
md `## Import Libraries `
Insert cell
vegalite = require("@observablehq/vega-lite@0.3")
Insert cell

import {vegaSync} from "@pierreleripoll/vegasync"

Insert cell
import {createFacts} from "@pierreleripoll/vegasync"
Insert cell
//crossfilter = require("crossfilter2")
Insert cell
crossfilter = require("crossfilter2@1.5.4")
Insert cell
import {fullscreen} from "@pierreleripoll/vegasync"

Insert cell
import {slider,button,select,text,radio,checkbox,number,date} from "@jashkenas/inputs"
Insert cell
import {candles, forwardRate} from "@pandawhisperer/binance-futures-with-forward-rate"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more