openscript 0.7.0__py3-none-any.whl → 0.7.2__py3-none-any.whl

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.
@@ -52,13 +52,22 @@ def _anchored(state: Region, ctx, value: Value, anchor: Value) -> Value:
52
52
  return ABSENT
53
53
  if price is None or traded is None:
54
54
  return ABSENT
55
- flow = held.get("flow", 0.0) + price * traded
55
+ # An overflowing product is an absent term under compiled-program.md 3.1:
56
+ # the bar is absent and neither total moves.
57
+ term = result(price * traded)
58
+ if term is None:
59
+ return ABSENT
60
+ flow = held.get("flow", 0.0) + term
56
61
  volume = held.get("traded", 0.0) + traded
57
62
  held["flow"] = flow
58
63
  held["traded"] = volume
59
- if volume == 0:
64
+ # An overflowed total is kept and is absent, so the average divided by it is
65
+ # too, rather than the exact zero a finite flow over an infinity would give.
66
+ numerator = result(flow)
67
+ divisor = result(volume)
68
+ if numerator is None or divisor is None or divisor == 0:
60
69
  return ABSENT
61
- return result(flow / volume)
70
+ return result(numerator / divisor)
62
71
 
63
72
 
64
73
  def balance(state: Region, ctx) -> Value:
@@ -93,6 +102,11 @@ def position_flow(ctx) -> Value:
93
102
  The two bracketed differences are formed first and subtracted, then divided by
94
103
  the span, then multiplied by the volume. **A bar whose span is not above zero
95
104
  contributes an exact 0** rather than ending the total.
