コード例 #1
0
def cfamounts(coupon_rate, pricing_date, maturity_date, period, basis):
    """
    Calculate price and accrued interest

    Args:

    coupon_rate:   coupon rate in decimal form (5% = .05)
    pricing_date:  the date where market data is observed. Settlement
                   is by default 2 days after pricing_date
    maturity_date: ... bond
    period:        periodicity of coupon payments
    basis:         day count basis for computing accrued interest


    Returns:
    cf_amounts: cash flow amount
    cf_dates:   cash flow dates

    """

    args = locals()
    the_shape, shape = common_shape(args)

    all_scalars = np.all([shape[key][0] == 'scalar' for key in shape])

    if all_scalars:
        cf_a, cf_d = _cfamounts(**args)
    else:
        raise Exception('Only scalar inputs are handled')

    return (cf_a, cf_d)
コード例 #2
0
ファイル: fixed_income.py プロジェクト: ChinaQuants/pyql
def cfamounts(coupon_rate, pricing_date, maturity_date,
             period, basis):
    """
    Calculate price and accrued interest

    Args:

    coupon_rate:   coupon rate in decimal form (5% = .05)
    pricing_date:  the date where market data is observed. Settlement
                   is by default 2 days after pricing_date
    maturity_date: ... bond
    period:        periodicity of coupon payments
    basis:         day count basis for computing accrued interest


    Returns:
    cf_amounts: cash flow amount
    cf_dates:   cash flow dates

    """

    args = locals()
    the_shape, shape  = common_shape(args)

    all_scalars = np.all([shape[key][0] == 'scalar' for key in shape])

    if all_scalars:
        cf_a, cf_d = _cfamounts(**args)
    else:
        raise Exception('Only scalar inputs are handled')

    return (cf_a, cf_d)
コード例 #3
0
def blsimpv(price, spot, strike, risk_free_rate, time,
             option_type='Call', dividend=0.0):

    args = locals()
    the_shape, shape = common_shape(args)

    all_scalars = np.all([shape[key][0] == 'scalar' for key in shape])

    if all_scalars:
        res = _blsimpv(**args)
    else:
        res = array_call(_blsimpv, shape, args)

    return res
コード例 #4
0
def bndprice(bond_yield,
             coupon_rate,
             pricing_date,
             maturity_date,
             period,
             basis,
             compounding_frequency=None):
    """
    Calculate price and accrued interest

    Args:

    bond_yield:    compound yield to maturity
    coupon_rate:   coupon rate in decimal form (5% = .05)
    pricing_date:  the date where market data is observed. Settlement
                   is by default 2 days after pricing_date
    maturity_date: ... bond
    period:        periodicity of coupon payments
    basis:         day count basis for computing accrued interest
    compounding_frequency: ... of yield. By default: annual for ISMA,
                           semi annual otherwise


    Returns:
    price: clean price
    ac:    accrued interest

    """

    args = locals()
    the_shape, shape = common_shape(args)

    if DEBUG:
        print(the_shape)
        print(shape)
        print(values)

    all_scalars = np.all([shape[key][0] == 'scalar' for key in shape])

    if all_scalars:
        price, ac = _bndprice(**args)
    else:
        res = array_call(_bndprice, shape, args)
        price = np.reshape([x[0] for x in res], the_shape)
        ac = np.reshape([x[1] for x in res], the_shape)
    return (price, ac)
コード例 #5
0
def blsprice(spot, strike, risk_free_rate, time, volatility,
             option_type=Call, dividend=0.0, calc='price'):

    """
    Matlab's blsprice + greeks (delta, gamma, theta, rho, vega, lambda)
    """
    args = locals()
    the_shape, shape = common_shape(args)

    all_scalars = np.all([shape[key][0] == 'scalar' for key in shape])

    if all_scalars:
        res = _blsprice(**args)
    else:
        res = array_call(_blsprice, shape, args)
        res = np.reshape(res, the_shape)
    return res
コード例 #6
0
ファイル: fixed_income.py プロジェクト: ChinaQuants/pyql
def bndprice(bond_yield, coupon_rate, pricing_date, maturity_date,
             period, basis, compounding_frequency=None):
    """
    Calculate price and accrued interest

    Args:

    bond_yield:    compound yield to maturity
    coupon_rate:   coupon rate in decimal form (5% = .05)
    pricing_date:  the date where market data is observed. Settlement
                   is by default 2 days after pricing_date
    maturity_date: ... bond
    period:        periodicity of coupon payments
    basis:         day count basis for computing accrued interest
    compounding_frequency: ... of yield. By default: annual for ISMA,
                           semi annual otherwise


    Returns:
    price: clean price
    ac:    accrued interest

    """

    args = locals()
    the_shape, shape  = common_shape(args)

    if DEBUG:
        print(the_shape)
        print(shape)
        print(values)

    all_scalars = np.all([shape[key][0] == 'scalar' for key in shape])

    if all_scalars:
        price, ac = _bndprice(**args)
    else:
        res = array_call(_bndprice, shape, args)
        price = np.reshape([x[0] for x in res], the_shape)
        ac = np.reshape([x[1] for x in res], the_shape)
    return (price, ac)