oakscriptpy 0.1.0__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.
- oakscriptpy/__init__.py +93 -0
- oakscriptpy/_metadata.py +118 -0
- oakscriptpy/_types.py +185 -0
- oakscriptpy/_utils.py +145 -0
- oakscriptpy/adapters/__init__.py +5 -0
- oakscriptpy/adapters/simple_input.py +63 -0
- oakscriptpy/array.py +342 -0
- oakscriptpy/box.py +151 -0
- oakscriptpy/chartpoint.py +21 -0
- oakscriptpy/color.py +134 -0
- oakscriptpy/indicator.py +82 -0
- oakscriptpy/input_.py +38 -0
- oakscriptpy/inputs.py +170 -0
- oakscriptpy/label.py +110 -0
- oakscriptpy/lib/__init__.py +5 -0
- oakscriptpy/lib/zigzag.py +158 -0
- oakscriptpy/line.py +120 -0
- oakscriptpy/linefill.py +26 -0
- oakscriptpy/math_.py +184 -0
- oakscriptpy/matrix.py +1136 -0
- oakscriptpy/plot_.py +49 -0
- oakscriptpy/polyline.py +60 -0
- oakscriptpy/runtime.py +150 -0
- oakscriptpy/runtime_types.py +52 -0
- oakscriptpy/series.py +292 -0
- oakscriptpy/str_.py +166 -0
- oakscriptpy/ta.py +1795 -0
- oakscriptpy/ta_series.py +353 -0
- oakscriptpy/time_.py +22 -0
- oakscriptpy-0.1.0.dist-info/METADATA +120 -0
- oakscriptpy-0.1.0.dist-info/RECORD +32 -0
- oakscriptpy-0.1.0.dist-info/WHEEL +4 -0
oakscriptpy/math_.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""Math namespace — mirrors PineScript math.* functions (scalar-only initially)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math as _math
|
|
6
|
+
import random as _random
|
|
7
|
+
|
|
8
|
+
pi = _math.pi
|
|
9
|
+
e = _math.e
|
|
10
|
+
phi = 1.618033988749895
|
|
11
|
+
rphi = 0.618033988749895
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def abs(value: float) -> float:
|
|
15
|
+
return _math.fabs(value)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def ceil(value: float) -> int:
|
|
19
|
+
return _math.ceil(value)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def floor(value: float) -> int:
|
|
23
|
+
return _math.floor(value)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def round(value: float, precision: int | None = None) -> float:
|
|
27
|
+
if precision is None:
|
|
28
|
+
return builtins_round(value)
|
|
29
|
+
multiplier = 10 ** precision
|
|
30
|
+
return builtins_round(value * multiplier) / multiplier
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
builtins_round = __builtins__["round"] if isinstance(__builtins__, dict) else getattr(__builtins__, "round")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def max(*values: float) -> float:
|
|
37
|
+
return builtins_max(values)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
builtins_max = __builtins__["max"] if isinstance(__builtins__, dict) else getattr(__builtins__, "max")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def min(*values: float) -> float:
|
|
44
|
+
return builtins_min(values)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
builtins_min = __builtins__["min"] if isinstance(__builtins__, dict) else getattr(__builtins__, "min")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def avg(*values: float) -> float:
|
|
51
|
+
return builtins_sum(values) / len(values)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
builtins_sum = __builtins__["sum"] if isinstance(__builtins__, dict) else getattr(__builtins__, "sum")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def sum(source: list[float], length: int) -> list[float]:
|
|
58
|
+
result: list[float] = []
|
|
59
|
+
for i in range(len(source)):
|
|
60
|
+
if i < length - 1:
|
|
61
|
+
result.append(float("nan"))
|
|
62
|
+
else:
|
|
63
|
+
total = 0.0
|
|
64
|
+
for j in range(length):
|
|
65
|
+
total += source[i - j]
|
|
66
|
+
result.append(total)
|
|
67
|
+
return result
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def sqrt(value: float) -> float:
|
|
71
|
+
return _math.sqrt(value)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def pow(base: float, exponent: float) -> float:
|
|
75
|
+
return base ** exponent
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def exp(value: float) -> float:
|
|
79
|
+
return _math.exp(value)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def log(value: float) -> float:
|
|
83
|
+
return _math.log(value)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def log10(value: float) -> float:
|
|
87
|
+
return _math.log10(value)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def log2(value: float) -> float:
|
|
91
|
+
return _math.log2(value)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def sin(value: float) -> float:
|
|
95
|
+
return _math.sin(value)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def cos(value: float) -> float:
|
|
99
|
+
return _math.cos(value)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def tan(value: float) -> float:
|
|
103
|
+
return _math.tan(value)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def asin(value: float) -> float:
|
|
107
|
+
return _math.asin(value)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def acos(value: float) -> float:
|
|
111
|
+
return _math.acos(value)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def atan(value: float) -> float:
|
|
115
|
+
return _math.atan(value)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def atan2(y: float, x: float) -> float:
|
|
119
|
+
return _math.atan2(y, x)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def sinh(value: float) -> float:
|
|
123
|
+
return _math.sinh(value)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def cosh(value: float) -> float:
|
|
127
|
+
return _math.cosh(value)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def tanh(value: float) -> float:
|
|
131
|
+
return _math.tanh(value)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def toradians(degrees: float) -> float:
|
|
135
|
+
return degrees * (_math.pi / 180)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def todegrees(radians: float) -> float:
|
|
139
|
+
return radians * (180 / _math.pi)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def random(min_val: float | None = None, max_val: float | None = None, _seed: int | None = None) -> float:
|
|
143
|
+
rand = _random.random()
|
|
144
|
+
if min_val is not None and max_val is not None:
|
|
145
|
+
return min_val + rand * (max_val - min_val)
|
|
146
|
+
return rand
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def sign(value: float) -> int:
|
|
150
|
+
if value > 0:
|
|
151
|
+
return 1
|
|
152
|
+
if value < 0:
|
|
153
|
+
return -1
|
|
154
|
+
return 0
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def round_to_mintick(number: float, mintick: float | None = None) -> float:
|
|
158
|
+
if _math.isnan(number):
|
|
159
|
+
return float("nan")
|
|
160
|
+
if mintick is None:
|
|
161
|
+
raise ValueError("math.round_to_mintick() requires mintick value.")
|
|
162
|
+
if mintick == 0:
|
|
163
|
+
return number
|
|
164
|
+
return builtins_round(number / mintick) * mintick
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def factorial(n: int) -> int:
|
|
168
|
+
return _math.factorial(n)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def combination(n: int, k: int) -> int:
|
|
172
|
+
return _math.comb(n, k)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def permutation(n: int, k: int) -> int:
|
|
176
|
+
return _math.perm(n, k)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def gcd(a: int, b: int) -> int:
|
|
180
|
+
return _math.gcd(a, b)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def lcm(a: int, b: int) -> int:
|
|
184
|
+
return _math.lcm(a, b)
|