Class: OptionLab::Models::Option
- Defined in:
- lib/option_lab/models.rb
Overview
Option position model
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#n ⇒ Object
Returns the value of attribute n.
-
#premium ⇒ Object
Returns the value of attribute premium.
-
#prev_pos ⇒ Object
Returns the value of attribute prev_pos.
-
#strike ⇒ Object
Returns the value of attribute strike.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
Constructor Details
This class inherits a constructor from OptionLab::Models::BaseModel
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
49 50 51 |
# File 'lib/option_lab/models.rb', line 49 def action @action end |
#expiration ⇒ Object
Returns the value of attribute expiration.
49 50 51 |
# File 'lib/option_lab/models.rb', line 49 def expiration @expiration end |
#n ⇒ Object
Returns the value of attribute n.
49 50 51 |
# File 'lib/option_lab/models.rb', line 49 def n @n end |
#premium ⇒ Object
Returns the value of attribute premium.
49 50 51 |
# File 'lib/option_lab/models.rb', line 49 def premium @premium end |
#prev_pos ⇒ Object
Returns the value of attribute prev_pos.
49 50 51 |
# File 'lib/option_lab/models.rb', line 49 def prev_pos @prev_pos end |
#strike ⇒ Object
Returns the value of attribute strike.
49 50 51 |
# File 'lib/option_lab/models.rb', line 49 def strike @strike end |
#type ⇒ Object
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
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 |