本文整理汇总了Python中quantlib.time.calendar.TARGET.advance方法的典型用法代码示例。如果您正苦于以下问题:Python TARGET.advance方法的具体用法?Python TARGET.advance怎么用?Python TARGET.advance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quantlib.time.calendar.TARGET
的用法示例。
在下文中一共展示了TARGET.advance方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_excel_example_with_fixed_rate_bond
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [as 别名]
def test_excel_example_with_fixed_rate_bond(self):
"""Port the QuantLib Excel adding bond example to Python. """
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_days = 3
face_amount = 100.0
coupon_rate = 0.05
redemption = 100.0
fixed_bond_schedule = Schedule(
effective_date, termination_date, Period(Annual), calendar, ModifiedFollowing, ModifiedFollowing, Backward
)
issue_date = effective_date
bond = FixedRateBond(
settlement_days,
face_amount,
fixed_bond_schedule,
[coupon_rate],
ActualActual(ISMA),
Following,
redemption,
issue_date,
)
discounting_term_structure = YieldTermStructure(relinkable=True)
flat_term_structure = FlatForward(
settlement_days=1,
forward=0.044,
calendar=NullCalendar(),
daycounter=Actual365Fixed(),
compounding=Continuous,
frequency=Annual,
)
discounting_term_structure.link_to(flat_term_structure)
engine = DiscountingBondEngine(discounting_term_structure)
bond.set_pricing_engine(engine)
self.assertEquals(Date(10, Jul, 2016), termination_date)
self.assertEquals(calendar.advance(todays_date, 3, Days), bond.settlement_date())
self.assertEquals(Date(11, Jul, 2016), bond.maturity_date)
self.assertAlmostEqual(0.6849, bond.accrued_amount(bond.settlement_date()), 4)
self.assertAlmostEqual(102.1154, bond.clean_price, 4)
示例2: test_excel_example_with_zero_coupon_bond
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [as 别名]
def test_excel_example_with_zero_coupon_bond(self):
todays_date = Date(25, August, 2011)
settlement_days = 3
face_amount = 100
calendar = TARGET()
maturity_date = Date(26, February, 2024)
bond = ZeroCouponBond(
settlement_days, calendar, face_amount, maturity_date, Following,
100., todays_date
)
discounting_term_structure = YieldTermStructure(relinkable=True)
flat_term_structure = FlatForward(
settlement_days = 1,
forward = 0.044,
calendar = NullCalendar(),
daycounter = Actual365Fixed(),
compounding = Continuous,
frequency = Annual)
discounting_term_structure.link_to(flat_term_structure)
bond.set_pricing_engine(discounting_term_structure)
self.assertEquals(
calendar.advance(todays_date, 3, Days), bond.settlement_date()
)
self.assertEquals(0., bond.accrued_amount(bond.settlement_date()))
self.assertAlmostEquals(57.6915, bond.clean_price, 4)
示例3: FlatForwardTestCase
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [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])
示例4: _cfamounts
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [as 别名]
def _cfamounts(coupon_rate, pricing_date, maturity_date,
period, basis):
"""
cash flow schedule
"""
_period = str_to_frequency(period)
evaluation_date = pydate_to_qldate(pricing_date)
settings = Settings()
settings.evaluation_date = evaluation_date
calendar = TARGET()
termination_date = pydate_to_qldate(maturity_date)
# effective date must be before settlement date, but do not
# care about exact issuance date of bond
effective_date = Date(termination_date.day, termination_date.month,
evaluation_date.year)
effective_date = calendar.advance(
effective_date, -1, Years, convention=Unadjusted)
face_amount = 100.0
redemption = 100.0
fixed_bond_schedule = Schedule(
effective_date,
termination_date,
Period(_period),
calendar,
ModifiedFollowing,
ModifiedFollowing,
Backward
)
issue_date = effective_date
cnt = DayCounter.from_name(basis)
settlement_days = 2
bond = FixedRateBond(
settlement_days,
face_amount,
fixed_bond_schedule,
[coupon_rate],
cnt,
Following,
redemption,
issue_date)
res = zip(*bond.cashflows)
return(res)
示例5: test_pricing_bond
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [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
示例6: test_pricing_bond
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [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))
)
示例7: test_excel_example_with_floating_rate_bond
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [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)
示例8: import
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [as 别名]
from quantlib.time.schedule import Schedule, Backward
from quantlib.settings import Settings
from quantlib.termstructures.yields.api import (
FlatForward, YieldTermStructure
)
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_days = 3
face_amount = 100.0
coupon_rate = 0.05
redemption = 100.0
fixed_bond_schedule = Schedule(
effective_date,
termination_date,
Period(Annual),
calendar,
ModifiedFollowing,
ModifiedFollowing,
示例9: test_bucketanalysis_bond
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [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))
#.........这里部分代码省略.........
示例10: test_display
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [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))
#.........这里部分代码省略.........
示例11: _bndprice
# 需要导入模块: from quantlib.time.calendar import TARGET [as 别名]
# 或者: from quantlib.time.calendar.TARGET import advance [as 别名]
def _bndprice(bond_yield, coupon_rate, pricing_date, maturity_date,
period, basis, compounding_frequency):
"""
Clean price and accrued interest of a bond
"""
_period = str_to_frequency(period)
evaluation_date = pydate_to_qldate(pricing_date)
settings = Settings()
settings.evaluation_date = evaluation_date
calendar = TARGET()
termination_date = pydate_to_qldate(maturity_date)
# effective date must be before settlement date, but do not
# care about exact issuance date of bond
effective_date = Date(termination_date.day, termination_date.month,
evaluation_date.year)
effective_date = calendar.advance(
effective_date, -1, Years, convention=Unadjusted)
settlement_date = calendar.advance(
evaluation_date, 2, Days, convention=ModifiedFollowing)
face_amount = 100.0
redemption = 100.0
fixed_bond_schedule = Schedule(
effective_date,
termination_date,
Period(_period),
calendar,
ModifiedFollowing,
ModifiedFollowing,
Backward
)
issue_date = effective_date
cnt = DayCounter.from_name(basis)
settlement_days = 2
bond = FixedRateBond(
settlement_days,
face_amount,
fixed_bond_schedule,
[coupon_rate],
cnt,
Following,
redemption,
issue_date
)
discounting_term_structure = YieldTermStructure(relinkable=True)
cnt_yield = DayCounter.from_name('Actual/Actual (Historical)')
flat_term_structure = FlatForward(
settlement_days=2,
forward=bond_yield,
calendar=NullCalendar(),
daycounter=cnt_yield,
compounding=Compounded,
frequency=_period)
discounting_term_structure.link_to(flat_term_structure)
engine = DiscountingBondEngine(discounting_term_structure)
bond.set_pricing_engine(engine)
price = bond.clean_price
ac = bond.accrued_amount(pydate_to_qldate(settlement_date))
return (price, ac)