Sending Your AmiBroker Exploration Results to Alera APM
Those familiar with SIG’s Trading and Investing Automation for AmiBroker course material already know how to drive the entire automation workflow through Alera Portfolio Manager (APM).
As the scheduling goes, this is a two-step process:
- Schedule the execution of the AmiBroker batch file responsible for generating and storing the signals in the appropriate APM folder
- Schedule the strategy run at the desired time (usually a few minutes after the signal generation ends)
The solution is simple and flexible enough to handle the EndOfDay strategies and most of the intraday ones with ease. Still, the two events are not being synchronized (the second event does not wait for the first to finish) and if the first event takes longer than the time allocated, the signal files will not be ready for processing.
Starting with version 2.1.4 Alera Portfolio Manager’s API allows a client to run a specific strategy via an Http POST Web Request. In the example below the client instructs the APM instance listening on port 7425 to run the strategy with id 1001:
POST http://localhost:7425/api/strategies/1001?cmd=run
Note:
Since this is a POST request copy-pasting the URL above in a browser will NOT trigger a strategy run in APM.
Here is how to use the new feature to drive the execution directly from AmiBroker:
- Create the AmiBroker Exploration batch file with the actions detailed in the course material mentioned above:
- Load Database
- Load Project
- Explore
- Export to File
- Add an Execute and Wait action item using the Windows PowerShell command below. The command executes a Windows PowerShell instance that sends a web request to Alera API to run a specific strategy. The parameters used are:
- 7430 is the Alera API port set up in the Account Settings Tab
- 1001 is the strategy id you wish to run
- batch1.log is the name of the log file used to verify if the run was successful (status code 200)
powershell.exe -Command Invoke-WebRequest -URI http://localhost:7430/api/strategies/1001?cmd=run -Method POST | Out-File -Append -FilePath C:\Program` Files\AmiBroker\Formulas\Custom\batch1.log
Note:
Be aware that all space characters contained in the file names have to be escaped by the character ` : e.g. \Program` Files
is correct while \Program Files\
will return an error (a successful command will append the result to the batch1.log log file).
- Schedule the Amibroker batchfile to run at the desired time interval either by:
- Using the Amibroker batchfile scheduler (this will require to keep AmiBroker up and running)
- Using the Windows task scheduler
As mentioned above, the new Alera API features allows an external client to run a strategy as soon as the signals are available for processing. Since the strategy run is triggered by the Amibroker Exploration Batch File, the process above works well when the signals are being generated using an AmiBroker Exploration. In a followup post I will share the AFL code and a few examples of how to use the Alera API to process signals generated using the AmiBroker Custom Backtester.
Dan
Systematic Investors Group Team