onetick-py 1.177.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.
Files changed (152) hide show
  1. locator_parser/__init__.py +0 -0
  2. locator_parser/acl.py +73 -0
  3. locator_parser/actions.py +262 -0
  4. locator_parser/common.py +368 -0
  5. locator_parser/io.py +43 -0
  6. locator_parser/locator.py +150 -0
  7. onetick/__init__.py +101 -0
  8. onetick/doc_utilities/__init__.py +3 -0
  9. onetick/doc_utilities/napoleon.py +40 -0
  10. onetick/doc_utilities/ot_doctest.py +140 -0
  11. onetick/doc_utilities/snippets.py +279 -0
  12. onetick/lib/__init__.py +4 -0
  13. onetick/lib/instance.py +141 -0
  14. onetick/py/__init__.py +293 -0
  15. onetick/py/_stack_info.py +89 -0
  16. onetick/py/_version.py +2 -0
  17. onetick/py/aggregations/__init__.py +11 -0
  18. onetick/py/aggregations/_base.py +648 -0
  19. onetick/py/aggregations/_docs.py +948 -0
  20. onetick/py/aggregations/compute.py +286 -0
  21. onetick/py/aggregations/functions.py +2216 -0
  22. onetick/py/aggregations/generic.py +104 -0
  23. onetick/py/aggregations/high_low.py +80 -0
  24. onetick/py/aggregations/num_distinct.py +83 -0
  25. onetick/py/aggregations/order_book.py +501 -0
  26. onetick/py/aggregations/other.py +1014 -0
  27. onetick/py/backports.py +26 -0
  28. onetick/py/cache.py +374 -0
  29. onetick/py/callback/__init__.py +5 -0
  30. onetick/py/callback/callback.py +276 -0
  31. onetick/py/callback/callbacks.py +131 -0
  32. onetick/py/compatibility.py +798 -0
  33. onetick/py/configuration.py +771 -0
  34. onetick/py/core/__init__.py +0 -0
  35. onetick/py/core/_csv_inspector.py +93 -0
  36. onetick/py/core/_internal/__init__.py +0 -0
  37. onetick/py/core/_internal/_manually_bound_value.py +6 -0
  38. onetick/py/core/_internal/_nodes_history.py +250 -0
  39. onetick/py/core/_internal/_op_utils/__init__.py +0 -0
  40. onetick/py/core/_internal/_op_utils/every_operand.py +9 -0
  41. onetick/py/core/_internal/_op_utils/is_const.py +10 -0
  42. onetick/py/core/_internal/_per_tick_scripts/tick_list_sort_template.script +121 -0
  43. onetick/py/core/_internal/_proxy_node.py +140 -0
  44. onetick/py/core/_internal/_state_objects.py +2312 -0
  45. onetick/py/core/_internal/_state_vars.py +93 -0
  46. onetick/py/core/_source/__init__.py +0 -0
  47. onetick/py/core/_source/_symbol_param.py +95 -0
  48. onetick/py/core/_source/schema.py +97 -0
  49. onetick/py/core/_source/source_methods/__init__.py +0 -0
  50. onetick/py/core/_source/source_methods/aggregations.py +809 -0
  51. onetick/py/core/_source/source_methods/applyers.py +296 -0
  52. onetick/py/core/_source/source_methods/columns.py +141 -0
  53. onetick/py/core/_source/source_methods/data_quality.py +301 -0
  54. onetick/py/core/_source/source_methods/debugs.py +272 -0
  55. onetick/py/core/_source/source_methods/drops.py +120 -0
  56. onetick/py/core/_source/source_methods/fields.py +619 -0
  57. onetick/py/core/_source/source_methods/filters.py +1002 -0
  58. onetick/py/core/_source/source_methods/joins.py +1413 -0
  59. onetick/py/core/_source/source_methods/merges.py +605 -0
  60. onetick/py/core/_source/source_methods/misc.py +1455 -0
  61. onetick/py/core/_source/source_methods/pandases.py +155 -0
  62. onetick/py/core/_source/source_methods/renames.py +356 -0
  63. onetick/py/core/_source/source_methods/sorts.py +183 -0
  64. onetick/py/core/_source/source_methods/switches.py +142 -0
  65. onetick/py/core/_source/source_methods/symbols.py +117 -0
  66. onetick/py/core/_source/source_methods/times.py +627 -0
  67. onetick/py/core/_source/source_methods/writes.py +986 -0
  68. onetick/py/core/_source/symbol.py +205 -0
  69. onetick/py/core/_source/tmp_otq.py +222 -0
  70. onetick/py/core/column.py +209 -0
  71. onetick/py/core/column_operations/__init__.py +0 -0
  72. onetick/py/core/column_operations/_methods/__init__.py +4 -0
  73. onetick/py/core/column_operations/_methods/_internal.py +28 -0
  74. onetick/py/core/column_operations/_methods/conversions.py +216 -0
  75. onetick/py/core/column_operations/_methods/methods.py +292 -0
  76. onetick/py/core/column_operations/_methods/op_types.py +160 -0
  77. onetick/py/core/column_operations/accessors/__init__.py +0 -0
  78. onetick/py/core/column_operations/accessors/_accessor.py +28 -0
  79. onetick/py/core/column_operations/accessors/decimal_accessor.py +104 -0
  80. onetick/py/core/column_operations/accessors/dt_accessor.py +537 -0
  81. onetick/py/core/column_operations/accessors/float_accessor.py +184 -0
  82. onetick/py/core/column_operations/accessors/str_accessor.py +1367 -0
  83. onetick/py/core/column_operations/base.py +1121 -0
  84. onetick/py/core/cut_builder.py +150 -0
  85. onetick/py/core/db_constants.py +20 -0
  86. onetick/py/core/eval_query.py +245 -0
  87. onetick/py/core/lambda_object.py +441 -0
  88. onetick/py/core/multi_output_source.py +232 -0
  89. onetick/py/core/per_tick_script.py +2256 -0
  90. onetick/py/core/query_inspector.py +464 -0
  91. onetick/py/core/source.py +1744 -0
  92. onetick/py/db/__init__.py +2 -0
  93. onetick/py/db/_inspection.py +1128 -0
  94. onetick/py/db/db.py +1327 -0
  95. onetick/py/db/utils.py +64 -0
  96. onetick/py/docs/__init__.py +0 -0
  97. onetick/py/docs/docstring_parser.py +112 -0
  98. onetick/py/docs/utils.py +81 -0
  99. onetick/py/functions.py +2398 -0
  100. onetick/py/license.py +190 -0
  101. onetick/py/log.py +88 -0
  102. onetick/py/math.py +935 -0
  103. onetick/py/misc.py +470 -0
  104. onetick/py/oqd/__init__.py +22 -0
  105. onetick/py/oqd/eps.py +1195 -0
  106. onetick/py/oqd/sources.py +325 -0
  107. onetick/py/otq.py +216 -0
  108. onetick/py/pyomd_mock.py +47 -0
  109. onetick/py/run.py +916 -0
  110. onetick/py/servers.py +173 -0
  111. onetick/py/session.py +1347 -0
  112. onetick/py/sources/__init__.py +19 -0
  113. onetick/py/sources/cache.py +167 -0
  114. onetick/py/sources/common.py +128 -0
  115. onetick/py/sources/csv.py +642 -0
  116. onetick/py/sources/custom.py +85 -0
  117. onetick/py/sources/data_file.py +305 -0
  118. onetick/py/sources/data_source.py +1045 -0
  119. onetick/py/sources/empty.py +94 -0
  120. onetick/py/sources/odbc.py +337 -0
  121. onetick/py/sources/order_book.py +271 -0
  122. onetick/py/sources/parquet.py +168 -0
  123. onetick/py/sources/pit.py +191 -0
  124. onetick/py/sources/query.py +495 -0
  125. onetick/py/sources/snapshots.py +419 -0
  126. onetick/py/sources/split_query_output_by_symbol.py +198 -0
  127. onetick/py/sources/symbology_mapping.py +123 -0
  128. onetick/py/sources/symbols.py +374 -0
  129. onetick/py/sources/ticks.py +825 -0
  130. onetick/py/sql.py +70 -0
  131. onetick/py/state.py +251 -0
  132. onetick/py/types.py +2131 -0
  133. onetick/py/utils/__init__.py +70 -0
  134. onetick/py/utils/acl.py +93 -0
  135. onetick/py/utils/config.py +186 -0
  136. onetick/py/utils/default.py +49 -0
  137. onetick/py/utils/file.py +38 -0
  138. onetick/py/utils/helpers.py +76 -0
  139. onetick/py/utils/locator.py +94 -0
  140. onetick/py/utils/perf.py +498 -0
  141. onetick/py/utils/query.py +49 -0
  142. onetick/py/utils/render.py +1374 -0
  143. onetick/py/utils/script.py +244 -0
  144. onetick/py/utils/temp.py +471 -0
  145. onetick/py/utils/types.py +120 -0
  146. onetick/py/utils/tz.py +84 -0
  147. onetick_py-1.177.0.dist-info/METADATA +137 -0
  148. onetick_py-1.177.0.dist-info/RECORD +152 -0
  149. onetick_py-1.177.0.dist-info/WHEEL +5 -0
  150. onetick_py-1.177.0.dist-info/entry_points.txt +2 -0
  151. onetick_py-1.177.0.dist-info/licenses/LICENSE +21 -0
  152. onetick_py-1.177.0.dist-info/top_level.txt +2 -0
