本文整理汇总了Python中quantlib.settings.Settings类的典型用法代码示例。如果您正苦于以下问题:Python Settings类的具体用法?Python Settings怎么用?Python Settings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Settings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:ChinaQuants,项目名称:pyql,代码行数:33,代码来源:test_zero_coupon.py
示例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
开发者ID:AlexArgus,项目名称:pyql,代码行数:27,代码来源:test_process.py
示例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"))
开发者ID:enthought,项目名称:pyql,代码行数:35,代码来源:test_zero_coupon.py
示例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)
开发者ID:ChinaQuants,项目名称:pyql,代码行数:30,代码来源:test_zero_coupon.py
示例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
开发者ID:student-t,项目名称:pyql,代码行数:27,代码来源:market.py
示例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))
开发者ID:enthought,项目名称:pyql,代码行数:33,代码来源:test_piecewise_yield_curve.py
示例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)
开发者ID:enthought,项目名称:pyql,代码行数:33,代码来源:test_piecewise_yield_curve.py
示例8: test_settings_instance_method
def test_settings_instance_method(self):
Settings.instance().evaluation_date = today()
self.assertEqual(
today(),
Settings.instance().evaluation_date
)
开发者ID:enthought,项目名称:pyql,代码行数:8,代码来源:test_settings.py
示例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
开发者ID:AlexArgus,项目名称:pyql,代码行数:10,代码来源:market.py
示例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)
开发者ID:AlexArgus,项目名称:pyql,代码行数:54,代码来源:term_structure.py
示例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)
开发者ID:phista,项目名称:pyql,代码行数:54,代码来源:test_bonds.py
示例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)
开发者ID:ChinaQuants,项目名称:pyql,代码行数:54,代码来源:fixed_income.py
示例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)
开发者ID:enthought,项目名称:pyql,代码行数:53,代码来源:test_piecewise_yield_curve.py
示例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)
开发者ID:bondgeek,项目名称:pyql,代码行数:53,代码来源:test_piecewise_yield_curve.py
示例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'))
开发者ID:enthought,项目名称:pyql,代码行数:13,代码来源:test_settings.py
示例16: make_rate_helper
def make_rate_helper(label, rate, dt_obs, currency='USD'):
"""
Wrapper for deposit and swaps rate helpers makers
For Swaps: assume USD swap fixed rates vs. 6M Libor
TODO: make this more general
"""
if(currency.upper() != 'USD'):
raise Exception("Only supported currency is USD.")
rate_type, tenor, period = _parse_rate_label(label)
if not 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
settlement_days = 2
settlement_date = calendar.advance(eval_date, settlement_days, Days)
# must be a business day
settlement_date = calendar.adjust(settlement_date)
end_of_month = True
if((rate_type == 'SWAP') & (period == 'Y')):
liborIndex = Libor(
'USD Libor', Period(6, Months), settlement_days,
USDCurrency(), calendar, Actual360()
)
spread = SimpleQuote(0)
fwdStart = Period(0, Days)
helper = SwapRateHelper.from_tenor(
SimpleQuote(rate),
Period(tenor, Years),
calendar, Annual,
Unadjusted, Thirty360(),
liborIndex, spread, fwdStart)
elif((rate_type == 'LIBOR') & (period == 'M')):
helper = DepositRateHelper(SimpleQuote(rate),
Period(tenor, Months),
settlement_days,
calendar,
ModifiedFollowing,
end_of_month,
Actual360())
else:
raise Exception("Rate type %s not supported" % label)
return (helper)
开发者ID:ChinaQuants,项目名称:pyql,代码行数:51,代码来源:rates.py
示例17: heston_helpers
def heston_helpers(spot, df_option, dtTrade, df_rates):
"""
Create array of heston options helpers
"""
DtSettlement = dateToQLDate(dtTrade)
settings = Settings()
settings.evaluation_date = DtSettlement
calendar = TARGET()
# convert data frame (date/value) into zero curve
# expect the index to be a date, and 1 column of values
risk_free_ts = dfToZeroCurve(df_rates['iRate'], dtTrade)
dividend_ts = dfToZeroCurve(df_rates['iDiv'], dtTrade)
# loop through rows in option data frame, construct
# helpers for bid/ask
oneDay = datetime.timedelta(days=1)
dtExpiry = [dtTrade + int(t*365)*oneDay for t in df_option['TTM']]
df_option['dtExpiry'] = dtExpiry
options = []
for index, row in df_option.T.iteritems():
strike = row['Strike']
if (strike/spot.value > 1.3) | (strike/spot.value < .7):
continue
days = int(365*row['TTM'])
maturity = Period(days, Days)
options.append(
HestonModelHelper(
maturity, calendar, spot.value,
strike, SimpleQuote(row['IVBid']),
risk_free_ts, dividend_ts,
ImpliedVolError))
options.append(
HestonModelHelper(
maturity, calendar, spot.value,
strike, SimpleQuote(row['IVAsk']),
risk_free_ts, dividend_ts,
ImpliedVolError))
return {'options':options, 'spot': spot}
开发者ID:AlexArgus,项目名称:pyql,代码行数:50,代码来源:heston_calibration.py
示例18: test_bond_schedule_anotherday
def test_bond_schedule_anotherday(self):
'''Test date calculations and role of settings when evaluation date
set to arbitrary date.
This test is known to fail with boost 1.42.
'''
todays_date = Date(30, 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.from_rule(
effective_date,
termination_date,
Period(Annual),
calendar,
ModifiedFollowing,
ModifiedFollowing,
Rule.Backward
)
issue_date = effective_date
bond = FixedRateBond(
settlement_days,
face_amount,
fixed_bond_schedule,
[coupon_rate],
ActualActual(ISMA),
Following,
redemption,
issue_date
)
self.assertEqual(
calendar.advance(todays_date, 3, Days), bond.settlement_date())
开发者ID:enthought,项目名称:pyql,代码行数:48,代码来源:test_settings.py
示例19: test_all_types_of_piecewise_curves
def test_all_types_of_piecewise_curves(self):
settings = Settings()
# Market information
calendar = TARGET()
todays_date = Date(12, September, 2008)
# must be a business day
settings.evaluation_date = calendar.adjust(todays_date)
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 = []
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)
tolerance = 1.0e-15
for trait in VALID_TRAITS:
for interpolation in VALID_INTERPOLATORS:
ts = PiecewiseYieldCurve(
trait, interpolation, settlement_date, rate_helpers,
deposit_day_counter, tolerance
)
self.assertIsNotNone(ts)
self.assertEqual( Date(18, September, 2008), ts.reference_date)
开发者ID:ChinaQuants,项目名称:pyql,代码行数:48,代码来源:test_piecewise_yield_curve.py
示例20: test_create_libor_index
def test_create_libor_index(self):
settings = Settings.instance()
# Market information
calendar = UnitedStates(LiborImpact)
# must be a business day
eval_date = calendar.adjust(today())
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)
term_structure = YieldTermStructure(relinkable=True)
term_structure.link_to(FlatForward(settlement_date, 0.05,
Actual365Fixed()))
index = Libor('USDLibor', Period(6, Months), settlement_days,
USDCurrency(), calendar, Actual360(),
term_structure)
default_libor = USDLibor(Period(6, Months))
for attribute in ["business_day_convention", "end_of_month",
"fixing_calendar", "joint_calendar", "tenor",
"fixing_days", "day_counter", "family_name", "name"]:
self.assertEqual(getattr(index, attribute),
getattr(default_libor, attribute))
开发者ID:enthought,项目名称:pyql,代码行数:29,代码来源:test_indexes.py
注:本文中的quantlib.settings.Settings类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论