Venice 0.7beta

org.mov.analyser.gp
Class Individual

java.lang.Object
  extended by org.mov.analyser.gp.Individual
All Implemented Interfaces:
java.lang.Comparable

public class Individual
extends java.lang.Object
implements java.lang.Comparable

A trading individual evovled by the GP. The Individual contains a buy rule and a sell rule that will have been evolved by the GP.

Author:
Andrew Leppard
See Also:
GeneticProgramme, Mutator

Constructor Summary
Individual(Expression buyRule, Expression sellRule)
          Create a new individual with the given buy and sell rules.
Individual(Mutator buyRuleMutator, Mutator sellRuleMutator)
          Randomly generate an individual using the two mutators.
Individual(java.util.Random random, Mutator buyRuleMutator, Mutator sellRuleMutator, Individual father, Individual mother)
          Create a new individual by "breeding" or combining the two parent individuals.
 
Method Summary
 int compareTo(java.lang.Object object)
          Compare the individuals' final values.
 boolean equals(java.lang.Object object)
          Test the invidiuals' final values for equality.
 Expression getBuyRule()
          Get the buy rule.
 Portfolio getPortfolio()
          Get the final portfolio.
 Expression getSellRule()
          Get the sell rule.
 int getTotalEquationSize()
          Return the combined number of nodes of both the buy and sell rules.
 Money getValue()
          Get the final value of the individual after paper trading.
 int hashCode()
          Calculate a hash code for the individual.
 boolean isValid(int min, int max)
          Check that the given buy and sell rules are valid.
 Money paperTrade(GPQuoteBundle quoteBundle, OrderCache orderCache, TradingDate startDate, TradingDate endDate, Money initialCapital, Money stockValue, int numberStocks, Money tradeCost, java.lang.String tradeValueBuy, java.lang.String tradeValueSell)
          Paper trade with the individual's buy and sell rules.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Individual

public Individual(Expression buyRule,
                  Expression sellRule)
Create a new individual with the given buy and sell rules.

Parameters:
buyRule - the buy indicator
sellRule - the sell indicator

Individual

public Individual(Mutator buyRuleMutator,
                  Mutator sellRuleMutator)
Randomly generate an individual using the two mutators.

Parameters:
buyRuleMutator - mutator used for creating buy rule
sellRuleMutator - mutator used for creating sell rule

Individual

public Individual(java.util.Random random,
                  Mutator buyRuleMutator,
                  Mutator sellRuleMutator,
                  Individual father,
                  Individual mother)
Create a new individual by "breeding" or combining the two parent individuals.

Parameters:
random - the random number generator
buyRuleMutator - mutator used for mutating buy rule
sellRuleMutator - mutator used for mutating sell rule
father - one parent individual
mother - another parent individual
Method Detail

isValid

public boolean isValid(int min,
                       int max)
Check that the given buy and sell rules are valid. This function will check that both the buy and sell rules are within the given size limits. These limits refer to the number of nodes in each rule. Rules that do not access quote data will also be rejected, e.g. rules that are only based on the day of the week, order, etc.

The minimum size check is to prevent us wasting time on too simplistic rules. The maximum size check is to prevent rules exponentially increasing and so reduce CPU time. We reject rules not based on quote data as also being too simplistic to be worthwhile.

Parameters:
min - the minimum number of nodes in each rule
max - the maximum number of nodes in each rule
Returns:
true if both rules are valid

getTotalEquationSize

public int getTotalEquationSize()
Return the combined number of nodes of both the buy and sell rules.

Returns:
number of nodes

paperTrade

public Money paperTrade(GPQuoteBundle quoteBundle,
                        OrderCache orderCache,
                        TradingDate startDate,
                        TradingDate endDate,
                        Money initialCapital,
                        Money stockValue,
                        int numberStocks,
                        Money tradeCost,
                        java.lang.String tradeValueBuy,
                        java.lang.String tradeValueSell)
                 throws EvaluationException
Paper trade with the individual's buy and sell rules. Set the stockValue to null to trade by number of stocks in the portfolio.

Parameters:
quoteBundle - the historical quote data
orderCache - cache of ordered symbols
startDate - start date of trading
endDate - last date of trading
initialCapital - initial capital in the portfolio
stockValue - the rough value of each stock holding
numberStocks - number of stocks in the portfolio
tradeCost - the cost of a trade
Returns:
value of individual after paper trading
Throws:
EvaluationException

getValue

public Money getValue()
Get the final value of the individual after paper trading.

Returns:
the final value

getBuyRule

public Expression getBuyRule()
Get the buy rule.

Returns:
buy rule

getSellRule

public Expression getSellRule()
Get the sell rule.

Returns:
sell rule

getPortfolio

public Portfolio getPortfolio()
Get the final portfolio.

Returns:
final portfolio

compareTo

public int compareTo(java.lang.Object object)
Compare the individuals' final values.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - the other individual
Returns:
-1 if this individual is worth less, 0 if the individuals are worth the same or 1 if this individual is worth more.

equals

public boolean equals(java.lang.Object object)
Test the invidiuals' final values for equality.

Overrides:
equals in class java.lang.Object
Returns:
true if the two individuals are worth the same

hashCode

public int hashCode()
Calculate a hash code for the individual.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

Venice 0.7beta