Class: CoveredCallExit
- Inherits:
-
Object
- Object
- CoveredCallExit
- Includes:
- ArgumentProcessor
- Defined in:
- lib/covered_call_exit.rb
Instance Attribute Summary collapse
-
#opening_position ⇒ Object
readonly
Returns the value of attribute opening_position.
-
#option ⇒ Object
readonly
Returns the value of attribute option.
Instance Method Summary collapse
- #annualized_return ⇒ Object
- #commission ⇒ Object
- #days_in_position ⇒ Object
- #exercise ⇒ Object
- #exit_date ⇒ Object
- #exit_type ⇒ Object
-
#initialize(args = {}) ⇒ CoveredCallExit
constructor
A new instance of CoveredCallExit.
- #num_shares ⇒ Object
- #option_sale ⇒ Object
- #period_return ⇒ Object
- #proceeds ⇒ Object
- #proceeds_per_share ⇒ Object
- #profit ⇒ Object
- #stock ⇒ Object
- #stock_sale ⇒ Object
Methods included from ArgumentProcessor
Constructor Details
#initialize(args = {}) ⇒ CoveredCallExit
Returns a new instance of CoveredCallExit.
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_position ⇒ Object (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 |
#option ⇒ Object (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_return ⇒ Object
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 |
#commission ⇒ Object
58 59 60 |
# File 'lib/covered_call_exit.rb', line 58 def commission opening_position.commission end |
#days_in_position ⇒ Object
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 |
#exercise ⇒ Object
70 71 72 |
# File 'lib/covered_call_exit.rb', line 70 def exercise (num_shares * option.strike) - commission.option_assignment end |
#exit_date ⇒ Object
66 67 68 |
# File 'lib/covered_call_exit.rb', line 66 def exit_date opening_position.date_established + days_in_position end |
#exit_type ⇒ Object
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_shares ⇒ Object
62 63 64 |
# File 'lib/covered_call_exit.rb', line 62 def num_shares opening_position.num_shares end |
#option_sale ⇒ Object
78 79 80 |
# File 'lib/covered_call_exit.rb', line 78 def option_sale (num_shares * option.price) - commission.option_entry end |
#period_return ⇒ Object
38 39 40 |
# File 'lib/covered_call_exit.rb', line 38 def period_return profit / opening_position.net_outlay.to_f end |
#proceeds ⇒ Object
46 47 48 |
# File 'lib/covered_call_exit.rb', line 46 def proceeds raise NotImplementedError end |
#proceeds_per_share ⇒ Object
50 51 52 |
# File 'lib/covered_call_exit.rb', line 50 def proceeds_per_share proceeds / num_shares end |
#profit ⇒ Object
42 43 44 |
# File 'lib/covered_call_exit.rb', line 42 def profit proceeds - opening_position.net_outlay end |
#stock ⇒ Object
54 55 56 |
# File 'lib/covered_call_exit.rb', line 54 def stock option.stock end |
#stock_sale ⇒ Object
74 75 76 |
# File 'lib/covered_call_exit.rb', line 74 def stock_sale (num_shares * stock.price) - commission.stock_entry end |