Go to the developer tab in Excel. If you don't have it, right click on the ribbon in Excel, choose 'Customize Ribbon', check the Developer tab and click OK.
-> Go to the Developer tab -> click Visual Basic -> to Insert toolbar -> click Module ->
-> Then copy and paste the code into the window.
The custom function should work at that point.
-> When saving, you must save it as a macro enabled workbook to access the custom formula in other workbooks
Based on the formula:
BEY = [( Par value - purchase price) / Purchase price] × (365 / days to maturity)
BEY = Bond Equivalent Yield
PV = Par Value
price = Purchase Price
DTM = Days to Maturity