To generate the function of pdf of noncentral chi-square in VBA for a application of CIR model,I followed the pdf formula in
http://en.wikipedia.org/wiki/Noncentral ... ibutionThe inputs are value X, k, the number of degrees of freedom and, λ, the noncentrality parameter.I also compared the result with function in R.Result of VBA is correct when dataset is normal, such as (60,4,50).In R code: > dchisq(60,4,50)[1] 0.0233497However, when I am using X = 6908.74,k = 51.5248723089,λ= 6821.6668981824, I could get the answer correctly in R, but the function I created in VBA always don?t generate the correct answer. I think the reason is that in pdf function, the exp((-X-lamda)/2) is too small in this case and Bassel function is not large enough.Did anyone know how to solve this problem?Thank you so much!!!VBA code:Public Sub test()X = 6908.74df = 51.5248723089 'kncp = 6821.6668981824 'λDim r1, r2, r3 As Doubler1 = 1 / 2 * Exp(-(X + ncp) / 2)r2 = (X / ncp) ^ (df / 4 - 0.5)r3 = BESSELi((ncp * X) ^ 0.5, (df / 2 - 1))pdfresule = r1 * r2 * r3End Sub