Posts made by darwinps
-
WARNING: Strategy trades non-liquid assets.
Hi
I am confused why the warning for trading non-liquid assets appears in the second scenario.
First scenario (no warning):
def strategy(data): close = spx_data.sel(field='close') rsi = qnt.ta.rsi(close, 14) rsi = qnt.ta.shift(rsi, periods=1) weights = xarray.where(rsi < 30, 1, 0) + xarray.where(rsi > 70, -1, 0) return weights weights = strategy(spx_data) is_liquid = spx_data.sel(field='is_liquid') weights = weights * is_liquid weights = qnt.output.clean(weights, spx_data, 'stocks_nasdaq100') stats = qnt.stats.calc_stat(spx_data, weights)
Second scenario (warning shows up):
def strategy(data): close = spx_data.sel(field='close') rsi = qnt.ta.rsi(close, 14) rsi = qnt.ta.shift(rsi, periods=1) weights = xarray.where(rsi < 30, 1, 0) + xarray.where(rsi > 70, -1, 0) filter = qnt.filter.filter_volatility_rolling(weights=weights, data=data, rolling_window=60, top_assets=20, metric='std', ascending=True) weights = weights * filter return weights weights = strategy(spx_data) is_liquid = spx_data.sel(field='is_liquid') weights = weights * is_liquid weights = qnt.output.clean(weights, spx_data, 'stocks_nasdaq100') stats = qnt.stats.calc_stat(spx_data, weights)
Since the 'is_liquid' is applied after the weights are calculated, shouldn't there be no warning?
Thank you in advance
regards
-
RE: single pass and multipass discrepancy
Hi @stefanm ,
How reckless of me, "data" should have been f_es_data. They are perfectly synced now.
Thank you so much. I really appreciate the help.sincerely
-
RE: single pass and multipass discrepancy
Hi @stefanm
Thank you for your detailed explanation
To be honest, I did think about the initialization period. But I added the extra (earlier) period for all data, not only for 'F_ES' as in the example (which should not matter?).
By the way, I used 'illegal' hand-picked single asset (as well as the trivial strategy) just to simplify the case.
Thanks for pointing out the opposite shift direction. It's a habit from different language (mql5).
I copied pasted the codes you modified; I still don't get the same results.
I only changed:
weights = strategy(f_es_data)
to
close = data.sel(field='close') close_one_day_ago = qnta.shift(close, periods=1) _open = data.sel(field='open') open_one_day_ago = qnta.shift(_open, periods=1) weights = xr.where(open_one_day_ago < close_one_day_ago, 1, 0)
kind regards
-
single pass and multipass discrepancy
Hi
I have been trying to write a simple example with both single pass and multi pass just to understand them better. But I can't get them to produce the same result. Here is what I use:single pass version:
import xarray as xr import qnt.ta as qnta import qnt.data as qndata data = qndata.futures_load_data(min_date='2006-01-01', max_date='2007-01-01', assets= ['F_ES']) close = data.sel(field='close') close_one_day_ago = qnta.shift(close, periods=1) _open = data.sel(field='open') open_one_day_ago = qnta.shift(_open, periods=1) weights = xr.where(open_one_day_ago < close_one_day_ago, 1, 0)
The result looks like the following.
multi pass version:
import xarray as xr import qnt.ta as qnta import qnt.backtester as qnbt import qnt.data as qndata def load_data(period): return qndata.futures_load_data(tail=period, assets=['F_ES']) def strategy(data): close = data.sel(field='close') close_one_day_ago = qnta.shift(close, periods=1) _open = data.sel(field='open') open_one_day_ago = qnta.shift(_open, periods=1) weights = xr.where(open_one_day_ago < close_one_day_ago, 1, 0) return weights weights = qnbt.backtest( competition_type= 'futures', load_data= load_data, lookback_period= 365, start_date= '2006-01-01', end_date= '2007-01-01', strategy= strategy )
The result look like the following.
Any help/hint/suggestion is greatly appreciated.