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

Multiple assets backtest using bt



  • Hello,
    Thanks for the great project!
    I have optimized weights for multiple assets and would like to backtest with monthly rebalancing. Any suggestions on how to proceed with backtesting with bt? Let me give an example on how to do this using zipline

    def initialize(context):
        context.securities = {
                            'AAPL': 0.25, 
                            'ABBV': 0.3, 
                            'ABC': 0.3, 
                            'CAT': 0.075, 
                            'CSCO': 0.075
        }
        schedule_function(rebalance, date_rules.month_start(), time_rules.market_open())
    
    def rebalance(context, data):
        # Loop through the securities
        for sec, weight in context.securities.items():
            sym = symbol(sec)
            if data.can_trade(sym):
                # Reset the weight
                order_target_percent(sym, weight)
    

    Appreciate any help!!



  • Have a look at this article and see if it helps.


Log in to reply
 

});