Navigation

    Quantiacs Community

    • Register
    • Login
    • Search
    • Categories
    • News
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Stocks strategy

    Strategy help
    3
    4
    392
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      spancham last edited by spancham

      Hi @support
      I saw an example where we could load stock data. Not sure if it's current or legacy.
      Anyway, I tried a simple stocks strategy just to continue learning the platform and got an error:

      ValueError: indexes along dimension 'time' are not equal
      
      

      Here is the code, I tried to follow what you had suggested for another strategy (the pairs one):

      import numpy as np
      import pandas as pd
      import qnt.data as qndata
      import qnt.backtester as qnbk
      import xarray as xr
      
      long_threshold = 600
      short_threshold = 300
      
      def load_data(period):
          data = qndata.stocks_load_data(tail=period)
          return data
      
      def single_pass_strategy(data):
          tclose = data.sel(field='close')
          yclose = data.sel(field='close').shift(time=1)
          
          tt = tclose.isel(time=-1)
          yt = yclose.isel(time=-1)
          
          uptoday = list(tt > yt).count(True)
      
          if uptoday > long_threshold:
              return xr.where(tt > yt, 1, 0)
          elif uptoday < short_threshold:
              return xr.where(tt < yt, -1, 0)
          else:
              return xr.where(tt,0,0)
      
      weights = qnbk.backtest(
                  competition_type="stocks",
                  load_data=load_data,
                  lookback_period= 4*365,
                  start_date= "2017-01-01",
                  strategy=single_pass_strategy
      )
      

      Do you mind taking a look and advise how I can get it to run?
      Thanks again for all your help.

      support 1 Reply Last reply Reply Quote 0
      • support
        support @spancham last edited by

        @spancham it is nor current, nor legacy, it is a leftover of an experiment, we are adding new instruments in addition to futures and crypto and testing them, please be patient for stocks. The logic will not change respect to futures or cryptos. Just more instruments and some details (dividends and splits).

        S 1 Reply Last reply Reply Quote 0
        • S
          Sheikh @support last edited by

          @support
          How are you guys coming along with the Equity data?
          Thanks.
          Sheikh

          support 1 Reply Last reply Reply Quote 0
          • support
            support @Sheikh last edited by

            @sheikh Hi, when it comes to stocks and historical simulations, the biggest issue is dealing with survivorship bias. The stock universe must include also stocks which have been delisted and we need to define trading rules which allow for trading instruments which make sense at each point in time. This week we are announing a new contest which is preparing the ground for stocks.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB | Contributors
            • Documentation
            • About
            • Career
            • My account
            • Privacy policy
            • Terms and Conditions
            • Cookies policy
            Home
            Copyright © 2014 - 2021 Quantiacs LLC.
            Powered by NodeBB | Contributors