2
A
回答
1
Excel PRICE函数是贴现现金流的简单总和,假设贴现率为零的贴现曲线打折。这里记录:Excel Help/PRICE。
我写了一个小的Java版本的函数,我在下面发表。 Java版本只需要一段“时间到期”,并且不支持不同的日期计算,而Excel PRICE函数则需要一个结算日期和到期日期,并支持不同的日计算。但是,您可以通过转换优惠券来为不同的日计算归因。还要注意的是,Excel函数在优惠券前有一个硬编码的奇怪的100。
基准两个实施的Excel工作表可以是downloaded here。该表格需要"Obba"。
Excel YIELD函数只是应用于PRICE函数的牛顿求解器,请参见Excel Help/YIELD。牛顿求解器的Java实现可以在finmath.net找到。
/*
* Created on 07.04.2012
*/
/**
* This class implements some functions as static class methods.
*
* (c) Copyright 2012 Christian Fries.
*
* @author Christian Fries
* @version 1.0
*/
public class SpreadsheetFunctions {
/**
* Re-implementation of the Excel PRICE function (a rather primitive bond price formula).
* The reimplementation is not exact, because this function does not consider daycount conventions.
* We assume we have (int)timeToMaturity/frequency future periods and the running period has
* an accrual period of timeToMaturity - frequency * ((int)timeToMaturity/frequency).
*
* @param timeToMaturity The time to maturity.
* @param coupon Coupon payment.
* @param yield Yield (discount factor, using frequency: 1/(1 + yield/frequency).
* @param redemption Redemption (notional repayment).
* @param frequency Frequency (1,2,4).
* @return price Clean price.
*/
public static double price(
double timeToMaturity,
double coupon,
double yield,
double redemption,
int frequency)
{
double price = 0.0;
if(timeToMaturity > 0) {
price += redemption;
}
double paymentTime = timeToMaturity;
while(paymentTime > 0) {
price += coupon/frequency;
// Discount back
price = price/(1.0 + yield/frequency);
paymentTime -= 1.0/frequency;
}
// Accrue running period
double accrualPeriod = 0.0-paymentTime; // amount of running period which lies in the past (before settlement)
price *= Math.pow(1.0 + yield/frequency, accrualPeriod*frequency);
price -= coupon/frequency * accrualPeriod*frequency;
return price;
}
}
0
相关问题
- 1. 如何从收益函数
- 2. Ruby:超载收益函数
- 3. 递归Linq函数和收益
- 4. [R data.table转换价格收益率的标准
- 5. Excel中巩固收益率唯一值
- 6. Excel Yield函数的.NET实现
- 7. 将指数从100开始的列添加到股票价格/收益矩阵
- 8. 转换Excel文本实现价值
- 9. Python收益率与Ruby收益率
- 10. 循环数据与收益和不收益有什么不同
- 11. 无法使用收益绑定到IEnumerable实现
- 12. 在Java中的收益率返回
- 13. 如何使收益不变的JAVA
- 14. 使用Excel的资产VBA数收益宏
- 15. Excel数据透视表计算字段总收益意外值
- 16. 在Java中实现递归lambda函数
- 17. 实现函数
- 18. 如何在Java中实现等价类?
- 19. NSInvocationOperation等效收益
- 20. 收益法混淆
- 21. 收益回报BRAINFREEZE
- 22. selected_options收益从IFRAME
- 23. Cognos等价于excel的sumif()函数
- 24. Excel VBA网络价格数据采集
- 25. 的Java SMPP实现接收短信
- 26. 实例化Excel函数
- 27. NGRX /存储选择收益函数,而不是对象
- 28. ES6/ES2015在封闭收益率内的函数*
- 29. 与java的Excel correl()函数?
- 30. Excel VBA函数到Java poi
不知道是否有一个使用完全相同计算的库,但Excel帮助为您提供了用于运行计算的确切算法,因此它应该相当容易复制。 – assylias 2012-02-27 15:15:32
Strata是一个面向市场风险的新Java库,可能会引起人们的兴趣(免责声明,我是作者) - http://strata.opengamma.io/ – JodaStephen 2016-10-10 10:13:04
@JodaStephen是否有可与java 1.7兼容的版本? ? – Ganapathi004 2018-02-21 16:40:13