Class: Options::Strategies::Strategy
- Inherits:
-
Object
- Object
- Options::Strategies::Strategy
- Defined in:
- lib/options/strategies.rb
Direct Known Subclasses
Hedge, IronStrategy, LongCall, LongPut, ShortCall, ShortPut, Straddle, Strangle, StrategyBuilder
Instance Attribute Summary collapse
-
#ce_increment ⇒ Object
Returns the value of attribute ce_increment.
-
#default_lot_size ⇒ Object
Returns the value of attribute default_lot_size.
-
#increment ⇒ Object
Returns the value of attribute increment.
-
#index_name ⇒ Object
Returns the value of attribute index_name.
-
#input_lot_size ⇒ Object
Returns the value of attribute input_lot_size.
-
#legs ⇒ Object
Returns the value of attribute legs.
-
#option_type_klasses ⇒ Object
Returns the value of attribute option_type_klasses.
-
#options_data ⇒ Object
Returns the value of attribute options_data.
-
#pe_increment ⇒ Object
Returns the value of attribute pe_increment.
-
#strike_price ⇒ Object
Returns the value of attribute strike_price.
Instance Method Summary collapse
- #construct ⇒ Object
-
#initialize(options = {}) ⇒ Strategy
constructor
A new instance of Strategy.
- #long=(option_type) ⇒ Object
- #lot_size=(val) ⇒ Object
- #merge_legs(input_legs) ⇒ Object
- #parse_option_type_klasses ⇒ Object
- #short=(option_type) ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Strategy
Returns a new instance of Strategy.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/options/strategies.rb', line 14 def initialize(={}) = @index_name = [:index_name] @increment = eval("Multiplier::#{@index_name}") @spot_price = [:spot_price] @strike_price = .key?(:strike_price) ? [:strike_price] : @increment * ((@spot_price + @increment/2.0).to_i / @increment) [:strike_price] = @strike_price @ce_increment = 0 @pe_increment = 0 @default_lot_size = 1 @input_lot_size = 1 = [] @legs = {OrderType::LONG => [], OrderType::SHORT => [], "index_name" => @index_name, "spot_price" => @spot_price, "strike_price" => @strike_price, "klass_name" => self.class.name.split('::').last} end |
Instance Attribute Details
#ce_increment ⇒ Object
Returns the value of attribute ce_increment.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def ce_increment @ce_increment end |
#default_lot_size ⇒ Object
Returns the value of attribute default_lot_size.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def default_lot_size @default_lot_size end |
#increment ⇒ Object
Returns the value of attribute increment.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def increment @increment end |
#index_name ⇒ Object
Returns the value of attribute index_name.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def index_name @index_name end |
#input_lot_size ⇒ Object
Returns the value of attribute input_lot_size.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def input_lot_size @input_lot_size end |
#legs ⇒ Object
Returns the value of attribute legs.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def legs @legs end |
#option_type_klasses ⇒ Object
Returns the value of attribute option_type_klasses.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def option_type_klasses @option_type_klasses end |
#options_data ⇒ Object
Returns the value of attribute options_data.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def end |
#pe_increment ⇒ Object
Returns the value of attribute pe_increment.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def pe_increment @pe_increment end |
#strike_price ⇒ Object
Returns the value of attribute strike_price.
12 13 14 |
# File 'lib/options/strategies.rb', line 12 def strike_price @strike_price end |
Instance Method Details
#construct ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/options/strategies.rb', line 61 def construct parse_option_type_klasses @default_lot_size = @input_lot_size * @default_lot_size .each do |option_data| option_data.size = @default_lot_size yield option_data end self end |
#long=(option_type) ⇒ Object
29 30 31 |
# File 'lib/options/strategies.rb', line 29 def long=(option_type) @legs[OrderType::LONG] << option_type.to_hash end |
#lot_size=(val) ⇒ Object
37 38 39 |
# File 'lib/options/strategies.rb', line 37 def lot_size=(val) @input_lot_size = val end |
#merge_legs(input_legs) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/options/strategies.rb', line 52 def merge_legs(input_legs) @legs.each do |k,v| if @legs[k].kind_of? Array @legs[k] << input_legs[k] unless input_legs[k].empty? @legs[k].flatten! end end end |
#parse_option_type_klasses ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/options/strategies.rb', line 41 def parse_option_type_klasses @option_type_klasses.each do |klass, option_strike_price| [:strike_price] = option_strike_price # puts "#{klass} --> #{option_strike_price} --> #{@options}" option = klass.new() # puts "#{option}" << option [:strike_price] = @strike_price end end |
#short=(option_type) ⇒ Object
33 34 35 |
# File 'lib/options/strategies.rb', line 33 def short=(option_type) @legs[OrderType::SHORT] << option_type.to_hash end |
#to_hash ⇒ Object
71 72 73 |
# File 'lib/options/strategies.rb', line 71 def to_hash self.legs end |
#to_json ⇒ Object
75 76 77 |
# File 'lib/options/strategies.rb', line 75 def to_json self.legs.to_json end |