MATLAB Portfolio Backtesting – A new app now on GitHub!
The following blog was written by Sara Galante, Senior Finance Application Engineer at Mathworks.
MathWorks has a new application to implement backtesting strategies available on GitHub. This custom application provides an intuitive GUI to import portfolio data, create backtesting strategies, and test and compare them against each other. The backtesting application can also automatically generate the code to run said strategies with the click of a button, making integration into the portfolio optimization workflow simpler.
The GitHub documentation and MATLAB files are available here.
To help you get started watch this video on how to use the BackTesting App in MATLAB:
Workflow and Features
- Import Data Module:
1.1. Import prices data directly from Excel sheet, .mat file or choose existing timetable from MATLAB workspace.
1.2. Optionally, import signal data directly from Excel sheet, .mat file or choose existing timetable from MATLAB workspace.
- Create Backtest Strategies:
2.1. In the main window, there is a tab showing the list of created backtest strategies
2.1.1.Text box shows list of backtest strategies created using application.
2.1.2. Add button: Add a brand new strategy.
2.1.3. Edit button: Edit existing strategy.
2.1.4. Duplicate button: Create a copy of existing strategy and simply modify their fields to create a new one.
2.1.5. Delete button: Delete an existing strategy.
2.2. Window 2B is launched in a different pane.
2.2.1. Default values from BacktestStrategy objects are pre populated.
2.2.2. If you choose to edit/duplicate a value, all fields will be populated from the selected strategy.
2.2.3. The Pre-exec text box on top executes MATLAB code before creating the BacktestStrategy object. This allows the user to compute any values/variables/function-handles before using them in the other fields.
- Create Backtest Engine:
3.1. With the imported data, create a backtest engine by selecting the strategies to consider and parameter values chosen.
3.2. The Prices and Signal data fields are un-editable and are only to inform of the data being worked on. - Run Backtest:
4.1. Choose the start and end dates for backtest to run in.
4.2. Optionally add an array of strings with the names of the cash assets and the names of the debt assets.
4.3. Upon running, find Equity Curve, Summary Table and Asset Area Curves plotted in different tabs.
- Use Export to Workspace button to export BacktestStrategy and BacktestEngine objects to ‘base’ workspace. This creates a new structure named backtestingStruct that has the backtest strategies and engine as its fields.
- Use Export Session and Import Session buttons to export application state as a appSession variable. Save this variable as mat file to import session later.
- Click Generate Code button to generate code for importing data, creating backtest strategies, backtest engine and then running the backtest.
评论
要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。