groovy - 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
解决方案
推荐阅读
- python - BIGQUERY - 整数范围分区表中的 UNPARTITIONED 分区
- javascript - 变量变化时如何创建动态表?
- laravel - laravel 中的日期格式
- machine-learning - 关于简单自动编码器实现的问题
- django - 预取相关提取的数据库行?
- sass - 触控笔多维数组
- javascript - 如何在 Typescript 中为现有的 JavaScript 模块模式编写模块模式
- ruby-on-rails - 将上传的文件路径传递给 File.read(path)
- c# - SQLite 在同一终端服务器网络上速度很慢,但在具有物理计算机的本地网络上却没有
- android - 在 Android MVVM 中更改另一个字段时更新字段