Class: OptionCalendar
- Inherits:
-
Object
- Object
- OptionCalendar
- Defined in:
- lib/option_calendar.rb
Constant Summary collapse
- FRIDAY =
5
Class Method Summary collapse
- .expiration_for(month) ⇒ Object
- .nearest_expiration(date, range = 3.days) ⇒ Object
- .next_expiring_months(from = Date.today) ⇒ Object
Class Method Details
.expiration_for(month) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/option_calendar.rb', line 14 def expiration_for(month) start = month.beginning_of_month expiry_week = start.advance(:days => 14) expiry_week += 1.day while expiry_week.wday != FRIDAY expiry_saturday = expiry_week + 1.day end |
.nearest_expiration(date, range = 3.days) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/option_calendar.rb', line 42 def nearest_expiration(date, range = 3.days) expiration_date = expiration_for(date + range) if date > expiration_date expiration_date = expiration_for(expiration_date.next_month) end if date >= expiration_date - range expiration_for(expiration_date.next_month) else expiration_date end end |
.next_expiring_months(from = Date.today) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/option_calendar.rb', line 24 def next_expiring_months(from = Date.today) this_month = expiration_for(from) next_month = expiration_for(from.next_month) expirations = [ this_month, next_month ] # If the first month has already expired, remove it, and add another month out if from >= (this_month - 1.day) expirations.shift expirations << expiration_for(next_month.next_month) end expirations end |