Meta-Heuristics in Finance - Dietmar Maringer Computational Economics and Finance Business and Economics Faculty, University of Basel SAMSI ...

Page created by Randy Guzman
 
CONTINUE READING
Meta-Heuristics in Finance - Dietmar Maringer Computational Economics and Finance Business and Economics Faculty, University of Basel SAMSI ...
Meta-Heuristics in Finance
Dietmar Maringer
Computational Economics and Finance
Business and Economics Faculty, University of Basel

SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop
March 8-12, 2021
Meta-Heuristics in Finance - Dietmar Maringer Computational Economics and Finance Business and Economics Faculty, University of Basel SAMSI ...
Contents 3 Trading and Asset Management
 3.1 portfolio: combination of assets . . . . . . . . . . . . . . . . .
 6
 6
 3.2 portfolio optimization . . . . . . . . . . . . . . . . . . . . . . . 7
 3.3 sample-based portfolio optimization . . . . . . . . . . . . . . . 11
 3.4 Differential Evolution . . . . . . . . . . . . . . . . . . . . . . . 12
1 where’s the problem? 3
 4 Algorithmic and Autotrading 17
2 modeling price processes and risk 4 4.1 some types of algorithmic trading systems . . . . . . . . . . . . 17
 4.2 machine learning and meta-heuristics techniques . . . . . . . . 18
 2.1 example: modeling risk . . . . . . . . . . . . . . . . . . . . . . 4
 2.2 further examples . . . . . . . . . . . . . . . . . . . . . . . . . . 5 5 Conclusion 21

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 2
March 8-12, 2021
1. where’s the problem?
 • typical tasks

 ⊲ investment decisions
 ⊲ describing, modelling, (and predicting) risky assets
 ⊲ dealing with requirements (regulators, investors)
 • data: “weather forecast” versus “climate change”

 ⊲ (ultra-)high frequency: highly liquid assets
 » latency (under colocation): < 1 microsecond
 » relevant for certain types of algo-trading strategies
 ⊲ low frequency: daily prices or lower
 » aggregate over longer stretches of time to reduce noise
 » thin trading: funds, bonds, ...
 ⊲ challenges
 » statistical / stylized facts
 » scaling laws
 » choice of model

 • need for meta-heuristics

 ⊲ non-convex models, challenging contraints

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 3
March 8-12, 2021
2. modeling price processes and risk