105
+
106
+ A span that overflows is absent under `compiled-program.md` 3.1, and the term
107
+ with it: dividing a finite numerator by the raw infinity would give an exact
108
+ zero for a bar whose position was never computed. Any other step that
109
+ overflows stays non-finite to the end, where ``result`` catches it.
96
110
  """
97
111
  high = number(ctx.bar("high"))
98
112
  low = number(ctx.bar("low"))
@@ -100,7 +114,9 @@ def position_flow(ctx) -> Value:
100
114
  traded = number(ctx.bar("volume"))
101
115
  if high is None or low is None or close is None or traded is None:
102
116
  return ABSENT
103
- span = high - low
117
+ span = result(high - low)
118
+ if span is None:
119
+ return ABSENT
104
120
  if span <= 0:
105
121
  return 0.0
106
122
  return result((((close - low) - (high - close)) / span) * traded)
@@ -149,7 +165,24 @@ def price_trend(state: Region, ctx) -> Value:
149
165
  before = back(contributed(state, "close", close, 2), 1)
150
166
  if close is None or traded is None or not isinstance(before, float) or before == 0:
151
167
  return ABSENT
152
- return running_total(state, "run", ((close - before) / before) * traded)
168
+ return running_total(state, "run", _trend_term(close, before, traded))
169
+
170
+
171
+ def _trend_term(close: float, before: float, traded: float) -> Value:
172
+ """The term ``pvt`` adds, checked after each operation as section 3.1 states.
173
+
174
+ A change that overflows is absent although the true proportion may be
175
+ finite, and an absent term leaves the running total where it was, so the
176
+ bar costs its own reading and nothing after it. Adding the unchecked
177
+ infinity instead would store it and end the reading for good.
178
+ """
179
+ change = result(close - before)
180
+ if change is None:
181
+ return ABSENT
182
+ proportion = result(change / before)
183
+ if proportion is None:
184
+ return ABSENT
185
+ return result(proportion * traded)
153
186
 
154
187
 
155
188
  def money_flow(state: Region, ctx, length: Optional[int]) -> Value:
@@ -179,8 +179,8 @@ def directional(state: Region, ctx, di_length: Optional[int], adx_length: Option
179
179
  if isinstance(before_high, float) and isinstance(before_low, float):
180
180
  up = high - before_high
181
181
  down = before_low - low
182
- up_move = up if up > down and up > 0 else 0.0
183
- down_move = down if down > up and down > 0 else 0.0
182
+ up_move = result(up) if up > down and up > 0 else 0.0
183
+ down_move = result(down) if down > up and down > 0 else 0.0
184
184
  smoothed_up = averages.smoothed(region(state, "up"), up_move, di_length)
185
185
  smoothed_down = averages.smoothed(region(state, "down"), down_move, di_length)
186
186
  smoothed_range = averages.smoothed(region(state, "range"), gap_range(ctx), di_length)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openscript
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: An open trading language: the engine that runs a compiled program.
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Homepage, https://github.com/marketcalls/openscript#readme
@@ -67,7 +67,7 @@ openscript/library/counting.py,sha256=SYvcC4v9aPnlzxJsBw2gQMXDzzrufur1RPwJuydSb6
67
67
  openscript/library/deviation.py,sha256=hbZwDW5fF-R_YaZSzw4ciqkO7vdIsIkZZ0455ylAO-M,6551
68
68
  openscript/library/elementary.py,sha256=LFiQ-X2Fbt7SSYCczMwwCQssJ41fno5BezfBZfE-iDo,4585
69
69
  openscript/library/extremes.py,sha256=nf84Lfwn5C1VVLwnLC2pw4x7ljUUyXabbfA5kW3xilo,5047
70
- openscript/library/flows.py,sha256=s61F6yj4_cnOqghKWLFPJsMwkm1b8REZBPHZ_dEM3t4,9408
70
+ openscript/library/flows.py,sha256=zsQe9Q8eY7ozYegdoO8xlMYNku8Pbl4M4VUT2VN9Sbg,10891
71
71
  openscript/library/gaussian.py,sha256=u9WNWwaqm3ykD-z7HdFdSDlKQxc-1sMmBbZmPP2_4Zg,1690
72
72
  openscript/library/history.py,sha256=teYf_2i0vD2bFvHsgxX7-tkZ2T5bfvSE-xGKNRzwF0g,2287
73
73
  openscript/library/hypotenuse.py,sha256=Yhmg80n7cY4c5BScgvUC9-mGdKzegSjXnFc7LNH_BZA,2257
@@ -83,7 +83,7 @@ openscript/library/stateless.py,sha256=tySstHpeiqk2td9kyLk2cFMYYH3b7_kh5JQ9GAVpw
83
83
  openscript/library/strength.py,sha256=vSn4efdwq9U9_6qbUQdbllTBwMEkHsE0DW0PCTVEBEI,7913
84
84
  openscript/library/strings.py,sha256=uK6hVJYqUwkkJ2xBj7Fav3l1OPQ5NRrq0c1Ajh03-44,7965
85
85
  openscript/library/transcendental.py,sha256=RkL7P-XPWVTkLtsdhHEiOa27a08xYUZhx196p4ocXGw,4606
86
- openscript/library/trend.py,sha256=Kq2kv4tTU3hP_osqGkRSbtvU4owqP93bIi56DUcrHmE,11560
86
+ openscript/library/trend.py,sha256=fLl5gkLbm7iLdoWhSxcw3WuVVavIBJhPjNAarTVNLsI,11576
87
87
  openscript/library/trigonometric.py,sha256=15_JoLg8tAtHTc4qtVh7rFDJrqap7BflDq3ce1VY8GI,6811
88
88
  openscript/library/values.py,sha256=tEsPh-QYGFW981yc6BEq0RScF7o3pMNlPyA0ueiWRhs,4107
89
89
  openscript/strategy/__init__.py,sha256=1aBMfQUSKh35WBvqrtQ1w_RW849R84Z2m5ODsZzOx7M,2976
@@ -106,7 +106,7 @@ openscript/surface/marks.py,sha256=nQE-gZmatiSvnKAMTV-2goGsaaJpwLZjgk5qJWnWOII,2
106
106
  openscript/surface/paints.py,sha256=Lfli13FqWVcdOxuuXeJtqRruRMM0FRnYIUfoRYHENaU,2815
107
107
  openscript/surface/plots.py,sha256=WIOEurGH9tJZFpaA3g0pfc3klOMxaGuFu2e6kQGwObk,2313
108
108
  openscript/surface/published.py,sha256=wOSuuvU1FyeTFt5EDW8P0CjV1evG1ChZ6M_frpqxNEk,5315
109
- openscript-0.7.0.dist-info/METADATA,sha256=654-TBa3MMB4-meJJHLrjK0-aMdz7eUHWdLD9EV8WMk,3465
110
- openscript-0.7.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
111
- openscript-0.7.0.dist-info/top_level.txt,sha256=hSW5scz3fl_m9YVHGPquKReZTFzNeTx3gRqXFWN95IM,11
112
- openscript-0.7.0.dist-info/RECORD,,
109
+ openscript-0.7.2.dist-info/METADATA,sha256=a0FeLWD3h6aPFRxCZ-D6h10ExDwTwhTPtMxdWAO9ZO0,3465
110
+ openscript-0.7.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
111
+ openscript-0.7.2.dist-info/top_level.txt,sha256=hSW5scz3fl_m9YVHGPquKReZTFzNeTx3gRqXFWN95IM,11
112
+ openscript-0.7.2.dist-info/RECORD,,