Qubx 0.1.88__cp311-cp311-manylinux_2_35_x86_64.whl → 0.1.90__cp311-cp311-manylinux_2_35_x86_64.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.

Potentially problematic release.


This version of Qubx might be problematic. Click here for more details.

qubx/core/series.pxd CHANGED
@@ -11,11 +11,16 @@ cdef class Indexed:
11
11
  cdef unsigned short _is_empty
12
12
 
13
13
 
14
+ cdef class Locator:
15
+ cdef TimeSeries _series
16
+
17
+
14
18
  cdef class TimeSeries:
15
19
  cdef public long long timeframe
16
20
  cdef public Indexed times
17
21
  cdef public Indexed values
18
22
  cdef public float max_series_length
23
+ cdef public Locator loc
19
24
  cdef unsigned short _is_new_item
20
25
  cdef public str name
21
26
  cdef dict indicators # it's used for indicators caching
qubx/core/series.pyx CHANGED
@@ -120,6 +120,54 @@ cdef class Indexed:
120
120
  global _plot_func
121
121
 
122
122
 
123
+ cdef class Locator:
124
+ """
125
+ Locator service class for TimeSeries
126
+ """
127
+
128
+ def __init__(self, TimeSeries series):
129
+ self._series = series
130
+
131
+ def __getitem__(self, idx):
132
+ cdef int _nlen = len(self._series)
133
+
134
+ if isinstance(idx, slice):
135
+ start = 0 if idx.start is None else idx.start
136
+ if isinstance(start, str):
137
+ start = max(self._get_time_index(start), 0)
138
+
139
+ if idx.stop is None:
140
+ stop = (_nlen - 1)
141
+ else:
142
+ if isinstance(idx.stop, str):
143
+ stop = self._get_time_index(idx.stop)
144
+ else:
145
+ stop = idx.stop - 1
146
+
147
+ new_ts = self._series._clone_empty(self._series.name, self._series.timeframe, self._series.max_series_length)
148
+ for i in range(start, min(stop + 1, _nlen)):
149
+ new_ts._add_new_item(self._series.times.values[i], self._series.values.values[i])
150
+ return new_ts
151
+
152
+ elif isinstance(idx, str):
153
+ # - handle single timestamp string
154
+ return self.find(idx)
155
+
156
+ return self._series.values[idx]
157
+
158
+ def _get_time_index(self, str t) -> int:
159
+ cdef long long _t = np.datetime64(t, 'ns').item()
160
+ cdef int idx = int(np.searchsorted(self._series.times.values, _t, side='right'))
161
+ idx = min(idx, len(self._series.values))
162
+ if idx == 0:
163
+ raise ValueError(f"Time {t} not found in {self._series.name}!")
164
+ return idx - 1
165
+
166
+ def find(self, str t):
167
+ ix = self._get_time_index(t)
168
+ return np.datetime64(self._series.times.values[ix], 'ns'), self._series.values.values[ix]
169
+
170
+
123
171
  cdef class TimeSeries:
124
172
 
