Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. backtrader
    B
    • Flag Profile
    • Block User
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    backtrader

    @backtrader

    administrators

    427
    Reputation
    2589
    Posts
    13351
    Profile views
    32
    Followers
    0
    Following
    Joined Last Online
    Website community.backtrader.com

    backtrader Follow
    administrators

    Posts made by backtrader

    • RE: linear regression and std #211

      Yes, that code is terribly wrong. The assignment of a bt.indicators.SMA instance to spread_mean[0] which is in an array.array of type d (aka double or float in Python) is bound to fail each an every time.

      Lines objects (Indicators et al.) are meant to be instantiated during __init__.

      posted in Indicators/Strategies/Analyzers
      B
      backtrader
    • RE: linear regression and std #211

      There may be two ways for it, which may be used simultaneously or not:

      • Using a category in the forum for user examples/contributed code

      • Creating a pull request in the main repository https://github.com/mementum/backtrader

        There could be also a contrib package with for example the following sub-packages:

        • indicators
        • strategies
        • analyzers
        • observers
      posted in Indicators/Strategies/Analyzers
      B
      backtrader
    • RE: linear regression and std #211

      Plotting options are detailed here: https://www.backtrader.com/docu/plotting/plotting.html

      posted in Indicators/Strategies/Analyzers
      B
      backtrader
    • RE: Limit order with a day valid never gets executed? #220

      The default mode of the broker unless you say otherwise with a defined comission scheme is to work with stock-like products.

      In this scenario when you sell something you get cash from the action of selling that something. It is difficult to get a margin call if you are getting cash injected.

      When you buy cash is detracted from your account. Your description doesn't indicate what your stake is and how much cash you have configured the broker with (the default is 10000). Without code and details one cannot say what's going wrong.

      posted in General Code/Help
      B
      backtrader
    • RE: linear regression and std #211

      The problem with the snippet being that pd.ols chokes on regular Python array-like structures (array.array, list, etc) needing pandas specific structures.

      The adapted and working code

      class OLS_Beta(bt.indicators.PeriodN):
          _mindatas = 2  # ensure at least 2 data feeds are passed
          lines = (('beta'),)
          params = (('period', 30),)
      
          def next(self):
              y, x = (pd.Series(d.get(size=self.p.period)) for d in self.datas)
              r_beta = pd.ols(y=y, x=x, window_type='full_sample')
              self.lines.beta[0] = r_beta.beta['x']
      
      

      In which the values from the dataX feeds is put into a pd.Series instance. There is, imho, no need to use a rolling operation because pd.ols only receives the needed data each time (the latest available data).

      The same concept can be applied other pandas operations and I guess to the code ported over to statsmodel

      posted in Indicators/Strategies/Analyzers
      B
      backtrader
    • RE: Limit order with a day valid never gets executed? #220

      The snippet above is meant to have the order expiring at the end of the next day, which was your use case above. As such the order will obviously be expired for the third day. To have the order still active, you would need to add extra days to the datetime.timedelta.

      If your operational plan for live trading includes having the orders expire after x days, you are going to have to deal with trading calendars yourself.

      There may be brokers which offer something like: VALID FOR THE NEXT 3 TRADING SESSIONS, which in theory would skip bank holidays and weekends. If you know of such a broker, just post it here.

      posted in General Code/Help
      B
      backtrader
    • RE: Preserving a linebuffer type in assignment

      This is a non-expected usage pattern and for sure one which is not going to work.

      LineBuffer is an internal object which is not meant for user consumption. And of course self.dval1 is turning into a float, you are assigning a float to the member attribute you created yourself.

      This is not the same as self.lines.xxx = yyy during the __init__ phase, because in that case self.lines is an object, and xxx is constructed by means of Descriptors, which allows controlling things like assignment (via __set__). But assignment cannot be controlled on a member attribute you have created.

      The use case is actually a lot easier:

      def __init__(self):
          self.dval1 = bt.ind.Lowest(self.data.low, period=10)  # or bt.ind.MinN(self.data.low, period=10)
      
      def next(self):
          print('the current lowest value is:', self.dval1[0])
      

      The indicator family is big and tries to cover all possible aspects

      • http://www.backtrader.com/docu/indautoref.html
      posted in Indicators/Strategies/Analyzers
      B
      backtrader
    • RE: linear regression and std #211

      Those were typed snippets no actual tested code. The actual line which produced the error would be helpful in understanding what part of the snippet is trying to iterate a builtin_function_or_method

      posted in Indicators/Strategies/Analyzers
      B
      backtrader
    • Release 1.9.19.105

      This was a quick update to introduce some errors introduced in plotting with the improvements added in 1.9.18.105, which didn't cover all the cases for overlay volume plotting and the display of the legend in the charts.

      There is also a new functionality to be able to compare a line against a datetime.time object, which should aid in creating comparisons for signals/indicators in __init__ rather than having to do a manual if comparison in next

      The changelog

      1.9.19.105

      • Add time comparison for single line operations
      • Correct plotting error calculations with volume and improve data on data
      • Remove cosmetic comma from new gold-vs-sp500 sample
      posted in Announcements
      B
      backtrader
    • Release 1.9.18.105

      This is a minor release adding some extra plot capabilities, some checks in order validity input and a pull request to correct the parameter candleFormat in the Oanda data feed. The changelog:

      1.9.18.105

      • PR #221 Correct onda candleFormat parameter
      • Allow data on data plotting and no data plotting
      • Remove double labeling on indicators
      • Analyzer LogReturnsRolling
      • Observer LogReturns
      • Improved order management of input for validity
      • Set default end date for online downloads in Yahoo if not set
      • Gold vs SP500 Sample

      The plotting changes come with an associated blog post (there is the motivation for the changes).

      • https://www.backtrader.com/blog/posts/2016-12-13-gold-vs-sp500/gold-vs-sp500.html
      posted in Announcements
      B
      backtrader
    • 1
    • 2
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 256 / 259