Skip to content
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

Merged

Conversation

gavincyi
Copy link
Contributor

@gavincyi gavincyi commented Mar 1, 2020

Add day count convention 30/360 which is used in Swiss Franc swap pricing.

I have added test cases from ISDA spreadsheet examples

@gavincyi gavincyi force-pushed the feature/add-daycount-30-360 branch 2 times, most recently from 115c3aa to 9f6e6e4 Compare March 1, 2020 18:07
start_date.day() >= 31,
tf.repeat(30, start_date.shape[0]),
start_date.day()
)
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

@saxena-ashish-g saxena-ashish-g left a 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(
Copy link
Contributor

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())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a884fb0

@gavincyi gavincyi force-pushed the feature/add-daycount-30-360 branch 2 times, most recently from a884fb0 to 75ac0aa Compare March 3, 2020 08:23
@gavincyi
Copy link
Contributor Author

gavincyi commented Mar 3, 2020

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]),
Copy link
Contributor

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.

Copy link
Contributor Author

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

@gavincyi gavincyi force-pushed the feature/add-daycount-30-360 branch from 75ac0aa to 2df67e1 Compare March 3, 2020 09:06
Copy link
Contributor

@cyrilchim cyrilchim left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 6fd5297

@gavincyi gavincyi force-pushed the feature/add-daycount-30-360 branch from 2df67e1 to 6fd5297 Compare March 4, 2020 11:09
@tf-quant-finance-robot tf-quant-finance-robot merged commit 5d5c82c into google:master Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants