| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This repository demonstrates how MATLAB® and Python® users can collaborate seamlessly to implement and test algorithmic trading strategies through table-to-DataFrame conversion and custom Live Tasks. Co-execution offers a significant time-saving advantage by allowing direct execution of pre-existing Python code alongside MATLAB. In environments where financial developers work across multiple teams, it’s often necessary to interface with or inherit code from both platforms. Recoding between these environments can be time-consuming, costly, and generally impractical. Instead, developers can execute Python code directly within MATLAB and easily convert between pandas DataFrames and MATLAB Tables, simplifying collaboration. This demo showcases how to use co-execution to create a custom Live Task that generates synthetic data in MATLAB tables, converts the tables to Python DataFrames for executing pre-written Python trading strategies, and finally converts the DataFrames back into MATLAB tables for analysis.
Co-execution involves using two frameworks in tandem to create a single, unified application. In this example, data is passed between MATLAB Tables and Python DataFrames using recent functionality introduced in MATLAB version 2024a. This approach offers several benefits. By interfacing multiple frameworks, development time and costs can be reduced, as teams no longer need to code in the same language. This enables teams to work in their preferred environments, avoiding the need to learn and retool code in unfamiliar languages. Co-executing Python with MATLAB leverages MATLAB's accessible functionality, allowing users to explore the parameter space and fine-tune trading strategies more efficiently.
MATLAB Tables and Python DataFrames are both data structures that are used for organizing and analyzing tabular data. Interfacing between these two is essential when integrating MATLAB with Python workflows, which is now possible through MATLAB version 2024a. Conversion between the two data types is simple and fundamental to the demo in this page. A MATLAB Table can be converted to a Python DataFrame, as well as the reverse, through one line of code, shown in the red boxes in the image below.
Live Tasks are small graphical user interfaces (GUI) that can be added to live scripts to execute specific MATLAB commands. A variety of Live Tasks are built into MATLAB, ranging from simple operations like plotting and visualization to more complex tasks like optimization. Live Tasks also have the capability to generate reusable code from the parameters that the user selected. In this demo, a custom Live Task provides a GUI that allows the user to explore the free parameters of the demo in a user-friendly way. The Live Task interfaces MATLAB with Python code under the hood. The gif below demonstrates how to use the Live Task, with editable fields and a drop down menu, while viewing the results on the fly.
Download or clone this repository to your machine and open it in MATLAB.
Requires:
For more information about installing Python to interface with MATLAB, see Install Supported Python Implementation.
Creating a custom Live Task takes a few steps - the major steps are highlighted below:
Select your code and go to the Live Editor tab in the MATLAB task bar. Click on the "Task" dropdown menu
a. Under "Create", click on the "Convert to Live Task" option, as shown below
b. Name your Live Task and click on the OK button. A new .m will appear in the Current Folder.
You can use the new Live Task by clicking on the "Task" dropdown menu and selecting it under "My Tasks"
To launch the custom algo trading Live Task in this repo:



The goal of this demo was to show:
The license is available in the License.txt file in this GitHub repository.
Sara Galante at sgalante@mathworks.com, Application Engineering
Copyright 2024 The MathWorks, Inc.
| Back | FazBrowse Home | New Git URL |