Skip to content

📦 SQA::Strategy

Description

This module needs to be extend'ed within a strategy class so that these common class methods are available in every trading strategy.

Source Information

Defined in: lib/sqa/strategy.rb:16

Inherits from: Object

🔨 Instance Methods

#strategies()

Returns

Type: Array<Method>

Collection of strategy trade methods

Source Location

lib/sqa/strategy.rb:19


#strategies=(value)

Sets the attribute strategies

Parameters

Name Type Description
value Any the value to set the attribute strategies to.
Source Location

lib/sqa/strategy.rb:19


#initialize()

Creates a new Strategy instance with an empty strategies collection.

Returns

Type: Strategy

a new instance of Strategy

Source Location

lib/sqa/strategy.rb:22


#add(a_strategy)

Adds a trading strategy to the collection. Strategies must be either a Class with a .trade method or a Method object.

Parameters

Name Type Description
a_strategy Class, Method Strategy to add

Returns

Type: Array<Method>

Updated strategies collection

Usage Examples

strategy.add(SQA::Strategy::RSI)
strategy.add(MyModule.method(:custom_trade))
Source Location

lib/sqa/strategy.rb:39


#execute(v)

Executes all registered strategies with the given data vector.

Parameters

Name Type Description
v OpenStruct Data vector containing indicator values and prices

Returns

Type: Array<Symbol>

Array of signals (:buy, :sell, or :hold) from each strategy

Usage Examples

vector = OpenStruct.new(rsi: 25, prices: prices_array)
signals = strategy.execute(vector)  # => [:buy, :hold, :sell]
Source Location

lib/sqa/strategy.rb:60


#auto_load(except: = [:common], only: = [])

Auto-loads strategy files from the strategy directory.

Parameters

Name Type Description
except Array<Symbol> Strategy names to exclude (default: [:common])
only Array<Symbol> If provided, only load these strategies

Returns

Type: nil

Usage Examples

strategy.auto_load(except: [:common, :random])
strategy.auto_load(only: [:rsi, :macd])
Source Location

lib/sqa/strategy.rb:79


#available()

Returns all available strategy classes in the SQA::Strategy namespace.

Returns

Type: Array<Class>

Array of strategy classes

Usage Examples

SQA::Strategy.new.available
# => [SQA::Strategy::RSI, SQA::Strategy::MACD, ...]
Source Location

lib/sqa/strategy.rb:108


📝 Attributes

🔄 strategies read/write