How to use the quantlib.settings.Settings function in QuantLib

To help you get started, we’ve selected a few QuantLib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / pyql / examples / scripts / stovol_calibration.py View on Github external
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
github enthought / pyql / quantlib / market / market.py View on Github external
def _set_evaluation_date(self, dt_obs):

        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
        self._eval_date = eval_date
        return eval_date
github enthought / pyql / quantlib / util / rates.py View on Github external
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)
github enthought / pyql / quantlib / mlab / fixed_income.py View on Github external
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
github enthought / pyql / examples / option_valuation.py View on Github external
def dividendOption():
    # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    # ++++++++++++++++++++ General Parameter for all the computation +++++++++++++++++++++++
    # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    # declaration of the today's date (date where the records are done)
    todaysDate = Date(24 , Jan ,2012)	# INPUT
    Settings.instance().evaluation_date = todaysDate #!\ IMPORTANT COMMAND REQUIRED FOR ALL VALUATIONS
    calendar = UnitedStates() # INPUT
    settlement_days	= 2	# INPUT
    # Calcul of the settlement date : need to add a period of 2 days to the todays date
    settlementDate =  calendar.advance(
        todaysDate, period=Period(settlement_days, Days)
    )
    dayCounter = Actual360() # INPUT
    currency = USDCurrency() # INPUT	

    print("Date of the evaluation:			", todaysDate)
    print("Calendar used:         			", calendar.name)
    print("Number of settlement Days:		", settlement_days)
    print("Date of settlement:       		", settlementDate)
    print("Convention of day counter:		", dayCounter.name)
    print("Currency of the actual context:\t\t", currency.name)
github enthought / pyql / examples / calibrate_heston.py View on Github external
def heston_helpers(df_option, dtTrade=None, df_rates=None, ival=None):
    """
    Create array of heston options helpers
    """

    if dtTrade is None:
        dtTrade = df_option['dtTrade'][0]
    DtSettlement = pydate_to_qldate(dtTrade)

    settings = Settings()
    settings.evaluation_date = DtSettlement

    calendar = TARGET()

    if df_rates is None:
        df_tmp = DataFrame.filter(df_option, items=['dtExpiry', 'IR', 'IDIV'])
        grouped = df_tmp.groupby('dtExpiry')
        df_rates = grouped.agg(lambda x: x[0])

    # convert data frame (date/value) into zero curve
    # expect the index to be a date, and 1 column of values

    risk_free_ts = df_to_zero_curve(df_rates['R'], dtTrade)
    dividend_ts = df_to_zero_curve(df_rates['D'], dtTrade)

    # back out the spot from any forward
github enthought / pyql / quantlib / mlab / term_structure.py View on Github external
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),
github enthought / pyql / examples / scripts / LiborRiskFactors.py View on Github external
def get_term_structure(df_libor, dtObs):
    
    settings = Settings()

    # libor as fixed in London, but cash-flows are determined according to
    # US calendar, hence the need to combine both holidays lists
    calendar = JointCalendar(UnitedStates(), UnitedKingdom())
    
    # must be a business day
    eval_date = calendar.adjust(dateToDate(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);

    depositData =[[1, Months, 'Libor1M'],
                  [3, Months, 'Libor3M'],