125
173
  def __init__(
@@ -133,6 +181,8 @@ cdef class TimeSeries:
133
181
  self.values = Indexed(max_series_length)
134
182
  self.indicators = dict()
135
183
  self.calculation_order = []
184
+ # - locator service
185
+ self.loc = Locator(self)
136
186
 
137
187
  # - processing every update
138
188
  self._process_every_update = process_every_update
@@ -142,13 +192,17 @@ cdef class TimeSeries:
142
192
  def __len__(self) -> int:
143
193
  return len(self.times)
144
194
 
145
- def loc(self, str t):
146
- _t = np.datetime64(t, 'ns').item()
147
- ix = int(np.searchsorted(self.times.values, _t, side='right'))
148
- ix = min(ix, len(self.values))
149
- if ix == 0:
150
- raise ValueError(f"Time {t} not found in {self.name} !")
151
- return np.datetime64(self.times.values[ix - 1], 'ns'), self.values.values[ix - 1]
195
+ def _clone_empty(self, str name, long long timeframe, float max_series_length):
196
+ """
197
+ Make empty TimeSeries instance (no data and indicators)
198
+ """
199
+ return TimeSeries(name, timeframe, max_series_length)
200
+
201
+ def clone(self):
202
+ """
203
+ Clone TimeSeries instance with data without indcators attached
204
+ """
205
+ return self.loc[:]
152
206
 
153
207
  def _on_attach_indicator(self, indicator: Indicator, indicator_input: TimeSeries):
154
208
  self.calculation_order.append((
@@ -322,7 +376,7 @@ cdef class Indicator(TimeSeries):
322
376
  self.name = name
323
377
 
324
378
  # - we need to make a empty copy and fill it
325
- self.series = self._instantiate_base_series(series.name, series.timeframe, series.max_series_length)
379
+ self.series = self._clone_empty(series.name, series.timeframe, series.max_series_length)
326
380
  self.parent = series
327
381
 
328
382
  # - notify the parent series that indicator has been attached
@@ -331,9 +385,6 @@ cdef class Indicator(TimeSeries):
331
385
  # - recalculate indicator on data as if it would being streamed
332
386
  self._initial_data_recalculate(series)
333
387
 
334
- def _instantiate_base_series(self, str name, long long timeframe, float max_series_length):
335
- return TimeSeries(name, timeframe, max_series_length)
336
-
337
388
  def _on_attach_indicator(self, indicator: Indicator, indicator_input: TimeSeries):
338
389
  self.parent._on_attach_indicator(indicator, indicator_input)
339
390
 
@@ -365,7 +416,7 @@ cdef class IndicatorOHLC(Indicator):
365
416
  """
366
417
  Extension of indicator class to be used for OHLCV series
367
418
  """
368
- def _instantiate_base_series(self, str name, long long timeframe, float max_series_length):
419
+ def _clone_empty(self, str name, long long timeframe, float max_series_length):
369
420
  return OHLCV(name, timeframe, max_series_length)
370
421
 
371
422
  def calculate(self, long long time, Bar value, short new_item_started) -> object:
@@ -724,6 +775,9 @@ cdef class OHLCV(TimeSeries):
724
775
 
725
776
  return self
726
777
 
778
+ def _clone_empty(self, str name, long long timeframe, float max_series_length):
779
+ return OHLCV(name, timeframe, max_series_length)
780
+
727
781
  def _add_new_item(self, long long time, Bar value):
728
782
  self.times.add(time)
729
783
  self.values.add(value)
qubx/ta/indicators.pyx CHANGED
@@ -627,14 +627,21 @@ cdef class Swings(IndicatorOHLC):
627
627
  cdef long long _max_t
628
628
  cdef OHLCV base
629
629
  cdef Indicator trend
630
- cdef public TimeSeries tops
631
- cdef public TimeSeries bottoms
630
+ # tops contain upper pivot point prices
631
+ # tops_detection_lag contain time lag when top was actually spotted
632
+ cdef public TimeSeries tops, tops_detection_lag
633
+ cdef public TimeSeries bottoms, bottoms_detection_lag
632
634
 
633
635
  def __init__(self, str name, OHLCV series, trend_indicator, **indicator_args):
634
636
  self.base = OHLCV("base", series.timeframe, series.max_series_length)
635
637
  self.trend = trend_indicator(self.base, **indicator_args)
638
+
636
639
  self.tops = TimeSeries("tops", series.timeframe, series.max_series_length)
640
+ self.tops_detection_lag = TimeSeries("tops_lag", series.timeframe, series.max_series_length)
641
+
637
642
  self.bottoms = TimeSeries("bottoms", series.timeframe, series.max_series_length)
643
+ self.bottoms_detection_lag = TimeSeries("bottoms_lag", series.timeframe, series.max_series_length)
644
+
638
645
  self._min_l = +np.inf
639
646
  self._max_h = -np.inf
640
647
  self._max_t = 0
@@ -652,6 +659,7 @@ cdef class Swings(IndicatorOHLC):
652
659
  if not np.isnan(_u):
653
660
  if self._max_t > 0:
654
661
  self.tops.update(self._max_t, self._max_h)
662
+ self.tops_detection_lag.update(self._max_t, time - self._max_t)
655
663
 
656
664
  if bar.low <= self._min_l:
657
665
  self._min_l = bar.low
@@ -663,6 +671,7 @@ cdef class Swings(IndicatorOHLC):
663
671
  elif not np.isnan(_d):
664
672
  if self._min_t > 0:
665
673
  self.bottoms.update(self._min_t, self._min_l)
674
+ self.bottoms_detection_lag.update(self._min_t, time - self._min_t)
666
675
 
667
676
  if bar.high >= self._max_h:
668
677
  self._max_h = bar.high
@@ -684,20 +693,34 @@ cdef class Swings(IndicatorOHLC):
684
693
  def pd(self) -> pd.DataFrame:
685
694
  _t, _d = self.get_current_trend_end()
686
695
  tps, bts = self.tops.pd(), self.bottoms.pd()
696
+ tpl, btl = self.tops_detection_lag.pd(), self.bottoms_detection_lag.pd()
687
697
  if _t is not None:
688
698
  if bts.index[-1] < tps.index[-1]:
689
699
  bts = srows(bts, pd.Series({_t: _d}))
700
+ btl = srows(btl, pd.Series({_t: 0})) # last lag is 0
690
701
  else:
691
702
  tps = srows(tps, pd.Series({_t: _d}))
703
+ tpl = srows(tpl, pd.Series({_t: 0})) # last lag is 0
704
+
705
+ # - convert tpl / btl to timedeltas
706
+ tpl, btl = tpl.apply(lambda x: pd.Timedelta(x, unit='ns')), btl.apply(lambda x: pd.Timedelta(x, unit='ns'))
692
707
 
693
708
  eid = pd.Series(tps.index, tps.index)
694
709
  mx = scols(bts, tps, eid, names=["start_price", "end_price", "end"])
695
710
  dt = scols(mx["start_price"], mx["end_price"].shift(-1), mx["end"].shift(-1)) # .dropna()
696
- dt = dt.assign(delta = dt["end_price"] - dt["start_price"])
711
+ dt = dt.assign(
712
+ delta = dt["end_price"] - dt["start_price"],
713
+ spotted = pd.Series(bts.index + btl, bts.index)
714
+ )
697
715
 
698
716
  eid = pd.Series(bts.index, bts.index)
699
717
  mx = scols(tps, bts, eid, names=["start_price", "end_price", "end"])
700
718
  ut = scols(mx["start_price"], mx["end_price"].shift(-1), mx["end"].shift(-1)) # .dropna()
719
+ ut = ut.assign(
720
+ delta = ut["end_price"] - ut["start_price"],
721
+ spotted = pd.Series(tps.index + tpl, tps.index)
722
+ )
723
+
701
724
  return scols(ut, dt, keys=["DownTrends", "UpTrends"])
702
725
 
703
726
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Qubx
3
- Version: 0.1.88
3
+ Version: 0.1.90
4
4
  Summary: Qubx - quantitative trading framework
5
5
  Home-page: https://github.com/dmarienko/Qubx
6
6
  Author: Dmitry Marienko
@@ -6,11 +6,11 @@ qubx/core/basics.py,sha256=2u7WV5KX-RbTmzoKfi1yT4HNLDPfQcFMCUZ1pVsM_VE,14777
6
6
  qubx/core/helpers.py,sha256=gPE78dO718NBY0-JbfqNGCzIvr4BVatFntNIy2RUrEY,11559
7
7
  qubx/core/loggers.py,sha256=HpgavBZegoDv9ssihtqX0pitXKULVAPHUpoE_volJw0,11910
8
8
  qubx/core/lookups.py,sha256=4aEC7b2AyEXFqHHGDenex3Z1FZGrpDSb8IwzBZrSqIA,13688
9
- qubx/core/series.cpython-311-x86_64-linux-gnu.so,sha256=A3tw0ZuTSxk-kthr1yU9tGGRNwPjTH0m6sdUG5Difn0,736872
10
- qubx/core/series.pxd,sha256=YC1w11gzn1eq6kBrLTufLlECsKd0YWLu70k_CuAMksg,2916
11
- qubx/core/series.pyx,sha256=zO1M9MtVgzQyy0oVhO9HOWaIqT2HwcqhR-MdxpEk-HI,29401
9
+ qubx/core/series.cpython-311-x86_64-linux-gnu.so,sha256=WE-5-tz9G9j6TuvZ24ewDCm-TyKb00IpGSP1GUd6tUs,762408
10
+ qubx/core/series.pxd,sha256=1KJGzun_R5GDDOynPbZER7Xg45a0JUM_S_lZ-9FFFJg,2994
11
+ qubx/core/series.pyx,sha256=fKBDHWyJIdgWXrKxef8vm98phFgKzzyfUI0_Adla4NU,31118
12
12
  qubx/core/strategy.py,sha256=Fs4fFyHaEGYuz7mBeQHBWFu3Ipg0yFzcxXhskgsPxJE,30330
13
- qubx/core/utils.cpython-311-x86_64-linux-gnu.so,sha256=O0DhQLUfGRcxtf8HDWPNgNGNvYuo8RCKw6liyM46mtA,74248
13
+ qubx/core/utils.cpython-311-x86_64-linux-gnu.so,sha256=C3fOY78zniScQYlIFQdE6wb0w9UbNnsZ-OZ4SCWp9cM,74248
14
14
  qubx/core/utils.pyx,sha256=csSIwI_lwvCd8CTbsp9Q0XiRCtGAHEuF62afHOJzCGQ,1382
15
15
  qubx/data/readers.py,sha256=YQvVbjyHsWDL54bVOzm78sTAF1ORYGT1eW4tVpnv5uA,32481
16
16
  qubx/impl/ccxt_connector.py,sha256=NqF-tgxfTATnmVqKUonNXCAzECrDU8YrgqM3Nq06fw8,9150
@@ -23,8 +23,8 @@ qubx/pandaz/__init__.py,sha256=Iw5uzicYGSC3FEKZ-W1O5-7cXq_P0kH11-EcXV0zZhs,175
23
23
  qubx/pandaz/ta.py,sha256=O17JPtee8MLyBoS8zdm32qsQcBJNtAPUpgFj3SMUKsA,85060
24
24
  qubx/pandaz/utils.py,sha256=FyLKQy8spkqxhBij_nPFC_ZzI_L3-IgB9O53MqWKmq0,19109
25
25
  qubx/ta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
- qubx/ta/indicators.cpython-311-x86_64-linux-gnu.so,sha256=HRaZHGW_uRMzu9cuqS1CPgLbL4_uDHrxF82Zg9GcLsc,518504
27
- qubx/ta/indicators.pyx,sha256=iKSUz5sW6qd6yaYwmHfMyp3i98GH8mwgTHpk10PGJHM,22314
26
+ qubx/ta/indicators.cpython-311-x86_64-linux-gnu.so,sha256=z0mAq4lgmbsHbPigDaPBes4dZec7VZl3lkti9E_bOEI,543240
27
+ qubx/ta/indicators.pyx,sha256=qUjRrwHgf2GkzU6U2hRA0Lfzk1RMt4gbmfFUDfgq77o,23473
28
28
  qubx/trackers/__init__.py,sha256=1y_yvIy0OQwBqfhAW_EY33NxFzFSWvI0qNAPU6zchYc,60
29
29
  qubx/trackers/rebalancers.py,sha256=QCzANCooZBi2VMCBjjCPMq_Dt1h1zrBelATnfmVve74,5522
30
30
  qubx/utils/__init__.py,sha256=XJFje4jP69pnPTp7fpTUmqwXz9PKzGYtJf8-kBofum0,273
@@ -34,6 +34,6 @@ qubx/utils/marketdata/binance.py,sha256=36dl4rxOAGTeY3uoONmiPanj8BkP0oBdDiH-URJJ
34
34
  qubx/utils/misc.py,sha256=hmG_c7nneLiJ-xgyeOQucckPRemNAQ0Hsr7OqDdhbhU,9868
35
35
  qubx/utils/runner.py,sha256=OY7SoRfxHwzn0rKTGB_lbg5zNASEL_49hQXWqs-LiMk,9306
36
36
  qubx/utils/time.py,sha256=_DjCdQditzZwMy_8rvPdWyw5tjw__2p24LMPgXdZ8i0,4911
37
- qubx-0.1.88.dist-info/METADATA,sha256=2ON3hgyJnqhDBQ5u_5ylo1RVvS83PZq4kvoxPIqwKbY,2524
38
- qubx-0.1.88.dist-info/WHEEL,sha256=MLOa6LysROdjgj4FVxsHitAnIh8Be2D_c9ZSBHKrz2M,110
39
- qubx-0.1.88.dist-info/RECORD,,
37
+ qubx-0.1.90.dist-info/METADATA,sha256=ZKKDtnzo0T4qMipZMAT2ZtcKbW4PUG6XyVBgoBOf3D4,2524
38
+ qubx-0.1.90.dist-info/WHEEL,sha256=MLOa6LysROdjgj4FVxsHitAnIh8Be2D_c9ZSBHKrz2M,110
39
+ qubx-0.1.90.dist-info/RECORD,,
File without changes