Hello, all!
I'm working on writing a support library for use with Python-based algorithms in QuantConnect. Presently, I'm trying to figure out how to set up this library for testing with main.py under ‘lean backtest’, such as before distributing the support library to PyPI.
Using lean CLI, I noticed that the ‘lean backtest’ command provides an --extra-docker-config arg. I tried the following, but this doesn't appear to have mounted the corresponding docker volume:
lean backtest --extra-docker-config '{"volume_driver": "volume", "mounts": [{"Target": "/env", "Source": "env_lean", "Type": "volume", "ReadOnly": false}]}' mytest00
The value for the --extra-docker-config is from the following python code:
import docker
import json
json.dumps({"volume_driver": "volume", "mounts": [docker.types.Mount("/env", "env_lean")]})
My idea here was to create a docker volume named ‘env_lean’ then to mount this under ‘/env’ in the backtest environment. This docker volume would then be available for creating a Python virtual environment using the miniconda Python and the set of system libraries installed in the lean backtest image. I was hoping that the ‘lib’ and ‘lib64’ directories from the Python virtual environment at /env could then be used with the following in lean.json:
"python-additional-paths": [
"/env/lib",
"/env/lib64"
],
My idea was to ensure that anything installed in the virtual environment in /env would be installed using only the system libraries, along with the python implementation and system pathnames available under the backtest image. I was also hoping to be able to synchronize this with something on the docker host, ideally to simplify the testing procedure.
I'm just not certain of how to make the ‘env_lean’ docker volume available under ‘lean backtest’. So, i tried using the --extra-docker-config arg for ‘lean backtest’.
For the usage above, it does not appear to have resulted in any error message. However, it does not seem to have resulted in any docker volume being mounted at ‘/env’, the section of shell scripting above:
lean backtest --extra-docker-config '{"volume_driver": "volume", "mounts": [{"Target": "/env", "Source": "env_lean", "Type": "volume", "ReadOnly": false}]}' mytest00
Previously, I'd tried using the --extra-docker-config arg to pass certain settings to the python environment under the lean backtest, e.g `PYTHONOPTIMIZE=1'. This also does not seem to have quite worked out, though it did not result in any error message.
Could there be any documentation illustrating how to use this ‘--extra-docker-config’ arg for lean backtest? I think it could really simplify the unit testing process for Python libraries with QuantConnect, if it can be used for instance to mount a custom docker volume within the backtest environment
Mia Alissi
I recommend reaching out to QuantConnect support or engaging with the community forums. They might provide more detailed guidance or alternative approaches for setting up your testing environment. If you have any other questions or need further assistance, feel free to ask!
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Sean Champ
If docker would keep any modifications to the image's filesystem after the container is shut down, I suppose it would be possible to install within a custom Python '/env' directly within the local quantconnect lean image, instead of using an intermediate docker volume.
This ‘/env’ would then provide a Python virtual environment independent of the main Python environment available with ‘lean backtest’. The test environment could be removed at any later time, using docker, without affecting the python virtual environment for backtests.
For any Python projects that may have been produced locally and may not be available at PyPI, one could use ‘python -m build’ in the project env, then install the resulting 'dist/*.whl' file within the test virtual environment. This would be separate to ‘lean backtest', instead using e.g ‘docker run’ to start a bash shell (or zsh, e.g) with the local lean image, here denoted as ‘lean-cli/engine’ (from a local build with the lean sources at GitHub)
Sean Champ
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!