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',)
-
@noka-sworld Hello, we should definitely improve the documentation. When you use the "load_crypto" API you are loading data on an hourly basis. This is a functionality we provided some time ago when introducing cryptos (7 cryptos only).
Later we extended the crypto universe to more assets, and provided a universe containing the top 10 in terms of market capitalization at each point in time, and reverted to daily data.
The API to be used is:
import qnt.data as qndata crypto_data = qndata.cryptodaily.load_data(tail = 365 * 5)
It will load crypto data on a daily basis and the code will not bug.