Public
Edited
Feb 5, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db
-- It's necessary that the input table have _specifically_ this name
-- so the macro can read from it
with xmr_input_table as (
select * from my_data
where i between ${start_index} and ${start_index + num_sampled}
)
select *
from xmr("Close")
Insert cell
create_xmr_macro_query = await dbref.query(`

create or replace macro xmr(X_col) AS TABLE (
with run_variables as (
select
X_col as X,
abs(X - lag(X) over ()) as mR,
from xmr_input_table
),

aggregate_calcs as (
select
mean(X) as X_average,
mean(mR) as mR_average,
X_average - 2.66 * mR_average as LNPL,
X_average + 2.66 * mR_average as UNPL,
mR_average * 3.269 as URL,
from run_variables
)

from aggregate_calcs
);
`)
Insert cell
db
select * from my_data
where i between ${start_index} and ${start_index + num_sampled}
Insert cell
Insert cell
dbref = DuckDBClient.of({
my_data: my_data
})
Insert cell
db = create_clamp_macro_query, create_xmr_macro_query, dbref
Insert cell
my_data = aapl.map((d,i) => Object({i, ...d}))
Insert cell
dbref
from my_data
Insert cell
create_clamp_macro_query = await dbref.query(`
create or replace macro clamp(x, x_floor, x_ceiling) as
case when x < x_floor
then x_floor
when x > x_ceiling
then x_ceiling
else x
end
;
`)
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