Files
quantconnect--lean/Algorithm.Python
Michael Handschuh 6362d101c1 Append type to custom data symbol
This is being done in an effort to prevent symbol collisions within the
custom data (SecurityType.Base) namespace. The custom data type's name,
is used for disambiguation. As written, this change will break several
user algorithms that still rely on using the implicit string -> Symbol
lift. Providing this type information is optional an currently only being
used by AddData<T> methods. Other consumers of SecurityType.Base symbols
arn't at risk for collision, such as the UserDefinedUniverse, ScheduledUniverse
and others that are LEAN controlled. In order to maintain backwards compatibility,
the SymbolCache was updated to do a hard search when the requested ticker was
not found, looking for the prefix ('ticker.').

Fixes #3332
2019-09-24 10:34:35 -03:00
..
2019-05-22 09:36:19 -07:00
2015-09-01 22:17:35 -04:00
2019-04-05 18:34:18 -03:00
2019-03-01 15:06:37 -08:00
2017-05-14 15:11:57 +01:00
2017-04-11 17:09:44 +01:00
2019-08-20 19:22:18 -03:00
2019-04-18 23:29:51 +01:00
2019-04-03 21:55:44 -03:00
2019-07-09 09:05:27 -07:00
2019-09-23 19:45:46 -03:00
2015-09-01 22:17:35 -04:00
2019-09-09 14:00:20 -07:00

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

  1. Use the Windows x86-64 MSI Python 3.6.6 installer from python.org or Anaconda for Windows installer.
  2. When asked to select the features to be installed, make sure you select "Add python.exe to Path"
  3. [Optional] Create PYTHONHOME system variables which value must be the location of your python installation (e.g. C:\Python36amd64 or C:\Anaconda3):
    1. Right mouse button on My Computer. Click Properties.
    2. Click Advanced System Settings -> Environment Variables -> System Variables
    3. Click New.
      • Name of the variable: PYTHONHOME.
      • Value of the variable: python installation path.
  4. Install pandas and its dependencies.
  5. Reboot computer to ensure changes are propogated.

macOS

  1. Use the macOS x86-64 package installer from Anaconda and follow "Installing on macOS" instructions from Anaconda documentation page.
  2. Install pandas and its dependencies.

Note: If you encounter the "System.DllNotFoundException: python3.6m" runtime error when running Python algorithms on macOS:

  1. Find libpython3.6m.dylib in your Python installation folder. If you installed Python with Anaconda, it may be find at
/Users/{your_user_name}/anaconda3/lib/libpython3.6m.dylib
  1. Open Lean/Launcher/bin/Debug/Python.Runtime.dll.config, add the following text and save:
 <configuration>
    <dllmap dll="python3.6m" target="{the path in step 1 including libpython3.6m.dylib}" os="!windows"/>
</configuration>

Note: Specify the install of v3.6.6 exactly, i.e. if with conda conda install python=3.6.6 as this is a known compatible version and other versions may have issues as of this writing.

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

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

  1. Update the config to run the python algorithm:
"algorithm-type-name": "BasicTemplateAlgorithm",
"algorithm-language": "Python",
"algorithm-location": "../../../Algorithm.Python/BasicTemplateAlgorithm.py",
  1. Rebuild LEAN.
  2. 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"