Files
playbook/docs/tsl/codegen/dotnet/bond/yield.md
T

327 lines
15 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 债券 / 债券收益率
## `bd_AdjustedDuration(end_t, return_value)`
返回指定债券指定日修正久期,该函数和证券代码有关。
| 参数 | 类型 | 说明 |
| -------------- | -------- | ------------------ |
| `end_t` | datetime | 时间区间的截止日期 |
| `return_value` | float | 修正久期 |
返回:float
## `bd_CoupDayBS(end_t, return_value)`
返回指定债券当前付息期内截止到交易日的天数,该函数和证券代码有关。
| 参数 | 类型 | 说明 |
| -------------- | -------- | ------------------------------ |
| `end_t` | datetime | 时间区间的截止日期 |
| `return_value` | any | 当前付息期内截止到交易日的天数 |
返回:float
## `bd_Duration3(return_value)`
返回指定债券久期,该函数和证券代码有关。
| 参数 | 类型 | 说明 |
| -------------- | ----- | -------- |
| `return_value` | float | 债券久期 |
返回:float
## `bd_RemainPayNumber(end_t, return_value)`
返回指定债券指定日剩余付息次数,该函数和证券代码有关。
| 参数 | 类型 | 说明 |
| -------------- | -------- | -------------------- |
| `end_t` | datetime | 时间区间的截止日期。 |
| `return_value` | float | 指定日剩余付息次数 |
返回:float
## `bd_RemainYear(end_t, return_value)`
返回指定债券指定日剩余年限(年),该函数和证券代码有关。
| 参数 | 类型 | 说明 |
| -------------- | -------- | ------------------ |
| `end_t` | datetime | 时间区间的截止日期 |
| `return_value` | float | 指定日剩余年限(年) |
返回:float
## `bd_YTM3()`
返回指定债券到期收益率(%),该函数和证券代码有关。
返回:float
## `bondAccruedInterest(option, model_method)`
指定日债券的应计利息。在不设置数据供应商的情况下,默认先调用中证数据,没有值时再调用TS算法处理。若直接调用TS算法,设置供应商pn\_ bonddataprovider()为2。 应计利息是指从上次付息日到结算日(购买日)债券所应该支付的应计利息。针对不同的债券,应付利息采取不同的算法: 定期付息应计利息,见模型BondAccruedInterest1说明 到期一次还本付息应计利息,见模型BondAccruedInterest2说明 零息债券应计利息,见模型BondAccruedInterest3说明 此模型为常见债券计算应付利息的总接口
| 参数 | 类型 | 说明 |
| -------------- | -------- | ---------------- |
| `option` | datetime | 函数返回结果类型 |
| `model_method` | int | 算法模型 |
返回:float
### 示例
```tsl
获得代码SH010107在20171218T的日间应计利息-现金流算法
Setsysparam(pn_Stock(),”SH010107”);
Setsysparam(pn_bonddataprovider(),2);//数据供应商选择TS计算
Endt:=20171218T;
Return BondInterest(Endt,0);
```
## `bondAccruedInterest1(par, coupon, f, t, ts)`
银行间债券周期性付息的应计利息中间函数。
| 参数 | 类型 | 说明 |
| -------- | ----- | -------------------------------------------------------------------------------------------------------------------- |
| `par` | float | 实数,剩余本金 |
| `coupon` | float | 本期票面利率(%) |
| `f` | int | 年付息频率 |
| `t` | int | 计息日到结算日的实际天数(含2月29) |
| `ts` | any | 当前周期的实际天数(算头不算尾,周期不是完整周期时表示的是虚拟的下个付息日(计息日为基准)与上个付息日的天数 含2月29) |
返回:float
## `bondAccruedInterest2(par, coupon, k, ty)`
银行间债券到期一次还本付息的应计利息
| 参数 | 类型 | 说明 |
| -------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `par` | float | 面值 |
| `coupon` | float | 票面利率(%),本期利率(%) |
| `k` | int | 计息日到结算日的整年数(按实际天数处理,计息日为基准);:上一理论付息日(计息日为基准按照周期性付息频率为1处理的上个付息日)到结算日的实际天数(含2月29) |
| `ty` | int | 本期年度计息天数(以计息日为基准的年度天数含2月29 |
返回:float
## `bondAccruedInterest3(par, pd)`
零息债券的应计利息中间函数
| 参数 | 类型 | 说明 |
| ----- | ----- | ---------------------------------------------------------------------------------------- |
| `par` | float | 实数,面值 |
| `pd` | float | 实数,债券发行价;T1:整数,起息日至到期兑付日的实际天数;:整数,起息日至结算日的实际天数 |
返回:float
## `bondAccruedInterest4(settlement_date)`
固定利率债券的应计利息
| 参数 | 类型 | 说明 |
| ----------------- | -------- | ------ |
| `settlement_date` | datetime | 结算日 |
返回:float
## `bondAccruedInterest5(par, coupon, t)`
交易所债券-周期性付息或者到期一次还本付息的应计利息
| 参数 | 类型 | 说明 |
| -------- | ----- | ----------------- |
| `par` | float | 实数。剩余本金 |
| `coupon` | float | 实数。本期利率(%) |
| `t` | int | 整数。已计息天数 |
返回:float
## `bondCouponExt(settlement_date)`
债券-结算日票面利率,与系统股票pn_stock()有关
| 参数 | 类型 | 说明 |
| ----------------- | -------- | ---------------- |
| `settlement_date` | datetime | 日期类型,结算日 |
返回:float
### 示例
```tsl
Setsysparam(pn_Stock(),"BK000000");
return BondCouponExt(20120703T);
```
## `bondDaysNewestPayment(settlement_date, option)`
当前计息年度的实际天数,与系统参数(证券代码)相关。
| 参数 | 类型 | 说明 |
| ----------------- | -------- | --------------------------- |
| `settlement_date` | datetime | 日期。结算日 |
| `option` | int | 用户自定义。方法,取值如下: |
返回:int
### 示例
```tsl
Setsysparam(pn_Stock(),"BK010004");
return BondDaysNewestPayment(20120703T,1);
```
## `bondDirtyPrice(settlement_date)`
债券全价 全价交易是指债券价格中把应计利息包含在债券报价中的债券交易。应计利息是指从上次付息日到结算日(购买日)债券所应该支付的应计利息。 目前在常见数据提供商提供的债券数据中(沪深交易所债券2002年后,银行间债券2001年7月后),都是以净价披露的。 即:债券全价=债券净价+应付利息 在净价交易制度下,交易系统直接实行净价报价,同时显示债券成交价格和应计利息额,并以两项之和为债券买卖价格;结算系统直接实行净价结算,以债券成交价格与应计利息额之和为债券结算交割价格。也就是说,在债券现券买卖中,债券的报价采用净价,而实际买卖价格和结算交割价格为全价
| 参数 | 类型 | 说明 |
| ----------------- | -------- | ------ |
| `settlement_date` | datetime | 结算日 |
返回:float
## `bondYieldToMaturity(settlement_date)`
指定日的到期收益率(%)。在不设置数据供应商的情况下,默认先调用中证数据,没有值时再调用TS算法处理。若直接调用TS算法,设置供应商pn\_ bonddataprovider()为2。 针对不同的债券,不同的代偿期,到期收益率采取不同的算法: 到期收益率(最后付息周期的定期付息债、待偿期在一年及以内的到期一次还本付息债券和零息债券),见函数BondYieldToMaturity1说明 到期收益率(待偿期在一年以上的到期一次还本付息债券和零息债券),见函数BondYieldToMaturity2说明 到期收益率(不处于最后付息周期的定期付息债),见函数BondYieldToMaturity3说明 此模型为常见债券计算到期收益率的总接口
| 参数 | 类型 | 说明 |
| ----------------- | -------- | ----------------------- |
| `settlement_date` | datetime | 结算日;Option:是否行权 |
返回:float
### 示例
```tsl
债券SH010107在20171228日收盘买入持有到到期的收益率
Endt:=20171228T;
Setsysparam(pn_Stock(),"SH010107");
Setsysparam(pn_bonddataprovider(),2);//数据供应商选择TS计算
Return BondYieldToMaturity(Endt);
```
## `bondYieldToMaturity1(pv, fv, d, ty)`
最后付息周期的定期付息债、待偿期在一年及以内的到期一次还本付息债券和零息债券的到期收益率 其中: y: 到期收益率; FV:到期兑付日债券本息和 PV:债券全价 D:债券结算日至到期兑付日的实际天数 TY:当前计息年度的实际天数,算头不算尾
| 参数 | 类型 | 说明 |
| ---- | ----- | ------------------------------------------------------- |
| `pv` | float | 实数,债券全价 |
| `fv` | float | 实数,债券到期兑付现金流(本息和) |
| `d` | int | 整数,结算日到到期日的实际天数。(含2月29) |
| `ty` | int | 整数,本期计息年度实际天数(计息起始日为基准,含2月29) |
返回:float
## `bondYieldToMaturity2(pv, fv, d)`
待偿期在一年以上的到期一次还本付息债券和零息债券的到期收益率 :债券全价 :到期兑付日债券本息和 : 到期收益率 :结算日至下一最近理论付息日的实际天数 :结算日至到期兑付日的整年数 TY :当前计息年度的实际天数,算头不算尾
| 参数 | 类型 | 说明 |
| ---- | ----- | --------------------------------------------------------------------------------------------------------------- |
| `pv` | float | 实数,债券全价 |
| `fv` | float | 实数,到期兑付日债券本息和 |
| `d` | int | 整数,结算日至下一最近理论付息日的实际天数;TY:整数,当前计息年度的实际天数;m:整数,结算日至到期兑付日的整年数 |
返回:float
## `bondYieldToMaturity3(pv)`
规则付息且非最后付息周期债券的到期收益率中间函数。付息次数处理—完整周期采用+1,非完整周期计算比例。(非完整周期主要是首个周期以及最后付息周期)。
| 参数 | 类型 | 说明 |
| ---- | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pv` | float | 实数,债券全价;CashFlow:数组,未来现金流数据,字段见现金流返回值。;f:整数,频率;d:整数,债券结算日至下一付息日之间的实际天数(含2月29);TS :整数,当前付息周期的实际天数(计息日为基准,含2月29) |
返回:float
## `bondYieldTomaturity4(settlementdate, cash_flow, pv)`
债券付息不规则的到期收益率。
| 参数 | 类型 | 说明 |
| ---------------- | -------- | ---------------- |
| `settlementdate` | datetime | 日期。指定日期 |
| `cash_flow` | array | 数组。债券现金流 |
| `pv` | float | 实数。现价 |
返回:float
## `BondYieldToMaturity_II(amortised_cost, settlement_date, option)`
到期收益率(%)-摊余成本法,与系统股票pn_stock()有关
| 参数 | 类型 | 说明 |
| ----------------- | -------- | --------------------- |
| `amortised_cost` | float | 实数,摊余成本 |
| `settlement_date` | datetime | 日期类型,结算日 |
| `option` | any | 用户自定义,取值如下: |
返回:float
## `isBondPayRegular(settlement_date, option)`
指定日付息是否规则。
| 参数 | 类型 | 说明 |
| ----------------- | -------- | ------------------------------- |
| `settlement_date` | datetime | 日期。指定日期 |
| `option` | int | 用户自定义。是否行权,取值如下: |
返回:int
## `isBondPayRugularByCash(cash_flow, period)`
现金流数据是否规则付息。
| 参数 | 类型 | 说明 |
| ----------- | ----- | ---------------- |
| `cash_flow` | array | 数组。债券现金流 |
| `period` | int | 整数。频率 |
返回:int
## `MID_BondYieldToMaturity(settlementdate, cash_f_low, pv, f)`
到期收益率(%)--中间函数。
| 参数 | 类型 | 说明 |
| ---------------- | -------- | -------------------------- |
| `settlementdate` | datetime | 日期。截止日期 |
| `cash_f_low` | array | 数组。债券指定日未来现金流 |
| `pv` | float | 实数。债券价格 |
| `f` | any | 整数。付息频率 |
返回:float
## `bondCleanPrice(settlement_date)`
债券净价
| 参数 | 类型 | 说明 |
| ----------------- | --------- | ------ |
| `settlement_date` | TDateTime | 结算日 |
返回:Real
## `bondFutureValue()`
到期兑付日债券本息和,与系统股票pn_stock()有关
返回:Real
### 示例
```tsl
//返回’ BK000002’的到期兑付日债券本息和
setSysParam(PN_Stock(),'BK000002');
return bondFutureValue();
//结果:102.8
```