本文整理匯總了Python中quantlib.time.calendar.TARGET.adjust方法的典型用法代碼示例。如果您正苦於以下問題:Python TARGET.adjust方法的具體用法?Python TARGET.adjust怎麽用?Python TARGET.adjust使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類quantlib.time.calendar.TARGET
的用法示例。
在下文中一共展示了TARGET.adjust方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FlatForwardTestCase
# 需要導入模塊: from quantlib.time.calendar import TARGET [as 別名]
# 或者: from quantlib.time.calendar.TARGET import adjust [as 別名]
class FlatForwardTestCase(unittest.TestCase):
def setUp(self):
self.calendar = TARGET()
self.settlement_days = 2
self.adjusted_today = self.calendar.adjust(today())
Settings().evaluation_date = self.adjusted_today
self.settlement_date = self.calendar.advance(today(), self.settlement_days, Days)
def test_reference_evaluation_data_changed(self):
"""Testing term structure against evaluation date change... """
quote = SimpleQuote()
term_structure = FlatForward(
settlement_days=self.settlement_days, forward=quote, calendar=NullCalendar(), daycounter=Actual360()
)
quote.value = 0.03
expected = []
for days in [10, 30, 60, 120, 360, 720]:
expected.append(term_structure.discount(self.adjusted_today + days))
Settings().evaluation_date = self.adjusted_today + 30
calculated = []
for days in [10, 30, 60, 120, 360, 720]:
calculated.append(term_structure.discount(self.adjusted_today + 30 + days))
for i, val in enumerate(expected):
self.assertAlmostEquals(val, calculated[i])
示例2: zbt_libor_yield
# 需要導入模塊: from quantlib.time.calendar import TARGET [as 別名]
# 或者: from quantlib.time.calendar.TARGET import adjust [as 別名]
def zbt_libor_yield(instruments, yields, pricing_date,
basis='Actual/Actual (Bond)',
compounding_freq='Continuous',
maturity_dates=None):
"""
Bootstrap a zero-coupon curve from libor rates and swap yields
Args:
insruments: list of instruments, of the form Libor?M for Libor rates
and Swap?Y for swap rates
yields: market rates
pricing_date: the date where market data is observed. Settlement
is by default 2 days after pricing_date
Optional:
compounding_frequency: ... of zero-coupon rates. By default:
'Continuous'
Returns:
zero_rate: zero-coupon rate
maturity_date: ... of corresponding rate
"""
calendar = TARGET()
settings = Settings()
# must be a business day
eval_date = calendar.adjust(pydate_to_qldate(pricing_date))
settings.evaluation_date = eval_date
rates = dict(zip(instruments, yields))
ts = make_term_structure(rates, pricing_date)
cnt = DayCounter.from_name(basis)
if maturity_dates is None:
# schedule of maturity dates from settlement date to last date on
# the term structure
s = Schedule(effective_date=ts.reference_date,
termination_date=ts.max_date,
tenor=Period(1, Months),
calendar=TARGET())
maturity_dates = [qldate_to_pydate(dt) for dt in s.dates()]
cp_freq = compounding_from_name(compounding_freq)
zc = [ts.zero_rate(date=pydate_to_qldate(dt),
day_counter=cnt,
compounding=cp_freq).rate for dt in maturity_dates]
return (maturity_dates, zc)
示例3: test_pricing_bond
# 需要導入模塊: from quantlib.time.calendar import TARGET [as 別名]
# 或者: from quantlib.time.calendar.TARGET import adjust [as 別名]
def test_pricing_bond():
'''Inspired by the C++ code from http://quantcorner.wordpress.com/.'''
settings = Settings()
# Date setup
calendar = TARGET()
# Settlement date
settlement_date = calendar.adjust(Date(28, January, 2011))
# Evaluation date
fixing_days = 1
settlement_days = 1
todays_date = calendar.advance(
settlement_date, -fixing_days, Days
)
settings.evaluation_date = todays_date
# Bound attributes
face_amount = 100.0
redemption = 100.0
issue_date = Date(27, January, 2011)
maturity_date = Date(31, August, 2020)
coupon_rate = 0.03625
bond_yield = 0.034921
discounting_term_structure = YieldTermStructure(relinkable=True)
flat_term_structure = FlatForward(
reference_date = settlement_date,
forward = bond_yield,
daycounter = Actual365Fixed(), #actual_actual.ActualActual(actual_actual.Bond),
compounding = Compounded,
frequency = Semiannual)
# have a look at the FixedRateBondHelper to simplify this
# construction
discounting_term_structure.link_to(flat_term_structure)
#Rate
fixed_bond_schedule = Schedule(
issue_date,
maturity_date,
Period(Semiannual),
UnitedStates(market=GOVERNMENTBOND),
Unadjusted,
Unadjusted,
Backward,
False);
bond = FixedRateBond(
settlement_days,
face_amount,
fixed_bond_schedule,
[coupon_rate],
ActualActual(Bond),
Unadjusted,
redemption,
issue_date
)
bond.set_pricing_engine(discounting_term_structure)
return bond
示例4: test_pricing_bond
# 需要導入模塊: from quantlib.time.calendar import TARGET [as 別名]
# 或者: from quantlib.time.calendar.TARGET import adjust [as 別名]
def test_pricing_bond(self):
'''Inspired by the C++ code from http://quantcorner.wordpress.com/.'''
settings = Settings()
# Date setup
calendar = TARGET()
# Settlement date
settlement_date = calendar.adjust(Date(28, January, 2011))
# Evaluation date
fixing_days = 1
settlement_days = 1
todays_date = calendar.advance(
settlement_date, -fixing_days, Days
)
settings.evaluation_date = todays_date
# Bound attributes
face_amount = 100.0
redemption = 100.0
issue_date = Date(27, January, 2011)
maturity_date = Date(31, August, 2020)
coupon_rate = 0.03625
bond_yield = 0.034921
discounting_term_structure = YieldTermStructure(relinkable=True)
flat_term_structure = FlatForward(
reference_date = settlement_date,
forward = bond_yield,
daycounter = Actual365Fixed(), #actual_actual.ActualActual(actual_actual.Bond),
compounding = Compounded,
frequency = Semiannual)
# have a look at the FixedRateBondHelper to simplify this
# construction
discounting_term_structure.link_to(flat_term_structure)
#Rate
fixed_bond_schedule = Schedule(
issue_date,
maturity_date,
Period(Semiannual),
UnitedStates(market=GOVERNMENTBOND),
Unadjusted,
Unadjusted,
Backward,
False);
bond = FixedRateBond(
settlement_days,
face_amount,
fixed_bond_schedule,
[coupon_rate],
ActualActual(Bond),
Unadjusted,
redemption,
issue_date
)
bond.set_pricing_engine(discounting_term_structure)
# tests
self.assertTrue(Date(27, January, 2011), bond.issue_date)
self.assertTrue(Date(31, August, 2020), bond.maturity_date)
self.assertTrue(settings.evaluation_date, bond.valuation_date)
# the following assertion fails but must be verified
self.assertAlmostEqual(101.1, bond.clean_price, 1)
self.assertAlmostEqual(101.1, bond.net_present_value, 1)
self.assertAlmostEqual(101.1, bond.dirty_price)
self.assertAlmostEqual(0.009851, bond.accrued_amount())
print settings.evaluation_date
print 'Principal: {}'.format(face_amount)
print 'Issuing date: {} '.format(bond.issue_date)
print 'Maturity: {}'.format(bond.maturity_date)
print 'Coupon rate: {:.4%}'.format(coupon_rate)
print 'Yield: {:.4%}'.format(bond_yield)
print 'Net present value: {:.4f}'.format(bond.net_present_value)
print 'Clean price: {:.4f}'.format(bond.clean_price)
print 'Dirty price: {:.4f}'.format(bond.dirty_price)
print 'Accrued coupon: {:.6f}'.format(bond.accrued_amount())
print 'Accrued coupon: {:.6f}'.format(
bond.accrued_amount(Date(1, March, 2011))
)
示例5: test_excel_example_with_floating_rate_bond
# 需要導入模塊: from quantlib.time.calendar import TARGET [as 別名]
# 或者: from quantlib.time.calendar.TARGET import adjust [as 別名]
def test_excel_example_with_floating_rate_bond(self):
todays_date = Date(25, August, 2011)
settings = Settings()
settings.evaluation_date = todays_date
calendar = TARGET()
effective_date = Date(10, Jul, 2006)
termination_date = calendar.advance(
effective_date, 10, Years, convention=Unadjusted
)
settlement_date = calendar.adjust(Date(28, January, 2011))
settlement_days = 3 #1
face_amount = 13749769.27 #2
coupon_rate = 0.05
redemption = 100.0
float_bond_schedule = Schedule(
effective_date,
termination_date,
Period(Annual),
calendar,
ModifiedFollowing,
ModifiedFollowing,
Backward
)#3
flat_discounting_term_structure = YieldTermStructure(relinkable=True)
forecastTermStructure = YieldTermStructure(relinkable=True)
dc = Actual360()
ibor_index = Euribor6M(forecastTermStructure) #5
fixing_days = 2 #6
gearings = [1,0.0] #7
spreads = [1,0.05] #8
caps = [] #9
floors = [] #10
pmt_conv = ModifiedFollowing #11
issue_date = effective_date
float_bond = FloatingRateBond(settlement_days, face_amount, float_bond_schedule, ibor_index, dc,
fixing_days, gearings, spreads, caps, floors, pmt_conv, redemption, issue_date)
flat_term_structure = FlatForward(
settlement_days = 1,
forward = 0.055,
calendar = NullCalendar(),
daycounter = Actual365Fixed(),
compounding = Continuous,
frequency = Annual)
flat_discounting_term_structure.link_to(flat_term_structure)
forecastTermStructure.link_to(flat_term_structure)
engine = DiscountingBondEngine(flat_discounting_term_structure)
float_bond.set_pricing_engine(engine)
cons_option_vol = ConstantOptionletVolatility(settlement_days, UnitedStates(SETTLEMENT), pmt_conv, 0.95, Actual365Fixed())
coupon_pricer = BlackIborCouponPricer(cons_option_vol)
set_coupon_pricer(float_bond,coupon_pricer)
self.assertEquals(Date(10, Jul, 2016), termination_date)
self.assertEquals(
calendar.advance(todays_date, 3, Days), float_bond.settlement_date()
)
self.assertEquals(Date(11, Jul, 2016), float_bond.maturity_date)
self.assertAlmostEqual(
0.6944, float_bond.accrued_amount(float_bond.settlement_date()), 4
)
self.assertAlmostEqual(98.2485, float_bond.dirty_price, 4)
self.assertAlmostEqual(13500805.2469, float_bond.npv,4)
示例6: test_bucketanalysis_bond
# 需要導入模塊: from quantlib.time.calendar import TARGET [as 別名]
# 或者: from quantlib.time.calendar.TARGET import adjust [as 別名]
def test_bucketanalysis_bond(self):
settings = Settings()
calendar = TARGET()
settlement_date = calendar.adjust(Date(28, January, 2011))
simple_quotes = []
fixing_days = 1
settlement_days = 1
todays_date = calendar.advance(
settlement_date, -fixing_days, Days
)
settings.evaluation_date = todays_date
face_amount = 100.0
redemption = 100.0
issue_date = Date(27, January, 2011)
maturity_date = Date(1, January, 2021)
coupon_rate = 0.055
bond_yield = 0.034921
flat_discounting_term_structure = YieldTermStructure(relinkable=True)
flat_term_structure = FlatForward(
reference_date = settlement_date,
forward = bond_yield,
daycounter = Actual365Fixed(),
compounding = Compounded,
frequency = Semiannual)
flat_discounting_term_structure.link_to(flat_term_structure)
fixed_bond_schedule = Schedule(
issue_date,
maturity_date,
Period(Semiannual),
UnitedStates(market=GOVERNMENTBOND),
Unadjusted,
Unadjusted,
Backward,
False);
bond = FixedRateBond(
settlement_days,
face_amount,
fixed_bond_schedule,
[coupon_rate],
ActualActual(Bond),
Unadjusted,
redemption,
issue_date
)
bfs=bf.BondFunctions()
d=bfs.startDate(bond)
bfs.display()
zspd=bfs.zSpread(bond,100.0,flat_term_structure,Actual365Fixed(),
Compounded,Semiannual,settlement_date,1e-6,100,0.5)
depositData = [[ 1, Months, 4.581 ],
[ 2, Months, 4.573 ],
[ 3, Months, 4.557 ],
[ 6, Months, 4.496 ],
[ 9, Months, 4.490 ]]
swapData = [[ 1, Years, 4.54 ],
[ 5, Years, 4.99 ],
[ 10, Years, 5.47 ],
[ 20, Years, 5.89 ],
[ 30, Years, 5.96 ]]
rate_helpers = []
end_of_month = True
for m, period, rate in depositData:
tenor = Period(m, Months)
sq_rate = SimpleQuote(rate/100)
helper = DepositRateHelper(sq_rate,
tenor,
settlement_days,
calendar,
ModifiedFollowing,
end_of_month,
Actual360())
simple_quotes.append(sq_rate)
rate_helpers.append(helper)
liborIndex = Libor('USD Libor', Period(6, Months), settlement_days,
USDCurrency(), calendar, Actual360(),
YieldTermStructure(relinkable=False))
#.........這裏部分代碼省略.........
示例7: test_display
# 需要導入模塊: from quantlib.time.calendar import TARGET [as 別名]
# 或者: from quantlib.time.calendar.TARGET import adjust [as 別名]
def test_display(self):
settings = Settings()
# Date setup
calendar = TARGET()
# Settlement date
settlement_date = calendar.adjust(Date(28, January, 2011))
# Evaluation date
fixing_days = 1
settlement_days = 1
todays_date = calendar.advance(
settlement_date, -fixing_days, Days
)
settings.evaluation_date = todays_date
# Bound attributes
face_amount = 100.0
redemption = 100.0
issue_date = Date(27, January, 2011)
maturity_date = Date(31, August, 2020)
coupon_rate = 0.03625
bond_yield = 0.034921
flat_discounting_term_structure = YieldTermStructure(relinkable=True)
flat_term_structure = FlatForward(
reference_date = settlement_date,
forward = bond_yield,
daycounter = Actual365Fixed(), #actual_actual.ActualActual(actual_actual.Bond),
compounding = Compounded,
frequency = Semiannual)
# have a look at the FixedRateBondHelper to simplify this
# construction
flat_discounting_term_structure.link_to(flat_term_structure)
#Rate
fixed_bond_schedule = Schedule(
issue_date,
maturity_date,
Period(Semiannual),
UnitedStates(market=GOVERNMENTBOND),
Unadjusted,
Unadjusted,
Backward,
False);
bond = FixedRateBond(
settlement_days,
face_amount,
fixed_bond_schedule,
[coupon_rate],
ActualActual(Bond),
Unadjusted,
redemption,
issue_date
)
d=bf.startDate(bond)
zspd=bf.zSpread(bond, 100.0, flat_term_structure, Actual365Fixed(),
Compounded, Semiannual, settlement_date, 1e-6, 100, 0.5)
#Also need a test case for a PiecewiseTermStructure...
depositData = [[ 1, Months, 4.581 ],
[ 2, Months, 4.573 ],
[ 3, Months, 4.557 ],
[ 6, Months, 4.496 ],
[ 9, Months, 4.490 ]]
swapData = [[ 1, Years, 4.54 ],
[ 5, Years, 4.99 ],
[ 10, Years, 5.47 ],
[ 20, Years, 5.89 ],
[ 30, Years, 5.96 ]]
rate_helpers = []
end_of_month = True
for m, period, rate in depositData:
tenor = Period(m, Months)
helper = DepositRateHelper(SimpleQuote(rate/100), tenor, settlement_days,
calendar, ModifiedFollowing, end_of_month,
Actual360())
rate_helpers.append(helper)
liborIndex = Libor('USD Libor', Period(6, Months), settlement_days,
USDCurrency(), calendar, Actual360(),
YieldTermStructure(relinkable=False))
#.........這裏部分代碼省略.........