- Modifying `IFillModel` interface removing old methods and adding new method `Fill Fill(FillModelParameters)`. This is a breaking change. - Adding new `PythonWrapper` property for the `FillModel` base class. This is required due to a limitation in PythonNet: - Given C# class T has `virtual` methods A and B. Where method A calls method B. And given custom python class L inherits class T. And overrides method B. When class L calls base method A (of class T). And when method A internally calls method B. It will call C# implementation, not the python override. This issue is solved going back to the `PythonWrapper`. Adding unit tests. - Adding new `Parameters` property for the `FillModel` base class that will be set by the call to `Fill()`. The `Parameters` property will be used by the modified `XxxxFill()` implementations - Adding new `Fill` result object for the `Fill(FillModelParameters)` method - Adding new check before removing a `SubscriptionDataConfig` due to the FillModels consuming the configuration collection when determining which Price to use. WIll now only remove the `SDC` if the symbol was removed from the selecting `universe`, this will avoid the case where the symbol is never deselected and the subscription ends, which happens at the end of all executions. - Adding unit tests showcasing retro compatibility. - Enabling C# `CustomModelsAlgorithm` as a regression test. Python version returns a different result due to random number generation.
QuantConnect Python Algorithm Project:
Before we enable python support, follow the installation instructions to get LEAN running C# algorithms in your machine.
Install Python 3.6:
Windows
- Use the Windows x86-64 MSI installer from python.org or Anaconda for Windows installer
- When asked to select the features to be installed, make sure you select "Add python.exe to Path"
[Optional]CreatePYTHONHOMEsystem variables which value must be the location of your python installation (e.g.C:\Python36amd64orC:\Anaconda3):- Right mouse button on My Computer. Click Properties.
- Click Advanced System Settings -> Environment Variables -> System Variables
- Click New.
- Name of the variable:
PYTHONHOME. - Value of the variable: python installation path.
- Name of the variable:
- Install pandas and its dependencies.
- Install Visual C++ for Python 2.7
- Install .NET Framework 3.5:
- Open the Control Panel
- Click on Programs and Features, then Turn Windows Features On or Off
- Mark ".NET Framework 3.5 (includes .NET 2.0 and 3.0)"
macOS
- Use the macOS x86-64 package installer from Anaconda and follow "Installing on macOS" instructions from Anaconda documentation page.
- Install pandas and its dependencies.
- Install pkg-config
Linux
By default, miniconda is installed in the users home directory ($HOME):
export PATH="$HOME/miniconda3/bin:$PATH"
wget https://cdn.quantconnect.com/miniconda/Miniconda3-4.3.31-Linux-x86_64.sh
bash Miniconda3-4.3.31-Linux-x86_64.sh -b
rm -rf Miniconda3-4.3.31-Linux-x86_64.sh
sudo ln -s $HOME/miniconda3/lib/libpython3.6m.so /usr/lib/libpython3.6m.so
conda update -y python conda pip
conda install -y cython pandas
Install clang and glib 2.0:
sudo apt-get -y install clang libglib2.0-dev
Note: There is a known issue with python 3.6.5 that prevents pythonnet installation, please upgrade python to version 3.6.6:
conda install -y python=3.6.6
Run python algorithm
- At Lean root directory, run the setup script:
python setup.py
It will install QuantConnect's version of pythonnet in your system.
- Update the config to run the python algorithm:
"algorithm-type-name": "BasicTemplateAlgorithm",
"algorithm-language": "Python",
"algorithm-location": "../../../Algorithm.Python/BasicTemplateAlgorithm.py",
- Rebuild LEAN.
- Run LEAN. You should see the same result of the C# algorithm you tested earlier.
Python.Runtime.dll compilation
LEAN users do not need to compile Python.Runtime.dll. The information below is targeted to developers who wish to improve it.
Download QuantConnect/pythonnet github clone or downloading the zip. If downloading the zip - unzip to a local pathway.
Note: QuantConnect's version of pythonnet is an enhanced version of pythonnet with added support for System.Decimal and System.DateTime.
Below we can find the compilation flags that create a suitable Python.Runtime.dll for each operating system.
Windows
msbuild pythonnet.sln /nologo /v:quiet /t:Clean;Rebuild /p:Platform=x64 /p:PythonInteropFile="interop36.cs" /p:Configuration=ReleaseWin /p:DefineConstants="PYTHON36,PYTHON3,UCS2"
macOS
msbuild pythonnet.sln /nologo /v:quiet /t:Clean;Rebuild /p:Platform=x64 /p:PythonInteropFile="interop36m.cs" /p:Configuration=ReleaseMono /p:DefineConstants="PYTHON36,PYTHON3,UCS4,MONO_OSX,PYTHON_WITH_PYMALLOC"
Linux
msbuild pythonnet.sln /nologo /v:quiet /t:Clean;Rebuild /p:Platform=x64 /p:PythonInteropFile="interop36m.cs" /p:Configuration=ReleaseMono /p:DefineConstants="PYTHON36,PYTHON3,UCS4,MONO_LINUX,PYTHON_WITH_PYMALLOC"