|
From: Kenji O. <for...@gm...> - 2026-01-04 11:22:30
|
Thank you for your suggestion.
My intention is to evaluate a Japanese inflation-linked bond using the
constructor of ql.CPIBond, which I find very powerful and convenient.
In order to do so, I need to construct a ZeroInflationIndex for Japan.
However, with my current setup, I am unable to successfully create the
Japanese CPI index, as shown below.
I am not questioning the CPI figures themselves; rather, I am trying to
understand the correct way to construct the ZeroInflationIndex in
QuantLib-python for this use case.
I would appreciate it if you could clarify whether my usage of the
ZeroInflationIndex constructor is incorrect, or if there is a known issue
or limitation in the current implementation. Any guidance would be very
helpful.
Kenji
<< my code >>
import QuantLib as ql
print(ql.__version__)
yieldHDL = ql.YieldTermStructureHandle(
ql.FlatForward(
ql.Date(1, ql.January, 2024),
0.02,
ql.Actual365Fixed() ))
jpCPI = ql.ZeroInflationIndex(
"Japan CPI",
ql.Japan(),
False,
ql.Monthly,
ql.Period(3, ql.Months),
ql.JPYCurrency(),
yieldHDL
)
1.40
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_10428\3520687904.py in ?()
7 ql.Date(1, ql.January, 2024),
8 0.02,
9 ql.Actual365Fixed() ))
10
---> 11 jpCPI = ql.ZeroInflationIndex(
12 "Japan CPI",
13 ql.Japan(),
14 False,
e:\local\anaconda3\Lib\site-packages\QuantLib\QuantLib.py in ?(self, *args)
23445 def __init__(self, *args):
23446 r"""__init__(ZeroInflationIndex self, std::string const &
familyName, Region region, bool revised, Frequency frequency, Period
availabilityLag, Currency currency, ZeroInflationTermStructureHandle h={})
-> ZeroInflationIndex"""
> 23447 _QuantLib.ZeroInflationIndex_swiginit(self,
_QuantLib.new_ZeroInflationIndex(*args))
TypeError: Wrong number or type of arguments for overloaded function
'new_ZeroInflationIndex'.
Possible C/C++ prototypes are:
ZeroInflationIndex::ZeroInflationIndex(std::string const &,Region const
&,bool,Frequency,Period const &,Currency const &,Handle<
ZeroInflationTermStructure > const &)
ZeroInflationIndex::ZeroInflationIndex(std::string const &,Region const
&,bool,Frequency,Period const &,Currency const &)
2026年1月4日(日) 10:10 dandalerovivaciously <dan...@gm...>:
> +Qua...@li...
> <Qua...@li...>
>
> On Sun, Jan 4, 2026 at 10:08 AM dandalerovivaciously <
> dan...@gm...> wrote:
>
>> Ogawa san,
>>
>> Why are you creating your own inflation Index, you dont trust the CPI
>> figures published?
>>
>> Try the following:
>>
>> import QuantLib as ql
>>
>> # Create the term structure first (you'll need to provide your inflation
>> data)
>> # For demonstration, I'll create a flat forward curve
>> today = ql.Date(1, ql.January, 2024)
>> ql.Settings.instance().evaluationDate = today
>>
>> # Create a flat forward term structure for CPI
>> rate = 0.02 # 2% inflation
>> observationLag = ql.Period(3, ql.Months)
>> cpiTermStructure = ql.FlatForward(
>> today,
>> rate,
>> ql.ActualActual(),
>> ql.Continuous
>> )
>>
>> # Create the ZeroInflationIndex
>> jpCPI = ql.ZeroInflationIndex(
>> "Japan CPI", # family name
>> ql.Japan(), # region
>> False, # revised
>> ql.Monthly, # frequency
>> observationLag, # availability lag
>> ql.JPYCurrency(), # currency
>> cpiTermStructure # term structure (required parameter)
>> )
>>
>> print(f"Created ZeroInflationIndex: {jpCPI.name()}")
>>
>>
>>
>>
>>
>> or this:
>>
>>
>> import QuantLib as ql
>>
>> # Create CPI fixing data
>> cpi_fixings = {
>> ql.Date(1, 1, 2023): 100.0,
>> ql.Date(1, 2, 2023): 100.2,
>> ql.Date(1, 3, 2023): 100.5,
>> # Add more historical data
>> }
>>
>> # Create term structure with interpolated data
>> today = ql.Date(1, ql.January, 2024)
>> ql.Settings.instance().evaluationDate = today
>>
>> # Create dates and rates for term structure
>> dates = [ql.Date(1, 1, 2023), ql.Date(1, 1, 2025), ql.Date(1, 1, 2030)]
>> rates = [0.02, 0.025, 0.03] # Inflation rates
>>
>> # Create interpolated term structure
>> cpiTermStructure = ql.ZeroInflationCurve(
>> today,
>> dates,
>> rates,
>> ql.ActualActual(),
>> ql.Japan(),
>> ql.Monthly,
>> ql.Period(3, ql.Months),
>> ql.Linear()
>> )
>>
>> # Create the index
>> jpCPI = ql.ZeroInflationIndex(
>> "Japan CPI",
>> ql.Japan(),
>> False,
>> ql.Monthly,
>> ql.Period(3, ql.Months),
>> ql.JPYCurrency(),
>> cpiTermStructure
>> )
>>
>> # Add historical fixings
>> for date, fixing in cpi_fixings.items():
>> jpCPI.addFixing(date, fixing)
>>
>> print(f"ZeroInflationIndex created successfully")
>> print(f"Evaluation date: {today}")
>> print(f"Index has term structure: {jpCPI.zeroInflationTermStructure() is
>> not None}")
>>
>>
>>
>>
>>
>>
>>
>>
|