onetick/py/math.py ADDED
@@ -0,0 +1,935 @@
1
+ from onetick.py.core.column_operations.base import _Operation
2
+ from onetick.py.types import value2str, nsectime, get_type_by_objects
3
+
4
+
5
+ def max(*objs):
6
+ """
7
+ Returns maximum value from list of ``objs``.
8
+ The objects must be of the same type.
9
+
10
+ Parameters
11
+ ----------
12
+ objs: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
13
+
14
+ Returns
15
+ -------
16
+ :py:class:`~onetick.py.Operation`
17
+
18
+ Examples
19
+ --------
20
+ >>> data = otp.Tick(A=1)
21
+ >>> data['MAX'] = otp.math.max(5, data['A'])
22
+ >>> otp.run(data)
23
+ Time A MAX
24
+ 0 2003-12-01 1 5
25
+ """
26
+ if len(objs) < 2:
27
+ raise ValueError("otp.math.max expects at least 2 values to compare")
28
+
29
+ def _max_func(*objs):
30
+ dtype = get_type_by_objects(objs)
31
+ onetick_params = map(value2str, objs)
32
+ if dtype is nsectime:
33
+ onetick_params = [f'NSECTIME_TO_LONG({param})' for param in onetick_params]
34
+ onetick_params_str = ', '.join(onetick_params)
35
+ return f"NSECTIME(MAX({onetick_params_str}))", dtype
36
+ else:
37
+ onetick_params_str = ', '.join(onetick_params)
38
+ return f"MAX({onetick_params_str})", dtype
39
+
40
+ return _Operation(
41
+ op_func=_max_func,
42
+ op_params=list(objs),
43
+ )
44
+
45
+
46
+ def min(*objs):
47
+ """
48
+ Returns minimum value from list of ``objs``.
49
+ The objects must be of the same type.
50
+
51
+ Parameters
52
+ ----------
53
+ objs: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
54
+
55
+ Returns
56
+ -------
57
+ :py:class:`~onetick.py.Operation`
58
+
59
+ Examples
60
+ --------
61
+ >>> data = otp.Tick(A=1)
62
+ >>> data['MIN'] = otp.math.min(-5, data['A'])
63
+ >>> otp.run(data)
64
+ Time A MIN
65
+ 0 2003-12-01 1 -5
66
+ """
67
+ if len(objs) < 2:
68
+ raise ValueError("otp.math.min expects at least 2 values to compare")
69
+
70
+ def _min_func(*objs):
71
+ dtype = get_type_by_objects(objs)
72
+ onetick_params = map(value2str, objs)
73
+ if dtype is nsectime:
74
+ onetick_params = [f'NSECTIME_TO_LONG({param})' for param in onetick_params]
75
+ onetick_params_str = ', '.join(onetick_params)
76
+ return f"NSECTIME(MIN({onetick_params_str}))", dtype
77
+ else:
78
+ onetick_params_str = ', '.join(onetick_params)
79
+ return f"MIN({onetick_params_str})", dtype
80
+
81
+ return _Operation(
82
+ op_func=_min_func,
83
+ op_params=list(objs),
84
+ )
85
+
86
+
87
+ def rand(min_value, max_value, seed=None):
88
+ """
89
+ Returns a pseudo-random value in the range between ``min_value`` and ``max_value`` (both inclusive).
90
+ If ``seed`` is not specified, the function produces different values each time a query is invoked.
91
+ If ``seed`` is specified, for this seed the function produces the same sequence of values
92
+ each time a query is invoked.
93
+
94
+ Parameters
95
+ ----------
96
+ min_value: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
97
+ max_value: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
98
+ seed: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
99
+
100
+ Returns
101
+ -------
102
+ :py:class:`~onetick.py.Operation`
103
+
104
+ Examples
105
+ --------
106
+ >>> data = otp.Tick(A=1)
107
+ >>> data['RAND'] = otp.math.rand(1, 1000)
108
+ >>> otp.run(data) # doctest: +SKIP
109
+ Time A RAND
110
+ 0 2003-12-01 1 155
111
+ """
112
+
113
+ if isinstance(min_value, int) and min_value < 0:
114
+ raise ValueError("It is not possible to use negative values for the `min_value`")
115
+ if isinstance(min_value, int) and isinstance(max_value, int) and min_value >= max_value:
116
+ raise ValueError("The `max_value` parameter should be more than `min_value`")
117
+
118
+ def _random_func(min_value, max_value, seed=None):
119
+ result = f'RAND({value2str(min_value)}, {value2str(max_value)}'
120
+ if seed is not None:
121
+ result += f', {value2str(seed)})'
122
+ else:
123
+ result += ')'
124
+ return result, int
125
+
126
+ return _Operation(
127
+ op_func=_random_func,
128
+ op_params=[min_value, max_value, seed],
129
+ )
130
+
131
+
132
+ def frand(min_value=0, max_value=1, *, seed=None):
133
+ """
134
+ Returns a pseudo-random value in the range between ``min_value`` and ``max_value``.
135
+
136
+ Parameters
137
+ ----------
138
+ min_value: float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
139
+ max_value: float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
140
+ seed: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
141
+ If not specified, the function produces different values each time a query is invoked.
142
+ If specified, for this seed the function produces the same sequence of values
143
+ each time a query is invoked.
144
+
145
+ Returns
146
+ -------
147
+ :py:class:`~onetick.py.Operation`
148
+
149
+ Examples
150
+ --------
151
+ >>> data = otp.Tick(A=otp.math.frand())
152
+ >>> otp.run(data) # doctest: +SKIP
153
+ Time A FRAND
154
+ 0 2003-12-01 1 0.667519
155
+ """
156
+
157
+ if isinstance(min_value, (int, float)) and min_value < 0:
158
+ raise ValueError("It is not possible to use negative values for the `min_value`")
159
+ if isinstance(min_value, (int, float)) and isinstance(max_value, (int, float)) and min_value >= max_value:
160
+ raise ValueError("The `max_value` parameter should be more than `min_value`")
161
+
162
+ def _frand_func(min_value, max_value, seed=None):
163
+ func_args = [min_value, max_value]
164
+ if seed is not None:
165
+ func_args.append(seed)
166
+ onetick_args_str = ', '.join(value2str(arg) for arg in func_args)
167
+ return f'FRAND({onetick_args_str})', float
168
+
169
+ return _Operation(
170
+ op_func=_frand_func,
171
+ op_params=[min_value, max_value, seed],
172
+ )
173
+
174
+
175
+ # TODO: this is not math, let's move it somewhere else
176
+ def now():
177
+ """
178
+ Returns the current time expressed as the number of milliseconds since the UNIX epoch in a GMT timezone.
179
+
180
+ Returns
181
+ -------
182
+ :py:class:`~onetick.py.Operation`
183
+
184
+ Examples
185
+ --------
186
+ >>> data = otp.Tick(A=1)
187
+ >>> data['NOW'] = otp.now()
188
+ >>> otp.run(data) # doctest: +SKIP
189
+ Time A NOW
190
+ 0 2003-12-01 1 2025-09-29 09:09:00.158
191
+ """
192
+ return _Operation(
193
+ op_func=lambda: ('NOW()', nsectime),
194
+ )
195
+
196
+
197
+ def ln(value):
198
+ """
199
+ Compute the natural logarithm of the ``value``.
200
+
201
+ Parameters
202
+ ----------
203
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
204
+
205
+ Returns
206
+ -------
207
+ :py:class:`~onetick.py.Operation`
208
+
209
+ Examples
210
+ --------
211
+ >>> data = otp.Tick(A=1)
212
+ >>> data['LN'] = otp.math.ln(2.718282)
213
+ >>> otp.run(data)
214
+ Time A LN
215
+ 0 2003-12-01 1 1.0
216
+
217
+ See Also
218
+ --------
219
+ :py:func:`onetick.py.math.exp`
220
+ """
221
+ return _Operation(
222
+ op_func=lambda v: (f'LOG({value2str(v)})', float),
223
+ op_params=[value],
224
+ )
225
+
226
+
227
+ log = ln
228
+
229
+
230
+ def log10(value):
231
+ """
232
+ Compute the base-10 logarithm of the ``value``.
233
+
234
+ Parameters
235
+ ----------
236
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
237
+
238
+ Returns
239
+ -------
240
+ :py:class:`~onetick.py.Operation`
241
+
242
+ Examples
243
+ --------
244
+ >>> data = otp.Tick(A=1)
245
+ >>> data['LOG10'] = otp.math.log10(100)
246
+ >>> otp.run(data)
247
+ Time A LOG10
248
+ 0 2003-12-01 1 2.0
249
+ """
250
+ return _Operation(
251
+ op_func=lambda v: (f'LOG10({value2str(v)})', float),
252
+ op_params=[value],
253
+ )
254
+
255
+
256
+ def exp(value):
257
+ """
258
+ Compute the natural exponent of the ``value``.
259
+
260
+ Parameters
261
+ ----------
262
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
263
+
264
+ Returns
265
+ -------
266
+ :py:class:`~onetick.py.Operation`
267
+
268
+ Examples
269
+ --------
270
+ >>> data = otp.Tick(A=1)
271
+ >>> data['E'] = otp.math.exp(1)
272
+ >>> otp.run(data)
273
+ Time A E
274
+ 0 2003-12-01 1 2.718282
275
+
276
+ See Also
277
+ --------
278
+ :py:func:`onetick.py.math.ln`
279
+ """
280
+ return _Operation(
281
+ op_func=lambda v: (f'EXP({value2str(v)})', float),
282
+ op_params=[value],
283
+ )
284
+
285
+
286
+ def sqrt(value):
287
+ """
288
+ Compute the square root of the ``value``.
289
+
290
+ Parameters
291
+ ----------
292
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
293
+
294
+ Returns
295
+ -------
296
+ :py:class:`~onetick.py.Operation`
297
+
298
+ Examples
299
+ --------
300
+ >>> data = otp.Tick(A=1)
301
+ >>> data['SQRT'] = otp.math.sqrt(4)
302
+ >>> otp.run(data)
303
+ Time A SQRT
304
+ 0 2003-12-01 1 2.0
305
+ """
306
+ return _Operation(
307
+ op_func=lambda v: (f'SQRT({value2str(v)})', float),
308
+ op_params=[value],
309
+ )
310
+
311
+
312
+ def sign(value):
313
+ """
314
+ Compute the sign of the ``value``.
315
+
316
+ Parameters
317
+ ----------
318
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
319
+
320
+ Returns
321
+ -------
322
+ :py:class:`~onetick.py.Operation`
323
+
324
+ Examples
325
+ --------
326
+ >>> data = otp.Tick(A=1)
327
+ >>> data['SIGN_POS'] = otp.math.sign(123)
328
+ >>> data['SIGN_ZERO'] = otp.math.sign(0)
329
+ >>> data['SIGN_NEG'] = otp.math.sign(-123)
330
+ >>> otp.run(data)
331
+ Time A SIGN_POS SIGN_ZERO SIGN_NEG
332
+ 0 2003-12-01 1 1 0 -1
333
+ """
334
+ return _Operation(
335
+ op_func=lambda v: (f'SIGN({value2str(v)})', int),
336
+ op_params=[value],
337
+ )
338
+
339
+
340
+ def pow(base, exponent):
341
+ """
342
+ Compute the ``base`` to the power of the ``exponent``.
343
+
344
+ Parameters
345
+ ----------
346
+ base: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
347
+ exponent: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
348
+
349
+ Returns
350
+ -------
351
+ :py:class:`~onetick.py.Operation`
352
+
353
+ Examples
354
+ --------
355
+ >>> data = otp.Tick(A=2)
356
+ >>> data['RES'] = otp.math.pow(data['A'], 10)
357
+ >>> otp.run(data)
358
+ Time A RES
359
+ 0 2003-12-01 2 1024.0
360
+ """
361
+ return _Operation(
362
+ op_func=lambda b, e: (f'POWER({value2str(b)}, {value2str(e)})', float),
363
+ op_params=[base, exponent],
364
+ )
365
+
366
+
367
+ def pi():
368
+ """
369
+ Returns the value of Pi number.
370
+
371
+ Returns
372
+ -------
373
+ :py:class:`~onetick.py.Operation`
374
+
375
+ Examples
376
+ --------
377
+ >>> data = otp.Tick(A=1)
378
+ >>> data['PI'] = otp.math.pi()
379
+ >>> otp.run(data)
380
+ Time A PI
381
+ 0 2003-12-01 1 3.141593
382
+ """
383
+ return _Operation(
384
+ op_func=lambda: ('PI()', float),
385
+ )
386
+
387
+
388
+ def sin(value):
389
+ """
390
+ Returns the value of trigonometric function `sin` for the given ``value`` number expressed in radians.
391
+
392
+ Parameters
393
+ ----------
394
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
395
+
396
+ Returns
397
+ -------
398
+ :py:class:`~onetick.py.Operation`
399
+
400
+ Examples
401
+ --------
402
+ >>> data = otp.Tick(A=1)
403
+ >>> data['SIN'] = otp.math.sin(otp.math.pi() / 6)
404
+ >>> otp.run(data)
405
+ Time A SIN
406
+ 0 2003-12-01 1 0.5
407
+
408
+ See Also
409
+ --------
410
+ :py:func:`onetick.py.math.pi`
411
+ :py:func:`onetick.py.math.asin`
412
+ """
413
+ return _Operation(
414
+ op_func=lambda v: (f'SIN({value2str(v)})', float),
415
+ op_params=[value],
416
+ )
417
+
418
+
419
+ def cos(value):
420
+ """
421
+ Returns the value of trigonometric function `cos` for the given ``value`` number expressed in radians.
422
+
423
+ Parameters
424
+ ----------
425
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
426
+
427
+ Returns
428
+ -------
429
+ :py:class:`~onetick.py.Operation`
430
+
431
+ Examples
432
+ --------
433
+ >>> data = otp.Tick(A=1)
434
+ >>> data['COS'] = otp.math.cos(otp.math.pi() / 3)
435
+ >>> otp.run(data)
436
+ Time A COS
437
+ 0 2003-12-01 1 0.5
438
+
439
+ See Also
440
+ --------
441
+ :py:func:`onetick.py.math.pi`
442
+ :py:func:`onetick.py.math.acos`
443
+ """
444
+ return _Operation(
445
+ op_func=lambda v: (f'COS({value2str(v)})', float),
446
+ op_params=[value],
447
+ )
448
+
449
+
450
+ def tan(value):
451
+ """
452
+ Returns the value of trigonometric function `tan` for the given ``value`` number expressed in radians.
453
+
454
+ Parameters
455
+ ----------
456
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
457
+
458
+ Returns
459
+ -------
460
+ :py:class:`~onetick.py.Operation`
461
+
462
+ Examples
463
+ --------
464
+ >>> data = otp.Tick(A=1)
465
+ >>> data['TAN'] = otp.math.tan(otp.math.pi() / 4)
466
+ >>> otp.run(data)
467
+ Time A TAN
468
+ 0 2003-12-01 1 1.0
469
+
470
+ See Also
471
+ --------
472
+ :py:func:`onetick.py.math.pi`
473
+ :py:func:`onetick.py.math.atan`
474
+ """
475
+ return _Operation(
476
+ op_func=lambda v: (f'TAN({value2str(v)})', float),
477
+ op_params=[value],
478
+ )
479
+
480
+
481
+ def cot(value):
482
+ """
483
+ Returns the value of trigonometric function `cot` for the given ``value`` number expressed in radians.
484
+
485
+ Parameters
486
+ ----------
487
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
488
+
489
+ Returns
490
+ -------
491
+ :py:class:`~onetick.py.Operation`
492
+
493
+ Examples
494
+ --------
495
+ >>> data = otp.Tick(A=1)
496
+ >>> data['COT'] = otp.math.cot(otp.math.pi() / 4)
497
+ >>> otp.run(data)
498
+ Time A COT
499
+ 0 2003-12-01 1 1.0
500
+
501
+ See Also
502
+ --------
503
+ :py:func:`onetick.py.math.pi`
504
+ :py:func:`onetick.py.math.acot`
505
+ """
506
+ return _Operation(
507
+ op_func=lambda v: (f'COT({value2str(v)})', float),
508
+ op_params=[value],
509
+ )
510
+
511
+
512
+ def asin(value):
513
+ """
514
+ Returns the value of inverse trigonometric function `arcsin`.
515
+
516
+ Parameters
517
+ ----------
518
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
519
+
520
+ Returns
521
+ -------
522
+ :py:class:`~onetick.py.Operation`
523
+
524
+ Examples
525
+ --------
526
+ >>> data = otp.Tick(A=1)
527
+ >>> data['ASIN'] = otp.math.asin(1).round(4) # should return pi/2 ~ 1.5708
528
+ >>> otp.run(data)
529
+ Time A ASIN
530
+ 0 2003-12-01 1 1.5708
531
+
532
+ `otp.math.arcsin()` is the alias for `otp.math.asin()`:
533
+
534
+ >>> data = otp.Tick(A=1)
535
+ >>> data['ASIN'] = otp.math.arcsin(1).round(4)
536
+ >>> otp.run(data)
537
+ Time A ASIN
538
+ 0 2003-12-01 1 1.5708
539
+
540
+ See Also
541
+ --------
542
+ :py:func:`onetick.py.math.pi`
543
+ :py:func:`onetick.py.math.sin`
544
+ """
545
+ return _Operation(
546
+ op_func=lambda v: (f'ASIN({value2str(v)})', float),
547
+ op_params=[value],
548
+ )
549
+
550
+
551
+ arcsin = asin
552
+
553
+
554
+ def acos(value):
555
+ """
556
+ Returns the value of inverse trigonometric function `arccos`.
557
+
558
+ Parameters
559
+ ----------
560
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
561
+
562
+ Returns
563
+ -------
564
+ :py:class:`~onetick.py.Operation`
565
+
566
+ Examples
567
+ --------
568
+ >>> data = otp.Tick(A=1)
569
+ >>> data['ACOS'] = otp.math.acos(-1).round(4) # should return pi ~ 3.1416
570
+ >>> otp.run(data)
571
+ Time A ACOS
572
+ 0 2003-12-01 1 3.1416
573
+
574
+ `otp.math.arccos()` is the alias for `otp.math.acos()`:
575
+
576
+ >>> data = otp.Tick(A=1)
577
+ >>> data['ACOS'] = otp.math.arccos(-1).round(4)
578
+ >>> otp.run(data)
579
+ Time A ACOS
580
+ 0 2003-12-01 1 3.1416
581
+
582
+ See Also
583
+ --------
584
+ :py:func:`onetick.py.math.pi`
585
+ :py:func:`onetick.py.math.cos`
586
+ """
587
+ return _Operation(
588
+ op_func=lambda v: (f'ACOS({value2str(v)})', float),
589
+ op_params=[value],
590
+ )
591
+
592
+
593
+ arccos = acos
594
+
595
+
596
+ def atan(value):
597
+ """
598
+ Returns the value of inverse trigonometric function `arctan`.
599
+
600
+ Parameters
601
+ ----------
602
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
603
+
604
+ Returns
605
+ -------
606
+ :py:class:`~onetick.py.Operation`
607
+
608
+ Examples
609
+ --------
610
+ >>> data = otp.Tick(A=1)
611
+ >>> data['ATAN'] = otp.math.atan(1).round(4) # should return pi/4 ~ 0.7854
612
+ >>> otp.run(data)
613
+ Time A ATAN
614
+ 0 2003-12-01 1 0.7854
615
+
616
+ `otp.math.arctan()` is the alias for `otp.math.atan()`:
617
+
618
+ >>> data = otp.Tick(A=1)
619
+ >>> data['ATAN'] = otp.math.arctan(1).round(4)
620
+ >>> otp.run(data)
621
+ Time A ATAN
622
+ 0 2003-12-01 1 0.7854
623
+
624
+ See Also
625
+ --------
626
+ :py:func:`onetick.py.math.pi`
627
+ :py:func:`onetick.py.math.tan`
628
+ """
629
+ return _Operation(
630
+ op_func=lambda v: (f'ATAN({value2str(v)})', float),
631
+ op_params=[value],
632
+ )
633
+
634
+
635
+ arctan = atan
636
+
637
+
638
+ def acot(value):
639
+ """
640
+ Returns the value of inverse trigonometric function `arccot`.
641
+
642
+ Parameters
643
+ ----------
644
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
645
+
646
+ Returns
647
+ -------
648
+ :py:class:`~onetick.py.Operation`
649
+
650
+ Examples
651
+ --------
652
+ >>> data = otp.Tick(A=1)
653
+ >>> data['ACOT'] = otp.math.acot(1).round(4) # should return pi/4 ~ 0.7854
654
+ >>> otp.run(data)
655
+ Time A ACOT
656
+ 0 2003-12-01 1 0.7854
657
+
658
+ `otp.math.arccot()` is the alias for `otp.math.acot()`:
659
+
660
+ >>> data = otp.Tick(A=1)
661
+ >>> data['ACOT'] = otp.math.arccot(1).round(4)
662
+ >>> otp.run(data)
663
+ Time A ACOT
664
+ 0 2003-12-01 1 0.7854
665
+
666
+ See Also
667
+ --------
668
+ :py:func:`onetick.py.math.pi`
669
+ :py:func:`onetick.py.math.cot`
670
+ """
671
+ return _Operation(
672
+ op_func=lambda v: (f'ACOT({value2str(v)})', float),
673
+ op_params=[value],
674
+ )
675
+
676
+
677
+ arccot = acot
678
+
679
+
680
+ def mod(value1, value2):
681
+ """
682
+ Computes the remainder from dividing ``value1`` by ``value2``.
683
+
684
+ Parameters
685
+ ----------
686
+ value1: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
687
+ value2: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
688
+
689
+ Returns
690
+ -------
691
+ :py:class:`~onetick.py.Operation`
692
+
693
+ Examples
694
+ --------
695
+ >>> data = otp.Tick(A=100)
696
+ >>> data['MOD'] = otp.math.mod(data['A'], 72)
697
+ >>> otp.run(data)
698
+ Time A MOD
699
+ 0 2003-12-01 100 28
700
+ """
701
+ return _Operation(
702
+ op_func=lambda v1, v2: (f'MOD({value2str(v1)}, {value2str(v2)})', int),
703
+ op_params=[value1, value2],
704
+ )
705
+
706
+
707
+ def div(value1, value2):
708
+ """
709
+ Computes the quotient by dividing ``value1`` by ``value2``.
710
+
711
+ Parameters
712
+ ----------
713
+ value1: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
714
+ value2: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
715
+
716
+ Returns
717
+ -------
718
+ :py:class:`~onetick.py.Operation`
719
+
720
+ Examples
721
+ --------
722
+ >>> data = otp.Tick(A=100)
723
+ >>> data['DIV'] = otp.math.div(data['A'], 72)
724
+ >>> otp.run(data)
725
+ Time A DIV
726
+ 0 2003-12-01 100 1
727
+ """
728
+ return _Operation(
729
+ op_func=lambda v1, v2: (f'DIV({value2str(v1)}, {value2str(v2)})', int),
730
+ op_params=[value1, value2],
731
+ )
732
+
733
+
734
+ def gcd(value1, value2):
735
+ """
736
+ Computes the greatest common divisor between ``value1`` and ``value2``.
737
+
738
+ Parameters
739
+ ----------
740
+ value1: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
741
+ value2: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
742
+
743
+ Returns
744
+ -------
745
+ :py:class:`~onetick.py.Operation`
746
+
747
+ Examples
748
+ --------
749
+ >>> data = otp.Tick(A=99)
750
+ >>> data['GCD'] = otp.math.gcd(data['A'], 72)
751
+ >>> otp.run(data)
752
+ Time A GCD
753
+ 0 2003-12-01 99 9
754
+ """
755
+ return _Operation(
756
+ op_func=lambda v1, v2: (f'GCD({value2str(v1)}, {value2str(v2)})', int),
757
+ op_params=[value1, value2],
758
+ )
759
+
760
+
761
+ def floor(value):
762
+ """
763
+ Returns a float value representing the largest number that is less than or equal to the ``value``.
764
+
765
+ Note
766
+ ----
767
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
768
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity.
769
+
770
+ Parameters
771
+ ----------
772
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
773
+
774
+ Returns
775
+ -------
776
+ :py:class:`~onetick.py.Operation`
777
+
778
+ Examples
779
+ --------
780
+ >>> data = otp.Ticks(A=[-1.7, -1.5, -1.2, -1, 0 , 1, 1.2, 1.5, 1.7, -otp.inf, otp.inf, otp.nan])
781
+ >>> data['FLOOR'] = otp.math.floor(data['A'])
782
+ >>> otp.run(data)
783
+ Time A FLOOR
784
+ 0 2003-12-01 00:00:00.000 -1.7 -2.0
785
+ 1 2003-12-01 00:00:00.001 -1.5 -2.0
786
+ 2 2003-12-01 00:00:00.002 -1.2 -2.0
787
+ 3 2003-12-01 00:00:00.003 -1.0 -1.0
788
+ 4 2003-12-01 00:00:00.004 0.0 0.0
789
+ 5 2003-12-01 00:00:00.005 1.0 1.0
790
+ 6 2003-12-01 00:00:00.006 1.2 1.0
791
+ 7 2003-12-01 00:00:00.007 1.5 1.0
792
+ 8 2003-12-01 00:00:00.008 1.7 1.0
793
+ 9 2003-12-01 00:00:00.009 -inf -inf
794
+ 10 2003-12-01 00:00:00.010 inf inf
795
+ 11 2003-12-01 00:00:00.011 NaN NaN
796
+ """
797
+ def fun(v):
798
+ v = value2str(v)
799
+ return f'CASE({v}, NAN(), NAN(), INFINITY(), INFINITY(), -INFINITY(), -INFINITY(), FLOOR({v}) * 1.0)', float
800
+
801
+ return _Operation(
802
+ op_func=fun,
803
+ op_params=[value],
804
+ )
805
+
806
+
807
+ def ceil(value):
808
+ """
809
+ Returns a float value representing the smallest number that is greater than or equal to the ``value``.
810
+
811
+ Note
812
+ ----
813
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
814
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity.
815
+
816
+ Parameters
817
+ ----------
818
+ value: int, float, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
819
+
820
+ Returns
821
+ -------
822
+ :py:class:`~onetick.py.Operation`
823
+
824
+ Examples
825
+ --------
826
+ >>> data = otp.Ticks(A=[-1.7, -1.5, -1.2, -1, 0 , 1, 1.2, 1.5, 1.7, -otp.inf, otp.inf, otp.nan])
827
+ >>> data['CEIL'] = otp.math.ceil(data['A'])
828
+ >>> otp.run(data)
829
+ Time A CEIL
830
+ 0 2003-12-01 00:00:00.000 -1.7 -1.0
831
+ 1 2003-12-01 00:00:00.001 -1.5 -1.0
832
+ 2 2003-12-01 00:00:00.002 -1.2 -1.0
833
+ 3 2003-12-01 00:00:00.003 -1.0 -1.0
834
+ 4 2003-12-01 00:00:00.004 0.0 0.0
835
+ 5 2003-12-01 00:00:00.005 1.0 1.0
836
+ 6 2003-12-01 00:00:00.006 1.2 2.0
837
+ 7 2003-12-01 00:00:00.007 1.5 2.0
838
+ 8 2003-12-01 00:00:00.008 1.7 2.0
839
+ 9 2003-12-01 00:00:00.009 -inf -inf
840
+ 10 2003-12-01 00:00:00.010 inf inf
841
+ 11 2003-12-01 00:00:00.011 NaN NaN
842
+ """
843
+ def fun(v):
844
+ v = value2str(v)
845
+ return f'CASE({v}, NAN(), NAN(), INFINITY(), INFINITY(), -INFINITY(), -INFINITY(), CEIL({v}) * 1.0)', float
846
+
847
+ return _Operation(
848
+ op_func=fun,
849
+ op_params=[value],
850
+ )
851
+
852
+
853
+ def round(value, precision=0, rounding_method='upward'):
854
+ """
855
+ Rounds value with specified ``precision`` and ``rounding_method``.
856
+
857
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
858
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity.
859
+
860
+ Parameters
861
+ ----------
862
+ precision: int
863
+ Number from -12 to 12.
864
+ Positive precision is precision after the floating point.
865
+ Negative precision is precision before the floating point (and the fraction part is dropped in this case).
866
+ rounding_method: str
867
+ Used for values that are exactly half-way between two integers (when the fraction part of value is exactly 0.5).
868
+ Available values are **upward**, **downward**, **towards_zero**, **away_from_zero**.
869
+ Default is **upward**.
870
+
871
+ Examples
872
+ --------
873
+
874
+ Different rounding methods produce different results for values that are exactly half-way between two integers:
875
+
876
+ >>> t = otp.Ticks(A=[-123.45, 123.45, -123.4, 123.6])
877
+ >>> t['UPWARD'] = otp.math.round(t['A'], precision=1, rounding_method='upward')
878
+ >>> t['DOWNWARD'] = otp.math.round(t['A'], precision=1, rounding_method='downward')
879
+ >>> t['TOWARDS_ZERO'] = otp.math.round(t['A'], precision=1, rounding_method='towards_zero')
880
+ >>> t['AWAY_FROM_ZERO'] = otp.math.round(t['A'], precision=1, rounding_method='away_from_zero')
881
+ >>> otp.run(t).head(2)
882
+ Time A UPWARD DOWNWARD TOWARDS_ZERO AWAY_FROM_ZERO
883
+ 0 2003-12-01 00:00:00.000 -123.45 -123.4 -123.5 -123.4 -123.5
884
+ 1 2003-12-01 00:00:00.001 123.45 123.5 123.4 123.4 123.5
885
+
886
+ Note that for other cases all methods produce the same results:
887
+
888
+ >>> otp.run(t).tail(2)
889
+ Time A UPWARD DOWNWARD TOWARDS_ZERO AWAY_FROM_ZERO
890
+ 2 2003-12-01 00:00:00.002 -123.4 -123.4 -123.4 -123.4 -123.4
891
+ 3 2003-12-01 00:00:00.003 123.6 123.6 123.6 123.6 123.6
892
+
893
+ Positive precision truncates to the number of digits *after* floating point:
894
+
895
+ >>> t = otp.Ticks(A=[-123.45, 123.45])
896
+ >>> t['ROUND1'] = otp.math.round(t['A'], 1)
897
+ >>> t['ROUND2'] = otp.math.round(t['A'], 2)
898
+ >>> otp.run(t)
899
+ Time A ROUND1 ROUND2
900
+ 0 2003-12-01 00:00:00.000 -123.45 -123.4 -123.45
901
+ 1 2003-12-01 00:00:00.001 123.45 123.5 123.45
902
+
903
+ Negative precision truncates to the number of digits *before* floating point
904
+ (and the fraction part is dropped in this case):
905
+
906
+ >>> t = otp.Ticks(A=[-123.45, 123.45])
907
+ >>> t['ROUND_M1'] = otp.math.round(t['A'], -1)
908
+ >>> t['ROUND_M2'] = otp.math.round(t['A'], -2)
909
+ >>> otp.run(t)
910
+ Time A ROUND_M1 ROUND_M2
911
+ 0 2003-12-01 00:00:00.000 -123.45 -120.0 -100.0
912
+ 1 2003-12-01 00:00:00.001 123.45 120.0 100.0
913
+
914
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
915
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity in all cases:
916
+
917
+ >>> t = otp.Ticks(A=[otp.inf, -otp.inf, otp.nan])
918
+ >>> t['ROUND_0'] = otp.math.round(t['A'])
919
+ >>> t['ROUND_P2'] = otp.math.round(t['A'], 2)
920
+ >>> t['ROUND_M2'] = otp.math.round(t['A'], -2)
921
+ >>> otp.run(t)
922
+ Time A ROUND_0 ROUND_P2 ROUND_M2
923
+ 0 2003-12-01 00:00:00.000 inf inf inf inf
924
+ 1 2003-12-01 00:00:00.001 -inf -inf -inf -inf
925
+ 2 2003-12-01 00:00:00.002 NaN NaN NaN NaN
926
+ """
927
+ if not -12 <= precision <= 12:
928
+ raise ValueError("Parameter 'precision' must be an integer in range [-12, 12]")
929
+ supported_rounding_methods = {'upward', 'downward', 'towards_zero', 'away_from_zero'}
930
+ if rounding_method not in supported_rounding_methods:
931
+ raise ValueError(f"Parameter 'rounding_method' must be one of {supported_rounding_methods}")
932
+ return _Operation(
933
+ op_func=lambda v, p, r: (f'ROUND_DOUBLE({value2str(v)},{value2str(p)},{value2str(r)})', float),
934
+ op_params=[value, precision, rounding_method],
935
+ )