首页 > 解决方案 > Java中Excel的YIELD公式

问题描述

有没有办法在 Java 中复制 Excel YIELD 公式?我能够计算 IRR 公式,并且在 Excel 中得到相同的结果。

但是,对于 YIELD 公式,我无法复制完全相同的结果。从我所见,有不同的例子,但他们有不同的参数。

我想复制完全相同的 Excel。

请找到我使用的示例:

def BondYieldNewton(def price , def faceValue, def periods, def rate, def years){


    def oldYield = 0
    def yield = 0.1

    def presentValue = 0.00
    def presentValueDerivate = 0.00

    def tolerance = 1E-16
    while (tolerance < Math.abs(yield - oldYield)) {

        oldYield = yield
        for(int i = 1; i < periods * years; i++) {
            presentValue += (rate / periods) * faceValue / Math.pow((1 + oldYield / periods), i)
        }
        presentValue += faceValue / Math.pow((1 + oldYield), periods) - price

        for(int i = 1; i < periods * years; i++) {

            presentValueDerivate += -i * (rate / periods) * faceValue / Math.pow((1 + oldYield / periods), years * i + 1) - years * periods * faceValue / Math.pow((1 + oldYield / years), years * periods + 1)

        }
        yield = oldYield - presentValue / presentValueDerivate


    }
    return yield
}

这些是一些参数:

        def price = 90
        def faceValue = 100;
        def years = 12;
        def period = 2
        def rate = 0.07

先感谢您,

更新:请在 Groovy 代码中找到我要复制的公式和更新 https://courses.lumenlearning.com/boundless-finance/chapter/valuing-bonds/ https://en.wikipedia.org/wiki/牛顿%27s_method

标签: groovyexcel-formulajvmfinance

解决方案


推荐阅读