excel价格,收益​​函数的java实现 [英] java implementation of excel price,yield functions

查看:89
本文介绍了excel价格,收益​​函数的java实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否有人可以将我指向提供Excel Price和Yield函数实现的开源Java量化库.

谢谢,Tapasvi

解决方案

Excel PRICE函数是折现现金流的简单总和,假设零利率折现曲线平坦,则折现现金流.在此处进行了记录: Excel帮助/价格./p>

我编写了该函数的一个小型Java版本,在下面发布.Java版本仅需要一个到期时间",并且不支持不同的日间计数,而Excel PRICE函数需要一个结算日期和到期日并支持不同的日间计数.但是,您可以通过转换优惠券来归因于不同的天数.还要注意,Excel函数在优惠券前有一个奇怪的硬编码概念100.

可以在在此处下载的Excel工作表中对这两种实现进行基准测试.该工作表要求"Obba" .

Excel YIELD函数只是应用于PRICE函数的牛顿求解器,请参见 Excel帮助/Yield .可以在 finmath.net 中找到牛顿求解器的Java实现.

 /**创建于2012年4月7日*//***此类将某些功能实现为静态类方法.**(c)2012年克里斯蒂安·弗里斯(Christian Fries)版权所有.** @作者克里斯蒂安·弗里斯(Christian Fries)* @版本1.0*/公共类SpreadsheetFunctions {/***重新实现Excel PRICE函数(一个相当原始的债券价格公式).*重新实现不是精确的,因为此函数不考虑日计数约定.*我们假设我们有(int)timeToMaturity/frequency未来期间,而运行期间有* timeToMaturity的应计时间段-频率*((int)timeToMaturity/frequency).** @param timeToMaturity到期时间.* @param优惠券付息.* @param yield yield(折扣系数,使用频率:1/(1 + yield/frequency).* @param兑换兑换(名义还款).* @参数频率频率(1,2,4).* @返回价格清洁价格.*/公共静态双倍价格(double timeToMaturity,双重优惠券,双倍产量双重赎回,内部频率){双倍价格= 0.0;if(timeToMaturity> 0){价格+ =赎回;}双倍的付款时间= timeToMaturity;while(paymentTime> 0){价格+ =优惠券/频率;//折回价格=价格/(1.0 +收益率/频率);paymentTime-= 1.0/频率;}//累计运行时间double accrualPeriod = 0.0-paymentTime;//过去(结算前)的运行时间量价格* = Math.pow(1.0 +收益率/频率,应计期*频率);价格-=优惠券/频率*应计期限*频率;退货价格}} 

Was wondering if anyone can point me to an open source java quant library that provides implementation for Excel Price and Yield functions.

Thanks, Tapasvi

解决方案

The Excel PRICE function is a simple sum of discounted cash flows, discounted assuming a flat zero rate discounting curve. It is documented here: Excel Help / PRICE.

I wrote a small Java version of the function, which I am posting below. The Java version just takes a "time to maturity" and does not support different daycountings, while the Excel PRICE function takes a settlement date and maturity date and supports different daycountings. However, you can attribute for the different daycountings by converting the coupon. Note also that the Excel function has a strange hardcoded notional of 100 in front of the coupon.

An Excel sheet benchmarking the two implementations can be downloaded here. The sheet requires "Obba".

The Excel YIELD function is just a Newton solver applied to the PRICE function, see Excel Help / YIELD. A Java implementation of the Newton solver can be found at 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;
    }
}

这篇关于excel价格,收益​​函数的java实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