Financial applications of Artificial Immune Systems
Artificial Immune Systems November 26th. 2007, 2:41am
Algorithms inspired by biological immune systems also find their application in Finance. Although not as popular as the Neural Net or GA and their derivatives, recent research has shown that these algorithms can provide optimisation and classification capabilities comparable to conventional methods [Gonzalez, Dasgupta]. The aim in designing artificial immune systems (AIS) is not to produce exact models of the natural immune system, but rather extract ideas and metaphors that can help solve real-world problems. There are two main categories of the Artificial Immune system namely Negative Selection and Clonal Selection which lend their inspiration to Classification and Optimisation respectively.

Background
The natural immune system is comprised of a network of specialised cells and chemical molecules which work together to defend the host organism from foreign objects (Pathogens) such as bacteria, fungi, chemical compound etc. The three main capabilities of the Natural Immune system are:
- Recognise a foreign body (pathogens) such as bacteria, fungi, chemical compound etc.
- Destroy the pathogen.
- Remember an almost unlimited number of pathogens.

There are two types of cells comprising the immune system: phagocytes and lymphocytes. The first group belongs to the innate immune system while the latter group mediates adaptive immunity. A major component of the population of lymphocytes is made up of B and T cells, whereas that of phagocytes comprises of B cells only. These cells are capable of recognising and responding to certain antigen (foreign body) patterns present on the surface of pathogens. The picture above tries to illustrate this.
Although the real workings of the immune system is complicated, the immunity process can be summarised as follows:
- Antigen-secreting pathogen enters the body
- B cells are activated by the foreign antigen
- With the help of T cells, B cells undergo cloning and mutation
- Plasma B cells secrete immunoglobulins which attach to the antigen
- Marked antigens are attacked by the immune system
- Memory of the antigen is maintained by B memory cells
The key point is that immune systems demonstrate self-organisation and adaptive behavior. From a modelling perspective, it can be considered as a sophisticated information processing system which possesses powerful pattern recognition and classification abilities. It also has the capability to adapt to new circumstances (problems), and can remember solutions to problems it has previously encountered. In designing artificial immune algorithms we wish to draw metamorphical inspiration from the workings of the natural immune system to design algorithms to solve computational problems. The negative selection algorithm and clonal expansion and selection algorithm are examples of applications of such metaphors.
Negative Selection Algorithm
The basis of the negative selection algorithm is the ability of the immune system to distinguish between two system states i.e. normal and abnormal. [Forrest] developed the negative selection algorithm and has been modified since by a number of researchers. The negative selection algorithm can be summarised as:
- Detector set D is empty
- Repeat
- Create a random vector x drawn from the valid range
- For every self element s in the self vector
- Calculate the euclidean distance between s and x
- If distance < threshold go to step 2
- Else add x (a valid non-self detector) to set D.
- Until set D contains the required number of detectors (assume N)
The flowchart below shows the above steps
To understand this let us assume we would like to classify corporate bonds so as to differentiate investment grade from junk grade. Assume that the diagnosis will be made on the basis of ratio information drawn from the financial statements of the companies and that we also have a data-set containing example ratios for financially healthy companies and also for companies which later defaulted on their bonds.
Self is defined as financially healthy companies. Next a set of detectors (of size D) is randomly created. Each of these detectors consists of a vector of real numbers, corresponding to financial data obtained from the financial statements (such as accounting ratios). The negative selection process is then applied, whereby a series of vectors of ratios corresponding to healthy companies is presented to the detectors. Any detector which is identical or similar (the degree of similarity could be measured using the euclidean distance) to a data vector corresponding to a healthy company is discarded. As detectors are discarded, new detectors are created to to build up the size of the population D, which are subject to the same negative selection process. If a detector is created which fails to match any vector in the training set of healthy companies, it is a potentially useful detector of an unhealthy company. This process is repeated until all the detectors in the out-of-sample set is exhausted.

