Troubleshooting LEAN locally
Command not found
Activate the repository environment:
cd /home/hi/qrt
uv run lean --versionDocker permission denied
q.bt.lean.backtest validates Docker access before launch. This error means the Python or Jupyter process cannot open the Docker socket:
Docker is not accessible to this Python/Jupyter user
permission denied while trying to connect to the docker API at
unix:///var/run/docker.sock
Compare the socket group, the account database, and the groups active in the current process:
stat -c 'owner=%U group=%G mode=%A' /var/run/docker.sock
getent group docker
id
docker versionFor the usual root:docker socket with mode 660, the user must appear in the docker group in both getent group docker and id. If the group database contains the user but id does not, the current login predates the group change. Activating or recreating a Python virtual environment does not change Linux group membership.
VS Code Remote SSH can keep its remote server, extension host, terminals, and Jupyter kernels alive after the local window disconnects. Save all work, run Remote-SSH: Kill VS Code Server on Host…, close every connection to that host, and reconnect. Then confirm id and docker version in a new integrated terminal before starting a new kernel.
If stale sessions remain, an administrator can terminate every process for the user:
sudo loginctl terminate-user <username>This immediately disconnects all SSH sessions and stops all notebooks for that user. newgrp docker can repair one terminal temporarily, but it does not change an already-running VS Code server or Jupyter kernel.
Do not use sudo docker, start Jupyter as root, or pass credentials through the Python API. Configure Docker group or rootless access instead.
Missing algorithm parameter
An initialization error such as:
int() argument must be a string, a bytes-like object or a real number,
not 'NoneType'
usually means self.get_parameter(...) returned None. When the Python adapter receives parameters={...}, treat it as the complete runtime parameter set rather than relying on values in config.json. The SMA demo requires:
parameters={
"backtest-start": "2024-01-02",
"backtest-end": "2024-12-30",
"daily-universe-name": "sweden100",
"expected-daily-universe-members": "100",
}Read the first ERROR:: entry in the run-specific log.txt; the final PythonInitializer.Shutdown() lines are cleanup messages, not the root cause.
Multiple Python files
Pass the desired file explicitly:
uv run lean backtest demo_sma.py --no-updateDirectory mode requires main.py or Main.cs. Multiple sibling demo files do not affect lean report, which consumes JSON only.
Custom market not found
Register the market before creating any Swedish symbols:
if Market.encode("sweden") is None:
Market.add("sweden", 900)Keep ID 900 stable because it is encoded into stored SIDs and universe rows.
Market hours entry not found
Check that market-hours-database.json is valid JSON and contains the exact key:
Equity-sweden-[*]
Index constituent universes additionally need Index-sweden-[*].
No data or failed requests
Enable missing-data logs in lean.json:
"show-missing-data-logs": trueThen inspect failed-data-requests-*.txt. Common causes are:
- wrong resolution folder;
- wrong ticker casing/path;
- wrong ZIP member name;
- missing intraday quote ZIPs;
- map-file date boundaries;
- absent zero-byte universe files on requested non-session dates.
LEAN does not fall back from minute or daily requests to tick files.
Price is off by 10,000
All equity prices in native files are actual_price * 10_000, regardless of quote currency. Volumes and sizes are not scaled.
Wrong timezone
Write Stockholm-local timestamps with dataTimeZone and exchangeTimeZone set to Europe/Stockholm. Do not use a fixed UTC offset; daylight saving changes it.
Fee model rejects Sweden
The default Interactive Brokers fee model rejects unknown equity market sweden. For a format test:
security.set_fee_model(ConstantFeeModel(0))Use a Sweden-aware model for real research.
Docker-owned files
Docker may leave lean.json, output directories, or __pycache__ owned by root. The generator replaces lean.json atomically through the writable parent directory. Write report compatibility files under host-owned report-results/, not inside Docker-owned timestamp directories.
Report option errors
These are invalid:
uv run lean report --no-update
uv run lean report --backtest-results backtests/<timestamp>Use an exact JSON file and omit --no-update.
Report cannot parse market 900
This is a standalone Report-process limitation, not a template problem. Follow Generate reports and prepare a compatibility copy.
Post-backtest analyzer requests SPY
LEAN 2.5’s result analyzer unconditionally requests USA SPY daily history. The isolated generator appends synthetic SPY daily data so offline 2024 fixture runs finish cleanly. This is an analyzer workaround, not Swedish market data.
Validate a run
A robust check combines the algorithm marker, engine log, and data monitor:
LATEST=$(find backtests -mindepth 1 -maxdepth 1 -type d | sort | tail -n 1)
grep 'VERIFIED' "$LATEST/log.txt"
! grep ' ERROR::' "$LATEST/log.txt"
grep 'Failed data requests 0' "$LATEST/log.txt"