velo-plot 2.0.0 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ChartCore-BhQ4j7f5.js → ChartCore-ivzLqxVb.js} +419 -393
- package/dist/ChartCore-ivzLqxVb.js.map +1 -0
- package/dist/{SciPlot-GJvw7GJo.js → SciPlot-CEU4ApgD.js} +2 -2
- package/dist/{SciPlot-GJvw7GJo.js.map → SciPlot-CEU4ApgD.js.map} +1 -1
- package/dist/{axisFormat-SPX-CD5s.js → axisFormat-CzumxpCL.js} +3 -3
- package/dist/axisFormat-CzumxpCL.js.map +1 -0
- package/dist/core/chart/ChartAxisManager.d.ts +2 -0
- package/dist/core/chart/ChartCore.d.ts +15 -0
- package/dist/core/chart/ChartPluginBridge.d.ts +1 -0
- package/dist/core/chart/ChartRenderLoop.d.ts +2 -0
- package/dist/core/chart/ChartStateManager.d.ts +2 -0
- package/dist/core/chart/types.d.ts +5 -0
- package/dist/core/sync/index.d.ts +0 -1
- package/dist/{createStackedChart-DJSmqerD.js → createStackedChart-DxNW0VkF.js} +178 -179
- package/dist/createStackedChart-DxNW0VkF.js.map +1 -0
- package/dist/{index-D7dTq6VB.js → index-BBpJwOct.js} +17 -19
- package/dist/index-BBpJwOct.js.map +1 -0
- package/dist/{index-CUGS98p4.js → index-CaXWSOTk.js} +3 -6
- package/dist/index-CaXWSOTk.js.map +1 -0
- package/dist/{index-CWipqOLP.js → index-qunX30Xu.js} +2 -2
- package/dist/{index-CWipqOLP.js.map → index-qunX30Xu.js.map} +1 -1
- package/dist/{index.core-fpZ1dYN0.js → index.core-COREBDNq.js} +25 -24
- package/dist/{index.core-fpZ1dYN0.js.map → index.core-COREBDNq.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{mockDatafeed-Cdg5hKEo.js → mockDatafeed-927foCM4.js} +2 -2
- package/dist/mockDatafeed-927foCM4.js.map +1 -0
- package/dist/plugins/analysis/contours.d.ts +31 -0
- package/dist/plugins/analysis.js +494 -407
- package/dist/plugins/analysis.js.map +1 -1
- package/dist/plugins/broken-axis.js +170 -181
- package/dist/plugins/broken-axis.js.map +1 -1
- package/dist/plugins/forecasting/algorithms.d.ts +7 -2
- package/dist/plugins/forecasting/types.d.ts +13 -3
- package/dist/plugins/forecasting.js +355 -175
- package/dist/plugins/forecasting.js.map +1 -1
- package/dist/plugins/latex/symbols.d.ts +50 -0
- package/dist/plugins/latex/types.d.ts +13 -1
- package/dist/plugins/latex.js +351 -331
- package/dist/plugins/latex.js.map +1 -1
- package/dist/plugins/ml-integration/native-algorithms.d.ts +24 -4
- package/dist/plugins/ml-integration/types.d.ts +19 -0
- package/dist/plugins/ml-integration.js +191 -140
- package/dist/plugins/ml-integration.js.map +1 -1
- package/dist/plugins/pattern-recognition/types.d.ts +28 -1
- package/dist/plugins/pattern-recognition.js +416 -343
- package/dist/plugins/pattern-recognition.js.map +1 -1
- package/dist/plugins/snapshot.js +36 -36
- package/dist/plugins/snapshot.js.map +1 -1
- package/dist/plugins/sync.js +1 -1
- package/dist/plugins/tools.js +1 -1
- package/dist/plugins/virtualization.js +1 -1
- package/dist/react.js +2 -2
- package/dist/symbols-DT0eLlpW.js +568 -0
- package/dist/symbols-DT0eLlpW.js.map +1 -0
- package/dist/trading.js +5 -5
- package/dist/velo-plot.full.js +184 -182
- package/dist/velo-plot.js +3 -3
- package/dist/workers/indicatorsAsync.d.ts +24 -0
- package/package.json +1 -1
- package/dist/ChartCore-BhQ4j7f5.js.map +0 -1
- package/dist/axisFormat-SPX-CD5s.js.map +0 -1
- package/dist/createStackedChart-DJSmqerD.js.map +0 -1
- package/dist/index-CUGS98p4.js.map +0 -1
- package/dist/index-D7dTq6VB.js.map +0 -1
- package/dist/mockDatafeed-Cdg5hKEo.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SeriesData } from '../../types';
|
|
2
2
|
|
|
3
|
-
export type ForecastingMethod = 'sma' | 'ema' | 'wma' | 'linear' | 'expSmoothing' | 'holt' | 'holtWinters';
|
|
3
|
+
export type ForecastingMethod = 'sma' | 'ema' | 'wma' | 'linear' | 'expSmoothing' | 'holt' | 'holtWinters' | 'arima';
|
|
4
4
|
export interface ForecastingOptions {
|
|
5
5
|
/** Method to use for forecasting */
|
|
6
6
|
method: ForecastingMethod;
|
|
@@ -24,6 +24,12 @@ export interface ForecastingParams {
|
|
|
24
24
|
period?: number;
|
|
25
25
|
/** Polynomial order for trend fitting (default: 1) */
|
|
26
26
|
polynomialOrder?: number;
|
|
27
|
+
/** ARIMA autoregressive order (p, default: 1) */
|
|
28
|
+
p?: number;
|
|
29
|
+
/** ARIMA differencing order (d, default: 1) */
|
|
30
|
+
d?: number;
|
|
31
|
+
/** ARIMA moving-average order (q, default: 0) */
|
|
32
|
+
q?: number;
|
|
27
33
|
}
|
|
28
34
|
export interface ForecastingResult {
|
|
29
35
|
/** Forecasted points (X values) */
|
|
@@ -39,9 +45,12 @@ export interface ForecastingResult {
|
|
|
39
45
|
/** Metadata and fit statistics */
|
|
40
46
|
metadata: {
|
|
41
47
|
mse?: number;
|
|
48
|
+
rmse?: number;
|
|
42
49
|
mae?: number;
|
|
43
50
|
r2?: number;
|
|
44
51
|
aic?: number;
|
|
52
|
+
/** Confidence level used to build the prediction band (e.g. 0.95) */
|
|
53
|
+
confidence?: number;
|
|
45
54
|
};
|
|
46
55
|
}
|
|
47
56
|
export interface ForecastingVisualizationConfig {
|
|
@@ -69,9 +78,10 @@ export interface PluginForecastingConfig {
|
|
|
69
78
|
}
|
|
70
79
|
export interface ForecastingAPI {
|
|
71
80
|
/**
|
|
72
|
-
* Forecast future values for a given dataset
|
|
81
|
+
* Forecast future values for a given dataset, or for a series by id when a
|
|
82
|
+
* string is passed (e.g. `forecast('s1', { method: 'arima', horizon: 50 })`).
|
|
73
83
|
*/
|
|
74
|
-
forecast(data: SeriesData | number[] | Float32Array, options: ForecastingOptions): ForecastingResult;
|
|
84
|
+
forecast(data: SeriesData | number[] | Float32Array | string, options: ForecastingOptions): ForecastingResult;
|
|
75
85
|
/**
|
|
76
86
|
* Forecast future values for a series by ID
|
|
77
87
|
*/
|
|
@@ -1,236 +1,416 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
function E(l) {
|
|
2
|
+
return Array.from(l);
|
|
3
|
+
}
|
|
4
|
+
function D(l) {
|
|
5
|
+
const a = [
|
|
6
|
+
[0.5, 0.674],
|
|
7
|
+
[0.68, 0.994],
|
|
8
|
+
[0.8, 1.282],
|
|
9
|
+
[0.9, 1.645],
|
|
10
|
+
[0.95, 1.96],
|
|
11
|
+
[0.975, 2.241],
|
|
12
|
+
[0.99, 2.576],
|
|
13
|
+
[0.995, 2.807]
|
|
14
|
+
];
|
|
15
|
+
let o = a[0], e = 1 / 0;
|
|
16
|
+
for (const c of a) {
|
|
17
|
+
const t = Math.abs(c[0] - l);
|
|
18
|
+
t < e && (e = t, o = c);
|
|
19
|
+
}
|
|
20
|
+
return o[1];
|
|
21
|
+
}
|
|
22
|
+
function C(l, a, o, e, c = {}, t = 0.95) {
|
|
23
|
+
const r = l.length;
|
|
24
|
+
if (r === 0) throw new Error("Dataset is empty");
|
|
25
|
+
const s = E(a), n = E(l), i = r > 1 ? (n[r - 1] - n[0]) / (r - 1) : 1, m = n[r - 1];
|
|
26
|
+
let f;
|
|
27
|
+
switch (o) {
|
|
7
28
|
case "sma":
|
|
8
|
-
|
|
29
|
+
f = X(s, e, c.windowSize || 10);
|
|
9
30
|
break;
|
|
10
31
|
case "ema":
|
|
11
|
-
|
|
32
|
+
f = R(s, e, c.alpha ?? 0.3);
|
|
12
33
|
break;
|
|
13
34
|
case "linear":
|
|
14
|
-
|
|
35
|
+
f = j(n, s, e);
|
|
15
36
|
break;
|
|
16
37
|
case "expSmoothing":
|
|
17
|
-
|
|
38
|
+
f = B(s, e, c.alpha ?? 0.3);
|
|
18
39
|
break;
|
|
19
40
|
case "holt":
|
|
20
|
-
|
|
41
|
+
f = F(s, e, c.alpha ?? 0.3, c.beta ?? 0.1);
|
|
21
42
|
break;
|
|
22
43
|
case "wma":
|
|
23
|
-
|
|
44
|
+
f = W(s, e, c.windowSize || 10);
|
|
24
45
|
break;
|
|
25
46
|
case "holtWinters":
|
|
26
|
-
|
|
47
|
+
f = Y(
|
|
48
|
+
s,
|
|
49
|
+
e,
|
|
50
|
+
c.period || 12,
|
|
51
|
+
c.alpha ?? 0.3,
|
|
52
|
+
c.beta ?? 0.1,
|
|
53
|
+
c.gamma ?? 0.1
|
|
54
|
+
);
|
|
55
|
+
break;
|
|
56
|
+
case "arima":
|
|
57
|
+
f = H(
|
|
27
58
|
s,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
l.gamma || 0.1
|
|
59
|
+
e,
|
|
60
|
+
c.p ?? 1,
|
|
61
|
+
c.d ?? 1,
|
|
62
|
+
c.q ?? 0
|
|
33
63
|
);
|
|
34
64
|
break;
|
|
35
65
|
default:
|
|
36
|
-
throw new Error(`Method ${
|
|
66
|
+
throw new Error(`Method ${o} not implemented yet`);
|
|
37
67
|
}
|
|
38
|
-
const
|
|
39
|
-
for (let
|
|
40
|
-
|
|
68
|
+
const w = new Array(e);
|
|
69
|
+
for (let S = 0; S < e; S++)
|
|
70
|
+
w[S] = m + (S + 1) * i;
|
|
71
|
+
const u = J(s, f.fitted), y = D(t), h = u.rmse, { lower: v, upper: x } = I(
|
|
72
|
+
f.yValues,
|
|
73
|
+
h,
|
|
74
|
+
y,
|
|
75
|
+
f.accumulates
|
|
76
|
+
);
|
|
41
77
|
return {
|
|
42
|
-
xValues:
|
|
43
|
-
yValues:
|
|
44
|
-
lowerBound:
|
|
45
|
-
upperBound:
|
|
46
|
-
method:
|
|
47
|
-
metadata:
|
|
48
|
-
// Simplified for now
|
|
78
|
+
xValues: w,
|
|
79
|
+
yValues: f.yValues,
|
|
80
|
+
lowerBound: v,
|
|
81
|
+
upperBound: x,
|
|
82
|
+
method: o,
|
|
83
|
+
metadata: { ...u, confidence: t }
|
|
49
84
|
};
|
|
50
85
|
}
|
|
51
|
-
function
|
|
52
|
-
const
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
const a = t / c;
|
|
59
|
-
return { yValues: new Array(s).fill(a) };
|
|
60
|
-
}
|
|
61
|
-
function L(n, s, r) {
|
|
62
|
-
const o = n.length, l = Math.min(r, o);
|
|
63
|
-
let t = 0;
|
|
64
|
-
for (let a = o - l; a < o; a++)
|
|
65
|
-
t += n[a];
|
|
66
|
-
const c = t / l;
|
|
67
|
-
return {
|
|
68
|
-
yValues: new Array(s).fill(c)
|
|
69
|
-
};
|
|
86
|
+
function I(l, a, o, e) {
|
|
87
|
+
const c = new Array(l.length), t = new Array(l.length);
|
|
88
|
+
for (let r = 0; r < l.length; r++) {
|
|
89
|
+
const s = e ? Math.sqrt(r + 1) : 1, n = o * a * s;
|
|
90
|
+
c[r] = l[r] - n, t[r] = l[r] + n;
|
|
91
|
+
}
|
|
92
|
+
return { lower: c, upper: t };
|
|
70
93
|
}
|
|
71
|
-
function W(
|
|
72
|
-
const o = n
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
94
|
+
function W(l, a, o) {
|
|
95
|
+
const e = l.length, c = Math.min(o, e), t = (n) => {
|
|
96
|
+
const i = Math.min(c, n);
|
|
97
|
+
let m = 0, f = 0;
|
|
98
|
+
for (let w = 0; w < i; w++) {
|
|
99
|
+
const u = w + 1;
|
|
100
|
+
m += l[n - i + w] * u, f += u;
|
|
101
|
+
}
|
|
102
|
+
return m / f;
|
|
103
|
+
}, r = new Array(e).fill(null);
|
|
104
|
+
for (let n = 1; n < e; n++) r[n] = t(n);
|
|
105
|
+
const s = t(e);
|
|
106
|
+
return { yValues: new Array(a).fill(s), fitted: r, accumulates: !1 };
|
|
79
107
|
}
|
|
80
|
-
function
|
|
81
|
-
const o = n
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
for (let
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
function X(l, a, o) {
|
|
109
|
+
const e = l.length, c = Math.min(o, e), t = (n) => {
|
|
110
|
+
const i = Math.min(c, n);
|
|
111
|
+
let m = 0;
|
|
112
|
+
for (let f = n - i; f < n; f++) m += l[f];
|
|
113
|
+
return m / i;
|
|
114
|
+
}, r = new Array(e).fill(null);
|
|
115
|
+
for (let n = 1; n < e; n++) r[n] = t(n);
|
|
116
|
+
const s = t(e);
|
|
117
|
+
return { yValues: new Array(a).fill(s), fitted: r, accumulates: !1 };
|
|
118
|
+
}
|
|
119
|
+
function R(l, a, o) {
|
|
120
|
+
const e = l.length;
|
|
121
|
+
let c = l[0];
|
|
122
|
+
const t = new Array(e).fill(null);
|
|
123
|
+
for (let r = 1; r < e; r++)
|
|
124
|
+
t[r] = c, c = o * l[r] + (1 - o) * c;
|
|
125
|
+
return { yValues: new Array(a).fill(c), fitted: t, accumulates: !1 };
|
|
126
|
+
}
|
|
127
|
+
function j(l, a, o) {
|
|
128
|
+
const e = l.length;
|
|
129
|
+
let c = 0, t = 0, r = 0, s = 0;
|
|
130
|
+
for (let h = 0; h < e; h++)
|
|
131
|
+
c += l[h], t += a[h], r += l[h] * a[h], s += l[h] * l[h];
|
|
132
|
+
const n = e * s - c * c, i = n !== 0 ? (e * r - c * t) / n : 0, m = (t - i * c) / e, f = new Array(e);
|
|
133
|
+
for (let h = 0; h < e; h++) f[h] = i * l[h] + m;
|
|
134
|
+
const w = l[e - 1], u = e > 1 ? (l[e - 1] - l[0]) / (e - 1) : 1, y = new Array(o);
|
|
135
|
+
for (let h = 0; h < o; h++) {
|
|
136
|
+
const v = w + (h + 1) * u;
|
|
137
|
+
y[h] = i * v + m;
|
|
138
|
+
}
|
|
139
|
+
return { yValues: y, fitted: f, accumulates: !0 };
|
|
140
|
+
}
|
|
141
|
+
function B(l, a, o) {
|
|
142
|
+
const e = l.length;
|
|
143
|
+
let c = l[0];
|
|
144
|
+
const t = new Array(e).fill(null);
|
|
145
|
+
for (let r = 1; r < e; r++)
|
|
146
|
+
t[r] = c, c = o * l[r] + (1 - o) * c;
|
|
147
|
+
return { yValues: new Array(a).fill(c), fitted: t, accumulates: !1 };
|
|
148
|
+
}
|
|
149
|
+
function F(l, a, o, e) {
|
|
150
|
+
const c = l.length;
|
|
151
|
+
if (c < 2)
|
|
152
|
+
return { yValues: new Array(a).fill(l[0] || 0), fitted: [], accumulates: !0 };
|
|
153
|
+
let t = l[0], r = l[1] - l[0];
|
|
154
|
+
const s = new Array(c).fill(null);
|
|
155
|
+
for (let i = 1; i < c; i++) {
|
|
156
|
+
s[i] = t + r;
|
|
157
|
+
const m = t;
|
|
158
|
+
t = o * l[i] + (1 - o) * (t + r), r = e * (t - m) + (1 - e) * r;
|
|
159
|
+
}
|
|
160
|
+
const n = new Array(a);
|
|
161
|
+
for (let i = 0; i < a; i++) n[i] = t + (i + 1) * r;
|
|
162
|
+
return { yValues: n, fitted: s, accumulates: !0 };
|
|
163
|
+
}
|
|
164
|
+
function Y(l, a, o, e, c, t) {
|
|
165
|
+
const r = l.length;
|
|
166
|
+
if (r < o * 2)
|
|
167
|
+
return F(l, a, e, c);
|
|
168
|
+
const s = new Array(o), n = new Array(Math.floor(r / o));
|
|
169
|
+
for (let u = 0; u < n.length; u++) {
|
|
170
|
+
let y = 0;
|
|
171
|
+
for (let h = 0; h < o; h++) y += l[u * o + h];
|
|
172
|
+
n[u] = y / o;
|
|
173
|
+
}
|
|
174
|
+
for (let u = 0; u < o; u++) {
|
|
175
|
+
let y = 0;
|
|
176
|
+
for (let h = 0; h < n.length; h++)
|
|
177
|
+
y += l[h * o + u] - n[h];
|
|
178
|
+
s[u] = y / n.length;
|
|
179
|
+
}
|
|
180
|
+
let i = n[0], m = (n[n.length - 1] - n[0]) / ((n.length - 1) * o);
|
|
181
|
+
const f = new Array(r).fill(null);
|
|
182
|
+
for (let u = 0; u < r; u++) {
|
|
183
|
+
const y = s[u % o];
|
|
184
|
+
u > 0 && (f[u] = i + m + y);
|
|
185
|
+
const h = i, v = l[u];
|
|
186
|
+
i = e * (v - y) + (1 - e) * (i + m), m = c * (i - h) + (1 - c) * m, s[u % o] = t * (v - i) + (1 - t) * y;
|
|
187
|
+
}
|
|
188
|
+
const w = new Array(a);
|
|
189
|
+
for (let u = 0; u < a; u++) {
|
|
190
|
+
const y = u + 1;
|
|
191
|
+
w[u] = i + y * m + s[(r + u) % o];
|
|
192
|
+
}
|
|
193
|
+
return { yValues: w, fitted: f, accumulates: !0 };
|
|
194
|
+
}
|
|
195
|
+
function H(l, a, o, e, c) {
|
|
196
|
+
const t = l.length, r = Math.max(o, c);
|
|
197
|
+
if (t < e + r + 2 || t < 4)
|
|
198
|
+
return F(l, a, 0.3, 0.1);
|
|
199
|
+
const s = [l.slice()];
|
|
200
|
+
for (let g = 0; g < e; g++)
|
|
201
|
+
s.push($(s[g]));
|
|
202
|
+
const n = s[e], i = n.length, m = n.reduce((g, A) => g + A, 0) / i, f = n.map((g) => g - m);
|
|
203
|
+
let w = new Array(i).fill(0);
|
|
204
|
+
if (c > 0) {
|
|
205
|
+
const g = Math.min(Math.max(o + c + 2, 5), Math.floor(i / 2)), { residuals: A } = _(f, g);
|
|
206
|
+
w = A;
|
|
207
|
+
}
|
|
208
|
+
const u = Math.max(o, c), y = [], h = [];
|
|
209
|
+
for (let g = u; g < i; g++) {
|
|
210
|
+
const A = [];
|
|
211
|
+
for (let d = 1; d <= o; d++) A.push(f[g - d]);
|
|
212
|
+
for (let d = 1; d <= c; d++) A.push(w[g - d]);
|
|
213
|
+
y.push(A), h.push(f[g]);
|
|
214
|
+
}
|
|
215
|
+
let v = [];
|
|
216
|
+
if (y.length > 0 && y[0].length > 0 && (v = L(y, h)), v.length !== o + c || v.some((g) => !Number.isFinite(g)))
|
|
217
|
+
return F(l, a, 0.3, 0.1);
|
|
218
|
+
const x = v.slice(0, o), S = v.slice(o, o + c), k = new Array(t).fill(null), T = new Array(i).fill(0);
|
|
219
|
+
for (let g = u; g < i; g++) {
|
|
220
|
+
let A = 0;
|
|
221
|
+
for (let d = 1; d <= o; d++) A += x[d - 1] * f[g - d];
|
|
222
|
+
for (let d = 1; d <= c; d++) A += S[d - 1] * T[g - d];
|
|
223
|
+
T[g] = f[g] - A, k[g + (t - i)] = O(s, e, g, A + m);
|
|
224
|
+
}
|
|
225
|
+
const V = f.slice(), b = T.slice(), p = [];
|
|
226
|
+
for (let g = 0; g < a; g++) {
|
|
227
|
+
let A = 0;
|
|
228
|
+
for (let d = 1; d <= o; d++)
|
|
229
|
+
A += x[d - 1] * V[V.length - d];
|
|
230
|
+
for (let d = 1; d <= c; d++)
|
|
231
|
+
A += S[d - 1] * b[b.length - d];
|
|
232
|
+
V.push(A), b.push(0), p.push(A + m);
|
|
233
|
+
}
|
|
234
|
+
return { yValues: N(s, e, p), fitted: k, accumulates: !0 };
|
|
235
|
+
}
|
|
236
|
+
function $(l) {
|
|
237
|
+
const a = new Array(l.length - 1);
|
|
238
|
+
for (let o = 1; o < l.length; o++) a[o - 1] = l[o] - l[o - 1];
|
|
239
|
+
return a;
|
|
240
|
+
}
|
|
241
|
+
function N(l, a, o) {
|
|
242
|
+
let e = o.slice();
|
|
243
|
+
for (let c = a; c >= 1; c--) {
|
|
244
|
+
const t = l[c - 1];
|
|
245
|
+
let r = t[t.length - 1];
|
|
246
|
+
const s = new Array(e.length);
|
|
247
|
+
for (let n = 0; n < e.length; n++)
|
|
248
|
+
r += e[n], s[n] = r;
|
|
249
|
+
e = s;
|
|
250
|
+
}
|
|
251
|
+
return e;
|
|
100
252
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
for (let
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
253
|
+
function O(l, a, o, e) {
|
|
254
|
+
return a === 0 ? e : l[a - 1][o] + e;
|
|
255
|
+
}
|
|
256
|
+
function _(l, a) {
|
|
257
|
+
const o = l.length, e = [], c = [];
|
|
258
|
+
for (let s = a; s < o; s++) {
|
|
259
|
+
const n = [];
|
|
260
|
+
for (let i = 1; i <= a; i++) n.push(l[s - i]);
|
|
261
|
+
e.push(n), c.push(l[s]);
|
|
262
|
+
}
|
|
263
|
+
const t = e.length > 0 ? L(e, c) : new Array(a).fill(0), r = new Array(o).fill(0);
|
|
264
|
+
for (let s = a; s < o; s++) {
|
|
265
|
+
let n = 0;
|
|
266
|
+
for (let i = 1; i <= a; i++) n += (t[i - 1] || 0) * l[s - i];
|
|
267
|
+
r[s] = l[s] - n;
|
|
268
|
+
}
|
|
269
|
+
return { coeffs: t, residuals: r };
|
|
270
|
+
}
|
|
271
|
+
function L(l, a) {
|
|
272
|
+
const o = l.length, e = l[0].length, c = Array.from({ length: e }, () => new Array(e).fill(0)), t = new Array(e).fill(0);
|
|
273
|
+
for (let r = 0; r < o; r++)
|
|
274
|
+
for (let s = 0; s < e; s++) {
|
|
275
|
+
t[s] += l[r][s] * a[r];
|
|
276
|
+
for (let n = 0; n < e; n++)
|
|
277
|
+
c[s][n] += l[r][s] * l[r][n];
|
|
278
|
+
}
|
|
279
|
+
for (let r = 0; r < e; r++) c[r][r] += 1e-8;
|
|
280
|
+
return G(c, t);
|
|
281
|
+
}
|
|
282
|
+
function G(l, a) {
|
|
283
|
+
const o = a.length, e = l.map((t, r) => [...t, a[r]]);
|
|
284
|
+
for (let t = 0; t < o; t++) {
|
|
285
|
+
let r = t;
|
|
286
|
+
for (let s = t + 1; s < o; s++)
|
|
287
|
+
Math.abs(e[s][t]) > Math.abs(e[r][t]) && (r = s);
|
|
288
|
+
if (Math.abs(e[r][t]) < 1e-12) return [];
|
|
289
|
+
[e[t], e[r]] = [e[r], e[t]];
|
|
290
|
+
for (let s = 0; s < o; s++) {
|
|
291
|
+
if (s === t) continue;
|
|
292
|
+
const n = e[s][t] / e[t][t];
|
|
293
|
+
for (let i = t; i <= o; i++) e[s][i] -= n * e[t][i];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const c = new Array(o);
|
|
297
|
+
for (let t = 0; t < o; t++) c[t] = e[t][o] / e[t][t];
|
|
298
|
+
return c;
|
|
299
|
+
}
|
|
300
|
+
function J(l, a) {
|
|
301
|
+
if (!a || a.length === 0)
|
|
302
|
+
return { mse: 0, rmse: 0, mae: 0, r2: 0 };
|
|
303
|
+
let o = 0, e = 0, c = 0;
|
|
304
|
+
const t = [];
|
|
305
|
+
for (let w = 0; w < a.length && w < l.length; w++) {
|
|
306
|
+
const u = a[w];
|
|
307
|
+
if (u == null || !Number.isFinite(u)) continue;
|
|
308
|
+
const y = l[w] - u;
|
|
309
|
+
o += y * y, e += Math.abs(y), t.push(l[w]), c++;
|
|
310
|
+
}
|
|
311
|
+
if (c === 0) return { mse: 0, rmse: 0, mae: 0, r2: 0 };
|
|
312
|
+
const r = o / c, s = Math.sqrt(r), n = e / c, i = t.reduce((w, u) => w + u, 0) / t.length, m = t.reduce((w, u) => w + (u - i) * (u - i), 0), f = m > 0 ? 1 - o / m : 0;
|
|
144
313
|
return {
|
|
145
|
-
mse:
|
|
146
|
-
|
|
147
|
-
|
|
314
|
+
mse: P(r),
|
|
315
|
+
rmse: P(s),
|
|
316
|
+
mae: P(n),
|
|
317
|
+
r2: P(f)
|
|
148
318
|
};
|
|
149
319
|
}
|
|
150
|
-
|
|
320
|
+
function P(l) {
|
|
321
|
+
return Math.round(l * 1e6) / 1e6;
|
|
322
|
+
}
|
|
323
|
+
const K = {
|
|
151
324
|
name: "velo-plot-forecasting",
|
|
152
325
|
version: "1.0.0",
|
|
153
326
|
description: "Time series forecasting for velo-plot",
|
|
154
327
|
provides: ["analysis", "forecasting"],
|
|
155
328
|
tags: ["statistics", "forecasting", "analysis"]
|
|
156
329
|
};
|
|
157
|
-
function
|
|
158
|
-
let
|
|
159
|
-
const
|
|
160
|
-
forecast(t,
|
|
161
|
-
let
|
|
162
|
-
if (
|
|
163
|
-
|
|
330
|
+
function Q(l = {}) {
|
|
331
|
+
let a = null;
|
|
332
|
+
const o = /* @__PURE__ */ new Map(), e = {
|
|
333
|
+
forecast(t, r) {
|
|
334
|
+
let s, n;
|
|
335
|
+
if (typeof t == "string") {
|
|
336
|
+
if (!a) throw new Error("Plugin not initialized");
|
|
337
|
+
const i = a.data.getAllSeries().find((f) => f.getId() === t);
|
|
338
|
+
if (!i) throw new Error(`Series not found: ${t}`);
|
|
339
|
+
const m = i.getData();
|
|
340
|
+
s = m.x, n = m.y;
|
|
341
|
+
} else if (Array.isArray(t))
|
|
342
|
+
n = t, s = t.map((i, m) => m);
|
|
164
343
|
else if (t.x && t.y)
|
|
165
|
-
|
|
344
|
+
s = t.x, n = t.y;
|
|
166
345
|
else
|
|
167
346
|
throw new Error("Invalid data format for forecasting");
|
|
168
|
-
return
|
|
347
|
+
return C(s, n, r.method, r.horizon, r.params, r.confidence);
|
|
169
348
|
},
|
|
170
|
-
async forecastSeries(t,
|
|
171
|
-
if (!
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
174
|
-
const
|
|
175
|
-
return this.forecast(
|
|
349
|
+
async forecastSeries(t, r) {
|
|
350
|
+
if (!a) throw new Error("Plugin not initialized");
|
|
351
|
+
const s = a.data.getAllSeries().find((i) => i.getId() === t);
|
|
352
|
+
if (!s) throw new Error(`Series not found: ${t}`);
|
|
353
|
+
const n = s.getData();
|
|
354
|
+
return this.forecast(n, r);
|
|
176
355
|
},
|
|
177
|
-
visualize(t,
|
|
178
|
-
const
|
|
356
|
+
visualize(t, r = {}) {
|
|
357
|
+
const s = `forecast-${Math.random().toString(36).substr(2, 9)}`, n = {
|
|
179
358
|
showLine: !0,
|
|
180
359
|
showConfidenceInterval: !0,
|
|
181
|
-
...
|
|
182
|
-
...
|
|
360
|
+
...l.defaultVisualization,
|
|
361
|
+
...r
|
|
183
362
|
};
|
|
184
|
-
return
|
|
363
|
+
return o.set(s, { result: t, config: n }), a == null || a.requestRender(), s;
|
|
185
364
|
},
|
|
186
365
|
clear(t) {
|
|
187
|
-
t ?
|
|
366
|
+
t ? o.delete(t) : o.clear(), a == null || a.requestRender();
|
|
188
367
|
}
|
|
189
368
|
};
|
|
190
|
-
function
|
|
191
|
-
const { render:
|
|
192
|
-
|
|
193
|
-
var
|
|
194
|
-
const { result:
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
for (let
|
|
200
|
-
const
|
|
201
|
-
|
|
369
|
+
function c(t) {
|
|
370
|
+
const { render: r, coords: s } = t, { ctx2d: n } = r;
|
|
371
|
+
n && o.forEach((i) => {
|
|
372
|
+
var v, x, S, k, T, V;
|
|
373
|
+
const { result: m, config: f } = i, { xValues: w, yValues: u, lowerBound: y, upperBound: h } = m;
|
|
374
|
+
if (n.save(), f.showConfidenceInterval && y && h) {
|
|
375
|
+
n.beginPath();
|
|
376
|
+
const b = ((v = f.intervalStyle) == null ? void 0 : v.opacity) ?? 0.15, p = ((x = f.intervalStyle) == null ? void 0 : x.fillColor) || ((S = f.lineStyle) == null ? void 0 : S.color) || "#3b82f6";
|
|
377
|
+
n.fillStyle = p.startsWith("rgba") ? p : p + Math.floor(b * 255).toString(16).padStart(2, "0");
|
|
378
|
+
for (let M = 0; M < w.length; M++) {
|
|
379
|
+
const g = s.dataToPixelX(w[M]), A = s.dataToPixelY(h[M]);
|
|
380
|
+
M === 0 ? n.moveTo(g, A) : n.lineTo(g, A);
|
|
202
381
|
}
|
|
203
|
-
for (let
|
|
204
|
-
const
|
|
205
|
-
|
|
382
|
+
for (let M = w.length - 1; M >= 0; M--) {
|
|
383
|
+
const g = s.dataToPixelX(w[M]), A = s.dataToPixelY(y[M]);
|
|
384
|
+
n.lineTo(g, A);
|
|
206
385
|
}
|
|
207
|
-
|
|
386
|
+
n.closePath(), n.fill();
|
|
208
387
|
}
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
for (let
|
|
212
|
-
const
|
|
213
|
-
|
|
388
|
+
if (f.showLine) {
|
|
389
|
+
n.beginPath(), n.strokeStyle = ((k = f.lineStyle) == null ? void 0 : k.color) || "#3b82f6", n.lineWidth = ((T = f.lineStyle) == null ? void 0 : T.width) || 2, (V = f.lineStyle) != null && V.dash ? n.setLineDash(f.lineStyle.dash) : n.setLineDash([5, 5]);
|
|
390
|
+
for (let b = 0; b < w.length; b++) {
|
|
391
|
+
const p = s.dataToPixelX(w[b]), M = s.dataToPixelY(u[b]);
|
|
392
|
+
b === 0 ? n.moveTo(p, M) : n.lineTo(p, M);
|
|
214
393
|
}
|
|
215
|
-
|
|
394
|
+
n.stroke();
|
|
216
395
|
}
|
|
217
|
-
|
|
396
|
+
n.restore();
|
|
218
397
|
});
|
|
219
398
|
}
|
|
220
399
|
return {
|
|
221
|
-
manifest:
|
|
400
|
+
manifest: K,
|
|
222
401
|
onInit(t) {
|
|
223
|
-
|
|
402
|
+
a = t;
|
|
224
403
|
},
|
|
225
|
-
onRenderOverlay(t,
|
|
226
|
-
|
|
404
|
+
onRenderOverlay(t, r) {
|
|
405
|
+
c(t);
|
|
227
406
|
},
|
|
228
|
-
api:
|
|
407
|
+
api: e
|
|
229
408
|
};
|
|
230
409
|
}
|
|
231
410
|
export {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
411
|
+
Q as PluginForecasting,
|
|
412
|
+
C as calculateForecast,
|
|
413
|
+
G as gaussianSolve,
|
|
414
|
+
K as manifestForecasting
|
|
235
415
|
};
|
|
236
416
|
//# sourceMappingURL=forecasting.js.map
|