Option Explicit


Sub ConvertRates_Module1()

    

    Dim ws As Worksheet

    Dim rInput As Double

    Dim rateType As String

    Dim m As Long

    

    Dim i_eff As Double      ' effective annual rate

    Dim j_nom As Double      ' nominal annual rate (convertible m-thly)

    Dim delta As Double      ' force of interest

    

    Set ws = ThisWorkbook.Sheets("Rates")

    

    ' ---- Read inputs ----

    rInput = ws.Range("B2").Value          ' rate value entered by user

    rateType = UCase(ws.Range("B3").Value) ' EFF / NOM / DELTA

    m = ws.Range("B4").Value               ' compounding frequency

    

    ' ---- Determine all three forms ----

    Select Case rateType

    

        Case "EFF"

            ' rInput is effective annual rate

            i_eff = rInput

            j_nom = m * ((1 + i_eff) ^ (1 / m) - 1)

            delta = Log(1 + i_eff)

        

        Case "NOM"

            ' rInput is nominal annual rate j, convertible m-thly

            j_nom = rInput

            i_eff = (1 + j_nom / m) ^ m - 1

            delta = Log(1 + i_eff)

        

        Case "DELTA"

            ' rInput is force of interest δ

            delta = rInput

            i_eff = Exp(delta) - 1

            j_nom = m * ((1 + i_eff) ^ (1 / m) - 1)

        

        Case Else

            MsgBox "Invalid rate type in B3. Use EFF, NOM or DELTA.", vbExclamation

            Exit Sub

    End Select

    

    ' ---- Write outputs ----

    ws.Range("B6").Value = i_eff

    ws.Range("B7").Value = j_nom

    ws.Range("B8").Value = delta

    

End Sub


Comments

Popular posts from this blog

LEARNING DISABILITY THROUGH ASTROLOGY

What Failed Surjit? A Story of Caste Pride and Cowardice

The Unseen Value of Struggle