Class: SQA::StrategyGenerator::ProfitablePoint

Inherits:
Object
  • Object
show all
Defined in:
lib/sqa/strategy_generator.rb

Overview

Represents a profitable trade opportunity discovered in historical data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_index:, entry_price:, exit_index:, exit_price:, fpl_data: nil) ⇒ ProfitablePoint

Returns a new instance of ProfitablePoint.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sqa/strategy_generator.rb', line 43

def initialize(entry_index:, entry_price:, exit_index:, exit_price:, fpl_data: nil)
  @entry_index = entry_index
  @entry_price = entry_price
  @exit_index = exit_index
  @exit_price = exit_price
  @gain_percent = ((exit_price - entry_price) / entry_price * 100.0)
  @holding_days = exit_index - entry_index
  @indicators = {}

  # FPL quality metrics
  if fpl_data
    @fpl_min_delta = fpl_data[:min_delta]
    @fpl_max_delta = fpl_data[:max_delta]
    @fpl_risk = fpl_data[:risk]
    @fpl_direction = fpl_data[:direction]
    @fpl_magnitude = fpl_data[:magnitude]
  end
end

Instance Attribute Details

#entry_indexObject

Returns the value of attribute entry_index.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def entry_index
  @entry_index
end

#entry_priceObject

Returns the value of attribute entry_price.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def entry_price
  @entry_price
end

#exit_indexObject

Returns the value of attribute exit_index.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def exit_index
  @exit_index
end

#exit_priceObject

Returns the value of attribute exit_price.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def exit_price
  @exit_price
end

#fpl_directionObject

Returns the value of attribute fpl_direction.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def fpl_direction
  @fpl_direction
end

#fpl_magnitudeObject

Returns the value of attribute fpl_magnitude.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def fpl_magnitude
  @fpl_magnitude
end

#fpl_max_deltaObject

Returns the value of attribute fpl_max_delta.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def fpl_max_delta
  @fpl_max_delta
end

#fpl_min_deltaObject

Returns the value of attribute fpl_min_delta.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def fpl_min_delta
  @fpl_min_delta
end

#fpl_riskObject

Returns the value of attribute fpl_risk.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def fpl_risk
  @fpl_risk
end

#gain_percentObject

Returns the value of attribute gain_percent.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def gain_percent
  @gain_percent
end

#holding_daysObject

Returns the value of attribute holding_days.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def holding_days
  @holding_days
end

#indicatorsObject

Returns the value of attribute indicators.



39
40
41
# File 'lib/sqa/strategy_generator.rb', line 39

def indicators
  @indicators
end

Instance Method Details

#to_sObject



62
63
64
65
# File 'lib/sqa/strategy_generator.rb', line 62

def to_s
  fpl_info = fpl_direction ? " dir=#{fpl_direction} risk=#{fpl_risk.round(2)}%" : ""
  "ProfitablePoint(gain=#{gain_percent.round(2)}%, days=#{holding_days}, entry=#{entry_index}#{fpl_info})"
end