Class: Options::Strategies::OptionType

Inherits:
Object
  • Object
show all
Defined in:
lib/options/strategies/option_type.rb

Direct Known Subclasses

CEOption, PEOption

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OptionType

Returns a new instance of OptionType.



12
13
14
15
16
# File 'lib/options/strategies/option_type.rb', line 12

def initialize(options={})
  @strike_price = options[:strike_price]
  @index_name = options[:index_name]
  @default_units = eval("IndexUnits::#{@index_name}")
end

Instance Attribute Details

#default_unitsObject (readonly)

Returns the value of attribute default_units.



10
11
12
# File 'lib/options/strategies/option_type.rb', line 10

def default_units
  @default_units
end

#execute_unitsObject (readonly)

Returns the value of attribute execute_units.



10
11
12
# File 'lib/options/strategies/option_type.rb', line 10

def execute_units
  @execute_units
end

#expiry_dateObject

Returns the value of attribute expiry_date.



10
11
12
# File 'lib/options/strategies/option_type.rb', line 10

def expiry_date
  @expiry_date
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



10
11
12
# File 'lib/options/strategies/option_type.rb', line 10

def index_name
  @index_name
end

#ltpObject

Returns the value of attribute ltp.



10
11
12
# File 'lib/options/strategies/option_type.rb', line 10

def ltp
  @ltp
end

#sizeObject

Returns the value of attribute size.



10
11
12
# File 'lib/options/strategies/option_type.rb', line 10

def size
  @size
end

#strike_priceObject (readonly)

Returns the value of attribute strike_price.



10
11
12
# File 'lib/options/strategies/option_type.rb', line 10

def strike_price
  @strike_price
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/options/strategies/option_type.rb', line 10

def type
  @type
end

Instance Method Details

#to_hashObject



35
36
37
38
39
40
41
42
43
# File 'lib/options/strategies/option_type.rb', line 35

def to_hash
  hash = {}.tap do |hash|
    self.instance_variables.each do |var|
      variable = var.to_s.tr('@', '')
      hash[variable] = instance_variable_get("@#{variable}")
    end
    hash["option_type"] = self.class.name.split('::').last
  end
end

#to_jsonObject



45
46
47
# File 'lib/options/strategies/option_type.rb', line 45

def to_json
  to_hash.to_json
end