2.1. example: modeling risk

 • stylized fact: volatility clustering in returns
 • Engle (1982): ARCH( ), Bollerslev (1986): GARCH( , )

 = + where ∼ (0, 2 )
 ∑︁ ∑︁
 2 2 2
 and = 0 + − + − 
 
 • estimating the parameters = [ , , ] with log-likelihood

 2 
  
 ∗ 1 ∑︁ 2 b
 = argmax L = − ln(2 ) − ) + 2
 ln(b
 2 2 =1 
 b

 • Chris Brooks, Simon P. Burke, and Gita Persand (2001). “Benchmarks and the Accuracy of GARCH
 Model Estimation”. In: International Journal of Forecasting 17.1, pp. 45–56

 ⊲ estimate GARCH(1,1) parameters [ , 0 , 1 , 1 ] with nine standard software packages
 ⊲ results differ noticeably
 • heuristic optimization can easily solve this problem

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 4
March 8-12, 2021
2.2. further examples
 • model estimation e.g., Nelson-Siegel-Svensson for yield of bond with time-to-maturity at :
 ) 2 )
 min (( − b
 , 
    
 1− − 
 ( ) = 1, + 2, ( / 1 ) + 3, ( / 1 ) − − / 1 + 4, ( / 2 ) − − / 2 where ( ) =
 
 b 

 • model selection challenging combinatorial problems, e.g., factor (or asset) selection:
 ) 2 ) :
 min (( − b
 F , 
 ∑︁
 =
 b s.t. F ⊂ M, ∈ D, and ♯F ≤  ♯M
 ∈F

 • joint estimation and selection problem: Vector Error Correction model (VECM) for interest rates:

 ∑︁
 Δ = + −1 +  Δ − + with Δ − = − − −−1
 =1
  11 ··· 1   Δ 1, −1−
  1   11 ··· 1   1, −1  ∑︁ " #  
 1 
 . .
 = .. + .. . . ..
 . . .
 .. + . .
 .. . . .. . .
 .. + ...
 1 ··· , −1 =1 1 ···  Δ , −1− 

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 5
March 8-12, 2021
3. Trading and Asset Management

3.1. portfolio: combination of assets
 • assets; return of asset are normally distributed

 ⊲ stock price: = 0 · (1 + )
 ⊲ returns: expectations = ( ) , standard deviations (“volatility”) and covariances 
 ⊲ estimates based on past observations [ ] and/ or models

 • portfolio
 Í
 ⊲ 0 , value at beginning, = 0: stocks =⇒ 0 = 0, 
 ⊲ , value at end of investment period:
 ∑︁ ∑︁ ∑︁ 0 ∑︁
 = , = 0 (1 + , ) = (1 + , ) = (1 + , ) = 1 + 
 
 0 
 0 

 hence,
 ∑︁ √︄∑︁ ∑︁ √
 ( ) = ( ) = = 2 2 + = 0 
 ≠ 

 0, 
 ⊲ asset weight: fraction of wealth invested in asset , =
 0

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 6
March 8-12, 2021
3.2. portfolio optimization
3.2.1. the problem
 • objective: find composition that meets investors’ and regulators’ requirements the best

 ⊲ decision variables: 
 ⊲ risk-adjusted performance
 ⊲ limitations on composition of portfolio

3.2.2. traditional approach: mean-variance portfolios

 • Harry Markowitz: achieve target return with minimum risk:
 ∑︁
 min 2 = 0 s.t. ( ) = ≥ ∗ , ≥ 0, = 1
 
 max ( − · 0 ) s.t. 1 = 1 and ≥ 0
 
 for given ≥ 0 =⇒quadratic programming problem

 • James Tobin, William Sharpe: include safe asset (return ) and maximize “Sharpe ratio”

 ( ) − 
 max =
 
 • negative positions, < 0: “short selling”

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 7
March 8-12, 2021
3.2.3. extensions
limitations on selection of assets, 

 • integer contraints on ∈ {0, 1, 2, ...} =⇒discrete weights = 0 / 0
 (
 = 0 asset not included
 • avoid tiny positions:
 ≥  asset included with (more than) minimum amount
 Í
 • (explicit) cardinality constraint: 1 ≠0 ≤ 

additional costs and effects on performance

 • additional transaction costs, management fees, bid-ask spreads: · | | · 0 + · 1 ≠0

 • market impact: large order moves price (in non-linear fashion and by uncertain amount)

investors’ preferences

 • risk aversion: higher wealth has more utility, but at decreasing rate

 ⊲ quadratic utility, (e.g., in Markowitz), − 2 : justifies mean-variance
 (
 ln( ) for = 1
 ⊲ more realistically: e.g., power utility with ≥ 0, ( , ) =
 ( 1− − 1)/(1 − ) otherwise

 • loss aversion (Kahnemann & Tversky): not just level of wealth, but also relative to initial
 endowment

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 8
March 8-12, 2021
distribution of returns

 • stock returns typically exhibit negative skewness, excess kurtosis

 • non-linear dependencies and correlations

additionale / alternative risk- and performance measures

 • tail-risk, focusing on losses, = −( − 0 ) :

 ⊲ “Value-at-Risk” (VaR): loss that will be exceeded only with probability ,
 prob( > ) = 
 ⊲ “conditional Value-at-Risk” (cVaR), ≈ “Expected Shortfall” (ES): ( | > )
 ⊲ in portfolio optimization:
 » constraint: equity requirements based VaR (regulations)
 » objective: minimize for giving VaR, minimize VaR for given 
 ∫∞
 (1− ( ))d (max( − ,0))
 • Keating and Shadwick: Ω = ∫
 =⇒ max − (min( − ,0))
 −∞
 ( )d

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 9
March 8-12, 2021
3.2.4. a quick reality check
 • Value-at-Risk under normal and empirical distribution

 • three assets, daily returns
 Í
 • constraints: ≥ 0 for = 1, 2 = 1 ⇔ 3 = 1 − 1 − 2

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 10
March 8-12, 2021
3.3. sample-based portfolio optimization
3.3.1. concept
 • back-testing, historical simulation:

 ⊲ get sample based on assets’ past observations
 ⊲ compute how portfolio would have performed in the past
 ⊲ evaluate strategy on past observations
 • sample-based optimization:

 ⊲ create (large) sample for assets’ returns that exhibits properties assumed for investment
 period
 ⊲ find portfolio / strategy that works best given criteria / objectives / constraints

3.3.2. how to solve it
 • data: samples for assets, ; objective function: ( | , )
 × 

 • decision variables: =⇒(in population-based method with individuals): 
 × 

 • constraints:

 ⊲ ideally: repair function, = R ( ) s.t. ∈ D
 ⊲ occasionally: punishment function

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 11
March 8-12, 2021
3.4. Differential Evolution
3.4.1. basic idea
 • suggested by Storn and Price (1995)

 • continuous, dimensional search space

 • population size of vectors, representing positions within search space

 = [ ], = 1 . . . , = 1 . . . 

 • evolution: repeat creation + tournament:

 ⊲ generate another solutions (“offspring”) , = 1 . . . 
 ⊲ for each current solution , pick one offspring 
 ?
 ⊲ compare fitness values of current and new solutions: ( ) ≷ ( )
 ⊲ the one with higher fitness survives

 ( ) < ( ) =⇒ := 

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 12
March 8-12, 2021
• creating new candidates
 current population (candidate solutions)
 ⊲ take one existing vector, 1 , and modify it new candidate solution
 Minimum

 ⊲ perturbations: vector weighted difference of two other (x 2 − x 3 )
 solutions, 2 − 3 x 3
 x 2 x 1
 ⊲ cross-over: elements of 4th solution ỹ = x 1 + · (x 2 − x 3 )

 (
 ˜ [ ] = 1 [ ] + · ( 2 [ ] − 3 [ ]) with prob. 
 [ ] :=
 [ ] otherwise

 Algorithm 1: DE pseudo-code for maximization and continuous search space
 1 set: population size , scaling factor , cross-over probability , halting criterion, etc.

 2 initialize: for = 1.. ;

 3 repeat
 4 foreach parent do
 5 randomly select individuals 1 , 2 , 3
 6 ˜ := 1 + · ( 2 − 3 )
 create linear combination 
 7 ˜ , , )
 create new offspring: := cross-over( 

 8 foreach offspring do
 9 if ( ) > ( ) then
 10 := 

 11 until halting criterion met;
 12 report elitist ∗ = argmax ( )
 =1: 

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 13
March 8-12, 2021
3.4.2. extended versions
 • add extra noise with ( ) = 0:

 ⊲ jitter: extra noise added to , ˜1 [ ]
 ⊲ extra noise added to difference vector, ˜2 [ ]
 (
 1 [ ] + ( +˜ 1 [ ]) · ( 2 [ ] − 3 [ ]+˜ 2 [ ]) with prob. 
 [ ] :=
 [ ] otherwise

 • additional difference vectors

 ⊲ e.g., using two current solutions, one current member and the elitist, ...

 • use elitist as base-vector 1

 • for more details, see, e.g., Price, Storn, and Lampinen 2005 or Brabazon, O’Neill, and McGarraghy
 2015, §6 and the literature quoted therein

3.4.3. constraints
 • repair function to ensure candidate is feasible

 • map candidate to feasible space during function evaluation

 • punishment term deteriorates OF when candidate is infeasible

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 14
March 8-12, 2021
3.4.4. (very) basic version of DE for maximization
 1 import numpy as np
 2 import numpy.random as rd
 3
 4 def DEmax(f, x0, repair=lambda x:x,
 5 popSize=30, FE=10000, F=0.7, probXO=.5):
 6 # initialize
 7 D = x0.shape[0] # provide x0 with shape (D,)
 8 xC = rd.randn(popSize,D)
 9
10 xC = repair(xC)
 11 fC = np.array( [f(xC[p]) for p in range(popSize)] )
 12 fE = np.min(fC)
 13
 14 # evolve
 15 for gen in range(int(FE/popSize)):
 16 # linear combination
 17 p = [rd.permutation(popSize) for i in range(3)]
 18 xN = xC[p[0]] + F * (xC[p[1]] − xC[p[2]])
 19
20 #cross−over
 21 XO = rd.rand(popSize,D)=fC
28 fC[improved] = +fN[improved]
 29 xC[improved] = +xN[improved]
30
 31 i = np.argmax(fC)
 32 return xC[i]

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 15
March 8-12, 2021
3.4.5. VaR optimization
 • constraint on asset weights:
 Í
 ⊲ repair function for ≥  , = 1
 1 def weight_repair(w,wL=0.0) −> np.array: # lower bound for weights: wL
 2 w = w.T
 3 while True:
 4 w /= np.sum(w,0)
 5 below = w
4. Algorithmic and Autotrading

4.1. some types of algorithmic trading systems
 • buy and sell orders are placed by algorithm / machine

 • arbitrage
 ⊲ self-financing portfolio that makes loss in no situation,
 EUR, €
 but profit in some

 ⊲ prices are out of equilibrium, e.g., currencies
 USD, $ GBP, £
 ⊲ different prices in different markets for same asset

 • executing rules

 ⊲ pre-specified trading rules
 ⊲ adjustment to market situations, e.g., iceberg orders
 • statistical arbitrage: probability of loss converges to 0, prob of profit to 1

 ⊲ e.g., pairs trading
 • self-adapting / learning systems

 ⊲ selection and/or combination of pre-specified rules, suitable for current situation
 ⊲ generation of new rules (algorithms)

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 17
March 8-12, 2021
4.2. machine learning and meta-heuristics techniques
4.2.1. setup
 • data: prices, factors, indices, news, etc.

 ⊲ sufficiently large sample of historical / generated data
 ⊲ online learning

 • objective: typically some risk-adjusted performance measure
 • model estimation and selection

 ⊲ e.g., genetic algorithms to find combination of indicators

 • pattern detection

 ⊲ e.g., neural network (convolutional, recurrent, long short term mem-
 ory, anfis, ...) to get trading signal

 • rule generation

 ⊲ e.g., genetic programming, grammatical evolution to generate trading and / or forecasting
 rules

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 18
March 8-12, 2021
4.2.2. example: Genetic Programming
 • concept: + Koza 1990

 ⊲ “population” of (valid) lines of code / equations / rules / . . .
 ⊲ evolve over generations by cross-over and mutation
 ( ) = sin( ) + 
 4
 ( ) = 3 ∗ (2 + ) ( ) = 
 4 ∗(2 + )
 + * *
 sin ÷ 3 + ÷ +
 4 2 4 2 

 ⊲ supervised learning: prefer solutions based on loss function
 ⊲ unsupervised learning: preference based on some quality criterion
 • examples in finance:

 ⊲ supervised: find pricing model (risk estimation model) that fit observations
 ⊲ unsupervised: find trading strategy that maximizes utility, Sharpe ratio, etc.
 ITE

 > L ITE Single tree 1bp, in−sample cumulated profits Single tree 1bp, out−of−sample cumulated profits

 0.8 0.3
 MA + < S N Cumulated profits 0.6 0.2

 Cumulated profits
 0.4 0.1

 C L1 MA K MA − 0.2 0

 0 −0.1

 C L2 C L1 MA K −0.2 −0.2

 −0.4 −0.3

 −0.4
 C L2 08/07/03 02/23/04 09/10/04 03/29/05 10/15/05 05/03/06 08/11/06 11/19/06 02/27/07 06/07/07
 Date Date

 average performance, results from individual runs, 95% and 99% confidence intervals

 © D Maringer, 4303110CR Numerical Optimisation and Simulation Learning (55)

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 19
March 8-12, 2021
4.2.3. example: Grammatical Evolution
 • concept: + Ryan, Collins, and O’Neill 1998

 • distinction genotype (list of integers) vs. phenotype (interpretation via grammar)

 • formal description of valid statements, e.g., Backus-Naur form:

 ⊲ “grammar” G with G = {N , T , S, P}
 ⊲ sets: N = non terminals, T = terminals, S = starting symbol, P = production rules
 • sequence of numbers, interpreted according to grammar (“lookup table” of functions and
 terminals)
 ⊲ genotype [0 0 1 . . .]
 
 [0 0 1] 
 [0 0 1] x
 ⊲ grammar:
 ::= 0 | ( ) 1 ⊲ genotype [1 0 0 2 0 3 1 . . .]
 
 ::= x 0 | y 1
 [1 0 0 2 0 3 1 . . .] ( )

 ::= + 0 | - 1 | * 2 | ÷3 [1 0 0 2 0 3 1 . . .] ( )
 [1 0 0 2 0 3 1 . . .] ( x )
 [1 0 0 2 0 3 1 . . .] ( x * )
 [1 0 0 2 0 3 1 . . .] ( x * )
 [1 0 0 2 0 3 1 . . .] ( x * y)

 • examples in finance:

 ⊲ create models for pricing and price impact, trading rules, etc.

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 20
March 8-12, 2021
5. Conclusion
 • some literature to get started

 ⊲ Manfred Gilli, Dietmar Maringer, and Enrico Schumann (2019). Numerical Methods and
 Optimization in Finance. 2nd edition. Academic Press. url: https:
 //www.elsevier.com/books/numerical-methods-and-optimization-in-finance/gilli/978-0-12-815065-8

 ⊲ Anthony Brabazon, Michael O’Neill, and Séan McGarraghy (2015). Natural Computing
 Algorithms. Springer
 ⊲ Dietmar Maringer (2005). Portfolio Management with Heuristic Optimization. Advances in
 Computational Management Science. Springer, Boston, MA. doi:
 https://doi.org/10.1007/b136219. url: https://doi.org/10.1007/b136219

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 21
March 8-12, 2021
Bibliography Maringer, Dietmar (2005). Portfolio Management with
 Heuristic Optimization. Advances in Computational
 Management Science. Springer, Boston, MA. doi:
Brabazon, Anthony, Michael O’Neill, and Séan McGarraghy https://doi.org/10.1007/b136219. url:
 (2015). Natural Computing Algorithms. Springer. https://doi.org/10.1007/b136219.
Brooks, Chris, Simon P. Burke, and Gita Persand (2001). Poli, Riccardo, William B. Langdon, and Nicholas F. McPhee
 “Benchmarks and the Accuracy of GARCH Model (2008). A Field Guide to Genetic Programming.
 Estimation”. In: International Journal of Forecasting 17.1, http://www.gp-field-guide.org.uk/. url:
 pp. 45–56. http://www.gp-field-guide.org.uk/.
Gilli, Manfred, Dietmar Maringer, and Enrico Schumann (2019). Price, Kenneth V., Rainer M. Storn, and Jouni A. Lampinen
 Numerical Methods and Optimization in Finance. 2nd (2005). Differential Evolution: A Practical Approach to
 edition. Academic Press. url: Global Optimization. Springer.
 https://www.elsevier.com/books/numerical-methods-and- Ryan, Conor, J.J. Collins, and Michael O’Neill (1998).
 optimization-in-finance/gilli/978-0-12-815065-8. “Grammatical Evolution: Evolving Programs for an
Koza, John R. (1990). Genetic Programming: A Paradigm for Arbitrary Language”. In: Lecture Notes in Computer
 Genetically Breeding Populations of Computer Programs Science 1391. First European Workshop on Genetic
 to Solve Problems. Tech. rep. STAN-CS-90-1314. Stanford Programming 1998. url:
 University Computer Science Department. url: http://www.grammatical-evolution.org/papers/eurogp98.ps.
 http://www.genetic-programming.com/jkpdf/tr1314.pdf.

Dietmar Maringer, Meta-Heuristics in Finance, SAMSI Metaheuristic Optimization, Machine Learning and AI Virtual Workshop 22
March 8-12, 2021
You can also read