1

如果传递给 Gamma_inv 的随机数大约高于 0.96,则返回错误。这在 Excel 和 VBA 中都会发生。我正在运行 Monte Carlo,而这仅在 40,000 多次运行中发生 10 次左右。这是我使用它的方式。alpha 和 beta 总是 >0。如果“gammatrunc”= 1,我得到错误。如果我将其设置为 0.95,则不会出现错误:

     alpha = B * B * bsy2 ^ -2
     beta = bsy2 * bsy2 / B
     rand = Rnd * gammatrunc
     B = WorksheetFunction.GAMMA_Inv(rand, alpha, beta)

错误如下所示:

带有错误消息的输出

我很感激任何关于为什么会发生这种情况的想法。

谢谢

4

1 回答 1

0
You can use this function to study a variable whose distribution may be skewed.

If any argument is text, Gamma_Inv returns the #VALUE! error value.

If probability < 0 or probability > 1, Gamma_Inv returns the #NUM! error value.

If alpha ≤ 0 or if beta ≤ 0, Gamma_Inv returns the #NUM! error value.

Given a value for probability, Gamma_Inv seeks that value x such that GAMMA_DIST(x, alpha, beta, TRUE) = probability. Thus, precision of Gamma_Inv depends on precision of Gamma_Dist. Gamma_Inv uses an iterative search technique. If the search has not converged after 100 iterations, the function returns the #N/A error value.

https://docs.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.gamma_inv

您可以使用 VBA 在代码中添加一些控件,例如 MIN 和 MAX。

于 2020-05-06T14:34:12.383 回答