agentleFS
QuantConnectQuantConnect/Documentation/skills/python/code-quality/SKILL.md

code-quality

Skill268 starsChanged 48 days agoApache-2.0View on GitHub

Use when writing, reviewing, or refactoring QuantConnect/LEAN algorithm code for style correctness. Triggers: new algorithm code, code review, cleanup, "fix code style", "review code quality", "clean up the algorithm", redundant imports, subscription variable usage, comment format, blank-line rules, multi-line boolean layout, or catch-all error handling. Skip when only debugging runtime behavior or performance, unless the fix also changes style.

77 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use spring-boot, logging-patterns and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • ffsshhttiikkSkill

    spring-boot

    Spring Boot framework and Java enterprise patterns

    Also in 3 projects that use this

  • DIL8654Skill

    logging-patterns

    Keep logs structured, correlated, low-noise, and safe for production support. Use when adding operational logging, reviewing observability, or improving diagnostics in .NET services.

    Also in 3 projects that use this

  • mstuder-slalomSkill

    jpa-patterns

    JPA/Hibernate patterns for entity design, relationships, query optimization, transactions, auditing, indexing, pagination, and pooling in Spring Boot.

    Also in 3 projects that use this

  • ffsshhttiikkSkill

    design-patterns

    Practical application and coding skills for Design Patterns

    Also in 4 projects that use this

  • glommerSkill

    pr-workflow

    General guidelines for Commits, formatting, CI, dependencies, security

    Also in 4 projects that use this

  • vm0-aiSkill

    cli-design

    Design patterns and conventions for the Okou CLI user experience

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 5 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 71 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use AlgorithmImports for LEAN APIs and common algorithm types.

    line 14
  2. Very specific:

    Start every Python file in the project, not only main.py, with from AlgorithmImports import *.

    line 16
  3. Distinctive:

    Use x in data and x not in data, not data.contains_key(x).

    line 29
  4. Distinctive:

    Follow PEP 8: block comments start with # , use complete sentences, start sentences with capitals, and end sentences with periods.

    line 31
  5. Distinctive:

    Put and/or at the end of each continued line.

    line 41
  6. Distinctive:

    Use two blank lines before top-level classes, one blank line before methods inside classes, and no blank lines inside method bodies.

    line 56
  7. Very specific:

    Do not wrap algorithm logic in try / except blocks.

    line 58

“Common” is measured: kept by at least 6 in 10 of the 71 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

QuantConnect Algorithm Code Quality

Apply these rules to main.py and custom data classes. The goal is compiling code that does not hide real failures.

Imports

Use AlgorithmImports for LEAN APIs and common algorithm types. Do not add redundant imports for datetime, timedelta, date, pandas, numpy, or math. Put required standard library imports before AlgorithmImports, separated by one blank line.

Start every Python file in the project, not only main.py, with from AlgorithmImports import *. The algorithm class inherits only from QCAlgorithm; hold shared logic in helper objects such as self._risk = RiskHelper(self).

Subscription Variables

Store the Security returned by add_data, add_equity, or add_crypto. Pass that Security directly anywhere a Symbol is expected; do not store or use .symbol.

# Bad
self._custom_symbol = self.add_data(MyData, "TICKER").symbol
data[self._custom_btc.symbol]
# Good
self._custom_btc = self.add_data(MyData, "TICKER")
if self._custom_btc not in data:
    return
bar = data[self._custom_btc]

Use x in data and x not in data, not data.contains_key(x).

Comments

Follow PEP 8: block comments start with # , use complete sentences, start sentences with capitals, and end sentences with periods. Inline comments are rare, separated from code by at least two spaces, and start with # .

# Bad
# add equity
x = price*quantity #calculate value
# Good
# Add the equity subscription.
x = price * quantity  # Calculate the order value.

Multi-Line Boolean Expressions

Put and/or at the end of each continued line.

# Bad
if (
    close > ema_fast
    and open_ > ema_fast
    and rsi > 50):
    return
# Good
if (close > ema_fast and
    open_ > ema_fast and
    rsi > 50):
    return

Blank Lines

Use two blank lines before top-level classes, one blank line before methods inside classes, and no blank lines inside method bodies.

Error Handling

Do not wrap algorithm logic in try / except blocks. Exceptions reveal invalid state, missing data, and incorrect assumptions; catch-all handlers make bugs invisible.

# Bad
try:
    self.set_holdings(self._spy, target_weight)
except Exception:
    pass
# Good
if target_weight:
    self.set_holdings(self._spy, target_weight)

Dictionary Keys and Values

LEAN dictionaries such as self.portfolio, self.securities, and the Slice collections expose keys(), values(), and items() as methods. Call them with parentheses to iterate the collection.

for holding in self.portfolio.values():
    pass
for symbol, bar in slice.bars.items():
    pass

Checklist

  1. Standard library imports precede AlgorithmImports.
  2. Stored subscription variables are Security objects, not .symbol values.
  3. Comments follow language-specific rules.
  4. Multi-line boolean expressions follow language-specific continuation style.
  5. Blank lines match language rules.
  6. Algorithm code has no try / except; it uses explicit guards for expected conditions.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.