SlideShare a Scribd company logo
Computational
  Financial
  Modeling
Enhancing Technical
Analysis With Genetic
    Algorithm

 SAIKIRAN |DEEPAK SHARMA | PRANJAL JAIN
              23RD NOV. 2012
How Genetic Algorithm can be used to improve the
    performance of a particular trading rule ?



We need to optimize the parameters used by
             the trading rule
HOW TO DO THIS NOW?

Consider a Simple Moving Average system, commonly used in trading
             simulators, which has two set of parameters


               The lengths of two moving averages
OUR MOTIVE

        To investigate how Genetic Algorithms, a class of
    Algorithms in evolutionary computation can be used to
     improve the performance of a particular trading rule


   How changes in the design of the GA itself can affect the
solution quality obtained in context of technical trading system.
The GA

   Search and global optimization procedure
   Based on the natural biological evolution.
   Stochastic in nature
   Characterized by speed
ALGORITHM
Genetic Algorithm ()
{
    Generate initial selection operator
    Evaluate the fitness value
While ( do not satisfy a stop condition)
{
      Execute the selection operator
      Execute the crossover operator
      Execute the mutation operator
      Evaluate the fitness value
}
}
The Way GA Works

   Beginning with random generation
   GA goal is to improve the fitness of solutions as the
    generation passes by.
   Stopping Condition:
       Until some fixed number of iterations or
       Achievement of satisfactory fitness level.
SOME USEFUL TERMS

Crossover
If two parents are represented by a high level of fitness, then
crossing them will lead to a better offspring (solution).



Mutation
As search space is large, some amount of randomness is
maintained through generations by mutation operator applied
infrequently.
Enhancing Moving Average
         System
A moving average for n days is given by:

                                   𝑛
                            1
                                           𝑃 𝑡−𝑖
                            𝑛
                                  𝑖=0

                            𝜃1                     𝜃2
           𝜃1 < 𝜃2     1                      1
                                   𝑃 𝑡−𝑖    >            𝑃 𝑡−𝑖
           If          𝜃1
                            𝑖=0
                                              𝜃2
                                                   𝑖=0
                                                                 𝐵𝑢𝑦 𝑠𝑖𝑔𝑛𝑎𝑙



          Else                                                   Sell 𝑠𝑖𝑔𝑛𝑎𝑙
CONTINUED…




   The lengths of MAs are chosen instinctively by the trader.
   If say we consider 500 days of data, then the number of
    possible ways of choosing lengths becomes 500x500


        That makes the search space exponentially larger!
FOCUS
    Optimizing our trading system means maximizing our Fitness
               Function such as Profit, given by
                                𝒇

                      𝑻𝑹 𝒇 =         (𝟏 + 𝑫𝑹 𝒊 )
                               𝒊=𝟏


                      𝑫𝑹 𝒊 =   𝑷 𝒊 − 𝑷 𝒊−𝟏 × 𝜹


TRf - Total return for the sample period
DRi - Daily return for the day i,
Pi denotes the stock price for the day i.
δ - dummy variable which generates value 1 for buy
and -1 for sell
ENCODING

   Each parameter in Genetic Algorithm is encoded as binary string and
    concatenated to form a chromosome.
   Shorter moving average goes from 1 session to 256 session i.e. string length
    of 8 bits ex. 01100101]
   Longer moving average goes from 1 session to 512 session i.e. string length
    of 9 bits [ex. 110010101] Thus total search space is of 17 bits [ex. 01100101;
    110010101] i.e. 217.
Simulation Process
I/P Used while Applying GA



 We have used TCS data from
National Stock Exchange from 1st
   July 2010 to 31st July 2012.
Implementation using R
                                Library used: genal


CODE:


