Software: Learning zero-cost portfolio selection with pattern matching
Abstract: We replicate and extend the adversarial expert based learning approach of Györfi et al to the situation of zero-cost portfolio selection implemented with a quadratic approximation derived from the mutual fund separation theorems. The algorithm is applied to daily sampled sequential Open-High-Low-Close data and sequential intraday 5-minute bar-data from the Johannesburg Stock Exchange (JSE). Statistical tests of the algorithms are considered. The algorithms are directly compared to standard NYSE test cases from prior literature. The learning algorithm is used to select parameters for experts generated by pattern matching past dynamics using a simple nearest-neighbour search algorithm. It is shown that there is a speed advantage associated with using an analytic solution of the mutual fund separation theorems. We argue that the strategies are on the boundary of profitability when considered in the context of their application to intraday quantitative trading but demonstrate that patterns in financial time-series on the JSE could be systematically exploited in collective and that they are persistent in the data investigated. We do not suggest that the strategies can be profitably implemented but argue that these types of patterns may exists for either structural of implementation cost reasons.
The Zip folder includes:
- /Data: This includes the NYSE merged and NYSE test data
- /Functions: pattern.m and a benchmark test function
- /Scripts: The scripts used to generate the figures and tables in the attached paper.
Software description: The key algorithm is the cash neutral pattern matching algorithm. The class implements a matching algorithm (pattern/match) and a learning algorithm (pattern/learn) iteratively on the data. Prior to the match-learn algorithm the data needs to be partitioned (in time) and clustered (in objects). The class supports trivial, overlapping, exclusive and side-information partitions. The match-learn algorithm loops over two hyper-parameters indexed by k and ell. The method adaptively "learns" the most effective k and ell combinations online as the data iterates and is return weighted in the learning algorithm using performance weighted learning (PWL):
B(T) = SUMK,L(SH(T-1|K,L) H(T|K,L)) / SUMK,L SH(T-1|K,L) Eqn. (1)
For B the resulting portfolio weights, K and L the hyper parameters, SH the performance measure at time T as a function of K and L e.g. portfolio wealth or profit-loss, and H the agent controls as a (N,M,T) weight matrix/tensor for N agents and M objects at times T.
Key function is a class: pattern.m (pattern/pattern)
PATTERN Pattern matching and learning class
The class implements both online and offline pattern matching and learning over k-tuples for M objects and N features as specified in an MxNxP data matrix X. The algorithm searches for L nearest-neighbour K-tuple matches in the provided partition of data. A quadratic approximation is used to find the log-optimal portfolio using T+1 expected return subsequent to the pattern matching times T for each k and ell to find H(K,L,CI;T) and SH(K,L,CI;T) for each K-tuple L value and cluster CI. The controls are then aggregate using machine learning to provide the controls B and realised accumulated performance S. If the K matching patterns are predefined then K is the index over the matching patterns. The default is an empty matching pattern and to use the last k-tuple as the matching pattern.
The class attributes are:
- B = aggregated controls a (T,M) matrix as: Time x Objects
- S = aggregated performance as a (T) vector: Time x 1
- H = agent controls as a (N,M,T) tensor: Agents x Objects x Time
- SH = agents performance as a (T,N) matrix: Time x Agents
The class has the constructor pattern/pattern
The class has key methods
- pattern/offline: Initial estimates of H and SH
- pattern/online: Iteratively update H and SH as new data arrives
- pattern/match: match the pattern using a nearest-neighbour methods
- pattern/learn: Update aggregated agent controls and performance (B,S)
- pattern/partition: partition the data in time for the matching by index
The online and offline methods are built on two loops. An "ell" loop and a "k" loop, so for each L from the ell-loop (over partition hyperparameters) and K from the "k-loop" of the test-tuple hyper-parameters:
- a (k,ell)-tuple is provided,
- A given partition (times) and given cluster (objects) is search for the tuples N nearest-neighbours (matching).
Using the N nearest-neighbour generated data blocks. A mean-variance optimisation is solved to provide optimal controls for each K and L combination. From these the agent wealth and computated. Then using performance weighted learning (PWL) the update equation 1 is used to find the new aggregate control B for the next time step.