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

Sanity testing on loaded data in BT.

  • Hello,
    I am currently writing a script to load multiple securities data and perform operations on them. Since I am loading the CSV data into BT, I wish to see all the data which is loaded, to make sure BT is correctly reading what I am passing it. Is there any way to do this.
    The reason arised because of implementation of one of the strategy,
    where I am passing cnx 200 stocks data.

    for ticker in tickers:
        data =  bt.feeds.GenericCSVData(dataname=f"G:\\{ticker}.csv",
                                fromdate=datetime(2015, 1, 1),
                                todate=datetime(2020, 7, 31),

    and defining a momentum strategy where regression slope will be calculated on rolling 90 dataclose.

    class Momentum(bt.Indicator):
        lines = ('trend',)
        params = (('period', 90),)
        #def __init__(self):
        def next(self):
            returns = np.log(
            x = np.arange(len(returns))
            #mask = ~np.isnan(x) & ~np.isnan(returns)
            slope, _, rvalue, _, _ = linregress(x, returns)
            annualized = (1 + slope) ** 252
            self.lines.trend[0] = annualized * (rvalue ** 2)

    The error which is being thrown is : ValueError: Inputs must not be empty.
    I need to know whether the data stored in cerebro is correct.

  • Is there any way to do this.

    Docs - Quick start Guide

Log in to reply