2012-02-27 73 views
2

想知道是否有人可以将我指向一个开源java定量库,它提供Excel Price和Yield函数的实现。java实现excel价格,收益​​函数

感谢, Tapasvi

+0

不知道是否有一个使用完全相同计算的库,但Excel帮助为您提供了用于运行计算的确切算法,因此它应该相当容易复制。 – assylias 2012-02-27 15:15:32

+0

Strata是一个面向市场风险的新Java库,可能会引起人们的兴趣(免责声明,我是作者) - http://strata.opengamma.io/ – JodaStephen 2016-10-10 10:13:04

+0

@JodaStephen是否有可与java 1.7兼容的版本? ? – Ganapathi004 2018-02-21 16:40:13

回答

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

你可能想看看QuantLib。这是一个定量金融的免费/开源库。

+0

使用来自Java的QuantLib需要通过SWIG。我担心业绩可能会成为一个问题。你有没有使用SWIG的经验? – tapasvi 2012-02-27 15:30:16

+0

对不起,我没有以前的SWIG经验。 – 2012-02-27 15:37:20