Class: Rupee::Security
- Inherits:
-
Object
- Object
- Rupee::Security
- Defined in:
- lib/rupee/security.rb,
ext/rupee/bond.c,
ext/rupee/rupee.c,
ext/rupee/future.c,
ext/rupee/option.c
Overview
An abstract class from which all Rupee security types inherit
Direct Known Subclasses
Class Method Summary collapse
-
.attr_alias(new_read, old_read) ⇒ Object
Aliases an attribute, taking into account both its getter and setter methods.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Security
constructor
Automatically sets all arguments passed to
initialize
to instance variables if they exist (think Rails mass assignment).
Constructor Details
#initialize(opts = {}) ⇒ Security
Automatically sets all arguments passed to initialize
to instance variables if they exist (think Rails mass assignment).
require "rupee"
call = Rupee::Call.new(
:underlying => 60,
:strike => 65,
:time => 0.25,
:rate => 0.08,
:div_yield => 0.00,
:volatility => 0.3
)
puts call.black_scholes
# => 2.1333718619275794
You still have the option of avoiding the creation of an object (and the overhead it entails) by using the class methods directly:
require "rupee"
puts Rupee::Option.black_scholes "c", 60, 65, 0.25, 0.08, 0, 0.3
# => 2.1333718619275794
27 28 29 30 31 32 33 34 |
# File 'lib/rupee/security.rb', line 27 def initialize(opts = {}) opts.each do |key, value| writer = key.to_s.+("=").to_sym if respond_to?(writer) send writer, value end end end |
Class Method Details
.attr_alias(new_read, old_read) ⇒ Object
Aliases an attribute, taking into account both its getter and setter methods. For example,
attr_accessor :price
attr_alias :value, :price
would add both a value
and a value=
that are equivalent to their price
counterparts and would modify the @price
instance variable. On the other hand,
attr :price
attr_alias :value, :price
would only add value
method that’s equivalent to price
.
52 53 54 55 56 57 |
# File 'lib/rupee/security.rb', line 52 def attr_alias(new_read, old_read) alias_method(new_read, old_read) if method_defined?(old_read) new_write = "#{new_read}=" old_write = "#{old_read}=" alias_method(new_write, old_write) if method_defined?(old_write) end |