Parallel Genetic Algorithms for the Calibration of Financial Models Riccardo Gismondi June 13, 2008 High Performance Computing in Finance and Insurance Research Institute for Computational Methods Vienna University of Economics and B.A. Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 1 / 47
Contents 1 Genetic Algorithms Introduction and General Concepts How GAs work 2 CIR Interest Rate Model A general overview of IR models CIR model calibration with Genetic Algorithms 3 Parallel Genetic Algorithms and Applications A classification of parallel GAs Application 4 Conclusion Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 2 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts GAs simulate the evolution of a population of individuals, which are possible solutions of a specific problem, through the evolution principle: Survival of the Fittest GAs are search algorithms which apply the mechanism of natural selection and sexual reproduction Genetic Algorithms (GA): John Holland, University of Michigan, 1968-1975 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 3 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts The original model of Holland: population of pop size binary strings of fix length l (called individuals, genotypes, structures, chromosomes) Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 4 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts the evaluation function f plays the role of the environment it rates solutions according to their fitness i.e. how good they are in solving the search problem for a population P of pop size individuals f : P (, + ); f (c i ) = f i, i = 1,..., pop size the set of all binary strings of fixed length l as {0, 1} = 2 l elements is the search space of the GA the fitness landscape is the set of fitness values of the evaluation function on the search space Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 5 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts once that a population of individuals is evaluated through the fitness function a new population is created applying certain operators these operators are selection (inspired from natural selection) crossover (inspired from genetics) mutation (inspired from genetics) crossover and mutation are called genetic operators Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 6 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts The Evolution theory from Darwin tells us that the strongest individuals have a higher ability to adapt to their environment. Therefore, the chance to survive (survival probability) is higher than for weaker individuals. In Holland s GA, the stronger individuals have the higher fitness values because they are better in solving the search problem. For reproduction purposes (mating), the stronger individuals have to be selected prior to the others. Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 7 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts Holland chooses a selection mechanism proportional to the fitness value of the individual. For an individual c i P with f (c i ) = f i, the selected probability is p i = f i pop size i=1 f i These probabilities are taken to construct a biased roulette (roulette wheel mechanism). Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 8 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts Figure: Roulette Wheel Mechanism The 4 individuals A1, A2, A3 and A4, with selection probability 0.12, 0.18, 0.3 and 0.4, are represented by the slots of the biased roulette. These slots are proportional to the probability of selection. Example: if the selection operator generates c = 0.88 as random number, the individual A4 is selected. Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 9 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts Each time an individual is selected, the individual is copied into the mating-pool. At the end of the selection process, the mating-pool contains exactly pop size individuals. After this, the new population is created applying the genetic operators crossover and mutation to the individuals of the mating-pool. Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 10 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts after a random selection of two parent individuals and one crossover point, the elements right to the crossover point are swapped two new individuals are created. The crossover operator is applied n 2 times, according to a certain probability p c such to generate exactly n new children. If the crossover-operator is not applied, the children are exactly like their parents. Figure: Crossover Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 11 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts after the application of the crossover, according to a certain (usually very small) probability p m, the mutation operator is applied to every bit of every individual and this changes the bit-value Figure: Mutation like the crossover is a metaphor of the sexual reproduction, the mutation operator models the genetic phenomenon of rare changes in the genetic code of an individual. Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 12 / 47
Genetic Algorithms Introduction and General Concepts Introduction and General Concepts Figure: GA Procedure Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 13 / 47
Genetic Algorithms Solving a Maximization Problem How GAs work To understand how genetic algorithms work, consider to find the maximum of the function f (x) = x sin (10πx) + 1, x [ 1, 2] In the implementation of the genetic algorithm, you have to consider the following points: Genetic representation of potential solution A way to create initial solution Evaluation function: fitness Selection process Genetic operators Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 14 / 47
Genetic Algorithms Solving a Maximization Problem How GAs work Figure: Function to be Maximized Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 15 / 47
Genetic Algorithms How GAs work Representation Binary vector as chromosome to represent real value of the variable x. Length of domain is 3. Precision requirements (for example): 6 places after decimal point. The range [ 1, 2] should be divided into at least 3 1.000.000 equal size range 22 bits are required as a binary vector, since 2.097.152 = 2 21 < 3.000.000 2 22 = 4.194.304 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 16 / 47
Genetic Algorithms How GAs work Representation The mapping for a binary string b 21 b 20... b 0 into a real number x is a 2-step procedure: 1 Convert the string b 21 b 20... b 0 from base 2 to a base 10 ( b 21 b 20... b 0 ) 2 = 2 find a corresponding real number x: ( 21 ) b i 2 i i=0 x = 1 + x 3 2 22 1 10 = x Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 17 / 47
Representation Genetic Algorithms How GAs work for example (1000101110110101000111) represents the number 0.637197, since and x = 1 + x (1000101110110101000111) 2 = 2288967 3 2 22 1 = 1 + 2288967 3 4194303 = 0.637197 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 18 / 47
Genetic Algorithms How GAs work Initial Population The initialization process is very simple: we create a random population of pop size binary vectors of 22 bits. e.g.: v 1 = (1000101110110101000111) v 2 = (1111101110110001010111)... v pop size = (1001101010000001010001) If we do have some knowledge about the distribution of potential optima, we may use such information. Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 19 / 47
Genetic Algorithms How GAs work Evaluation Function Evaluation function for binary vectors is equivalent to the function f. e.g.: v 1 = (1000101110110101000111) = 0.637197 v 2 = (0000001110000000010000) = 0.958973 v 3 = (1110000000111111000101) = 1.6227888 consequently: eval(v 1 ) = f (v 1 ) = 1.586345 eval(v 2 ) = f (v 2 ) = 0.078878 eval(v 3 ) = f (v 3 ) = 2.250650 and v 3 is the best of the 3 chromosomes (max. problem!) Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 20 / 47
Genetic Algorithms How GAs work Genetic Operators - Mutation Mutation alters one or more genes (positions in a chromosome) with probability equal to the p m. Assume that the fifth gene from the v 3 chromosome was selected for a mutation. Since the fifth gene is 0, it would be flipped to 1. After this operation the new chromosome would be v 3 = (1110100000111111000101) = 1.721638 with eval(v 3) = f (v 3) = 0.082257 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 21 / 47
Genetic Algorithms Genetic Operators - Mutation How GAs work On the other hand, if the 10th gene was selected, then v 3 = (1110000001111111000101) = 1.630818 eval(v 3 ) = f (v 3 ) = 2.343555 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 22 / 47
Genetic Algorithms How GAs work Genetic Operators - Crossover Let us illustrate the crossover operator on v 2 and v 3 which are selected from a population with probability p c Suppose that the (one-)crossover point was (randomly) selected after the fifth gene: the new off spring are v 2 = (00000 01110000000010000) = 0.958973 v 3 = (11100 00000111111000101) = 1.6227888 v 2 = (11100 01110000000010000) = 0.998113 v 3 = (00000 00000111111000101) = 1.666028 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 23 / 47
Genetic Algorithms Genetic Operators - Crossover How GAs work In general: 1-point crossover: 2-point crossover: m-point crossover (e.g. m=4): v 2 = (00000 01110000000010000) v 3 = (11100 00000111111000101) v 2 = (00000 0111000000001 0000) v 3 = (11100 0000011111100 0101) v 2 = (00000 01 11000000 001 0000) v 3 = (11100 00 00011111 100 0101) Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 24 / 47
Genetic Algorithms How GAs work Selection Process Different methods for selection: in this talk Roulette wheel Without any loss of generality, we can assume a maximization problem only, in fact: min (f (x)) = max ( f (x)) Moreover we can assume that f takes only positive values; otherwise we can add a positive constant C: max (f (x)) = max (f (x) + C) In order to construct a Roulette wheel with slots sized according to the fitness we proceed as follows (see next slides) Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 25 / 47
Selection Process Genetic Algorithms How GAs work Calculate the fitness value eval(v i ) for each chromosome v i (i = 1,..., pop size) Find the total fitness of the population F = pop size i=1 eval(v i ) Calculate the probability of selection p i for each chromosome v i (i = 1,..., pop size): p i = eval(v i) F Calculate a cumulative probability q i for each chromosome v i (i = 1,..., pop size): i q i = j=1 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 26 / 47 p j
Selection Process Genetic Algorithms How GAs work Figure: Roulette Wheel Mechanism Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 27 / 47
Genetic Algorithms How GAs work Selection Process The selection process is based on spinning the roulette pop size times each time we select a single chromosome for a new population in the following way: 1 generate a random number R U(0, 1) 2 if r < q 1 then select the chromosome v 1 ; otherwise select the i-th chromosome v i (2 i pop size) such that q i 1 < r q i Obviously, some chromosome would be selected more than once: the best chromosomes get more copies, the average stay even, and the worst die off (Schema Theorem) Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 28 / 47
CIR Interest Rate Model A general overview of IR models A general overview of IR models The interest rate, usually written r(t, T ) is the rate at which an entity can borrow money for period T t of time The short rate, usually written r t is the (annualized) interest rate at which an entity can borrow money for an infinitesimally short period of time, r t = r(t, t) Specifying the current short rate does not specify the entire yield curve. Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 29 / 47
CIR Interest Rate Model A general overview of IR models A general overview of IR models However, no-arbitrage arguments show that, under some fairly relaxed technical conditions, if we model the evolution of r t as a stochastic process under a risk-neutral measure Q then the price at time t of a zero-coupon bond maturing at time T is given by ( T ) P(t, T ) = E(exp r s ds F t ) t where F t is the natural filtration for the process. Thus specifying a model for the short rate specifies future bond prices. This means that forward rates are also specified by the usual formula: f (t, T ) = ln (P(t, T )) T Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 30 / 47
CIR Interest Rate Model A general overview of IR models A general overview of IR models In finance there are different models for the short rate we differentiate between one-factor and multi-factor-models one-factor models: Vasicek Model: dr t = a(b r t)dt + σdw t Cox-Ingersoll-Ross-Model: multi-factor models: Longstaff-Schwarz-Model: dr t = α(γ r t)dt + ρ r tdw t dx t = (θ Y t)dt + X tσdw t Chen-Model: dy t = (ζ Y t)dt + Y tσdw t dr t = (θ α t)dt + r tσ tdw t dα t = (ζ α t)dt + α tσ tdw t dσ t = (β σ t)dt + (σ t)ηdw t Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 31 / 47
CIR model calibration CIR Interest Rate Model CIR model calibration with Genetic Algorithms Once that a model for the short rate is chosen, it is very important to estimate the optimal parameters of the model. In Finance this procedure is well known as the calibration of the model. We are looking for the model-parameters that optimally generate prices that are very near to real market prices. That means the calibration of a model is equivalent to solve an optimization problem of the form: f (θ 1, θ 2,..., θ n ) = n w i ( ) Pi mod Pi market 2 i=1 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 32 / 47
CIR model calibration CIR Interest Rate Model CIR model calibration with Genetic Algorithms For the CIR model: f (r 0, φ 1, φ 2, φ 3 ) = n w i ( Pi mod i=1 ) Pi market 2 Pi mod (t, T i ) = F (t, T i ) exp ( G(t,T i )r 0 ) [ φ 1 exp (φ 2(T i t)) F (t, T i ) = ( φ 2 exp (φ 1 (T i t)) 1 ) + φ 1 [ ( exp (φ 1 (T i t)) 1 ) ] G(t, T i ) = φ 2 ( exp (φ 1 (T i t)) 1 ) + φ 1 the CIR model is characterized by a very high non-linear objective function it is also not known whether this function is convex or concave (global optimization) Genetic Algorithm Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 33 / 47 ] φ3
Parallel Genetic Algorithms and Applications A classification of parallel GAs Classification of parallel GA The basic idea behind most parallel programs is to divide a large problem into smaller tasks tasks are solved simultaneously on multiple processors In the classification of parallel GA (Adamidis 1994, Lin et al. 1994, Alba & Troya 1999, Tomassini 1999, Cantu-Paz 2000) we can recognize 4 major types Single-Population master-slave GAs, Multiple-population GAs, Fine-grained GAs, Hierarchical hybrids Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 34 / 47
Parallel Genetic Algorithms and Applications Classification of parallel GA A classification of parallel GAs Single-population master-slave GAs have a single population one master node executes the GA (selection, crossover, mutation) and the evaluation of fitness is performed by the slave nodes Multiple-population GAs (island model) they consist of several subpopulations that exchange individuals occassionally this exchange is called migration and is controlled by several parameters (e.g. frequency of migration, number and destination of migrants, and the selection method for choosing the migrants) Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 35 / 47
Parallel Genetic Algorithms and Applications Classification of parallel GA A classification of parallel GAs Fine-grained GAs they consist of a single-spatially-structured population the population structure is usually 2-dimensional and there is only one individual per grid point ideally, there is one processor per individual, so the evaluation of fitness is performed simultaneously for all the individuals selection and mating are restricted to a small neighbourhood around each individual this class of parallel GA is also sometimes called as diffusion-model Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 36 / 47
Parallel Genetic Algorithms and Applications Classification of parallel GA A classification of parallel GAs Hierarchical GAs these are multiple-deme algorithms with single-population parallel GAs a hierarchical parallel GA combines the benefits of its components and has the potential of better performance than any of them alone the hierarchical algorithms are very well suited to be implemented on symmetric multi-processors Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 37 / 47
Parallel Genetic Algorithms and Applications Application CIR model calibration with a Parallel GA we implemented a Parallel Genetic Algorithm in the programming language C and MPI it is a Multiple-Population GA based on a n m torus therefore we need, n m slave nodes and 1 master node our application has approx. 2000 lines of code Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 38 / 47
Parallel Genetic Algorithms and Applications Application CIR model calibration with a Parallel GA description of the algorithm the master-node reads the input parameters and broadcasts them to all slave nodes every slave node generates a start-population applies the roulette wheel mechanism for selection applies single-point crossovers applies mutations evaluates the fitness of the population every epoch sends elements to its neighbours according to the chosen migration strategy (no migration, random selection, elitist selection) and sends the best individual back to the master-node the master node evaluates all the individuals and again chooses the best Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 39 / 47
Parallel Genetic Algorithms and Applications Application CIR model calibration with a Parallel GA the Torus Topology Figure: 6 x 4 Torus Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 40 / 47
Parallel Genetic Algorithms and Applications Application CIR model calibration with a Parallel GA the visualization with XMPI clearly tells us that this is no highly parallel application there is a huge communication overhead between the slaves Figure: Migration of Elements between the Neighbours Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 41 / 47
Parallel Genetic Algorithms and Applications Application CIR model calibration with a Parallel GA to test the efficiency of the migration strategy we performed 100 runs with the following parameters generations: 5000 1 epoch = 250 generations popsize = 50 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 42 / 47
Parallel Genetic Algorithms and Applications Application CIR model calibration with a Parallel GA migration with 2 elements preliminary results: No Random Elitist Migration Migration Migration Min 0.00035200 0.00035300 0.00035600 Max 0.00042800 0.00042000 0.00043700 Std.Dev. 0.00001650 0.00001319 0.00001510 Mean 0.00037709 0.00037467 0.00037933 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 43 / 47
Parallel Genetic Algorithms and Applications Application CIR model calibration with a Parallel GA migration with 5 elements preliminary results: No Random Elitist Migration Migration Migration Min 0.00035200 0.00035400 0.00035300 Max 0.00042800 0.00044500 0.00043000 Std.Dev. 0.00001650 0.00001610 0.00001547 Mean 0.00037709 0.00037910 0.00037961 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 44 / 47
Parallel Genetic Algorithms and Applications Application CIR model calibration with a Parallel GA migration with 10 elements preliminary results: No Random Elitist Migration Migration Migration Min 0.00035200 0.00035100 0.00035200 Max 0.00042800 0.00041400 0.00042700 Std.Dev. 0.00001650 0.00001321 0.00001525 Mean 0.00037709 0.00037461 0.00037829 Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 45 / 47
Conclusion Conclusion Parallel Genetic Algorithms definitely outperform Single Node GAs the way of migrating the elements, e.g. swapping the elements with the neighbours only or to apply a hamming-distance-based sending method as well as the selection of the elements sent, e.g. random sampling of elements send elements that fit best can be discussed in further detail Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 46 / 47
Conclusion Thank you for your attention! Riccardo Gismondi () Parallel Genetic Algorithms June 13, 2008 47 / 47