Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Check Market Trading Day

    General Code/Help
    2
    5
    1269
    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.
    • C
      cwse last edited by

      Hi,

      How can I check the current market trading day in the next() loop?

      Should i add the market index (say "XJO") to the data feed, then in the next() statement, as I loop over my many datafeeds, have something like this if I were to only consider buys/sells on a MONDAY?:

      weekday = self.data['XJO'].datetime.date().isoweekday()
      if weekday == 1:
          ...assess stocks...
      

      Thanks again for your help!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        isoweekday Python 2 Docs - datetime - isoweekday returns 1 as Monday, so it would be the value to check.

        1 Reply Last reply Reply Quote 0
        • C
          cwse last edited by

          @backtrader thanks but I am wanting to know if the self.data['XJO']...is the way to go if I want to use a market index data freed called 'XJO' as the date reference point?

          B 1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @cwse last edited by

            That depends if you have put a dict with the asset in the key XJO under self.data. You would be overwriting one of the automatically created references (in this case to self.datas[0]), but it is up to the developer to do so if wished.

            If not, then see getdatabyname

            • Docs - Strategy Reference
            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by

              Check out also this thread where a discussion on the same topic on access by name has also started: Community - Multi-asset ranking and rebalancing

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }