Class: BondCalculator::SpreadToCurve
- Inherits:
-
BaseCalculator
- Object
- BaseCalculator
- BondCalculator::SpreadToCurve
- Defined in:
- lib/bond_calculator/spread_to_curve.rb
Overview
Class that handle the calculation of the spread to curve
Since the corporate bond term is not exactly the same as its benchmark term, we use linear interpolation to calculate the spread to the curve.
Instance Attribute Summary collapse
-
#bonds ⇒ Object
readonly
Returns the value of attribute bonds.
Instance Method Summary collapse
-
#calculate ⇒ Hash
Execute the bussines rule to calculate the spread to curve.
- #initialize(bond_file_path) ⇒ <void> constructor
Methods inherited from BaseCalculator
Constructor Details
#initialize(bond_file_path) ⇒ <void>
18 19 20 |
# File 'lib/bond_calculator/spread_to_curve.rb', line 18 def initialize(bond_file_path) @bonds = csv_to_bonds(bond_file_path) end |
Instance Attribute Details
#bonds ⇒ Object (readonly)
Returns the value of attribute bonds.
13 14 15 |
# File 'lib/bond_calculator/spread_to_curve.rb', line 13 def bonds @bonds end |
Instance Method Details
#calculate ⇒ Hash
Execute the bussines rule to calculate the spread to curve
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bond_calculator/spread_to_curve.rb', line 25 def calculate response = [] corps = bonds_by_type('corporate', @bonds) govs = bonds_by_type('government', @bonds) corps.each do |corp| upper_bond = nil lower_bond = nil govs.each do |gov| if corp.term_years <= gov.term_years lower_bond = gov break else upper_bond = gov end end spread_to_curve = (corp.yield_percent - yield_on_curve(corp, lower_bond, upper_bond)).round(2) response << { bond_name: corp.name, spread_to_curve: spread_to_curve } end print_response(response) response end |