Skip to content
All library documents

Fixing a Stock List Attribute Error in a Backtest Strategy

Article BigQuant

Summary

This BigQuant forum entry addresses an error caused by referencing a locally created stock list as though it were an attribute of the backtest context. Its central correction is to use the variable where it was defined, without the context prefix, unless the list has explicitly been stored on that object. The example shows a daily stock strategy that builds candidate and held-stock lists, reads adjusted price history, calculates K, D, and J values, and places or exits orders based on indicator and price conditions.

The code illustrates a possible implementation pattern, but it is not a validated strategy or a reliable template as presented. It contains repeated, lengthy code and apparent issues in list construction and data handling, while offering no performance evidence. The useful lesson is narrowly about Python variable scope and object attributes in the platform's backtest callbacks. The indicator logic and portfolio sizing shown should be reviewed independently before any use.

Key ideas

  • A locally defined variable is not automatically an attribute of the backtest context object.
  • The reported fix is to reference the stock list by its local variable name unless it was stored on the context.
  • The example calculates a KDJ-style indicator from historical stock prices and uses it in order decisions.
  • The posted code contains implementation complexities and has no backtest evidence establishing its effectiveness.
  • Portfolio allocation and indicator conditions require independent review before practical use.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.