Group Details Private

administrators

Member List

  • RE: cerebro.resampledata() vs pandas .resample()

    Seeing how the data is actually resampled (what pandas gives you and what backtrader gives you) would seem relevant. Not only when buying and selling.

    In addition to that and since the differences you see seem to be in the transition from 2015-03-13 to 2015-03-14, it would be ideal to see how the 1-minute bars around the transition look like.

    backtrader gives you a resampled 1-day bar which is at the end of the day. The rationale behind:

    • If you mix that with a smaller timeframe, the 1-day bar is after the smaller timeframes.

    pandas is giving you a resampled data at the beginning of the day. Now you mix 2 timeframes and:

    • 2015-03-13 10:01:00 (1-minute timeframe) happens actually later than 2015-03-13 00:00:00 (1-day resampled by pandas)

    Which wouldn't really make sense.

    posted in General Code/Help
  • RE: cerebro.resampledata() vs pandas .resample()

    The following would actually help:

    • print the actual datetime and open, close prices in your next.

    Additionally

    @qwert666 said in cerebro.resampledata() vs pandas .resample():

    def notify_order():
        # ....
        if order.issell():
            self.log('SELL EXECUTED, Price: %.2f, Cost: %.2f, Comm %.2f' %
                        (order.executed.price,
                        order.executed.value,
                        order.executed.comm))
    

    Should one assume that you are checking the actual notification status before printing? (Accepted, Completed)

    Of course it is also assumed that both things are running with the same parameters and not one with cheat-on-close (or similar approach) and not the other.

    posted in General Code/Help
  • RE: Backtrader & OANDA

    v20 is not supported currently. Your example cannot work.

    posted in General Code/Help
  • RE: Base and quote currencies

    The best way seems to apply a filter to the data feed and invert the value.

    With a filter you intercept each data point and deliver it changed.

    They are easy to implement. See Docs - Filters

    To double the closing price

    class CloseDoubler(object):
        def __init__(self, data):
            pass
    
        def __call__(self, data):
            data.close[0] *= 2.0
    
    posted in General Code/Help
  • RE: Creating buy order with trailing stop and take profit. All in one

    Actually version 1.9.61.122 allows the suppression of one of the two brackets.

    See: Community - Release 1.9.61.122

    Look for the reference in the corresponding methods of the strategy: buy_bracket, sell_bracket. See: Docs - Strategy

    posted in General Code/Help
  • RE: Interested in using RSS (or similar)

    There are several libraries to track RSS feeds: https://wiki.python.org/moin/RssLibraries

    But the key issue here is how you implement the model in a trading strategy:

    • Pull

      Using some other trigger event (like a 1-minute data feed) you pull to see if a new event is available and act accordingly. This doesn't preclude background processing, in which case the pulled info will not be directly the feed but whatever you want to make out of it

    • Push

      Whenever your listening thread and processing engine detect something, you do immediately act. In this case and within the context of backtrader and using the 1-minute data feed from above, it could mean that when you act with the RSS event, your price information is, for example, 45 seconds too old. Where you are the one defining too old. It might be that you need to react with the latest info and latest price quotes to make your strategy work or that 45 seconds is an acceptable delay.

      You can of course reduce the timeframe resolution and work with 10-seconds bars to reduce the lag.

    posted in Indicators/Strategies/Analyzers
  • RE: InteractiveBrokers: No error, bar from the future, and exit

    Not enough info (at least for this brain) to really understand the setup. It seems like you might be working with assets which are outside of your timezone. Is that the case? Are timezones provided to the data feed?

    Just trying to look into how it looks like and what could have gone wrong ...

    posted in General Discussion
  • RE: Save out indicator values into a dataframe

    Indicators can be written out automatically (to the destination of your choice) with a Writer. See

    And to automatically add a writer to cerebro which writes to standard output. See

    • Docs - Cerebro

      Use cerebro = Cerebro(writer=True) or cerebro.run(writer=True)

    Indicators are by default not added to the output of writers, you need to enable it. For example

    def __init__(self):
        mysma = bt.indicators.SMA(period=15)
        mysma.csv = True
    

    As for writing the values to a DataFrame, you may pass a DataFrame as a named argument to the indicator and add the values, but taking into account that appending values to a DataFrame is a very expensive operation, you may prefer to do it at once during Strategy.stop

    def stop(self):
        myvalues = self.mysma.sma.get(size=len(self.mysma))
    

    which you can easily put into a DataFrame

    posted in Indicators/Strategies/Analyzers
  • Algotopian

    Following ideas, proposals, pushes and comments similar and disimilar to those, for example, in this post Community - What is the direction of backtrader, the last weeks have been used to craft an idea about the potential future of backtrader.

    It has been named Algotopian and it's being shared today, for review, comments, feedback. First in this community (for which a Category will be opened), because backtrader is the root of it and later in usual forums.

    Visit:

    The Whitepaper has been worked and reworked several times and this first shared version and will probably be extended with a couple of topics which are under discussion. It has been felt in any case, that the concept and feasibility of the ideas presented were mature enough.

    Other alternatives such as Patreon, Kickstarter and direct engagement have been considered, but the one presented in the paper has emerged as the winner. It may be the right choice and it may be not. This is left to people to decide.

    posted in Algotopian
  • Algotopian

    Following ideas, proposals, pushes and comments similar and disimilar to those, for example, in this post Community - What is the direction of backtrader, the last weeks have been used to craft an idea about the potential future of backtrader.

    It has been named Algotopian and it's being shared today, for review, comments, feedback. First in this community (for which a Category will be opened), because backtrader is the root of it and later in usual forums.

    Visit:

    The Whitepaper has been worked and reworked several times and this first shared version and will probably be extended with a couple of topics which are under discussion. It has been felt in any case, that the concept and feasibility of the ideas presented were mature enough.

    Other alternatives such as Patreon, Kickstarter and direct engagement have been considered, but the one presented in the paper has emerged as the winner. It may be the right choice and it may be not. This is left to people to decide.

    posted in Announcements

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.