I created an Excel-DNA xll and it seems to be loaded just fine by Excel. But the UDF was not registered since I can't see it in the formula wizard. How do I trouble shoot stuff like this ?
Below is the DNA file.
<DnaLibrary RuntimeVersion="v4.0" Name="Application Events Test" Language="VB" >
<Reference Name="Microsoft.Office.Interop.Excel" />
<Reference Name="Office" />
<![CDATA[
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Core
Imports ExcelDna.Integration.XlCall
Public Module MyFunctions
Public Sub getParameters(inputMtx As Object(,), _
ByRef MaxLTVSharePrice As Double, _
ByRef MaxLoanAmt As Double, _
ByRef ADTV As Double, _
ByRef BlockSaleDiscount As Double, _
ByRef BlockSaleDiscountFlag As Boolean, _
ByRef BlockSaleMultiplier As Double, _
ByRef numCollateralShares As Double)
MaxLTVSharePrice = inputMtx(0, 0)
MaxLoanAmt = inputMtx(1, 0)
ADTV = inputMtx(2, 0)
BlockSaleDiscount = inputMtx(3, 0)
BlockSaleDiscountFlag = inputMtx(4, 0)
BlockSaleMultiplier = inputMtx(5, 0)
numCollateralShares = inputMtx(6, 0)
End Sub
<ExcelFunction(Description:="liquidationPnL", IsThreadSafe:=True, Category:="Useful Excel-DNA Functions")>
Public Function liquidationPnL(inputMtx As Object(,), path As Double(,)) As Object
Dim MaxLTVSharePrice As Double
Dim MaxLoanAmt As Double
Dim ADTV As Double
Dim BlockSaleDiscount As Double
Dim BlockSaleDiscountFlag As Boolean
Dim BlockSaleMultiplier As Double
Dim numCollateralShares As Double
Dim nSharesLeft As Long
Dim totalDollarSaleValue As Double
Dim S(,) As Double
Dim nDays As Integer
Dim t As Integer
Call getParameters(inputMtx, _
MaxLTVSharePrice, _
MaxLoanAmt, _
ADTV, _
BlockSaleDiscount, _
BlockSaleDiscountFlag, _
BlockSaleMultiplier, _
numCollateralShares)
S = path
nDays = path.Length
nSharesLeft = numCollateralShares
totalDollarSaleValue = 0
For t = 1 To nDays
Dim nSharesThisDay As Double
Dim saleDollarValueThisDay As Double
nSharesThisDay = XlCall.Excel(XlCall.xlfMin, BlockSaleMultiplier * ADTV, nSharesLeft)
If BlockSaleDiscountFlag = False And t <> 1 Then
saleDollarValueThisDay = S(0, t - 1) * nSharesThisDay
Else
saleDollarValueThisDay = S(0, t - 1) * (1 - BlockSaleDiscount) * nSharesThisDay
End If
totalDollarSaleValue = totalDollarSaleValue + saleDollarValueThisDay
nSharesLeft = nSharesLeft - nSharesThisDay
If nSharesLeft = 0 Then
Exit For
End If
Next t
If nSharesLeft > 0 Then
liquidationPnL = "Error: more paths!"
Else
liquidationPnL = XlCall.Excel(XlCall.xlfMin, totalDollarSaleValue - MaxLoanAmt, 0)
End If
End Function
End Module
]]>
</DnaLibrary>