@support that is really useful! thank you very much!
N
Latest posts made by noka'sworld
-
RE: Use of Technical indicators
-
Use of Technical indicators
Thank you! I am looking at the indicator (TAs) documentation right now
You can get the fast stochastic indicator or k with:
stoch_k = qnta.stochastic_k(high, low, close, 14)
To get k and d for both, the fast and slow stochastic indicator:
stoch_fast_k, stoch_fast_d = qnta.stochastic(high, low, close, 14) stoch_slow_k, stoch_slow_d = qnta.slow_stochastic(high, low, close, 14)
as Investopedia and Wikipedia mentioned, the indicator should be in range of 0-100,
I tried the followingdef strategy(data): high = data.sel(field="high") low = data.sel(field="low") close = data.sel(field="close") is_liquid = data.sel(field='is_liquid') stoch_k = qnta.stochastic_k(high, low, close, 14) if stoch_k>30 : weights = 1 elif stoch_k<80 : weights = -1 else : weights = 0 weights = weights / 10.0 weights = weights * is_liquid return weights
but get the following error
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-33-b67077d72c3d> in <module> 39 strategy= strategy, 40 analyze= True, ---> 41 build_plots= True 42 ) ~/book/qnt/backtester.py in backtest(competition_type, strategy, load_data, lookback_period, test_period, start_date, end_date, window, step, analyze, build_plots, collect_all_states) 288 if is_submitted() and args_count > 1: 289 state = qnstate.read() --> 290 result = strategy_wrap(data, state) 291 result, state = unpack_result(result) 292 ~/book/qnt/backtester.py in <lambda>(d, s) 268 269 args_count = len(inspect.getfullargspec(strategy).args) --> 270 strategy_wrap = (lambda d, s: strategy(d)) if args_count < 2 else strategy 271 272 # --- <ipython-input-33-b67077d72c3d> in strategy(data) 19 stoch_k = qnta.stochastic_k(high, low, close, 14) 20 ---> 21 if stoch_k>30 : 22 weights = 1 23 elif stoch_k<80 : /usr/local/lib/python3.7/site-packages/xarray/core/common.py in __bool__(self) 127 128 def __bool__(self: Any) -> bool: --> 129 return bool(self.values) 130 131 def __float__(self: Any) -> float: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
-
WARNING! The data type and the competition type are mismatch.
I had tried to follow the documentation. and develop a really easy strategy to test out the function of the platform. it simply do a long position when volume in this hour>volume in previous hour but get the following error
import xarray as xr import qnt.ta as qnta import qnt.backtester as qnbt import qnt.data as qndata def load_hourdata(period): return qndata.crypto.load_data(tail = 365 * 5) def strategy(data): crypto_data = qndata.crypto.load_data( tail = 365 * 5) BTC_vol = crypto_data.sel(field = 'vol').sel(asset = 'BTC') BTC_past_vol= qnta.shift(BTC_vol, periods=1) weights = xr.where(BTC_vol > BTC_past_vol, 1, -1) # 1 - long position (**buy**), -1 - short position (**sell**) return weights weights = qnbt.backtest( competition_type= "crypto_daily_long_short", load_data= load_data, lookback_period= 365*4, start_date= "2014-01-01", strategy= strategy, analyze= True, build_plots= True )
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-19-dcf17b33384f> in <module> 29 strategy= strategy, 30 analyze= True, ---> 31 build_plots= True 32 ) ~/book/qnt/backtester.py in backtest(competition_type, strategy, load_data, lookback_period, test_period, start_date, end_date, window, step, analyze, build_plots, collect_all_states) 293 log_info("Load data for cleanup...") 294 data = qndata.load_data_by_type(competition_type, assets=result.asset.values.tolist(), tail=60) --> 295 result = qnout.clean(result, data) 296 result.name = competition_type 297 log_info("Write result...") ~/book/qnt/output.py in clean(output, data, kind, debug) 66 # uniq asset fix 67 val,idx = np.unique(output.asset, return_index=True) ---> 68 output = output.isel(asset=idx) 69 70 if single_day: /usr/local/lib/python3.7/site-packages/xarray/core/dataarray.py in isel(self, indexers, drop, missing_dims, **indexers_kwargs) 1145 # lists, or zero or one-dimensional np.ndarray's 1146 -> 1147 variable = self._variable.isel(indexers, missing_dims=missing_dims) 1148 1149 coords = {} /usr/local/lib/python3.7/site-packages/xarray/core/variable.py in isel(self, indexers, missing_dims, **indexers_kwargs) 1130 indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "isel") 1131 -> 1132 indexers = drop_dims_from_indexers(indexers, self.dims, missing_dims) 1133 1134 key = tuple(indexers.get(dim, slice(None)) for dim in self.dims) /usr/local/lib/python3.7/site-packages/xarray/core/utils.py in drop_dims_from_indexers(indexers, dims, missing_dims) 838 if invalid: 839 raise ValueError( --> 840 f"Dimensions {invalid} do not exist. Expected one or more of {dims}" 841 ) 842 ValueError: Dimensions {'asset'} do not exist. Expected one or more of ('time',)