global: 4y zscore + 200d sma + mayer's multiple

This commit is contained in:
nym21
2025-06-17 10:01:49 +02:00
parent 7e1fb6472d
commit bbe9f1bad2
8 changed files with 945 additions and 295 deletions

View File

@@ -141,7 +141,7 @@ function createChartElement({
}
: {}),
// ..._options,
})
}),
);
ichart.priceScale("right").applyOptions({
@@ -173,7 +173,7 @@ function createChartElement({
},
},
});
}
},
);
signals.createEffect(index, (index) => {
@@ -181,12 +181,12 @@ function createChartElement({
index === /** @satisfies {MonthIndex} */ (7)
? 1
: index === /** @satisfies {QuarterIndex} */ (19)
? 2
: index === /** @satisfies {YearIndex} */ (23)
? 6
: index === /** @satisfies {DecadeIndex} */ (1)
? 60
: 0.5;
? 2
: index === /** @satisfies {YearIndex} */ (23)
? 6
: index === /** @satisfies {DecadeIndex} */ (1)
? 60
: 0.5;
ichart.applyOptions({
timeScale: {
@@ -209,7 +209,7 @@ function createChartElement({
activeResources.forEach((v) => {
v.fetch();
});
})
}),
);
if (fitContent) {
@@ -240,7 +240,8 @@ function createChartElement({
const children = Array.from(parent.childNodes).filter(
(element) =>
/** @type {HTMLElement} */ (element).dataset.position === position
/** @type {HTMLElement} */ (element).dataset.position ===
position,
);
if (children.length === 1) {
@@ -262,7 +263,7 @@ function createChartElement({
fieldset.append(createChild(pane));
}),
paneIndex ? 50 : 0
paneIndex ? 50 : 0,
);
}
@@ -346,7 +347,7 @@ function createChartElement({
// Or remove ?
iseries.applyOptions({
visible: active,
})
}),
);
iseries.setSeriesOrder(order);
@@ -377,7 +378,7 @@ function createChartElement({
index,
index === /** @satisfies {Height} */ (5)
? "timestamp-fixed"
: "timestamp"
: "timestamp",
);
timeResource.fetch();
@@ -400,13 +401,17 @@ function createChartElement({
({ _indexes, values }) => {
if (!_indexes?.length || !values?.length) return;
const consoleTimeLabel = `${vecId}-time`;
console.time(consoleTimeLabel);
const indexes = /** @type {number[]} */ (_indexes);
let length = Math.min(indexes.length, values.length);
// TODO: Don't create new Array if data already present, update instead
/** @type {LineData[] | CandlestickData[]} */
const data = new Array(length);
const data = /** @type {LineData[] | CandlestickData[]} */ (
Array.from({ length })
);
let prevTime = null;
let timeOffset = 0;
@@ -489,54 +494,81 @@ function createChartElement({
while (i < data.length) {
const dataI = data[i];
const iTime = dataI.time;
const seriesDataJ = /** @type {typeof dataI} */ (
seriesData[j]
);
const jTime = seriesDataJ.time;
if (iTime === jTime) {
const historicalUpdate = iTime < last.time;
if ("value" in dataI) {
if (
// @ts-ignore
dataI.value !== seriesDataJ.value &&
// @ts-ignore
(!isNaN(dataI.value) || !isNaN(seriesDataJ.value))
) {
// console.log(vecId);
iseries.update(dataI, historicalUpdate);
}
} else if (
// @ts-ignore
dataI.open !== seriesDataJ.open ||
// @ts-ignore
dataI.high !== seriesDataJ.high ||
// @ts-ignore
dataI.low !== seriesDataJ.low ||
// @ts-ignore
dataI.close !== seriesDataJ.close
) {
// console.log({
// vecId,
// dataI,
// i,
// data,
// j,
// seriesDataJ,
// seriesData,
// });
iseries.update(dataI, historicalUpdate);
}
i++;
j++;
} else if (iTime < jTime) {
iseries.update(dataI, true);
i++;
} else if (iTime > last.time) {
if (iTime > last.time) {
console.log(0, {
vecId,
dataI,
i,
data,
});
iseries.update(dataI);
i++;
} else if (iTime > jTime) {
j++;
} else {
const seriesDataJ = /** @type {typeof dataI} */ (
seriesData[j]
);
const jTime = seriesDataJ.time;
if (iTime === jTime) {
const historicalUpdate = iTime < last.time;
if ("value" in dataI) {
if (
// @ts-ignore
dataI.value !== seriesDataJ.value &&
// @ts-ignore
(!isNaN(dataI.value) || !isNaN(seriesDataJ.value))
) {
console.log(1, {
vecId,
dataI,
i,
data,
j,
seriesDataJ,
seriesData,
});
iseries.update(dataI, historicalUpdate);
}
} else if (
// @ts-ignore
dataI.open !== seriesDataJ.open ||
// @ts-ignore
dataI.high !== seriesDataJ.high ||
// @ts-ignore
dataI.low !== seriesDataJ.low ||
// @ts-ignore
dataI.close !== seriesDataJ.close
) {
console.log(2, {
vecId,
dataI,
i,
data,
j,
seriesDataJ,
seriesData,
});
iseries.update(dataI, historicalUpdate);
}
i++;
j++;
} else if (iTime < jTime) {
console.log(3, {
vecId,
dataI,
i,
data,
j,
seriesDataJ,
seriesData,
});
iseries.update(dataI, true);
i++;
} else if (iTime > jTime) {
j++;
} else {
throw Error("Unreachable");
}
}
}
}
@@ -546,7 +578,9 @@ function createChartElement({
index,
unit,
});
}
console.timeEnd(consoleTimeLabel);
},
);
} else {
activeResources.delete(valuesResource);
@@ -639,7 +673,7 @@ function createChartElement({
borderVisible: false,
visible: defaultActive !== false,
},
paneIndex
paneIndex,
)
);
@@ -695,7 +729,7 @@ function createChartElement({
color: color(),
...options,
},
paneIndex
paneIndex,
)
);
@@ -763,7 +797,7 @@ function createChartElement({
topFillColor2: "transparent",
lineVisible: true,
},
paneIndex
paneIndex,
)
);
@@ -926,7 +960,7 @@ function createLegend({ signals, utils }) {
} else {
spanColor.style.backgroundColor = tameColor(color);
}
}
},
);
});
@@ -1086,17 +1120,17 @@ function numberToShortUSFormat(value, digits) {
if (modulused === 0) {
return `${numberToUSFormat(
value / (1_000_000 * 1_000 ** letterIndex),
3
3,
)}${letter}`;
} else if (modulused === 1) {
return `${numberToUSFormat(
value / (1_000_000 * 1_000 ** letterIndex),
2
2,
)}${letter}`;
} else {
return `${numberToUSFormat(
value / (1_000_000 * 1_000 ** letterIndex),
1
1,
)}${letter}`;
}
}
@@ -1146,7 +1180,7 @@ function createOklchToRGBA() {
return rgb.map((c) =>
Math.abs(c) > 0.0031308
? (c < 0 ? -1 : 1) * (1.055 * Math.abs(c) ** (1 / 2.4) - 0.055)
: 12.92 * c
: 12.92 * c,
);
}
/**
@@ -1158,7 +1192,7 @@ function createOklchToRGBA() {
1, 0.3963377773761749, 0.2158037573099136, 1, -0.1055613458156586,
-0.0638541728258133, 1, -0.0894841775298119, -1.2914855480194092,
]),
lab
lab,
);
const LMS = /** @type {[number, number, number]} */ (
LMSg.map((val) => val ** 3)
@@ -1169,7 +1203,7 @@ function createOklchToRGBA() {
-0.0405757452148008, 1.112286803280317, -0.0717110580655164,
-0.0763729366746601, -0.4214933324022432, 1.5869240198367816,
]),
LMS
LMS,
);
}
/**
@@ -1182,7 +1216,7 @@ function createOklchToRGBA() {
-0.9692436362808796, 1.8759675015077202, 0.04155505740717559,
0.05563007969699366, -0.20397695888897652, 1.0569715142428786,
],
xyz
xyz,
);
}
@@ -1205,8 +1239,8 @@ function createOklchToRGBA() {
});
const rgb = srgbLinear2rgb(
xyz2rgbLinear(
oklab2xyz(oklch2oklab(/** @type {[number, number, number]} */ (lch)))
)
oklab2xyz(oklch2oklab(/** @type {[number, number, number]} */ (lch))),
),
).map((v) => {
return Math.max(Math.min(Math.round(v * 255), 255), 0);
});