想知道是否有人可以指向我提供Excel价格和收益函数实现的开源java量子库。
谢谢, Tapasvi
答案 0 :(得分:1)
Excel PRICE函数是贴现现金流量的简单总和,假设零利率贴现曲线平均折现。这里记录了:Excel Help / PRICE。
我写了一个小Java版本的函数,我将在下面发布。 Java版本只需要“成熟时间”并且不支持不同的日计数,而Excel PRICE函数需要结算日期和到期日并支持不同的日期计数。但是,您可以通过转换优惠券来归因于不同的日计数。另请注意,Excel功能在优惠券前面有一个奇怪的硬编码名称为100。
对两个实现进行基准测试的Excel工作表可以是downloaded here。该表格需要"Obba"。
Excel YIELD函数只是应用于PRICE函数的牛顿求解器,请参阅Excel Help / YIELD。可以在finmath.net找到牛顿求解器的Java实现。
/*
* 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;
}
}
答案 1 :(得分:0)
您可能需要查看QuantLib。它是一个免费/开源的量化金融库。