Class: CoveredCallExit

Inherits:
Object
  • Object
show all
Includes:
ArgumentProcessor
Defined in:
lib/covered_call_exit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ArgumentProcessor

#process_args

Constructor Details

#initialize(args = {}) ⇒ CoveredCallExit

Returns a new instance of CoveredCallExit.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/covered_call_exit.rb', line 6

def initialize(args = {})
  @opening_position = args[:opening_position]

  @option = opening_position.option.dup
  @option.stock = opening_position.stock.dup

  stock.price = args[:stock_price] if args[:stock_price]
  option.price = args[:option_price] if args[:option_price]
  option.current_date = args[:exit_date] if args[:exit_date]

  raise ArgumentError, "Stock does not match" unless stock == opening_position.stock
  raise ArgumentError, "Option does not match" unless option == opening_position.option

  extend exit_type
end

Instance Attribute Details

#opening_positionObject (readonly)

Returns the value of attribute opening_position.



4
5
6
# File 'lib/covered_call_exit.rb', line 4

def opening_position
  @opening_position
end

#optionObject (readonly)

Returns the value of attribute option.



4
5
6
# File 'lib/covered_call_exit.rb', line 4

def option
  @option
end

Instance Method Details

#annualized_returnObject



33
34
35
36
# File 'lib/covered_call_exit.rb', line 33

def annualized_return
  #(1 + period_return) ** (1 / (opening_position.option.days_to_expiry/365.0)) - 1
  (1 + period_return) ** (1 / (days_in_position/365.0)) - 1
end

#commissionObject



58
59
60
# File 'lib/covered_call_exit.rb', line 58

def commission
  opening_position.commission
end

#days_in_positionObject



29
30
31
# File 'lib/covered_call_exit.rb', line 29

def days_in_position
  ([option.expires, option.current_date].min - opening_position.date_established).to_i
end

#exerciseObject



70
71
72
# File 'lib/covered_call_exit.rb', line 70

def exercise
  (num_shares * option.strike) - commission.option_assignment
end

#exit_dateObject



66
67
68
# File 'lib/covered_call_exit.rb', line 66

def exit_date
  opening_position.date_established + days_in_position
end

#exit_typeObject



22
23
24
25
26
27
# File 'lib/covered_call_exit.rb', line 22

def exit_type
  if    option.expired? and option.in_the_money?  then CoveredCallExpiryItmExit
  elsif option.expired? and option.out_the_money? then CoveredCallExpiryOtmExit
  else                                                 CoveredCallEarlyExit
  end
end

#num_sharesObject



62
63
64
# File 'lib/covered_call_exit.rb', line 62

def num_shares
  opening_position.num_shares
end

#option_saleObject



78
79
80
# File 'lib/covered_call_exit.rb', line 78

def option_sale
  (num_shares * option.price) - commission.option_entry
end

#period_returnObject



38
39
40
# File 'lib/covered_call_exit.rb', line 38

def period_return
  profit / opening_position.net_outlay.to_f
end

#proceedsObject

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/covered_call_exit.rb', line 46

def proceeds
  raise NotImplementedError
end

#proceeds_per_shareObject



50
51
52
# File 'lib/covered_call_exit.rb', line 50

def proceeds_per_share
  proceeds / num_shares
end

#profitObject



42
43
44
# File 'lib/covered_call_exit.rb', line 42

def profit
  proceeds - opening_position.net_outlay
end

#stockObject



54
55
56
# File 'lib/covered_call_exit.rb', line 54

def stock
  option.stock
end

#stock_saleObject



74
75
76
# File 'lib/covered_call_exit.rb', line 74

def stock_sale
  (num_shares * stock.price) - commission.stock_entry
end