📦 SQA::GeneticProgram¶
🔨 Instance Methods¶
#stock()¶
Returns the value of attribute stock.
Source Location
#population()¶
Returns the value of attribute population.
Source Location
#best_individual()¶
Returns the value of attribute best_individual.
Source Location
#generation()¶
Returns the value of attribute generation.
Source Location
#history()¶
Returns the value of attribute history.
Source Location
#population_size()¶
Returns the value of attribute population_size.
Source Location
#population_size=(value)¶
Sets the attribute population_size
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
the value to set the attribute population_size to. |
Source Location
#generations()¶
Returns the value of attribute generations.
Source Location
#generations=(value)¶
Sets the attribute generations
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
the value to set the attribute generations to. |
Source Location
#mutation_rate()¶
Returns the value of attribute mutation_rate.
Source Location
#mutation_rate=(value)¶
Sets the attribute mutation_rate
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
the value to set the attribute mutation_rate to. |
Source Location
#crossover_rate()¶
Returns the value of attribute crossover_rate.
Source Location
#crossover_rate=(value)¶
Sets the attribute crossover_rate
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
the value to set the attribute crossover_rate to. |
Source Location
#elitism_count()¶
Returns the value of attribute elitism_count.
Source Location
#elitism_count=(value)¶
Sets the attribute elitism_count
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
the value to set the attribute elitism_count to. |
Source Location
#initialize(stock:, population_size: = 50, generations: = 100, mutation_rate: = 0.15, crossover_rate: = 0.7, elitism_count: = 2)¶
Returns
Type: GeneticProgram
a new instance of GeneticProgram
Source Location
#define_genes(**constraints)¶
Define the parameter space for evolution
Example: gp.define_genes( indicator: [:rsi, :macd, :stoch], period: (5..30).to_a, buy_threshold: (20..40).to_a, sell_threshold: (60..80).to_a )
Source Location
#fitness(&block)¶
Define how to evaluate fitness for an individual
The block receives an individual's genes hash and should return a numeric fitness value (higher is better)
Example: gp.fitness do |genes| backtest = SQA::Backtest.new( stock: stock, strategy: create_strategy_from_genes(genes), initial_capital: 10_000 ) results = backtest.run results.total_return # Higher return = higher fitness end
Source Location
#evolve()¶
Run the genetic algorithm evolution
Source Location
📝 Attributes¶
👁️ stock read-only¶
Returns the value of attribute stock.
👁️ population read-only¶
Returns the value of attribute population.
👁️ best_individual read-only¶
Returns the value of attribute best_individual.
👁️ generation read-only¶
Returns the value of attribute generation.
👁️ history read-only¶
Returns the value of attribute history.
🔄 population_size read/write¶
Returns the value of attribute population_size.
🔄 generations read/write¶
Returns the value of attribute generations.
🔄 mutation_rate read/write¶
Returns the value of attribute mutation_rate.
🔄 crossover_rate read/write¶
Returns the value of attribute crossover_rate.
🔄 elitism_count read/write¶
Returns the value of attribute elitism_count.