Navigation

    Quantiacs Community

    • Register
    • Login
    • Search
    • Categories
    • News
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    1. Home
    2. darwinps
    3. Posts
    D
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 7
    • Best 1
    • Groups 0
    • Blog

    Posts made by darwinps

    • RE: WARNING: Strategy trades non-liquid assets.

      Hi @support ,

      That makes perfect sense

      Thank so much

      regards

      posted in Support
      D
      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

      posted in Support
      D
      darwinps
    • 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

      posted in Support
      D
      darwinps
    • 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

      posted in Support
      D
      darwinps
    • RE: single pass and multipass discrepancy

      Dear @support

      Thank you for your confirmation

      regards

      posted in Support
      D
      darwinps
    • 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.
      singlepass.JPG

      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.
      multipass.JPG

      Any help/hint/suggestion is greatly appreciated.

      posted in Support
      D
      darwinps
    • Documentation
    • About
    • Career
    • My account
    • Privacy policy
    • Terms and Conditions
    • Cookies policy
    Home
    Copyright © 2014 - 2021 Quantiacs LLC.
    Powered by NodeBB | Contributors