The main challenges in applying this algorithm are:
- It ignores the fact that examples of past failing corporate bonds exist
- The task of generating a population of valid detectors will grow rapidly as the size of self increases.
These issues depend on on whether a good seed is used in generating the random number which depend on historical values of the accounting ratios. A good seed inevitably leads to early convergence which improves classification at steady state.
Clonal Expansion and Selection Algorithm
Unlike the negative selection algorithm, the clonal selection algorithm aims to mimic the creation of a large number of antibodies which will bind strongly to a specific antigen. This metaphor is adopted to design an optimisation algorithm in which the antibody can be considered as a potential solution, where the degree of the binding or fit between the antibody and the antigen represents the quality of the solution. The objective, therefore, is to start from an initial population of solutions, rest them against the antigens, using the algorithm iteratively. The steps in the clonal expansion and selection algorithm can be summarised as:
- Create an initial random population P of solution vectors (antibodies)
- Select a subset F of the solutions from P, biasing the selection process towards better solutions
- For each member of F (parents), create a set of clones, with better members of F producing more clones
- Mutate each of these clones, in inverse proportion to the parent’s fitness. Better solutions are mutated less (hypermutation)
- Select a subset of newly generated solutions S
- Create a number of newly created random solutions R
- Replace poorer members of P with better solutions from S and R
- Repeat steps 2 - 7 until termination condition is reached
The key difference between the clonal selection algorithm and other evolutionary algorithms is that this method in which variety of candidate solutions is generated when seeking to iteratively improve solutions.

As an example I apply the clonal selection algorithm to finding the maximum value of a two dimensional multi-modal function. The multi-modal function could for instance describe the fitness of an asset allocation problem. I set my parameters as follows:
- Number of iterations: 25
- Number of antibodies: 100
- Number of clones per antibody: 10
- Clone Mutation rate: 0.010
Our initial population of 2-dimensional solution antibodies occupies different locations of the function:

After 25 iterations we see the clonal algorithm has managed to converge to the maximum points on the function

We have shown that the clonal expansion and selection can be used to optimise a 2-dimensional multi-modal function. This example can be extended to problems of n-dimension such as optimising trading rules or tactically allocating a portfolio of stocks to meet certain risk /return requirements. We will hopefully discuss such problems in due course. I hope this post gives the reader a rough idea of how Artificial Immune Systems can be applied to finance. Off-course complete understanding of these algorithms comes from the workings of the actual biological process from which the metaphors are drawn, which the reader may be keen to explore further before attempting to apply these algorithms.

November 26th, 2007 at 5:26 am
[…] idRooT | Web Hosting - Reseller Hosting - Domain Registration - IIX - Indonesia - USA placed an observative post today on Financial applications of Artificial Immune Systems […]
December 18th, 2007 at 2:23 am
You should consider citing your sources.
December 18th, 2007 at 10:13 am
Bijan,
My sources can be found under the “References” section of my blog, which sometimes gets out of sync depending on how frequently I update. By all means I try to be specific with references within each entry but and I apologize on this occasion for being reluctant to do so. I shall update likewise.
Piyush.
December 19th, 2007 at 10:52 pm
[…] Immune System works. I thought it would be a great addition to one of my previous posts “Financial applications of Artificial Immune Systems“. I’ve copied it below for easy […]
December 25th, 2007 at 7:50 am
Piyush,
Thanks. Great writeup, by the way. This is one of the better descriptions of this algorithm out there.
January 7th, 2008 at 7:57 pm
Thanks , that was helpful to me very much
How can I get the source code of the Clonal Expansion and Selection Algorithm
Thanks again
January 8th, 2008 at 6:35 pm
John,
In what language to you want the source code? I only have the Matlab source if that’s what you are looking for.
Piyush.
January 9th, 2008 at 8:08 am
Piyush,
Yes Matlab code will be great
I will be pleasure if you send it to me
yrh2010 at yahoo dot com
Thanks in advance
April 17th, 2008 at 8:08 am
Hye…would appreciate if you can send the source code to me to… ritahani at gmail dot com