openalgo-script 0.7.0 → 0.7.2
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/CHANGELOG.md +55 -0
- package/README.md +12 -3
- package/dist/core/stdlib/volume/accumulation.d.ts +14 -0
- package/dist/core/stdlib/volume/accumulation.d.ts.map +1 -1
- package/dist/core/stdlib/volume/accumulation.js +32 -2
- package/dist/core/stdlib/volume/accumulation.js.map +1 -1
- package/dist/core/stdlib/volume/flow.d.ts.map +1 -1
- package/dist/core/stdlib/volume/flow.js +3 -1
- package/dist/core/stdlib/volume/flow.js.map +1 -1
- package/dist/core/stdlib/volume/weighted.d.ts +7 -0
- package/dist/core/stdlib/volume/weighted.d.ts.map +1 -1
- package/dist/core/stdlib/volume/weighted.js +15 -3
- package/dist/core/stdlib/volume/weighted.js.map +1 -1
- package/dist/core/version/version.generated.d.ts +1 -1
- package/dist/core/version/version.generated.js +1 -1
- package/package.json +1 -1
- package/src/core/stdlib/volume/accumulation.ts +37 -2
- package/src/core/stdlib/volume/flow.ts +3 -1
- package/src/core/stdlib/volume/weighted.ts +14 -3
- package/src/core/version/version.generated.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,61 @@ nothing, fails the build before it can become permanent.
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## 0.7.2
|
|
11
|
+
|
|
12
|
+
Running totals in both engines now survive one overflowing bar. `pvt` added its
|
|
13
|
+
per-bar term without checking it, so a price change, proportion or product that
|
|
14
|
+
overflowed stored an infinite total and every later reading was absent. `vwap`
|
|
15
|
+
and `vwapAnchor` did the same with an overflowing price times volume. Such a term
|
|
16
|
+
is now absent: that bar reads `none` and the total carries on from the bar
|
|
17
|
+
before it, as the specification's per-operation rule and its running-total rule
|
|
18
|
+
require together. Closes of 1, 1e308, -1e308, 2 and 3 on a volume of 1 now give
|
|
19
|
+
`pvt` readings of `none`, 1e308, `none`, 1e308 and 1e308, where 0.7.1 gave
|
|
20
|
+
`none` from the third bar on.
|
|
21
|
+
|
|
22
|
+
Two neighbouring readings change with it. `vwap` and `vwapAnchor` read `none`,
|
|
23
|
+
not an exact zero, while their volume total has overflowed, until the next anchor
|
|
24
|
+
or session starts it again. `ad`, `adOsc` and `cmf` treat a bar whose high to low
|
|
25
|
+
span overflows as absent instead of adding a zero term for it, so `ad` reads
|
|
26
|
+
`none` on that bar and `cmf` on the windows that hold it. A total that overflows
|
|
27
|
+
although its term was finite is still kept, and its readings stay `none`, as
|
|
28
|
+
before. Section 20.6 of the library specification now says both rules in so many
|
|
29
|
+
words.
|
|
30
|
+
|
|
31
|
+
Both engines were wrong in the same way, which is why exact agreement between
|
|
32
|
+
them never showed it. Independent expected results now cover every case above,
|
|
33
|
+
through compiled programs, forming-bar updates and restored checkpoints, and new
|
|
34
|
+
conformance cases pin the specified values. The strict numerical gates
|
|
35
|
+
compare 1,504,962 accepted calls with no differing bits or absent values, and
|
|
36
|
+
the library vectors for ordinary inputs are unchanged.
|
|
37
|
+
|
|
38
|
+
Separately, the TypeScript engine read `cmf` as `none` on any window whose volume sums
|
|
39
|
+
below zero; the Python engine divided, as the rule that a ratio is absent only
|
|
40
|
+
where its divisor is zero requires. Both now divide, and a fifth conformance case
|
|
41
|
+
pins it.
|
|
42
|
+
|
|
43
|
+
Upgrade both packages together. No source migration or compiled-format change
|
|
44
|
+
is required. Recompute stored `pvt`, `vwap`, `vwapAnchor`, `ad`, `adOsc` or `cmf`
|
|
45
|
+
results over data whose prices, volumes or their products come near the largest
|
|
46
|
+
finite number.
|
|
47
|
+
|
|
48
|
+
## 0.7.1
|
|
49
|
+
|
|
50
|
+
Python's ADX now normalizes a selected overflowing directional movement to
|
|
51
|
+
absence before smoothing it. An overflow before seeding no longer prevents a
|
|
52
|
+
later valid seed, and an overflow after seeding no longer poisons the recurrence.
|
|
53
|
+
The raw direction comparison and tie rules are unchanged. This corrects a
|
|
54
|
+
Python-only discrepancy found after 0.7.0 was published; ordinary finite-input
|
|
55
|
+
vectors are unchanged.
|
|
56
|
+
|
|
57
|
+
Compiled histories, forming-bar replacements and independent expected results
|
|
58
|
+
cover both directions, missing inputs, competing movements and positive ties.
|
|
59
|
+
The expanded numerical gates compare 1,504,918 accepted calls with no differing
|
|
60
|
+
bits or absent values. These finite corpora do not exhaust every input history.
|
|
61
|
+
|
|
62
|
+
Upgrade both packages together. No source migration or compiled-format change
|
|
63
|
+
is required; recompute stored ADX results affected by overflowing movements.
|
|
64
|
+
|
|
10
65
|
## 0.7.0
|
|
11
66
|
|
|
12
67
|
Both engines now pass exact numerical comparisons for all 116 scalar and
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ execution; see [Phase 6](./ROADMAP.md#phase-6-the-second-engine-and-live-running
|
|
|
26
26
|
|
|
27
27
|
## Status
|
|
28
28
|
|
|
29
|
-
**`0.7.
|
|
29
|
+
**`0.7.2` runs studies, backtests strategies, draws a strategy on a chart,
|
|
30
30
|
imports scripts from another chart language, and ships the language
|
|
31
31
|
intelligence an editor needs.** The Python engine is on PyPI
|
|
32
32
|
as `openscript`, at the same version, and the two are released together.
|
|
@@ -45,7 +45,16 @@ examples on every run rather than asserting it in a page. Two records can be put
|
|
|
45
45
|
beside each other, and a pair over different bars is reported incomparable
|
|
46
46
|
instead of being subtracted into a table that reads like a result.
|
|
47
47
|
|
|
48
|
-
**New in `0.7.
|
|
48
|
+
**New in `0.7.2`:** in both engines, one bar whose term overflows no longer
|
|
49
|
+
ends `pvt`, `vwap` or `vwapAnchor` for good, and no longer counts as a false
|
|
50
|
+
zero in `ad`, `adOsc` or `cmf`. That bar reads `none` and later bars carry on.
|
|
51
|
+
Ordinary vectors and the compiled format are unchanged. Upgrade both packages
|
|
52
|
+
together.
|
|
53
|
+
|
|
54
|
+
`0.7.1` made Python's ADX recover from overflowing directional movements with
|
|
55
|
+
the same values as the JavaScript engine.
|
|
56
|
+
|
|
57
|
+
The `0.7.0` numerical work established exact comparisons across
|
|
49
58
|
all 116 scalar and stateful numerical signatures. Portable elementary kernels,
|
|
50
59
|
changing-window corrections and checkpoint tests remove confirmed numerical
|
|
51
60
|
deviations. Compiled cases also cover numeric arrays and conversions. Upgrade
|
|
@@ -107,7 +116,7 @@ first thing a stranger reads:
|
|
|
107
116
|
corroborating implementation, not a result. That is why no conformance badge
|
|
108
117
|
is shown here, though `npm run badge` will make one for an engine that passes.
|
|
109
118
|
|
|
110
|
-
The version is `0.7.
|
|
119
|
+
The version is `0.7.2` rather than `1.0` because of that list. The studies
|
|
111
120
|
surface is the part that is finished, and it is the part to build on.
|
|
112
121
|
|
|
113
122
|
`ROADMAP.md` says what each phase owes before it is allowed to finish. The
|
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
* A running total is the one thing a lookback cannot stand in for, so each of
|
|
11
11
|
* these carries its total in the state region rather than in a closure: that is
|
|
12
12
|
* what lets an engine roll one back with the rest of a moving bar's state.
|
|
13
|
+
*
|
|
14
|
+
* A bar's term is checked after every operation that forms it
|
|
15
|
+
* (`compiled-program.md` section 3.1), and a term that is not finite is an absent
|
|
16
|
+
* term: the bar is absent and the total is left where it was, so one overflowing
|
|
17
|
+
* bar costs its own reading and nothing after it. A total that overflows although
|
|
18
|
+
* its term was finite is kept as the arithmetic produced it, and every later
|
|
19
|
+
* reading is absent, which is what `stdlib.md` section 20.6 says of every running
|
|
20
|
+
* total there.
|
|
13
21
|
*/
|
|
14
22
|
import type { Bar, StateRecord, Tail, Value } from '../values/index.js';
|
|
15
23
|
/**
|
|
@@ -19,6 +27,12 @@ import type { Bar, StateRecord, Tail, Value } from '../values/index.js';
|
|
|
19
27
|
* A bar whose high and low are equal has no position inside it to report, and
|
|
20
28
|
* the settled treatment is that such a bar contributes nothing rather than
|
|
21
29
|
* ending the running total.
|
|
30
|
+
*
|
|
31
|
+
* A span that overflows is not that bar. It is absent (`compiled-program.md`
|
|
32
|
+
* section 3.1), and so is the term, because the one later step that could hide
|
|
33
|
+
* it is this division: a finite numerator over an infinite span is an exact
|
|
34
|
+
* zero, a term for a bar whose position was never computed. Every other step
|
|
35
|
+
* that overflows stays non-finite to the end and the last check catches it.
|
|
22
36
|
*/
|
|
23
37
|
export declare function moneyFlow(bar: Bar): Value;
|
|
24
38
|
/** `obv()`: the running total of volume signed by the close's direction, from bar 0, seeded 0. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accumulation.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/accumulation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"accumulation.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/accumulation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAIxE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,KAAK,CAOzC;AAED,kGAAkG;AAClG,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,KAAK,CAsBxE;AAED,yBAAyB;AACzB,wBAAgB,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAE1C;AAED,kCAAkC;AAClC,wBAAgB,GAAG,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,KAAK,EAAE,CAEjD;AAED,uFAAuF;AACvF,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,KAAK,CAMvE;AAED,wBAAwB;AACxB,wBAAgB,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAEzC;AAED,iCAAiC;AACjC,wBAAgB,EAAE,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,KAAK,EAAE,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,IAAI,EAAE,MAAM,GAAG,IAAI,GAClB,KAAK,CAMP;AAED,qCAAqC;AACrC,wBAAgB,SAAS,CAAC,IAAI,SAAI,EAAE,IAAI,SAAK,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAE/D;AAED,8CAA8C;AAC9C,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,IAAI,SAAI,EAAE,IAAI,SAAK,GAAG,KAAK,EAAE,CAExE;AAoBD;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,KAAK,CAiBxE;AAED,yBAAyB;AACzB,wBAAgB,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAE1C;AAED,kCAAkC;AAClC,wBAAgB,GAAG,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,KAAK,EAAE,CAEjD"}
|
|
@@ -7,13 +7,21 @@ import { emaStep } from '../averages/index.js';
|
|
|
7
7
|
* A bar whose high and low are equal has no position inside it to report, and
|
|
8
8
|
* the settled treatment is that such a bar contributes nothing rather than
|
|
9
9
|
* ending the running total.
|
|
10
|
+
*
|
|
11
|
+
* A span that overflows is not that bar. It is absent (`compiled-program.md`
|
|
12
|
+
* section 3.1), and so is the term, because the one later step that could hide
|
|
13
|
+
* it is this division: a finite numerator over an infinite span is an exact
|
|
14
|
+
* zero, a term for a bar whose position was never computed. Every other step
|
|
15
|
+
* that overflows stays non-finite to the end and the last check catches it.
|
|
10
16
|
*/
|
|
11
17
|
export function moneyFlow(bar) {
|
|
12
18
|
if (!isPresent(bar.high) || !isPresent(bar.low))
|
|
13
19
|
return NONE;
|
|
14
20
|
if (!isPresent(bar.close) || !isPresent(bar.volume))
|
|
15
21
|
return NONE;
|
|
16
|
-
const span = bar.high - bar.low;
|
|
22
|
+
const span = result(bar.high - bar.low);
|
|
23
|
+
if (!isPresent(span))
|
|
24
|
+
return NONE;
|
|
17
25
|
if (!(span > 0))
|
|
18
26
|
return 0;
|
|
19
27
|
return result((((bar.close - bar.low) - (bar.high - bar.close)) / span) * bar.volume);
|
|
@@ -89,6 +97,25 @@ export function adOscTail(fast = 3, slow = 10) {
|
|
|
89
97
|
export function adOsc(bars, fast = 3, slow = 10) {
|
|
90
98
|
return fold(adOscTail(fast, slow), bars);
|
|
91
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* The per-bar term `pvt` adds: the change, then the proportion, then the
|
|
102
|
+
* product with the volume, each checked as it is formed.
|
|
103
|
+
*
|
|
104
|
+
* A change can overflow although the true proportion is finite: a close of
|
|
105
|
+
* -1e308 after one of 1e308 is a proportion of -2. Section 3.1 makes that change
|
|
106
|
+
* absent, and so the term. Each step is checked where it rounds because that is
|
|
107
|
+
* how the rule is stated, not because a later step could turn an infinity back
|
|
108
|
+
* into a number here: none of these three can.
|
|
109
|
+
*/
|
|
110
|
+
function trendTerm(close, before, volume) {
|
|
111
|
+
const change = result(close - before);
|
|
112
|
+
if (!isPresent(change))
|
|
113
|
+
return NONE;
|
|
114
|
+
const proportion = result(change / before);
|
|
115
|
+
if (!isPresent(proportion))
|
|
116
|
+
return NONE;
|
|
117
|
+
return result(proportion * volume);
|
|
118
|
+
}
|
|
92
119
|
/**
|
|
93
120
|
* `pvt()`: the running total of volume weighted by percentage change, from bar
|
|
94
121
|
* 1, seeded 0.
|
|
@@ -112,7 +139,10 @@ export function pvtStep(state, key, bar) {
|
|
|
112
139
|
return NONE;
|
|
113
140
|
if (!isPresent(bar.close) || !isPresent(bar.volume))
|
|
114
141
|
return NONE;
|
|
115
|
-
const
|
|
142
|
+
const term = trendTerm(bar.close, before, bar.volume);
|
|
143
|
+
if (!isPresent(term))
|
|
144
|
+
return NONE;
|
|
145
|
+
const total = slot(state, totalKey, 0) + term;
|
|
116
146
|
state[totalKey] = total;
|
|
117
147
|
return result(total);
|
|
118
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accumulation.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/accumulation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"accumulation.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/accumulation.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,GAAQ;IAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACjE,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,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AAC;AAED,kCAAkC;AAClC,MAAM,UAAU,GAAG,CAAC,IAAoB;IACtC,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/flow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAOxE,kGAAkG;AAClG,wBAAgB,OAAO,CACrB,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,IAAI,GACjB,KAAK,
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/flow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAOxE,kGAAkG;AAClG,wBAAgB,OAAO,CACrB,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,IAAI,GACjB,KAAK,CAOP;AAED,4BAA4B;AAC5B,wBAAgB,OAAO,CAAC,GAAG,SAAK,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAElD;AAED,qCAAqC;AACrC,wBAAgB,GAAG,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,SAAK,GAAG,KAAK,EAAE,CAE3D;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,IAAI,GACjB,K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,CAAC,CAE7D;AAED,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,SAAK,GAAG,KAAK,EAAE,CAEtE"}
|
|
@@ -6,7 +6,9 @@ import { moneyFlow } from './accumulation.js';
|
|
|
6
6
|
export function cmfStep(state, key, bar, len) {
|
|
7
7
|
const flow = sumStep(state, `${key}f`, moneyFlow(bar), len);
|
|
8
8
|
const traded = sumStep(state, `${key}v`, bar.volume, len);
|
|
9
|
-
|
|
9
|
+
// A ratio is absent where its divisor is zero, and only there: a window whose
|
|
10
|
+
// volume sums below zero divides like any other.
|
|
11
|
+
if (!isPresent(flow) || !isPresent(traded) || traded === 0)
|
|
10
12
|
return NONE;
|
|
11
13
|
return result(flow / traded);
|
|
12
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/flow.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,kGAAkG;AAClG,MAAM,UAAU,OAAO,CACrB,KAAkB,EAClB,GAAW,EACX,GAAQ,EACR,GAAkB;IAElB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,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AE,GAAQ,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,4CAA4C;AAC5C,MAAM,UAAU,UAAU,CAAC,IAAoB,EAAE,GAAG,GAAG,EAAE;IACvD,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,kBAAkB,CAChC,KAAkB,EAClB,GAAW,EACX,MAAa,EACb,GAAkB;IAElB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACpD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtE,OAAO,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,uCAAuC;AACvC,MAAM,UAAU,kBAAkB,CAAC,GAAG,GAAG,EAAE;IACzC,OAAO,MAAM,CAAC,CAAC,KAAK,EAAE,GAAQ,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;AACrF,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,cAAc,CAAC,IAAoB,EAAE,GAAG,GAAG,EAAE;IAC3D,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -27,6 +27,13 @@ export interface Anchored {
|
|
|
27
27
|
* The bar the condition holds on is the first bar of the new average, not the
|
|
28
28
|
* last bar of the old one. Absent before the condition has ever been true,
|
|
29
29
|
* because there is no anchor to measure from and zero would read as a price.
|
|
30
|
+
*
|
|
31
|
+
* A price times volume that overflows is an absent term (`compiled-program.md`
|
|
32
|
+
* section 3.1): the bar is absent and neither total moves, so the bar costs its
|
|
33
|
+
* own reading and nothing after it. A total that overflows is kept as the
|
|
34
|
+
* arithmetic produced it and is absent, so the average divided by it is absent
|
|
35
|
+
* until the next anchor rather than the exact zero a finite flow over an
|
|
36
|
+
* infinite volume would give.
|
|
30
37
|
*/
|
|
31
38
|
export declare function vwapAnchorStep(state: StateRecord, key: string, input: Anchored): Value;
|
|
32
39
|
/** `vwapAnchor(src, resetWhen)` as a tail. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weighted.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/weighted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3E,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED
|
|
1
|
+
{"version":3,"file":"weighted.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/weighted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3E,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,KAAK,CAqBtF;AAED,8CAA8C;AAC9C,wBAAgB,cAAc,IAAI,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAEtD;AAED,sDAAsD;AACtD,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,OAAO,EAAE,GAC5B,KAAK,EAAE,CAST;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAEhD;AAED,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,KAAK,CAEhF;AAED,qCAAqC;AACrC,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,SAAS,OAAO,EAAE,GAC/B,KAAK,EAAE,CAET"}
|
|
@@ -5,6 +5,13 @@ import { NONE, flag, fold, isPresent, result, slot, tailOf } from '../values/ind
|
|
|
5
5
|
* The bar the condition holds on is the first bar of the new average, not the
|
|
6
6
|
* last bar of the old one. Absent before the condition has ever been true,
|
|
7
7
|
* because there is no anchor to measure from and zero would read as a price.
|
|
8
|
+
*
|
|
9
|
+
* A price times volume that overflows is an absent term (`compiled-program.md`
|
|
10
|
+
* section 3.1): the bar is absent and neither total moves, so the bar costs its
|
|
11
|
+
* own reading and nothing after it. A total that overflows is kept as the
|
|
12
|
+
* arithmetic produced it and is absent, so the average divided by it is absent
|
|
13
|
+
* until the next anchor rather than the exact zero a finite flow over an
|
|
14
|
+
* infinite volume would give.
|
|
8
15
|
*/
|
|
9
16
|
export function vwapAnchorStep(state, key, input) {
|
|
10
17
|
const flowKey = `${key}f`;
|
|
@@ -19,13 +26,18 @@ export function vwapAnchorStep(state, key, input) {
|
|
|
19
26
|
return NONE;
|
|
20
27
|
if (!isPresent(input.src) || !isPresent(input.volume))
|
|
21
28
|
return NONE;
|
|
22
|
-
const
|
|
29
|
+
const term = result(input.src * input.volume);
|
|
30
|
+
if (!isPresent(term))
|
|
31
|
+
return NONE;
|
|
32
|
+
const flow = slot(state, flowKey, 0) + term;
|
|
23
33
|
const traded = slot(state, tradedKey, 0) + input.volume;
|
|
24
34
|
state[flowKey] = flow;
|
|
25
35
|
state[tradedKey] = traded;
|
|
26
|
-
|
|
36
|
+
const numerator = result(flow);
|
|
37
|
+
const divisor = result(traded);
|
|
38
|
+
if (!isPresent(numerator) || !isPresent(divisor) || divisor === 0)
|
|
27
39
|
return NONE;
|
|
28
|
-
return result(
|
|
40
|
+
return result(numerator / divisor);
|
|
29
41
|
}
|
|
30
42
|
/** `vwapAnchor(src, resetWhen)` as a tail. */
|
|
31
43
|
export function vwapAnchorTail() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weighted.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/weighted.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AASvF
|
|
1
|
+
{"version":3,"file":"weighted.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/weighted.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AASvF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,KAAkB,EAAE,GAAW,EAAE,KAAe;IAC7E,MAAM,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC;IAC1B,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,CAAC;IAC5B,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,CA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KAAK,EAAE,KAAe,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,UAAU,CACxB,GAAW,EACX,MAAc,EACd,SAA6B;IAE7B,OAAO,IAAI,CACT,cAAc,EAAE,EAChB,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACzB,GAAG,EAAE,KAAK;QACV,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI;QAC7B,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI;KACjC,CAAC,CAAC,CACJ,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,cAAc,EAAE,CAAC;AAC1B,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,QAAQ,CAAC,KAAkB,EAAE,GAAW,EAAE,KAAe;IACvE,OAAO,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAC3C,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,IAAI,CAClB,GAAW,EACX,MAAc,EACd,YAAgC;IAEhC,OAAO,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// VERSION comes from package.json and COMPILED_FORMAT_VERSION from
|
|
4
4
|
// spec/compiled-program.md, so neither can drift from the thing it names.
|
|
5
5
|
/** This build's package version. The release refuses to publish unless the tag, the manifest and this agree. */
|
|
6
|
-
export const VERSION = "0.7.
|
|
6
|
+
export const VERSION = "0.7.2";
|
|
7
7
|
/**
|
|
8
8
|
* The compiled program format this compiler emits.
|
|
9
9
|
*
|
package/package.json
CHANGED
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
* A running total is the one thing a lookback cannot stand in for, so each of
|
|
11
11
|
* these carries its total in the state region rather than in a closure: that is
|
|
12
12
|
* what lets an engine roll one back with the rest of a moving bar's state.
|
|
13
|
+
*
|
|
14
|
+
* A bar's term is checked after every operation that forms it
|
|
15
|
+
* (`compiled-program.md` section 3.1), and a term that is not finite is an absent
|
|
16
|
+
* term: the bar is absent and the total is left where it was, so one overflowing
|
|
17
|
+
* bar costs its own reading and nothing after it. A total that overflows although
|
|
18
|
+
* its term was finite is kept as the arithmetic produced it, and every later
|
|
19
|
+
* reading is absent, which is what `stdlib.md` section 20.6 says of every running
|
|
20
|
+
* total there.
|
|
13
21
|
*/
|
|
14
22
|
import type { Bar, StateRecord, Tail, Value } from '../values/index.js';
|
|
15
23
|
import { NONE, fold, held, isPresent, result, slot, tailOf } from '../values/index.js';
|
|
@@ -22,11 +30,18 @@ import { emaStep } from '../averages/index.js';
|
|
|
22
30
|
* A bar whose high and low are equal has no position inside it to report, and
|
|
23
31
|
* the settled treatment is that such a bar contributes nothing rather than
|
|
24
32
|
* ending the running total.
|
|
33
|
+
*
|
|
34
|
+
* A span that overflows is not that bar. It is absent (`compiled-program.md`
|
|
35
|
+
* section 3.1), and so is the term, because the one later step that could hide
|
|
36
|
+
* it is this division: a finite numerator over an infinite span is an exact
|
|
37
|
+
* zero, a term for a bar whose position was never computed. Every other step
|
|
38
|
+
* that overflows stays non-finite to the end and the last check catches it.
|
|
25
39
|
*/
|
|
26
40
|
export function moneyFlow(bar: Bar): Value {
|
|
27
41
|
if (!isPresent(bar.high) || !isPresent(bar.low)) return NONE;
|
|
28
42
|
if (!isPresent(bar.close) || !isPresent(bar.volume)) return NONE;
|
|
29
|
-
const span = bar.high - bar.low;
|
|
43
|
+
const span = result(bar.high - bar.low);
|
|
44
|
+
if (!isPresent(span)) return NONE;
|
|
30
45
|
if (!(span > 0)) return 0;
|
|
31
46
|
return result((((bar.close - bar.low) - (bar.high - bar.close)) / span) * bar.volume);
|
|
32
47
|
}
|
|
@@ -115,6 +130,24 @@ export function adOsc(bars: readonly Bar[], fast = 3, slow = 10): Value[] {
|
|
|
115
130
|
return fold(adOscTail(fast, slow), bars);
|
|
116
131
|
}
|
|
117
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The per-bar term `pvt` adds: the change, then the proportion, then the
|
|
135
|
+
* product with the volume, each checked as it is formed.
|
|
136
|
+
*
|
|
137
|
+
* A change can overflow although the true proportion is finite: a close of
|
|
138
|
+
* -1e308 after one of 1e308 is a proportion of -2. Section 3.1 makes that change
|
|
139
|
+
* absent, and so the term. Each step is checked where it rounds because that is
|
|
140
|
+
* how the rule is stated, not because a later step could turn an infinity back
|
|
141
|
+
* into a number here: none of these three can.
|
|
142
|
+
*/
|
|
143
|
+
function trendTerm(close: number, before: number, volume: number): Value {
|
|
144
|
+
const change = result(close - before);
|
|
145
|
+
if (!isPresent(change)) return NONE;
|
|
146
|
+
const proportion = result(change / before);
|
|
147
|
+
if (!isPresent(proportion)) return NONE;
|
|
148
|
+
return result(proportion * volume);
|
|
149
|
+
}
|
|
150
|
+
|
|
118
151
|
/**
|
|
119
152
|
* `pvt()`: the running total of volume weighted by percentage change, from bar
|
|
120
153
|
* 1, seeded 0.
|
|
@@ -136,7 +169,9 @@ export function pvtStep(state: StateRecord, key: string, bar: Bar): Value {
|
|
|
136
169
|
if (!started) return NONE;
|
|
137
170
|
if (!isPresent(before) || before === 0) return NONE;
|
|
138
171
|
if (!isPresent(bar.close) || !isPresent(bar.volume)) return NONE;
|
|
139
|
-
const
|
|
172
|
+
const term = trendTerm(bar.close, before, bar.volume);
|
|
173
|
+
if (!isPresent(term)) return NONE;
|
|
174
|
+
const total = slot(state, totalKey, 0) + term;
|
|
140
175
|
state[totalKey] = total;
|
|
141
176
|
return result(total);
|
|
142
177
|
}
|
|
@@ -21,7 +21,9 @@ export function cmfStep(
|
|
|
21
21
|
): Value {
|
|
22
22
|
const flow = sumStep(state, `${key}f`, moneyFlow(bar), len);
|
|
23
23
|
const traded = sumStep(state, `${key}v`, bar.volume, len);
|
|
24
|
-
|
|
24
|
+
// A ratio is absent where its divisor is zero, and only there: a window whose
|
|
25
|
+
// volume sums below zero divides like any other.
|
|
26
|
+
if (!isPresent(flow) || !isPresent(traded) || traded === 0) return NONE;
|
|
25
27
|
return result(flow / traded);
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -30,6 +30,13 @@ export interface Anchored {
|
|
|
30
30
|
* The bar the condition holds on is the first bar of the new average, not the
|
|
31
31
|
* last bar of the old one. Absent before the condition has ever been true,
|
|
32
32
|
* because there is no anchor to measure from and zero would read as a price.
|
|
33
|
+
*
|
|
34
|
+
* A price times volume that overflows is an absent term (`compiled-program.md`
|
|
35
|
+
* section 3.1): the bar is absent and neither total moves, so the bar costs its
|
|
36
|
+
* own reading and nothing after it. A total that overflows is kept as the
|
|
37
|
+
* arithmetic produced it and is absent, so the average divided by it is absent
|
|
38
|
+
* until the next anchor rather than the exact zero a finite flow over an
|
|
39
|
+
* infinite volume would give.
|
|
33
40
|
*/
|
|
34
41
|
export function vwapAnchorStep(state: StateRecord, key: string, input: Anchored): Value {
|
|
35
42
|
const flowKey = `${key}f`;
|
|
@@ -42,12 +49,16 @@ export function vwapAnchorStep(state: StateRecord, key: string, input: Anchored)
|
|
|
42
49
|
}
|
|
43
50
|
if (!flag(state, anchoredKey)) return NONE;
|
|
44
51
|
if (!isPresent(input.src) || !isPresent(input.volume)) return NONE;
|
|
45
|
-
const
|
|
52
|
+
const term = result(input.src * input.volume);
|
|
53
|
+
if (!isPresent(term)) return NONE;
|
|
54
|
+
const flow = slot(state, flowKey, 0) + term;
|
|
46
55
|
const traded = slot(state, tradedKey, 0) + input.volume;
|
|
47
56
|
state[flowKey] = flow;
|
|
48
57
|
state[tradedKey] = traded;
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
const numerator = result(flow);
|
|
59
|
+
const divisor = result(traded);
|
|
60
|
+
if (!isPresent(numerator) || !isPresent(divisor) || divisor === 0) return NONE;
|
|
61
|
+
return result(numerator / divisor);
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
/** `vwapAnchor(src, resetWhen)` as a tail. */
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// spec/compiled-program.md, so neither can drift from the thing it names.
|
|
5
5
|
|
|
6
6
|
/** This build's package version. The release refuses to publish unless the tag, the manifest and this agree. */
|
|
7
|
-
export const VERSION = "0.7.
|
|
7
|
+
export const VERSION = "0.7.2";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* The compiled program format this compiler emits.
|