For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Are there any simple portfolio rebalancing strategies for reference?

  • per title

  • Don't know but it should be fairly easy (a couple of free hours during the Christmas break ... )

    def next(self):
        rebalanced_datas = sorted(self.criteria.items(), lambda data, criterion: criterion)
        l = len(rebalanced_datas)
        upper = 90
        lower = 10
        # simple weight allocation
        percents = [(upper - x * (upper - lower) / (l - 1)) / 100.0 for x in range(l)]
        # normalize the percentages
        sperc = sum(percents)
        percents = [p / sperc for p in percents]
        for data, percent in zip(rebalanced_datas, percents):
            self.order_target_percent(data, target=percent)

    The sauce is obviously in the values of the self.criteria dictionary which will probably be custom indicators which decide what the most attractive asset is.

Log in to reply

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