本文整理汇总了Python中quantlib.settings.Settings类的典型用法代码示例。如果您正苦于以下问题:Python Settings类的具体用法?Python Settings怎么用?Python Settings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Settings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extrapolation
def test_extrapolation(self):
rate_helpers = build_helpers()
settings = Settings()
calendar = TARGET()
# must be a business Days
dtObs = date(2007, 4, 27)
eval_date = calendar.adjust(pydate_to_qldate(dtObs))
settings.evaluation_date = eval_date
settlement_days = 2
settlement_date = calendar.advance(eval_date, settlement_days, Days)
# must be a business day
settlement_date = calendar.adjust(settlement_date)
print('dt Obs: %s\ndt Eval: %s\ndt Settle: %s' %
(dtObs, eval_date, settlement_date))
ts_day_counter = ActualActual(ISDA)
tolerance = 1.0e-2
ts = PiecewiseYieldCurve('discount',
'loglinear',
settlement_date,
rate_helpers,
ts_day_counter,
tolerance)
# max_date raises an exception without extrapolaiton...
self.assertFalse(ts.extrapolation)
with self.assertRaisesRegexp(RuntimeError,
"1st iteration: failed at 2nd alive instrument"):
dtMax = ts.max_date
示例2: setUp
def setUp(self):
settlement_date = today()
settings = Settings()
settings.evaluation_date = settlement_date
daycounter = ActualActual()
self.calendar = NullCalendar()
i_rate = .1
i_div = .04
self.risk_free_ts = flat_rate(i_rate, daycounter)
self.dividend_ts = flat_rate(i_div, daycounter)
self.s0 = SimpleQuote(32.0)
# Bates model
self.v0 = 0.05
self.kappa = 5.0
self.theta = 0.05
self.sigma = 1.0e-4
self.rho = 0.0
self.Lambda = .1
self.nu = .01
self.delta = .001
示例3: test_extrapolation
def test_extrapolation(self):
rate_helpers = build_helpers()
settings = Settings()
calendar = TARGET()
# must be a business Days
dtObs = date(2007, 4, 27)
eval_date = calendar.adjust(pydate_to_qldate(dtObs))
settings.evaluation_date = eval_date
settlement_days = 2
settlement_date = calendar.advance(eval_date, settlement_days, Days)
# must be a business day
settlement_date = calendar.adjust(settlement_date)
print('dt Obs: %s\ndt Eval: %s\ndt Settle: %s' %
(dtObs, eval_date, settlement_date))
ts_day_counter = ActualActual(ISDA)
tolerance = 1.0e-2
ts = PiecewiseYieldCurve.from_reference_date(BootstrapTrait.Discount,
Interpolator.LogLinear,
settlement_date,
rate_helpers,
ts_day_counter,
tolerance)
# max_date raises an exception without extrapolaiton...
self.assertFalse(ts.extrapolation)
with self.assertRaises(RuntimeError) as ctx:
ts.discount(ts.max_date + 1)
self.assertTrue(str(ctx.exception) in (
"time (30.011) is past max curve time (30.0082)",
"1st iteration: failed at 2nd alive instrument"))
示例4: test_zero_curve
def test_zero_curve(self):
rate_helpers = build_helpers()
settings = Settings()
calendar = TARGET()
# must be a business Days
dtObs = date(2007, 4, 27)
eval_date = calendar.adjust(pydate_to_qldate(dtObs))
settings.evaluation_date = eval_date
settlement_days = 2
settlement_date = calendar.advance(eval_date, settlement_days, Days)
# must be a business day
settlement_date = calendar.adjust(settlement_date)
ts_day_counter = ActualActual(ISDA)
tolerance = 1.0e-2
ts = PiecewiseYieldCurve('discount',
'loglinear',
settlement_date,
rate_helpers,
ts_day_counter,
tolerance)
# max_date raises an exception...
ts.extrapolation = True
zr = ts.zero_rate(Date(10, 5, 2027), ts_day_counter, 2)
self.assertAlmostEqual(zr.rate, 0.0539332)
示例5: bootstrap_term_structure
def bootstrap_term_structure(self, interpolator=Interpolator.LogLinear):
tolerance = 1.0e-15
settings = Settings()
calendar = JointCalendar(UnitedStates(), UnitedKingdom())
# must be a business day
eval_date = self._eval_date
settings.evaluation_date = eval_date
settlement_days = self._params.settlement_days
settlement_date = calendar.advance(eval_date, settlement_days, Days)
# must be a business day
settlement_date = calendar.adjust(settlement_date)
ts = PiecewiseYieldCurve.from_reference_date(
BootstrapTrait.Discount,
interpolator,
settlement_date,
self._rate_helpers,
DayCounter.from_name(self._termstructure_daycount),
tolerance,
)
self._term_structure = ts
self._discount_term_structure = YieldTermStructure()
self._discount_term_structure.link_to(ts)
self._forecast_term_structure = YieldTermStructure()
self._forecast_term_structure.link_to(ts)
return ts
示例6: test_discount_curve
def test_discount_curve(self):
settings = Settings()
settings.evaluation_date = Date(6, 10, 2016)
# Market information
calendar = TARGET()
quotes = [SimpleQuote(0.0096), SimpleQuote(0.0145), SimpleQuote(0.0194)]
tenors = [3, 6, 12]
deposit_day_counter = Actual365Fixed()
convention = ModifiedFollowing
end_of_month = True
fixing_days = 3
rate_helpers = [DepositRateHelper(
quote, Period(month, Months), fixing_days, calendar, convention, end_of_month,
deposit_day_counter) for quote, month in zip(quotes, tenors)]
ts_day_counter = ActualActual(ISDA)
tolerance = 1.0e-15
ts = PiecewiseYieldCurve(
BootstrapTrait.ForwardRate, Interpolator.BackwardFlat, 2, calendar, rate_helpers,
ts_day_counter, tolerance
)
dates = [rh.latest_date for rh in rate_helpers]
dfs = [ts.discount(d) for d in dates]
dates.insert(0, ts.reference_date)
dfs.insert(0, 1)
ts_discount = DiscountCurve(dates, dfs, ts_day_counter, calendar)
self.assertTrue(ts.discount(0.75), ts_discount.discount(0.75))
示例7: test_bump_yieldcurve
def test_bump_yieldcurve(self):
settings = Settings()
settings.evaluation_date = Date(6, 10, 2016)
# Market information
calendar = TARGET()
quotes = [SimpleQuote(0.0096), SimpleQuote(0.0145), SimpleQuote(0.0194)]
tenors = [3, 6, 12]
deposit_day_counter = Actual365Fixed()
convention = ModifiedFollowing
end_of_month = True
fixing_days = 3
rate_helpers = [DepositRateHelper(
quote, Period(month, Months), fixing_days, calendar, convention, end_of_month,
deposit_day_counter) for quote, month in zip(quotes, tenors)]
ts_day_counter = ActualActual(ISDA)
tolerance = 1.0e-15
ts = PiecewiseYieldCurve(
BootstrapTrait.Discount, Interpolator.LogLinear, 2, calendar, rate_helpers,
ts_day_counter, tolerance
)
old_discount = ts.discount(ts.max_date)
# parallel shift of 1 bps
for rh in rate_helpers:
rh.quote.value += 1e-4
self.assertEqual([q.value for q in quotes], [rh.quote.value for rh in rate_helpers])
new_discount = ts.discount(ts.max_date)
self.assertTrue(new_discount < old_discount)
示例8: test_settings_instance_method
def test_settings_instance_method(self):
Settings.instance().evaluation_date = today()
self.assertEqual(
today(),
Settings.instance().evaluation_date
)
示例9: _set_evaluation_date
def _set_evaluation_date(self, dt_obs):
if(~isinstance(dt_obs, Date)):
dt_obs = pydate_to_qldate(dt_obs)
settings = Settings()
calendar = JointCalendar(UnitedStates(), UnitedKingdom())
# must be a business day
eval_date = calendar.adjust(dt_obs)
settings.evaluation_date = eval_date
self._eval_date = eval_date
return eval_date
示例10: zbt_libor_yield
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)
示例11: test_excel_example_with_fixed_rate_bond
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)
示例12: _cfamounts
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)
示例13: test_creation
def test_creation(self):
settings = Settings()
# Market information
calendar = TARGET()
# must be a business day
settings.evaluation_date = calendar.adjust(today())
settlement_date = Date(18, September, 2008)
# must be a business day
settlement_date = calendar.adjust(settlement_date);
quotes = [SimpleQuote(0.0096), SimpleQuote(0.0145), SimpleQuote(0.0194)]
tenors = [3, 6, 12]
rate_helpers = []
calendar = TARGET()
deposit_day_counter = Actual365Fixed()
convention = ModifiedFollowing
end_of_month = True
for quote, month in zip(quotes, tenors):
tenor = Period(month, Months)
fixing_days = 3
helper = DepositRateHelper(
quote, tenor, fixing_days, calendar, convention, end_of_month,
deposit_day_counter
)
rate_helpers.append(helper)
ts_day_counter = ActualActual(ISDA)
tolerance = 1.0e-15
ts = PiecewiseYieldCurve.from_reference_date(
BootstrapTrait.Discount, Interpolator.LogLinear, settlement_date, rate_helpers,
ts_day_counter, tolerance
)
self.assertIsNotNone(ts)
self.assertEqual( Date(18, September, 2008), ts.reference_date)
# this is not a real test ...
self.assertAlmostEqual(0.9975, ts.discount(Date(21, 12, 2008)), 4)
self.assertAlmostEqual(0.9944, ts.discount(Date(21, 4, 2009)), 4)
self.assertAlmostEqual(0.9904, ts.discount(Date(21, 9, 2009)), 4)
示例14: test_creation
def test_creation(self):
settings = Settings()
# Market information
calendar = TARGET()
# must be a business day
settings.evaluation_date = calendar.adjust(today())
settlement_date = Date(18, September, 2008)
# must be a business day
settlement_date = calendar.adjust(settlement_date);
quotes = [0.0096, 0.0145, 0.0194]
tenors = [3, 6, 12]
rate_helpers = []
calendar = TARGET()
deposit_day_counter = Actual365Fixed()
convention = ModifiedFollowing
end_of_month = True
for quote, month in zip(quotes, tenors):
tenor = Period(month, Months)
fixing_days = 3
helper = DepositRateHelper(
quote, tenor, fixing_days, calendar, convention, end_of_month,
deposit_day_counter
)
rate_helpers.append(helper)
ts_day_counter = ActualActual(ISDA)
tolerance = 1.0e-15
ts = term_structure_factory(
'discount', 'loglinear', settlement_date, rate_helpers,
ts_day_counter, tolerance
)
self.assertIsNotNone(ts)
self.assertEquals( Date(18, September, 2008), ts.reference_date)
# this is not a real test ...
self.assertAlmostEquals(0.9975, ts.discount(Date(21, 12, 2008)), 4)
self.assertAlmostEquals(0.9944, ts.discount(Date(21, 4, 2009)), 4)
self.assertAlmostEquals(0.9904, ts.discount(Date(21, 9, 2009)), 4)
示例15: test_using_settings
def test_using_settings(self):
settings = Settings()
evaluation_date = today()
# have to set the evaluation date before the test as it is a global
# attribute for the whole library ... meaning that previous test_cases
# might have set this to another date
settings.evaluation_date = evaluation_date
self.assertEqual(settings.evaluation_date, evaluation_date)
self.assertTrue(settings.version.startswith('1'))