Last active
December 20, 2015 10:19
-
-
Save adamstrickland/6114124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ng_products = Product.where(:"commodity.name" => /ng/i).each do |p| | |
p.expiry_rule = :preceeding_weekday | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Expiry | |
def preceeding_weekday(trade) | |
[-5..-1].map{ |i| trade.tenor_start + i.days }.select(&:nerc_weekday?).last | |
end | |
# other expiry rules | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product | |
include Expiry | |
def expiry | |
self.send(self.expiry_rule, self) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Trade | |
delegate :expiry, to: :product | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment