Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. samk
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    S
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 43
    • Best 0
    • Controversial 0
    • Groups 0

    samk

    @samk

    0
    Reputation
    1413
    Profile views
    43
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    samk Unfollow Follow

    Latest posts made by samk

    • RE: How can I construct matrix of returns for 4 stocks

      @backtrader

      I am trying:

      X = ret_1m_mat.join(ret_3m_mat).join(ret_6m_mat).join(ret_12m_mat).dropna()

      However, getting error saying:

      AttributeError: 'list' object has no attribute 'join'

      Thanks for the help in advance as always..........

      posted in Indicators/Strategies/Analyzers
      S
      samk
    • RE: How can I construct matrix of returns for 4 stocks

      Also, I want to set the name of this giant Matrix that is combined from these 4 lines of code to 'X'............

      posted in Indicators/Strategies/Analyzers
      S
      samk
    • RE: How can I construct matrix of returns for 4 stocks

      @backtrader said in How can I construct matrix of returns for 4 stocks:

      ret_1m_mat = [x[0] for x in self.rets_1m]

      Hello there,

      Thanks for the response. Much appreciated. Ok so for the second part, to create the individual matrices, I continued your logic and have:

       # combine 1 month, 3 month, 6 month, and 12 month returns into one matrix
              ret_1m_mat = [x[0] for x in self.rets_1m]
              ret_3m_mat = [x[0] for x in self.rets_3m]
              ret_6m_mat = [x[0] for x in self.rets_6m]
              ret_12m_mat = [x[0] for x in self.rets_12m]
      

      My question is, how would I now go about in combining all of the 4 lines of code above into one giant matrix by joining them all together?

      Thanks in advance for all the help as always!

      Sam

      posted in Indicators/Strategies/Analyzers
      S
      samk
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      @Ed-Bartosh

      I did that. This is what I get:

      C:\Users\Sam>python -c "import ccxt; print(getattr(ccxt, 'gemini'))"
      Traceback (most recent call last):
      File "<string>", line 1, in <module>
      ImportError: No module named ccxt

      Keep in mind, this is after this was completed too:

      C:\Users\Sam>pip install git+https://github.com/bartosh/backtrader.git@ccxt
      Collecting git+https://github.com/bartosh/backtrader.git@ccxt
      Cloning https://github.com/bartosh/backtrader.git (to ccxt) to c:\users\sam\appdata\local\temp\pip-merrrk-build
      Installing collected packages: backtrader
      Running setup.py install for backtrader ... done
      Successfully installed backtrader-1.9.59.122

      Which is very odd because I have already pip installed and imported ccxt.......

      posted in General Discussion
      S
      samk
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      @Ed-Bartosh

      So I went ahead again and gave a crack at it trying to install using:

      pip install git+https://github.com/bartosh/backtrader.git@ccxt

      Here is what went into command line:

      C:\Users\Sam>pip install git+https://github.com/bartosh/backtrader.git@ccxt
      Collecting git+https://github.com/bartosh/backtrader.git@ccxt
      Cloning https://github.com/bartosh/backtrader.git (to ccxt) to c:\users\sam\appdata\local\temp\pip-merrrk-build
      Installing collected packages: backtrader
      Running setup.py install for backtrader ... done
      Successfully installed backtrader-1.9.59.122

      Now, my question is, looks like it was cloned to the directory:

      c:\users\sam\appdata\local\temp\pip-merrrk-build

      However, I work my python environment in:

      c:\users\sam\anaconda64best\

      Am I having an issue Ed because I need to copy everything from the first directory to my Python working directory? Then it should work?

      Thanks for the help.........

      posted in General Discussion
      S
      samk
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      @Ed-Bartosh

      Thank you I found it. Instead of cloning github, which obviously caused me many issues, I have went ahead and saved the files from your github manually. These files being 'ccxtbroker.py' (which holds the class CCXTBroker) and 'ccxt.py' (which holds the class CCXT ).

      I am receiving an error however saying:

      ***Traceback (most recent call last):
      File "C:/Users/Sam/PycharmProjects/Test/.ipynb_checkpoints/Crypto Backtrader Algorithm Using CCXT Broker & Gemini.py", line 71, in <module>
      sys.exit(runstrategy(sys.argv))
      File "C:/Users/Sam/PycharmProjects/Test/.ipynb_checkpoints/Crypto Backtrader Algorithm Using CCXT Broker & Gemini.py", line 51, in runstrategy
      broker = ccxtbroker.CCXTBroker(exchange='gemini', currency='USD', config=broker_config)
      File "C:\Users\Sam\Anaconda64Best\lib\site-packages\backtrader\metabase.py", line 88, in call
      _obj, args, kwargs = cls.doinit(_obj, *args, **kwargs)
      File "C:\Users\Sam\Anaconda64Best\lib\site-packages\backtrader\metabase.py", line 78, in doinit
      _obj.init(args, kwargs)
      File "C:\Users\Sam\PycharmProjects\Test.ipynb_checkpoints\ccxtbroker.py", line 42, in init
      self.exchange = getattr(ccxt, exchange)(config)
      AttributeError: module 'ccxt' has no attribute 'gemini'

      Curious on why this may be happening? My full code is pasted below for reference. Thanks Ed.

      Code:

      from __future__ import (absolute_import, division, print_function,
                              unicode_literals)
      
      from datetime import datetime, timedelta
      import os.path  # To manage paths
      import sys  # To find out the script name (in argv[0])
      
      import ccxtbroker
      import ccxt
      import backtrader as bt
      
      # Import the backtrader platform
      import backtrader as bt
      import backtrader.feeds as btfeeds
      import datetime  # For datetime objects
      import argparse
      import time
      import backtrader.analyzers as btan
      from backtrader import Analyzer
      import math
      import numpy as np
      import datetime
      
      class TestStrategy(bt.Strategy):
          def next(self):
              for data in self.datas:
                  print('*' * 5, 'NEXT:', bt.num2date(data.datetime[0]), data._name, data.open[0], data.high[0],
                        data.low[0], data.close[0], data.volume[0],
                        bt.TimeFrame.getname(data._timeframe), len(data))
                  if not self.getposition(data):
                      order = self.buy(data, exectype=bt.Order.Limit, size=10, price=data.close[0])
                  else:
                      order = self.sell(data, exectype=bt.Order.Limit, size=10, price=data.close[0])
      
          def notify_order(self, order):
              print('*' * 5, "NOTIFY ORDER", order)
      
      def runstrategy(argv):
          # Create a cerebro
          cerebro = bt.Cerebro()
      
          # Create broker
          broker_config = {'urls': {'api': 'https://api.sandbox.gemini.com'},
                           'apiKey': '<42o4kPgIwkYTyqKdrMD4>',
                           'secret': '<2hi9U3Md3ahMVeTDqfRPXzCebS38>',
                           'nonce': lambda: str(int(time.time() * 1000))
                          }
          broker = ccxtbroker.CCXTBroker(exchange='gemini', currency='USD', config=broker_config)
          cerebro.setbroker(broker)
      
          # Create data feeds
          data_ticks = ccxt.CCXT(exchange='gdax', symbol='BTC/USD', name="btc_usd_tick",
                                     timeframe=bt.TimeFrame.Ticks, compression=1)
          cerebro.adddata(data_ticks)
      
          hist_start_date = datetime.utcnow() - timedelta(minutes=30)
          data_min = ccxt.CCXT(exchange="gdax", symbol="BTC/USD", name="btc_usd_min",
                                   timeframe=bt.TimeFrame.Minutes, fromdate=hist_start_date)
          cerebro.adddata(data_min)
      
          # Add the strategy
          cerebro.addstrategy(TestStrategy)
      
          # Run the strategy
          cerebro.run()
      
      if __name__ == '__main__':
          sys.exit(runstrategy(sys.argv))
      
      posted in General Discussion
      S
      samk
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      @Ed-Bartosh

      I am on your page here:

      https://github.com/bartosh/backtrader/tree/master/backtrader/brokers

      And I do not see any file called ccxtbroker.py, in order to identify the CCXTBroker class? I only see IB, oanda, VC, and bboker.

      Is there somewhere on your git page where I can find the ccxtbroker.py?

      Thanks......

      posted in General Discussion
      S
      samk
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      @Søren-Pallesen @Ed-Bartosh

      Guys,

      So I followed Soren's method. Created a new environment, added git, then did pip install ccxt and pip install git+https://github.com/bartosh/backtrader.git@ccxt

      Both loaded just fine.

      However when I am running the script, still getting an error:

      ModuleNotFoundError: No module named 'backtrader.brokers.ccxtbroker'

      As if it is still not reading it in my Pycharm interface. Even though everything was said to have installed ok!

      I am very confused here. the statement I am using in the file to import CCXT is:

      from backtrader.brokers.ccxtbroker import CCXTBroker

      Is this not correct maybe? Or another import line of code I am supposed to use?

      Please let me know. I really want to get this going so I can help collaborate with you guys by applying some created ML and deep learning models I have used on equities, equity options, and futures on the crypto currencies specifically. Think there may be substantial value there...........

      posted in General Discussion
      S
      samk
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      @Ed-Bartosh

      So I use conda to install git and it worked great. then I did pip install as you mentioned:

      C:\Users\Sam>pip install git+https://github.com/bartosh/backtrader.git@ccxt
      Collecting git+https://github.com/bartosh/backtrader.git@ccxt
      Cloning https://github.com/bartosh/backtrader.git (to ccxt) to c:\users\sam\appdata\local\temp\pip-yljmoz-build
      Installing collected packages: backtrader
      Running setup.py install for backtrader ... done
      Successfully installed backtrader-1.9.59.122

      So looks like it was a success. However when I run your file I am getting same error as @soren:

      C:\Users\Sam\Anaconda64Best\python.exe "C:/Users/Sam/PycharmProjects/Test/.ipynb_checkpoints/Backtrader Bitcoin Algorithm.py"
      Traceback (most recent call last):
      File "C:/Users/Sam/PycharmProjects/Test/.ipynb_checkpoints/Backtrader Bitcoin Algorithm.py", line 68, in <module>
      sys.exit(runstrategy(sys.argv))
      File "C:/Users/Sam/PycharmProjects/Test/.ipynb_checkpoints/Backtrader Bitcoin Algorithm.py", line 48, in runstrategy
      broker = bt.brokers.CCXTBroker(exchange='gemini', currency='USD', config=broker_config)
      AttributeError: module 'backtrader.brokers' has no attribute 'CCXTBroker'

      Do we need to import something at the top? Because using:

      import backtrader.brokers.ccxtbroker

      seems to do nothing. Please let me know.......Thanks Ed..

      posted in General Discussion
      S
      samk
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      @Ed-Bartosh

      I even tried to run

      pip install git+https://github.com/bartosh/backtrader.git@ccxt

      after changing to directory that I saved git in which is: C:\Users\Sam\Anaconda64Best

      But still getting the same error.......

      C:\Users\Sam\Anaconda64Best\Lib\site-packages\backtrader>cd C:\Users\Sam\Anaconda64Best

      *************C:\Users\Sam\Anaconda64Best>pip install git+https://github.com/bartosh/backtrader.git@ccxt

      Collecting git+https://github.com/bartosh/backtrader.git@ccxt
      Cloning https://github.com/bartosh/backtrader.git (to ccxt) to c:\users\sam\appdata\local\temp\pip-al_ctv-build
      Error [Error 2] The system cannot find the file specified while executing command git clone -q https://github.com/bartosh/backtrader.git c:\users\sam\appdata\local\temp\pip-al_ctv-build
      Cannot find command 'git'*************

      posted in General Discussion
      S
      samk