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