Figure A.6 Configuration Manager.
configuration provided by the toolbox. Initially, the content of the default and the
active configuration are the same. A new configuration can be created by clicking
on the Configuration button in the start window. It automatically loads the active
configuration, to which the user can add or delete new algorithms or datasets.
A.2.2 Command Line Interface
In the CLI,userscan run algorithms by calling the commands.Inparticular, we provide
a meta-function named manager, which is responsible for preprocessing (such as ini-
tializing datasets and variables, etc.), calling specified strategies, and postprocessing
(such as analyzing and outputting the results, etc.).
T&F Cat #K23731 — K23731_A001 — page 153 — 9/28/2015 — 20:46
A.2.2.1 Trading Manager
Algorithm A.2: Trading manager for online portfolio selection.
Input: strategy_name: A string of the specified strategy;
dataset_name: A string of the specified dataset;
varargins: A variable-length input argument list for the specified strategy;
opts: A variable for options controlling the trading environment.
Output: cumulative_ret: Final cumulative wealth;
Cumprod_ret: Cumulative wealth at the end of each period;
daily ret: Daily return for each period;
ra_et: Analyzed results, including risk-adjusted returns;
run_time: Time for the strategy (in seconds).
Initialize market data from dataset;
Open the log file and mat file;
Start the time variables;
Call strategy with parameters in varargins;
Terminate the time variables;
Analyze the results;
Close the log file and mat file;
The Trading Manager, as shown in Algorithm A.2, controls the whole simulation
of OLPS. At the start (Line 2), it loads market data from the specified dataset. Note
that this can be easily extended to load data from real brokers. Then, Lines 3 and 8
open and close two logging files, one for text and one for .MAT format. Lines 4 and
6 measure the computational time of the execution of a specified strategy. Measuring
the time in the trading manager ensures a fair comparison of the computational time
among different strategies. Line 5 is the core component, which calls the specified
strategy with specified parameters. Section A.3 will illustrate all included strategies
and their usages. Line 7 analyzes the executed results of the strategy, which will be
introduced later. The “manager.m” usage is shown as follows.
function [cum_ret, cumprod_ret, daily_ret, ra_ret,
= manager(strategy name, dataset name, varargins,
cum_ret: cumulative return;
cumprod_ret: a vector of cumulative returns at the end of every trading day;
daily_ret: a vector of daily returns at the end of every trading day;
ra_ret: analyzed result;
run_time: computational time of the core strategy (excluding the manager routine);
T&F Cat #K23731 — K23731_A001 — page 154 — 9/28/2015 — 20:46
strategy_name: the name of the strategy (all implemented strategies’ names are
listed in the fourth column of Table A.1);
dataset_name: the name of the dataset;
varargins: variable-length input argument list; and
opts: options for behavioral control.
Example This example calls the ubah (Uniform Buy and Hold, or commonly
referred to as the market strategy) strategy on the “NYSE (O)” dataset.
[cum_ret, cumprod_ret, daily_ret, ra_ret, run_time]...
= manager(’ubah’, ’nyse-o’, {0}, opts);
To facilitate the debugging of trading strategies, we also use controlling variables
to control the trading environment. In particular, the last parameter opts in the above
example contains the controlling variables. As shown in Table A.3, it consists of five
controlling variables.
The Results Manager analyzes the results and returns an array containing the basic
statistics, the Sharpe ratio and Calmar ratio, and their related statistics. Details about
the returned statistics are described in Table A.4.
function [ra_ret] ...
= ra_result_analyze(fid, data, cum_ret, cumprod_ret,
daily_ret, opts);
AddingYour Own Strategy or Data Adding new strategies and datasets in the CLI
mode is similar to that in the GUI mode. Adding the strategy involves replacing the
portfolio update component of the algorithms, and adding a dataset involves storing
the market matrix and placing the files in the data folder.
Table A.3 Controlling variables
Possible Explanation
Variables Descriptions Values for Values
opts.quiet_mode display debug info? 0 or 1 No or Yes
opts.display_interval display info time interval? Any number Display every
(e.g., 500) 500 periods
opts.log_record record the .log file? 0 or 1 No or Yes
opts.mat_record record the .mat file? 0 or 1 No or Yes
opts.analyze_mode analyze the algorithm? 0 or 1 No or Yes
opts.progress show the progress bar? 0 or 1 No or Yes
T&F Cat #K23731 — K23731_A001 — page 155 — 9/28/2015 — 20:46
Table A.4 Vector of the analyzed results
Index Descriptions
1 Number of periods
2 Strategy’s average period return
3 Market’s average period return
4 Strategy’s winning ratio over the market
5 Alpha (α)
6 Beta (β)
7 t-statistics
8 p-value
9 Annualized percentage yield
10 Annualized standard deviation
11 Sharpe ratio
12 Drawdown at the end
13 Maximum drawdown during the periods
14 Calmar ratio
A.2.2.2 Examples
Example 1 Calling a BCRP strategy on the SP500 dataset, mute verbosed outputs:
>> opts.quiet_mode = 1; opts.display_interval = 500;
opts.log_mode = 1; opts.mat_mode = 1;
opts.analyze_mode = 1; opts.progress = 0;
>> manager(’bcrp’, ’sp500’, {0}, opts);
Then the algorithm outputs are listed below:
>> manager(’bcrp’, ’sp500’, {0}, opts);
----Begin bcrp on sp500-----
BCRP(tc=0.0000), Final return: 4.07
----End bcrp on sp500-----
Example 2 Calling a BCRP strategy on the SP500 dataset, display verbosed outputs:
>> opts.quiet_mode = 0; opts.display_interval = 200;
opts.log_mode = 1; opts.mat_mode = 1;
opts.analyze_mode = 1; opts.progress = 0;
>> manager(’bcrp’, ’sp500’, {0}, opts);
T&F Cat #K23731 — K23731_A001 — page 156 — 9/28/2015 — 20:46
Then the algorithm outputs are listed below:
>> manager(’bcrp’, ’sp500’, {0}, opts);
Running strategy bcrp on dataset sp500
Loading dataset sp500.
Finish loading dataset sp500
The size of the dataset is 1276x25.
Start Time: 2013-0721-13-22-05-664.
----Begin bcrp on sp500-----
Parameters [tc:0.000000]
day Daily Return Total return
500 1.055339 4.634783
1000 1.018404 4.560191
BCRP(tc=0.0000), Final return: 4.07
----End bcrp on sp500-----
Stop Time: 2013-0721-13-22-08-144.
Elapse time(s): 2.486262.
Result Analysis
Statistical Test
Size: 1276
MER(Strategy): 0.0015
Risk Adjusted Return
Volatility Risk analysis
APY: 0.3240
Volatility Risk: 0.4236
Sharpe Ratio: 0.6705
Drawdown analysis
APY: 0.3240
DD: 0.3103
MDD: 0.5066
CR: 0.6395
T&F Cat #K23731 — K23731_A001 — page 157 — 9/28/2015 — 20:46
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.