|
From: Trent M. <tr...@ma...> - 2023-10-03 21:24:54
|
Python below for Camara. You'll need blp, blpapi, and QuantLib installed in your environment and the Bloomberg terminal running (otherwise skip the blp parts and put your quotes in the _data dictionary.
import
QuantLib
as
ql
from
blp
import
blp
class
Quotes
:
_data: dict[str, ql.SimpleQuote] = {} # put quotes here if you don't have BBG. e.g. {"
CHSWPA Curncy": ql.SimpleQuote(9.3), ...}
def
get
(self, ticker: str)
->
ql
.
SimpleQuote
:
if
ticker
not
in
self._data:
self._data[ticker] = ql.SimpleQuote(
0.0
)
return
self._data[ticker]
def
set
(self, ticker: str, value: float)
->
None
:
self.get(ticker).setValue(value)
def
update
(self)
->
None
:
with
blp.BlpQuery(host=
"localhost"
)
as
bq:
data = bq.bdp(list(self._data.keys()), [
"px_last"
])
for
_, row
in
data.iterrows():
ticker = row[
"security"
]
px_last = row[
"px_last"
]
self.set(ticker, px_last)
def
main
()
:
quotes = Quotes()
calendar = ql.Chile()
accr_handle = ql.RelinkableYieldTermStructureHandle()
disc_handle = ql.RelinkableYieldTermStructureHandle()
tickers = [
(
"1M"
,
"CHSWPA Curncy"
),
(
"2M"
,
"CHSWPB Curncy"
),
(
"3M"
,
"CHSWPC Curncy"
),
(
"6M"
,
"CHSWPF Curncy"
),
(
"9M"
,
"CHSWPI Curncy"
),
(
"1Y"
,
"CHSWP1 Curncy"
),
(
"18M"
,
"CHSWP1F Curncy"
),
(
"2Y"
,
"CHSWP2 Curncy"
),
(
"3Y"
,
"CHSWP3 Curncy"
),
(
"4Y"
,
"CHSWP4 Curncy"
),
(
"5Y"
,
"CHSWP5 Curncy"
),
(
"6Y"
,
"CHSWP6 Curncy"
),
(
"7Y"
,
"CHSWP7 Curncy"
),
(
"8Y"
,
"CHSWP8 Curncy"
),
(
"9Y"
,
"CHSWP9 Curncy"
),
(
"10Y"
,
"CHSWP10 Curncy"
),
(
"12Y"
,
"CHSWP12 Curncy"
),
(
"15Y"
,
"CHSWP15 Curncy"
),
(
"20Y"
,
"CHSWP20 Curncy"
),
]
index = ql.OvernightIndex(
"CLP Camara"
,
0
, ql.CLPCurrency(), calendar, ql.Actual360(), accr_handle)
helpers = [
ql.OISRateHelper(
2
,
ql.Period(tenor),
ql.QuoteHandle(ql.DerivedQuote(ql.QuoteHandle(quotes.get(ticker)),
lambda
x: x /
100
)),
index,
disc_handle,
False
,
0
,
ql.ModifiedFollowing,
ql.Semiannual
if
ql.Period(tenor) > ql.Period(
"18M"
)
else
ql.Once,
calendar,
)
for
tenor, ticker
in
tickers
]
curve = ql.PiecewiseLogCubicDiscount(
0
, calendar, helpers, ql.Actual360())
accr_handle.linkTo(curve)
disc_handle.linkTo(curve)
quotes.update()
for
date
in
curve.dates():
print(date.to_date(), curve.zeroRate(date, ql.Actual365Fixed(), ql.Continuous).rate())
if
__name__ ==
"__main__"
:
main()
------- Original Message -------
On Tuesday, October 3rd, 2023 at 12:32, Trent Maetzold <tr...@ma...> wrote:
> What Chile curve are you trying to build? Camara is built using only OISRateHelper (Semiannual after 18m, Once 18m and under). Pretty straightforward construction. Use PiecewiseLogCubicDiscount for the curve constructor.
>
> Sent from [Proton Mail](https://proton.me/mail/home) for iOS
>
> On Sun, Oct 1, 2023 at 18:14, Gabriel Campolina <[cam...@gm...](mailto:On Sun, Oct 1, 2023 at 18:14, Gabriel Campolina <<a href=)> wrote:
>
>> Hello.
>>
>> I'm trying to build a SwapRateHelper for a Swap of bullet 18M tenor, using the function "SwapRateHelper2" and when I use "FixedLegFrequency" of "Once" and "Annual", it gives me the same result of Zero Rate, and it's quite different from the correct zero rate. (I'm trying to build a yield curve using chilean IRS)
>>
>> Also, when I build a yield curve using an IborIndex built with a forward curve using the FlatForward function with "Simple" compounding, it gives me the same result as using "Continuous" and "Compounded" arguments.
>>
>> Is there something that might be missing in the functions, or am I getting something wrong?
>>
>> Thanks in advance, I would really appreciate your help !
>> --
>>
>> Gabriel Assumpção Campolina |