2012-02-27 74 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