본문으로 건너뛰기
라이브러리 문서 전체

보간 수익률 곡선에서 할인계수 추출하기

기사 Quant Q&A · 저자: Mike

요약

이 문서는 QuantLib 할인 곡선을 만드는 데 사용된 기준 만기 사이의 날짜에서 할인계수를 구하는 방법을 보여줍니다. 스왑 금리 입력값으로 구간별 로그 선형 할인 곡선을 만든 뒤, 예시에서는 미래 날짜의 연속을 생성하고 각 날짜에 곡선의 discount 메서드를 호출합니다. 그 결과로 곡선에서 일정한 간격으로 값을 추출해 날짜와 함께 표시할 수 있습니다.

예시 코드는 5년 간격으로 값을 추출하지만 질문은 반기 간격을 요청합니다. 같은 방법으로 날짜를 6개월 간격으로 선택하면 됩니다. 두 번째 답변은 핵심을 명확히 합니다. 곡선은 요청된 날짜라면 무엇이든 할인계수를 반환하므로 원래 곡선 노드로 출력을 제한할 필요가 없습니다. 예시는 합성 스웨덴 크로나 스왑 데이터를 사용하고 마지막 입력 만기 이후 외삽을 활성화합니다. 따라서 결과는 시장 근거가 아니라 API 사용 사례를 보여주며, 외삽 값은 곡선의 가정과 설정에 따라 달라집니다.

핵심 아이디어

  • 구축된 할인 곡선은 입력 만기 노드 사이의 날짜에 대해서도 할인계수를 반환할 수 있습니다.
  • 원하는 날짜 간격을 정하고 각 날짜마다 곡선에 값을 요청합니다.
  • 예시는 5년 간격으로 값을 추출하며, 날짜 간격을 바꾸면 반기 단위 추출도 가능합니다.
  • 마지막 곡선 노드 이후의 할인계수는 외삽 설정에 의존할 수 있으므로 그에 맞게 해석해야 합니다.

태그

전문
# QuantLib Python - Discount Factor Interpolation within curve nodes


# QuantLib Python - Discount Factor Interpolation within curve nodes












Generated a discount curve, dCurve.PiecewiseLogLinearDiscount() using input par rate for terms (.5Y, 1Y, 2Y, 3Y, 5Y, 7Y, 10Y, 15Y, 20Y, 30Y) and output discount curve matching the input term structure. Any suggestions on how to output the discount factor curve on a .5Y interval term structure up to 30Y?

## Answer by Xiarpedia (score 1)

https://quant.stackexchange.com/a/77563

Based on your question I created the following curve example:

```
import QuantLib as ql
import pandas as pd

# Set the evaluation date
ql.Settings.instance().evaluationDate = ql.Date(30, 12, 2022)
# Declare a store variable for the helpers
helpers = []
# Create the attributes of the swap
calendar = ql.Sweden()
frequency = ql.Annual
convention = ql.ModifiedFollowing
# Synthetic market data
daycount = ql.Thirty360(ql.Thirty360.BondBasis)
index = ql.IborIndex(
    "MyIndex",
    ql.Period("3M"),
    2,
    ql.SEKCurrency(),
    calendar,
    ql.Following,
    False,
    daycount,
)

tenor = ["4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "12Y", "15Y", "20Y", "25Y", "30Y"]
quotes = [
    3.33,
    3.2775,
    3.235,
    3.205,
    3.1775,
    3.1525,
    3.1325,
    3.095,
    3.0275,
    2.92,
    2.815,
    2.6925,
]
for r, m in zip(quotes, tenor):
    rate = ql.QuoteHandle(ql.SimpleQuote(r / 100.0))
    tenor = ql.Period(m)
    helpers.append(
        ql.SwapRateHelper(
            rate, tenor, calendar, frequency, convention, daycount, index
        )
    )
curve = ql.PiecewiseLogLinearDiscount(0, calendar, helpers, ql.Actual365Fixed())
curve.enableExtrapolation()
dates, rates = zip(*curve.nodes())
```

Which leaves me at the stage you are at. We can then interpolate on a 5 year interval as following:

```
# Interpolate on a 5Y interval
nodes = []
start_date = ql.Date(30, 12, 2022)
while True:
    start_date += ql.Period("5Y")
    nodes.append(start_date)
    if start_date > ql.Date(30, 12, 2053):
        break
discount_factors = [curve.discount(d) for d in nodes]
display(pd.DataFrame(dict({"Date": nodes, "Discount Factor": discount_factors})))
```

Which results in:

|  | Date | Discount Factor |
| 0 | December 30th, 2027 | 0.851205 |
| 1 | December 30th, 2032 | 0.735589 |
| 2 | December 30th, 2037 | 0.641855 |
| 3 | December 30th, 2042 | 0.567462 |
| 4 | December 30th, 2047 | 0.508218 |
| 5 | December 30th, 2052 | 0.464726 |
| 6 | December 30th, 2057 | 0.424997 |

## Answer by Luigi Ballabio (score 0)

https://quant.stackexchange.com/a/77564

You can pass any date you like to the `discount` method of the curve you built. It will return the corresponding discount factor.

출처의 라이선스에 따라 출처를 표시하고 전문을 공개합니다. 라이선스: CC BY-SA 4.0 (Stack Exchange)

이 요약은 원문을 바탕으로 Stratmill의 리서치 에이전트가 작성했으며, 원문을 복사한 것이 아닙니다.