Backtrader Community

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

    randietrades

    @randietrades

    2
    Reputation
    2
    Profile views
    4
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    randietrades Unfollow Follow

    Best posts made by randietrades

    • bta-lib adx() => Error (??!)

      Hi there. I'm having trouble getting bta-lib's adx() to work. Would greatly appreciate any help I can get from this group.

      Here's a small piece of code that demonstrates the problem, and below the code is the output I get from running it.

      C O D E:
      https://gist.github.com/randie/5cac0dbf845b8b323a311ed32abea2c7

      import pandas as pd
      import btalib as bta
      
      df = pd.read_csv("data/tickers/AMD.csv", parse_dates=True, index_col='Date')
      
      df['rsi'] = bta.rsi(df).df  # works
      df['adx'] = bta.adx(df).df  # does not work
      
      print(df.tail())
      

      O U T P U T:

      #
      # Output with adx() line commented out => works
      #
      (sandbox) 10:38 • screener • master • d5822cb ✗
      ❯ /opt/anaconda3/envs/sandbox/bin/python /Users/randie/projects/screener/bta-adx.py
                       Open       High        Low      Close  Adj Close    Volume        rsi
      Date                                                                                  
      2021-03-19  78.489998  79.339996  77.589996  79.059998  79.059998  42247100  42.284132
      2021-03-22  79.989998  81.269997  79.220001  80.300003  80.300003  39648600  44.939105
      2021-03-23  80.129997  80.339996  77.949997  78.379997  78.379997  40466600  41.737588
      2021-03-24  77.550003  78.800003  76.400002  76.480003  76.480003  43753600  38.792404
      2021-03-25  75.849998  76.949997  74.959999  76.220001  76.220001  44663000  38.393151
      
      #
      # Output with adx() line back in => does not work!
      #
      (sandbox) 10:38 • screener • master • d5822cb ✗
      ❯ /opt/anaconda3/envs/sandbox/bin/python /Users/randie/projects/screener/bta-adx.py
      Traceback (most recent call last):
        File "/Users/randie/projects/sandbox/python/screener/adx.py", line 8, in <module>
          df['adx'] = bta.adx(df).df  # does not work
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicator.py", line 152, in __call__
          b_init(self, *args, **kwargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicators/directionalmove.py", line 97, in __init__
          self._pdm = self._smoother(pdm, **smoothargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicator.py", line 152, in __call__
          b_init(self, *args, **kwargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicators/directionalmove.py", line 52, in __init__
          self.o.smacc = _ewm._lfilter(alpha=1.0, beta=(p - 1) / p)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/meta/lines.py", line 343, in _lfilter
          return self._apply(_sp_lfilter)  # trigger __getattr__ for _apply
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/meta/lines.py", line 379, in call_op
          result[self._minidx:] = r = op(*sargs, **kwargs)  # run/store
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 469, in _apply
          return self._apply_blockwise(homogeneous_func, name)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 384, in _apply_blockwise
          return self._apply_series(homogeneous_func, name)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 373, in _apply_series
          result = homogeneous_func(values)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 461, in homogeneous_func
          result = calc(values)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 455, in calc
          return func(x, start, end, min_periods)
      TypeError: _sp_lfilter() takes 1 positional argument but 4 were given
      
      posted in bta-lib
      randietrades
      randietrades
    • RE: bta-lib adx() => Error (??!)

      @run-out I found the library version incompatibility! I was running with numpy v1.20.1, the latest version. I installed an older version, the version of numpy available right around when btalib v1.0.0 was released, numpy v1.18.2. It worked 🙌🏼 So that means bta-lib needs to be updated to work with the latest versions of pandas and numpy.

      Thanks again for taking the time to work this out with me 👍🏼🌷

      Here's my output now:

      (sandbox) 13:13 • screener • master • d5822cb ✗
      ❯ python bta-adx.py
      numpy v1.18.2
      pandas v1.0.4
      btalib v1.0.0
                       Open       High        Low  ...    Volume        rsi        adx
      Date                                         ...
      2021-03-22  79.989998  81.269997  79.220001  ...  39648600  44.939105  26.393616
      2021-03-23  80.129997  80.339996  77.949997  ...  40466600  41.737588  26.112061
      2021-03-24  77.550003  78.800003  76.400002  ...  43753600  38.792404  26.252038
      2021-03-25  75.849998  76.949997  74.959999  ...  44735100  38.393151  26.729348
      2021-03-26  76.620003  77.500000  75.029999  ...  49109400  41.367524  26.915669
      
      [5 rows x 8 columns]
      
      posted in bta-lib
      randietrades
      randietrades

    Latest posts made by randietrades

    • RE: bta-lib adx() => Error (??!)

      @run-out I found the library version incompatibility! I was running with numpy v1.20.1, the latest version. I installed an older version, the version of numpy available right around when btalib v1.0.0 was released, numpy v1.18.2. It worked 🙌🏼 So that means bta-lib needs to be updated to work with the latest versions of pandas and numpy.

      Thanks again for taking the time to work this out with me 👍🏼🌷

      Here's my output now:

      (sandbox) 13:13 • screener • master • d5822cb ✗
      ❯ python bta-adx.py
      numpy v1.18.2
      pandas v1.0.4
      btalib v1.0.0
                       Open       High        Low  ...    Volume        rsi        adx
      Date                                         ...
      2021-03-22  79.989998  81.269997  79.220001  ...  39648600  44.939105  26.393616
      2021-03-23  80.129997  80.339996  77.949997  ...  40466600  41.737588  26.112061
      2021-03-24  77.550003  78.800003  76.400002  ...  43753600  38.792404  26.252038
      2021-03-25  75.849998  76.949997  74.959999  ...  44735100  38.393151  26.729348
      2021-03-26  76.620003  77.500000  75.029999  ...  49109400  41.367524  26.915669
      
      [5 rows x 8 columns]
      
      posted in bta-lib
      randietrades
      randietrades
    • RE: bta-lib adx() => Error (??!)

      @run-out Thanks again for responding 👍🏼

      I tried pandas v1.0.4 (the version that worked for you), but some other error came up 🤨 This time the error looks like it's in numpy- what version of numpy is installed in your venv? Mine is v1.20.1.

      Here's my output:

      (sandbox) 11:47 • screener • master • d5822cb ✗
      ❯ python
      Python 3.8.8 (default, Feb 24 2021, 13:46:16)
      [Clang 10.0.0 ] :: Anaconda, Inc. on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import btalib
      >>> btalib.__version__
      '1.0.0'
      >>> import pandas as pd
      >>> pd.__version__
      '1.0.4'
      >>> df = pd.read_csv("data/tickers/AMD.csv", parse_dates=True, index_col='Date')
      >>> adx = btalib.ADX(df).df
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicator.py", line 152, in __call__
          b_init(self, *args, **kwargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicators/directionalmove.py", line 92, in __init__
          upmove = self.i.high.diff(periods=self.p._period)  # can apply diff
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/meta/lines.py", line 140, in real_standard_op
          result = pd.Series(np.nan, index=self._series.index)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/series.py", line 305, in __init__
          data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/construction.py", line 465, in sanitize_array
          subarr = construct_1d_arraylike_from_scalar(value, len(index), dtype)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/dtypes/cast.py", line 1452, in construct_1d_arraylike_from_scalar
          subarr = np.empty(length, dtype=dtype)
      TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type
      
      posted in bta-lib
      randietrades
      randietrades
    • RE: bta-lib adx() => Error (??!)

      @run-out Thanks for your response.

      It's not a notebook thing- I am running in the terminal, not a Jupyter notebook.

      A little surprised it works in Pycharm but fails in other environments because the error is a TypeError regarding positional args which makes me think it's either a coding error or some library version incompatibility? ¯\_(ツ)_/¯

      Btw, I'm running python v3.8.8 from the Anaconda distribution. What version of python are you running? Can you post your output, the one that works in Pycharm?

      From my terminal:

      (sandbox) 20:32 • screener • master • d5822cb ✗
      ❯ hardpath $(which python)
      /opt/anaconda3/envs/sandbox/bin/python3.8
      
      (sandbox) 20:32 • screener • master • d5822cb ✗
      ❯ python bta-adx.py
      Traceback (most recent call last):
        File "bta-adx.py", line 7, in <module>
          df['adx'] = bta.adx(df).df  # does not work
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicator.py", line 152, in __call__
          b_init(self, *args, **kwargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicators/directionalmove.py", line 97, in __init__
          self._pdm = self._smoother(pdm, **smoothargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicator.py", line 152, in __call__
          b_init(self, *args, **kwargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicators/directionalmove.py", line 52, in __init__
          self.o.smacc = _ewm._lfilter(alpha=1.0, beta=(p - 1) / p)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/meta/lines.py", line 343, in _lfilter
          return self._apply(_sp_lfilter)  # trigger __getattr__ for _apply
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/meta/lines.py", line 379, in call_op
          result[self._minidx:] = r = op(*sargs, **kwargs)  # run/store
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 469, in _apply
          return self._apply_blockwise(homogeneous_func, name)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 384, in _apply_blockwise
          return self._apply_series(homogeneous_func, name)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 373, in _apply_series
          result = homogeneous_func(values)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 461, in homogeneous_func
          result = calc(values)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 455, in calc
          return func(x, start, end, min_periods)
      TypeError: _sp_lfilter() takes 1 positional argument but 4 were given
      
      posted in bta-lib
      randietrades
      randietrades
    • bta-lib adx() => Error (??!)

      Hi there. I'm having trouble getting bta-lib's adx() to work. Would greatly appreciate any help I can get from this group.

      Here's a small piece of code that demonstrates the problem, and below the code is the output I get from running it.

      C O D E:
      https://gist.github.com/randie/5cac0dbf845b8b323a311ed32abea2c7

      import pandas as pd
      import btalib as bta
      
      df = pd.read_csv("data/tickers/AMD.csv", parse_dates=True, index_col='Date')
      
      df['rsi'] = bta.rsi(df).df  # works
      df['adx'] = bta.adx(df).df  # does not work
      
      print(df.tail())
      

      O U T P U T:

      #
      # Output with adx() line commented out => works
      #
      (sandbox) 10:38 • screener • master • d5822cb ✗
      ❯ /opt/anaconda3/envs/sandbox/bin/python /Users/randie/projects/screener/bta-adx.py
                       Open       High        Low      Close  Adj Close    Volume        rsi
      Date                                                                                  
      2021-03-19  78.489998  79.339996  77.589996  79.059998  79.059998  42247100  42.284132
      2021-03-22  79.989998  81.269997  79.220001  80.300003  80.300003  39648600  44.939105
      2021-03-23  80.129997  80.339996  77.949997  78.379997  78.379997  40466600  41.737588
      2021-03-24  77.550003  78.800003  76.400002  76.480003  76.480003  43753600  38.792404
      2021-03-25  75.849998  76.949997  74.959999  76.220001  76.220001  44663000  38.393151
      
      #
      # Output with adx() line back in => does not work!
      #
      (sandbox) 10:38 • screener • master • d5822cb ✗
      ❯ /opt/anaconda3/envs/sandbox/bin/python /Users/randie/projects/screener/bta-adx.py
      Traceback (most recent call last):
        File "/Users/randie/projects/sandbox/python/screener/adx.py", line 8, in <module>
          df['adx'] = bta.adx(df).df  # does not work
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicator.py", line 152, in __call__
          b_init(self, *args, **kwargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicators/directionalmove.py", line 97, in __init__
          self._pdm = self._smoother(pdm, **smoothargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicator.py", line 152, in __call__
          b_init(self, *args, **kwargs)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/indicators/directionalmove.py", line 52, in __init__
          self.o.smacc = _ewm._lfilter(alpha=1.0, beta=(p - 1) / p)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/meta/lines.py", line 343, in _lfilter
          return self._apply(_sp_lfilter)  # trigger __getattr__ for _apply
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/btalib/meta/lines.py", line 379, in call_op
          result[self._minidx:] = r = op(*sargs, **kwargs)  # run/store
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 469, in _apply
          return self._apply_blockwise(homogeneous_func, name)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 384, in _apply_blockwise
          return self._apply_series(homogeneous_func, name)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 373, in _apply_series
          result = homogeneous_func(values)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 461, in homogeneous_func
          result = calc(values)
        File "/opt/anaconda3/envs/sandbox/lib/python3.8/site-packages/pandas/core/window/rolling.py", line 455, in calc
          return func(x, start, end, min_periods)
      TypeError: _sp_lfilter() takes 1 positional argument but 4 were given
      
      posted in bta-lib
      randietrades
      randietrades