Class: OptionLab::Models::Option

Inherits:
BaseModel show all
Defined in:
lib/option_lab/models.rb

Overview

Option position model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from OptionLab::Models::BaseModel

Instance Attribute Details

#actionObject

Returns the value of attribute action.



49
50
51
# File 'lib/option_lab/models.rb', line 49

def action
  @action
end

#expirationObject

Returns the value of attribute expiration.



49
50
51
# File 'lib/option_lab/models.rb', line 49

def expiration
  @expiration
end

#nObject

Returns the value of attribute n.



49
50
51
# File 'lib/option_lab/models.rb', line 49

def n
  @n
end

#premiumObject

Returns the value of attribute premium.



49
50
51
# File 'lib/option_lab/models.rb', line 49

def premium
  @premium
end

#prev_posObject

Returns the value of attribute prev_pos.



49
50
51
# File 'lib/option_lab/models.rb', line 49

def prev_pos
  @prev_pos
end

#strikeObject

Returns the value of attribute strike.



49
50
51
# File 'lib/option_lab/models.rb', line 49

def strike
  @strike
end

#typeObject

Returns the value of attribute type.



49
50
51
# File 'lib/option_lab/models.rb', line 49

def type
  @type
end

Instance Method Details

#validate!Object

Raises:

  • (ArgumentError)


51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/option_lab/models.rb', line 51

def validate!
  raise ArgumentError, "type must be 'call' or 'put'" unless OPTION_TYPES.include?(type)
  raise ArgumentError, 'strike must be positive' unless strike.is_a?(Numeric) && strike.positive?
  raise ArgumentError, 'premium must be positive' unless premium.is_a?(Numeric) && premium.positive?
  raise ArgumentError, 'n must be positive' unless n.is_a?(Numeric) && n.positive?
  raise ArgumentError, "action must be 'buy' or 'sell'" unless ACTION_TYPES.include?(action)

  # Validate expiration if provided
  if expiration.is_a?(Integer)
    raise ArgumentError, 'If expiration is an integer, it must be greater than 0' unless expiration.positive?
  end
end