avg <- function(data,min,max)
{
sum <- 0;
for(i in min:max)
{
  sum <- sum+data[i,]
}
sum <- sum/(max-min+1)
return (sum);
}
evaluate <- function(string=c()) {
      returnVal = 0;
      if (length(string) == 2) {
        theta1 <- string[1];
        theta2 <- string[2];
        for(i in (1:(dim(data))){
          if(i > max(theta1,theta2)+1){
            delta <- 0
            avg1 <- avg(data,max(i-theta1,1),i)
            avg2 <- avg(data,max(i-theta2,1),i)
            if(avg1>avg2){
              delta = 1;
            }
            else{
              delta = -1;
            }
            returnVal <- returnVal+(delta*(data[i,]-data[i-1,]));
          }
         }
      }
      else {
        stop("Expecting a chromosome of length 2!");
      }
      return (returnVal+max((theta1-theta2)*1000,0));
    }
Maximum fitness function performance for
GA applied for different population sizes
RESULT




         Different Population
                 sizes
                For 50
                For 30
RESULT


Population Size         50             30
     𝜃1, 𝜃2            11,50         91,114
  Max Profit        Rs. 217.65/-   Rs. 198.24/-
 Max Return          127.48%        125.04%
Results given in paper
Genetic Algorithm: An Application to Technical Trading System
Design by V. Kapoor, S.Dey, A.P. Khurana



    Population
                      20             50            70           100
       size
       𝜃1/𝜃2       235/414          4/40         12/173        9/212
    Max. Profit   Rs. 834.35     Rs.932.84/-    Rs.936/-      Rs.947/-
       Avg.
                  Rs. 709.46/-   Rs. 745.9/-   Rs. 732.14/- Rs. 672.02/-
      Return
       Max.
                   116.60%        141.27%       160.39%       150.38%
      Return
     Std. dev.
                  83.029836      98.232199      99.66883    109.248246
     of Profits
       Max.
      profit./    10.048797      9.4962752     9.3911005    8.66833139
      St.dev.
INFERENCES
   As long as the population size is increased, the best possible
    solution obtained is higher.
   In case of average fitness, it increases after population size of
    20, till 50 and then decreases, showing that the solution series
    becomes noisy in nature.
   Standard deviation is the measure of diversity in the
    population.
   Population size increase the solution quality.
CONCLUSION

   Genetic Algorithm performs better than the moving average lengths
    derived from rules in finance literature.
   To a great extent we are able to beat “Efficient Market Hypothesis”(EMH)
    (Any public information is reflected in the stock price and it is difficult to
    beat market.)
REFERENCES

   Genetic Algorithm: An Application to Technical Trading System Design
    (V. Kapoor, S.Dey, A.P. Khurana)
   Genetic Algorithm: Wikipedia
   NSE Site
THANK YOU
    Deepak Sharma
      IIT Mandi




Copyright 2013 Deepak Sharma IIT Mandi

More Related Content

Similar to Genetic algorithm

Simple rules for building robust machine learning models
Simple rules for building robust machine learning modelsSimple rules for building robust machine learning models
Simple rules for building robust machine learning models
Kyriakos Chatzidimitriou
 
Transformers.pdf
Transformers.pdfTransformers.pdf
Transformers.pdf
Ali Zoljodi
 
Intro to Quant Trading Strategies (Lecture 8 of 10)
Intro to Quant Trading Strategies (Lecture 8 of 10)Intro to Quant Trading Strategies (Lecture 8 of 10)
Intro to Quant Trading Strategies (Lecture 8 of 10)
Adrian Aley
 
Intro to Quantitative Investment (Lecture 6 of 6)
Intro to Quantitative Investment (Lecture 6 of 6)Intro to Quantitative Investment (Lecture 6 of 6)
Intro to Quantitative Investment (Lecture 6 of 6)
Adrian Aley
 
Lecture4.pptx
Lecture4.pptxLecture4.pptx
Lecture4.pptx
yasir149288
 
Explore ml day 2
Explore ml day 2Explore ml day 2
Explore ml day 2
preetikumara
 
Deep Learning: Introduction & Chapter 5 Machine Learning Basics
Deep Learning: Introduction & Chapter 5 Machine Learning BasicsDeep Learning: Introduction & Chapter 5 Machine Learning Basics
Deep Learning: Introduction & Chapter 5 Machine Learning Basics
Jason Tsai
 
Optimal Learning for Fun and Profit with MOE
Optimal Learning for Fun and Profit with MOEOptimal Learning for Fun and Profit with MOE
Optimal Learning for Fun and Profit with MOE
Yelp Engineering
 
User Payment Prediction in Free-to-Play
User Payment Prediction in Free-to-PlayUser Payment Prediction in Free-to-Play
User Payment Prediction in Free-to-PlayAhmed Hassan
 
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an..."Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
Quantopian
 
Regression
RegressionRegression
Regression
Ncib Lotfi
 
Random Forest / Bootstrap Aggregation
Random Forest / Bootstrap AggregationRandom Forest / Bootstrap Aggregation
Random Forest / Bootstrap Aggregation
Rupak Roy
 
Methods of Optimization in Machine Learning
Methods of Optimization in Machine LearningMethods of Optimization in Machine Learning
Methods of Optimization in Machine Learning
Knoldus Inc.
 
2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...
2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...
2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...
Masanori HIRANO
 
[GAN by Hung-yi Lee]Part 1: General introduction of GAN
[GAN by Hung-yi Lee]Part 1: General introduction of GAN[GAN by Hung-yi Lee]Part 1: General introduction of GAN
[GAN by Hung-yi Lee]Part 1: General introduction of GAN
NAVER Engineering
 
Pricing optimization poster version 2 (1)
Pricing optimization poster version 2 (1)Pricing optimization poster version 2 (1)
Pricing optimization poster version 2 (1)Alex Potocki
 
Topic 2 economic optimization
Topic 2 economic optimizationTopic 2 economic optimization
Topic 2 economic optimization
nouman ali
 
Scheduling advertisements on a web page to maximize revenue
Scheduling advertisements on a web page to maximize revenueScheduling advertisements on a web page to maximize revenue
Scheduling advertisements on a web page to maximize revenueShu-Jeng Hsieh
 
Causal reasoning and Learning Systems
Causal reasoning and Learning SystemsCausal reasoning and Learning Systems
Causal reasoning and Learning Systems
Trieu Nguyen
 

Similar to Genetic algorithm (20)

Simple rules for building robust machine learning models
Simple rules for building robust machine learning modelsSimple rules for building robust machine learning models
Simple rules for building robust machine learning models
 
Transformers.pdf
Transformers.pdfTransformers.pdf
Transformers.pdf
 
Intro to Quant Trading Strategies (Lecture 8 of 10)
Intro to Quant Trading Strategies (Lecture 8 of 10)Intro to Quant Trading Strategies (Lecture 8 of 10)
Intro to Quant Trading Strategies (Lecture 8 of 10)
 
Intro to Quantitative Investment (Lecture 6 of 6)
Intro to Quantitative Investment (Lecture 6 of 6)Intro to Quantitative Investment (Lecture 6 of 6)
Intro to Quantitative Investment (Lecture 6 of 6)
 
Lecture4.pptx
Lecture4.pptxLecture4.pptx
Lecture4.pptx
 
Explore ml day 2
Explore ml day 2Explore ml day 2
Explore ml day 2
 
Deep Learning: Introduction & Chapter 5 Machine Learning Basics
Deep Learning: Introduction & Chapter 5 Machine Learning BasicsDeep Learning: Introduction & Chapter 5 Machine Learning Basics
Deep Learning: Introduction & Chapter 5 Machine Learning Basics
 
Optimal Learning for Fun and Profit with MOE
Optimal Learning for Fun and Profit with MOEOptimal Learning for Fun and Profit with MOE
Optimal Learning for Fun and Profit with MOE
 
User Payment Prediction in Free-to-Play
User Payment Prediction in Free-to-PlayUser Payment Prediction in Free-to-Play
User Payment Prediction in Free-to-Play
 
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an..."Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
"Quantitative Trading as a Mathematical Science" by Dr. Haksun Li, Founder an...
 
Regression
RegressionRegression
Regression
 
Random Forest / Bootstrap Aggregation
Random Forest / Bootstrap AggregationRandom Forest / Bootstrap Aggregation
Random Forest / Bootstrap Aggregation
 
Methods of Optimization in Machine Learning
Methods of Optimization in Machine LearningMethods of Optimization in Machine Learning
Methods of Optimization in Machine Learning
 
2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...
2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...
2020/11/19 PRIMA2020: Simulation of Unintentional Collusion Caused by Auto Pr...
 
193_report (1)
193_report (1)193_report (1)
193_report (1)
 
[GAN by Hung-yi Lee]Part 1: General introduction of GAN
[GAN by Hung-yi Lee]Part 1: General introduction of GAN[GAN by Hung-yi Lee]Part 1: General introduction of GAN
[GAN by Hung-yi Lee]Part 1: General introduction of GAN
 
Pricing optimization poster version 2 (1)
Pricing optimization poster version 2 (1)Pricing optimization poster version 2 (1)
Pricing optimization poster version 2 (1)
 
Topic 2 economic optimization
Topic 2 economic optimizationTopic 2 economic optimization
Topic 2 economic optimization
 
Scheduling advertisements on a web page to maximize revenue
Scheduling advertisements on a web page to maximize revenueScheduling advertisements on a web page to maximize revenue
Scheduling advertisements on a web page to maximize revenue
 
Causal reasoning and Learning Systems
Causal reasoning and Learning SystemsCausal reasoning and Learning Systems
Causal reasoning and Learning Systems
 

More from Deepak Sharma

Deepak sharma resume
Deepak sharma resumeDeepak sharma resume
Deepak sharma resumeDeepak Sharma
 
ME 590 Final report_ideepaks_Fall'14
ME 590 Final report_ideepaks_Fall'14ME 590 Final report_ideepaks_Fall'14
ME 590 Final report_ideepaks_Fall'14Deepak Sharma
 
Hands-on Robotics_Robotic Arm
Hands-on Robotics_Robotic ArmHands-on Robotics_Robotic Arm
Hands-on Robotics_Robotic ArmDeepak Sharma
 
Hands-on Robotics_Way Point Navigation
Hands-on Robotics_Way Point NavigationHands-on Robotics_Way Point Navigation
Hands-on Robotics_Way Point NavigationDeepak Sharma
 
Portfolio: Deepak Sharma
Portfolio: Deepak Sharma Portfolio: Deepak Sharma
Portfolio: Deepak Sharma
Deepak Sharma
 
Why Siren sounds the way it dioes?
Why Siren sounds the way it dioes?Why Siren sounds the way it dioes?
Why Siren sounds the way it dioes?
Deepak Sharma
 
Police Siren Analysis
Police Siren AnalysisPolice Siren Analysis
Police Siren Analysis
Deepak Sharma
 
Memory disorders
Memory disordersMemory disorders
Memory disorders
Deepak Sharma
 
Rolling Process
Rolling ProcessRolling Process
Rolling Process
Deepak Sharma
 
Gears and Gear Trains
Gears and Gear Trains Gears and Gear Trains
Gears and Gear Trains
Deepak Sharma
 
Work Culture at Management Consulting Firms
Work Culture at Management Consulting FirmsWork Culture at Management Consulting Firms
Work Culture at Management Consulting Firms
Deepak Sharma
 
Layout Strategy
Layout StrategyLayout Strategy
Layout Strategy
Deepak Sharma
 

More from Deepak Sharma (12)

Deepak sharma resume
Deepak sharma resumeDeepak sharma resume
Deepak sharma resume
 
ME 590 Final report_ideepaks_Fall'14
ME 590 Final report_ideepaks_Fall'14ME 590 Final report_ideepaks_Fall'14
ME 590 Final report_ideepaks_Fall'14
 
Hands-on Robotics_Robotic Arm
Hands-on Robotics_Robotic ArmHands-on Robotics_Robotic Arm
Hands-on Robotics_Robotic Arm
 
Hands-on Robotics_Way Point Navigation
Hands-on Robotics_Way Point NavigationHands-on Robotics_Way Point Navigation
Hands-on Robotics_Way Point Navigation
 
Portfolio: Deepak Sharma
Portfolio: Deepak Sharma Portfolio: Deepak Sharma
Portfolio: Deepak Sharma
 
Why Siren sounds the way it dioes?
Why Siren sounds the way it dioes?Why Siren sounds the way it dioes?
Why Siren sounds the way it dioes?
 
Police Siren Analysis
Police Siren AnalysisPolice Siren Analysis
Police Siren Analysis
 
Memory disorders
Memory disordersMemory disorders
Memory disorders
 
Rolling Process
Rolling ProcessRolling Process
Rolling Process
 
Gears and Gear Trains
Gears and Gear Trains Gears and Gear Trains
Gears and Gear Trains
 
Work Culture at Management Consulting Firms
Work Culture at Management Consulting FirmsWork Culture at Management Consulting Firms
Work Culture at Management Consulting Firms
 
Layout Strategy
Layout StrategyLayout Strategy
Layout Strategy
 

Recently uploaded

Introduction to Indian Financial System ()
Introduction to Indian Financial System ()Introduction to Indian Financial System ()
Introduction to Indian Financial System ()
Avanish Goel
 
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Vighnesh Shashtri
 
when will pi network coin be available on crypto exchange.
when will pi network coin be available on crypto exchange.when will pi network coin be available on crypto exchange.
when will pi network coin be available on crypto exchange.
DOT TECH
 
how can i use my minded pi coins I need some funds.
how can i use my minded pi coins I need some funds.how can i use my minded pi coins I need some funds.
how can i use my minded pi coins I need some funds.
DOT TECH
 
Intro_Economics_ GPresentation Week 4.pptx
Intro_Economics_ GPresentation Week 4.pptxIntro_Economics_ GPresentation Week 4.pptx
Intro_Economics_ GPresentation Week 4.pptx
shetivia
 
234Presentation on Indian Debt Market.ppt
234Presentation on Indian Debt Market.ppt234Presentation on Indian Debt Market.ppt
234Presentation on Indian Debt Market.ppt
PravinPatil144525
 
how to sell pi coins in South Korea profitably.
how to sell pi coins in South Korea profitably.how to sell pi coins in South Korea profitably.
how to sell pi coins in South Korea profitably.
DOT TECH
 
Isios-2024-Professional-Independent-Trustee-Survey.pdf
Isios-2024-Professional-Independent-Trustee-Survey.pdfIsios-2024-Professional-Independent-Trustee-Survey.pdf
Isios-2024-Professional-Independent-Trustee-Survey.pdf
Henry Tapper
 
655264371-checkpoint-science-past-papers-april-2023.pdf
655264371-checkpoint-science-past-papers-april-2023.pdf655264371-checkpoint-science-past-papers-april-2023.pdf
655264371-checkpoint-science-past-papers-april-2023.pdf
morearsh02
 
what is a pi whale and how to access one.
what is a pi whale and how to access one.what is a pi whale and how to access one.
what is a pi whale and how to access one.
DOT TECH
 
GeM ppt in railway for presentation on gem
GeM ppt in railway  for presentation on gemGeM ppt in railway  for presentation on gem
GeM ppt in railway for presentation on gem
CwierAsn
 
This assessment plan proposal is to outline a structured approach to evaluati...
This assessment plan proposal is to outline a structured approach to evaluati...This assessment plan proposal is to outline a structured approach to evaluati...
This assessment plan proposal is to outline a structured approach to evaluati...
lamluanvan.net Viết thuê luận văn
 
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
beulahfernandes8
 
What price will pi network be listed on exchanges
What price will pi network be listed on exchangesWhat price will pi network be listed on exchanges
What price will pi network be listed on exchanges
DOT TECH
 
The secret way to sell pi coins effortlessly.
The secret way to sell pi coins effortlessly.The secret way to sell pi coins effortlessly.
The secret way to sell pi coins effortlessly.
DOT TECH
 
The WhatsPump Pseudonym Problem and the Hilarious Downfall of Artificial Enga...
The WhatsPump Pseudonym Problem and the Hilarious Downfall of Artificial Enga...The WhatsPump Pseudonym Problem and the Hilarious Downfall of Artificial Enga...
The WhatsPump Pseudonym Problem and the Hilarious Downfall of Artificial Enga...
muslimdavidovich670
 
What website can I sell pi coins securely.
What website can I sell pi coins securely.What website can I sell pi coins securely.
What website can I sell pi coins securely.
DOT TECH
 
what is the future of Pi Network currency.
what is the future of Pi Network currency.what is the future of Pi Network currency.
what is the future of Pi Network currency.
DOT TECH
 
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
Falcon Invoice Discounting
 
how to sell pi coins in all Africa Countries.
how to sell pi coins in all Africa Countries.how to sell pi coins in all Africa Countries.
how to sell pi coins in all Africa Countries.
DOT TECH
 

Recently uploaded (20)

Introduction to Indian Financial System ()
Introduction to Indian Financial System ()Introduction to Indian Financial System ()
Introduction to Indian Financial System ()
 
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
 
when will pi network coin be available on crypto exchange.
when will pi network coin be available on crypto exchange.when will pi network coin be available on crypto exchange.
when will pi network coin be available on crypto exchange.
 
how can i use my minded pi coins I need some funds.
how can i use my minded pi coins I need some funds.how can i use my minded pi coins I need some funds.
how can i use my minded pi coins I need some funds.
 
Intro_Economics_ GPresentation Week 4.pptx
Intro_Economics_ GPresentation Week 4.pptxIntro_Economics_ GPresentation Week 4.pptx
Intro_Economics_ GPresentation Week 4.pptx
 
234Presentation on Indian Debt Market.ppt
234Presentation on Indian Debt Market.ppt234Presentation on Indian Debt Market.ppt
234Presentation on Indian Debt Market.ppt
 
how to sell pi coins in South Korea profitably.
how to sell pi coins in South Korea profitably.how to sell pi coins in South Korea profitably.
how to sell pi coins in South Korea profitably.
 
Isios-2024-Professional-Independent-Trustee-Survey.pdf
Isios-2024-Professional-Independent-Trustee-Survey.pdfIsios-2024-Professional-Independent-Trustee-Survey.pdf
Isios-2024-Professional-Independent-Trustee-Survey.pdf
 
655264371-checkpoint-science-past-papers-april-2023.pdf
655264371-checkpoint-science-past-papers-april-2023.pdf655264371-checkpoint-science-past-papers-april-2023.pdf
655264371-checkpoint-science-past-papers-april-2023.pdf
 
what is a pi whale and how to access one.
what is a pi whale and how to access one.what is a pi whale and how to access one.
what is a pi whale and how to access one.
 
GeM ppt in railway for presentation on gem
GeM ppt in railway  for presentation on gemGeM ppt in railway  for presentation on gem
GeM ppt in railway for presentation on gem
 
This assessment plan proposal is to outline a structured approach to evaluati...
This assessment plan proposal is to outline a structured approach to evaluati...This assessment plan proposal is to outline a structured approach to evaluati...
This assessment plan proposal is to outline a structured approach to evaluati...
 
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
 
What price will pi network be listed on exchanges
What price will pi network be listed on exchangesWhat price will pi network be listed on exchanges
What price will pi network be listed on exchanges
 
The secret way to sell pi coins effortlessly.
The secret way to sell pi coins effortlessly.The secret way to sell pi coins effortlessly.
The secret way to sell pi coins effortlessly.
 
The WhatsPump Pseudonym Problem and the Hilarious Downfall of Artificial Enga...
The WhatsPump Pseudonym Problem and the Hilarious Downfall of Artificial Enga...The WhatsPump Pseudonym Problem and the Hilarious Downfall of Artificial Enga...
The WhatsPump Pseudonym Problem and the Hilarious Downfall of Artificial Enga...
 
What website can I sell pi coins securely.
What website can I sell pi coins securely.What website can I sell pi coins securely.
What website can I sell pi coins securely.
 
what is the future of Pi Network currency.
what is the future of Pi Network currency.what is the future of Pi Network currency.
what is the future of Pi Network currency.
 
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
 
how to sell pi coins in all Africa Countries.
how to sell pi coins in all Africa Countries.how to sell pi coins in all Africa Countries.
how to sell pi coins in all Africa Countries.
 

Genetic algorithm

  • 2. Enhancing Technical Analysis With Genetic Algorithm SAIKIRAN |DEEPAK SHARMA | PRANJAL JAIN 23RD NOV. 2012
  • 3. How Genetic Algorithm can be used to improve the performance of a particular trading rule ? We need to optimize the parameters used by the trading rule
  • 4. HOW TO DO THIS NOW? Consider a Simple Moving Average system, commonly used in trading simulators, which has two set of parameters The lengths of two moving averages
  • 5. OUR MOTIVE To investigate how Genetic Algorithms, a class of Algorithms in evolutionary computation can be used to improve the performance of a particular trading rule How changes in the design of the GA itself can affect the solution quality obtained in context of technical trading system.
  • 6. The GA  Search and global optimization procedure  Based on the natural biological evolution.  Stochastic in nature  Characterized by speed
  • 7. ALGORITHM Genetic Algorithm () { Generate initial selection operator Evaluate the fitness value While ( do not satisfy a stop condition) { Execute the selection operator Execute the crossover operator Execute the mutation operator Evaluate the fitness value } }
  • 8. The Way GA Works  Beginning with random generation  GA goal is to improve the fitness of solutions as the generation passes by.  Stopping Condition:  Until some fixed number of iterations or  Achievement of satisfactory fitness level.
  • 9. SOME USEFUL TERMS Crossover If two parents are represented by a high level of fitness, then crossing them will lead to a better offspring (solution). Mutation As search space is large, some amount of randomness is maintained through generations by mutation operator applied infrequently.
  • 10. Enhancing Moving Average System A moving average for n days is given by: 𝑛 1 𝑃 𝑡−𝑖 𝑛 𝑖=0 𝜃1 𝜃2 𝜃1 < 𝜃2 1 1 𝑃 𝑡−𝑖 > 𝑃 𝑡−𝑖 If 𝜃1 𝑖=0 𝜃2 𝑖=0 𝐵𝑢𝑦 𝑠𝑖𝑔𝑛𝑎𝑙 Else Sell 𝑠𝑖𝑔𝑛𝑎𝑙
  • 11. CONTINUED…  The lengths of MAs are chosen instinctively by the trader.  If say we consider 500 days of data, then the number of possible ways of choosing lengths becomes 500x500 That makes the search space exponentially larger!
  • 12. FOCUS Optimizing our trading system means maximizing our Fitness Function such as Profit, given by 𝒇 𝑻𝑹 𝒇 = (𝟏 + 𝑫𝑹 𝒊 ) 𝒊=𝟏 𝑫𝑹 𝒊 = 𝑷 𝒊 − 𝑷 𝒊−𝟏 × 𝜹 TRf - Total return for the sample period DRi - Daily return for the day i, Pi denotes the stock price for the day i. δ - dummy variable which generates value 1 for buy and -1 for sell
  • 13. ENCODING  Each parameter in Genetic Algorithm is encoded as binary string and concatenated to form a chromosome.  Shorter moving average goes from 1 session to 256 session i.e. string length of 8 bits ex. 01100101]  Longer moving average goes from 1 session to 512 session i.e. string length of 9 bits [ex. 110010101] Thus total search space is of 17 bits [ex. 01100101; 110010101] i.e. 217.
  • 15. I/P Used while Applying GA We have used TCS data from National Stock Exchange from 1st July 2010 to 31st July 2012.
  • 16. Implementation using R Library used: genal CODE: avg <- function(data,min,max) { sum <- 0; for(i in min:max) { sum <- sum+data[i,] } sum <- sum/(max-min+1) return (sum); }
  • 17. evaluate <- function(string=c()) { returnVal = 0; if (length(string) == 2) { theta1 <- string[1]; theta2 <- string[2]; for(i in (1:(dim(data))){ if(i > max(theta1,theta2)+1){ delta <- 0 avg1 <- avg(data,max(i-theta1,1),i) avg2 <- avg(data,max(i-theta2,1),i) if(avg1>avg2){ delta = 1; } else{ delta = -1; } returnVal <- returnVal+(delta*(data[i,]-data[i-1,])); } } } else { stop("Expecting a chromosome of length 2!"); } return (returnVal+max((theta1-theta2)*1000,0)); }
  • 18. Maximum fitness function performance for GA applied for different population sizes
  • 19. RESULT Different Population sizes For 50 For 30
  • 20. RESULT Population Size 50 30 𝜃1, 𝜃2 11,50 91,114 Max Profit Rs. 217.65/- Rs. 198.24/- Max Return 127.48% 125.04%
  • 21. Results given in paper Genetic Algorithm: An Application to Technical Trading System Design by V. Kapoor, S.Dey, A.P. Khurana Population 20 50 70 100 size 𝜃1/𝜃2 235/414 4/40 12/173 9/212 Max. Profit Rs. 834.35 Rs.932.84/- Rs.936/- Rs.947/- Avg. Rs. 709.46/- Rs. 745.9/- Rs. 732.14/- Rs. 672.02/- Return Max. 116.60% 141.27% 160.39% 150.38% Return Std. dev. 83.029836 98.232199 99.66883 109.248246 of Profits Max. profit./ 10.048797 9.4962752 9.3911005 8.66833139 St.dev.
  • 22. INFERENCES  As long as the population size is increased, the best possible solution obtained is higher.  In case of average fitness, it increases after population size of 20, till 50 and then decreases, showing that the solution series becomes noisy in nature.  Standard deviation is the measure of diversity in the population.  Population size increase the solution quality.
  • 23. CONCLUSION  Genetic Algorithm performs better than the moving average lengths derived from rules in finance literature.  To a great extent we are able to beat “Efficient Market Hypothesis”(EMH) (Any public information is reflected in the stock price and it is difficult to beat market.)
  • 24. REFERENCES  Genetic Algorithm: An Application to Technical Trading System Design (V. Kapoor, S.Dey, A.P. Khurana)  Genetic Algorithm: Wikipedia  NSE Site
  • 25. THANK YOU Deepak Sharma IIT Mandi Copyright 2013 Deepak Sharma IIT Mandi