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

Best way to filter through a large universe of tickers?

  • I have a folder that contains a separate CSV for 4,000+ tickers, and each file name is the ticker (ex. SPY.csv) and each contain OHLC data. What would be the best way to filter through all of these tickers and return those that meet specific criteria?

    I also have a single csv that includes the joined closes for the entire universe. The first column are dates, and everything to the right is a separate ticker, below that is all the closing prices. Would this method be possible in Backtrader?


  • administrators

    There is no best way as such.

    Case 1: 4000+ tickers.

    • You load the 4000+ tickers, run your indicators on them (a single GenericCSVData would be enough for each, here the assumption is that all of them have the same format)
    • For example those with the larger positive distance: close - SimpleMovingAverage
    • You do something with the top 10 (print out the names for example)

    Case 2: 1 data feed with 4000+ price columns

    • You create an extended data feed with 4000+ lines (for example with the names close0001, close0002 ...)
    • You run individual indicators on each of the closesABCD: close0001 - bt.ind.SMA(close0001)
    • You keep the top 10 and print them out (index based for example)

    Although the 2nd case can for sure be fully automated with for loops and is probably less expensive in terms of memory and CPU, it seems not as clear as the 1st one.

Log in to reply