Class: CoveredCallPosition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ArgumentProcessor

#process_args

Constructor Details

#initialize(args = {}) ⇒ CoveredCallPosition

Returns a new instance of CoveredCallPosition.



6
7
8
# File 'lib/covered_call_position.rb', line 6

def initialize(args = {})
  process_args(args)
end

Instance Attribute Details

#date_establishedObject

Returns the value of attribute date_established.



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

def date_established
  @date_established
end

#num_sharesObject

Returns the value of attribute num_shares.



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

def num_shares
  @num_shares
end

#optionObject

Returns the value of attribute option.



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

def option
  @option
end

Instance Method Details

#call_saleObject



30
31
32
# File 'lib/covered_call_position.rb', line 30

def call_sale
  num_shares * option.price - commission.option_entry
end

#commissionObject



14
15
16
17
18
# File 'lib/covered_call_position.rb', line 14

def commission
  @commission_instance ||= Commission.const_get(@commission).new(
    :shares => num_shares, :contracts => num_shares / 100
  )
end

#commission=(name) ⇒ Object



10
11
12
# File 'lib/covered_call_position.rb', line 10

def commission=(name)
  @commission = name.to_s
end

#downside_protectionObject



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

def downside_protection
  (net_per_share.to_f - stock.price) / stock.price
end

#implied_volatilityObject



50
51
52
53
54
55
56
57
58
# File 'lib/covered_call_position.rb', line 50

def implied_volatility
  @iv ||= BlackScholes.call_iv(
    stock.price / 100.0, 
    option.strike / 100.0, 
    0.27, # TODO: risk-free rate
    option.days_to_expiry(date_established),
    option.price / 100.0
  )
end

#net_outlayObject



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

def net_outlay
  stock_total - call_sale
end

#net_per_shareObject



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

def net_per_share
  net_outlay.to_f / num_shares
end

#probability_max_profitObject



60
61
62
63
64
65
66
67
# File 'lib/covered_call_position.rb', line 60

def probability_max_profit
  BlackScholes.probability_above(
    stock.price / 100.0,
    option.strike / 100.0,
    option.days_to_expiry(date_established),
    implied_volatility
  )
end

#probability_profitObject



69
70
71
72
73
74
75
76
# File 'lib/covered_call_position.rb', line 69

def probability_profit
  BlackScholes.probability_above(
    stock.price / 100.0,
    net_per_share / 100.0,
    option.days_to_expiry(date_established),
    implied_volatility
  )
end

#stockObject



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

def stock
  option.stock
end

#stock_totalObject



26
27
28
# File 'lib/covered_call_position.rb', line 26

def stock_total
  num_shares * stock.price + commission.stock_entry
end