-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add day count convention 30/360 #25
Add day count convention 30/360 #25
Conversation
115c3aa
to
9f6e6e4
Compare
start_date.day() >= 31, | ||
tf.repeat(30, start_date.shape[0]), | ||
start_date.day() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more succinctly expressed as
d1_days = tf.math.maximum(start_date.day(), 30)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you meant minimum instead. Fixed in a884fb0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the very clean CL! I will approve after the two minor comments are fixed.
tf.repeat(30, start_date.shape[0]), | ||
start_date.day() | ||
) | ||
d2_days = tf.where( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar rewrite here would be more efficient:
d2_days = tf.where(tf.math.equal(d1_days, 30) & tf.math.equal(end_date.day(), 31),
30,
end_date.day())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a884fb0
a884fb0
to
75ac0aa
Compare
Rebased master and addressed the comments. |
d1_days = tf.minimum(start_date.day(), 30) | ||
d2_days = tf.where( | ||
tf.equal(d1_days, 30) & tf.equal(end_date.day(), 31), | ||
tf.repeat(30, start_date.shape[0]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the tf.repeat here. tf.where in v2 does broadcasting so simply putting 30 here will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops sorry I missed it in the first comment you mentioned. Fixed in 2df67e1
75ac0aa
to
2df67e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor correction! Thank you again, Gavin
month_difference = (end_date.month() - start_date.month()) * 30 | ||
year_difference = (end_date.year() - start_date.year()) * 360 | ||
|
||
return (day_difference + month_difference + year_difference) / 360 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please cast (day_difference + month_difference + year_difference) to the correct dtype
(before dividing by 360)? As it stands, the output is always of float32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 6fd5297
2df67e1
to
6fd5297
Compare
Add day count convention 30/360 which is used in Swiss Franc swap pricing.
I have added test cases from ISDA spreadsheet examples