Overview
TheGenome class defines the complete genetic representation of a trading bot’s strategy. All gene values are stored as floats in the range [0.0, 1.0] and decoded into actual trading parameters by the decode_genome() function.
Genome Class
Fields
Identity
Unique 8-character identifier (auto-generated)
Generation number this genome belongs to
IDs of parent genomes (1 for clone/elite, 2 for crossover)
Market Selection Genes (5 genes)
Minimum 24h volume filter (decoded: 0-5000)
Minimum open interest filter (decoded: 0-2000)
Minimum hours until market expiry (decoded: 0-24h)
Maximum hours until market expiry (decoded: 0-24h)
Bitmask for market categories to trade (decoded to category list)
Entry Signal Genes (8 genes)
Signal strategy selector (decoded: price_level, momentum, mean_reversion, value, contrarian)
Low price threshold (decoded: 0.01-0.50)
High price threshold (decoded: 0.50-0.99)
Momentum lookback period (decoded: 1-60 ticks)
Momentum trigger threshold (decoded: -10% to +10%)
Mean reversion z-score threshold (decoded: 0.5-3.0)
Minimum value edge required (decoded: 0.01-0.30)
Contrarian confidence threshold (decoded: 0.60-0.95)
Side Selection Genes (2 genes)
Directional bias: less than 0.2 = always no, 0.2-0.8 = signal, greater than 0.8 = always yes
Probability of randomly flipping side (decoded: 0-0.5)
Position Sizing Genes (3 genes)
Fraction of bankroll to risk per trade (decoded: 0.005-0.10)
Maximum concurrent open positions (decoded: 1-20)
Max allocation to single market (decoded: 0.01-0.25)
Risk Management Genes (4 genes)
Daily loss limit as % of equity (decoded: 0.02-0.30)
Maximum trades per day (decoded: 1-100)
Minimum acceptable contract price (decoded: 0.01-0.50)
Maximum acceptable contract price (decoded: 0.50-0.99)
Class Methods
gene_names()
Get list of all evolvable gene field names.List of 22 gene field names
random(generation=0)
Create a genome with all genes randomized uniformly in [0, 1].Generation number to assign
New genome with random gene values
Instance Methods
clone()
Create a deep copy with a new unique ID.Cloned genome with new ID
to_dict()
Serialize genome to dictionary for JSON persistence.Dict containing all genome fields
from_dict(d)
Deserialize genome from dictionary.Dictionary containing genome fields
Reconstructed genome instance
Signal Types
Thesignal_type gene is discretized into one of these strategies:
decode_genome Function
Convert [0,1] gene values into actual trading parameters.Genome to decode
List of market categories available
Decoded trading parameters ready for bot execution
Gene Evolution
Genes evolve through:- Crossover: Random mix of parent genes
- Mutation: Gaussian perturbation clamped to [0,1]
- Immigration: Fresh random genomes for diversity