Example #1
0
 def set_market_data(self, market_data):
     self.today = misc.datetime2xl(datetime.datetime.strptime(market_data['MarketDate'], '%Y-%m-%d'))
     misc.Date.set_origin(*[int(s) for s in market_data['MarketDate'].split('-')][::-1])
     super(FXOptionPricer, self).set_market_data(market_data)
     fwd_quotes = market_data["FXFwd_" + self.ccypair]
     fwdtenors = [misc.datetime2xl(datetime.datetime.strptime(knot[2], '%Y-%m-%d')) for knot in fwd_quotes]
     spot_date = misc.Date(str(market_data['MarketDate']))
     fwds = [knot[1] for knot in fwd_quotes]
     self.fx_spot = fwds[0]
     fwdcurve = curve.ForwardCurve.from_array(fwdtenors, fwds)
     self.fx_fwd = fwdcurve(self.expiry)
     vol_field = "FXVOL_" + self.ccypair
     calendar = misc.Calendar.US
     voltenors = [ float(calendar.advance(spot_date, misc.Period(str(knot[0]))) - spot_date) for knot in market_data[vol_field]['ATM']]
     volmark = {}
     volmark['tenor'] = voltenors
     for field in ['ATM', 'RRd25', 'RRd10', 'BFd25', 'BFd10']:
         volmark[field] = [market_data[vol_field][field][i][1] for i in range(len(voltenors))]
     tom = self.expiry - self.today
     volpts = {}
     for field in ['ATM', 'RRd25', 'RRd10', 'BFd25', 'BFd10']:
         if field == 'ATM':
             mode = curve.VolCurve.InterpMode.LinearTime
         else:
             mode = curve.VolCurve.InterpMode.SqrtTime
         vcurve = curve.VolCurve.from_array( volmark['tenor'], volmark[field], interp_mode = mode )
         volpts[field] = vcurve(tom)
     self.atm = volpts['ATM']
     self.v10 = volpts['BFd10'] + volpts['RRd10']/2.0    
     self.v90 = volpts['BFd10'] - volpts['RRd10']/2.0 
     self.v25 = volpts['BFd25'] + volpts['RRd25']/2.0
     self.v75 = volpts['BFd25'] - volpts['RRd25']/2.0
     self.volnode = pyktlib.Delta5VolNode(self.today, self.expiry, self.fx_fwd, self.atm, self.v90, self.v75, self.v25, self.v10, "act365")
Example #2
0
def calibrate_ycurve(market_data, field='IRYCurve_usd3m'):
    today = Date(str(market_data['MarketDate']), "YYYY-MM-DD")
    Settings.instance().evaluationDate = today
    quotes = market_data[field]
    calib_helpers = []
    calendar = misc.Calendar.US_UK
    dayroll = misc.DayRoll.ModifiedFollowing
    daycount = misc.DayCount.ACT360
    for quote in quotes:
        inst_name, inst_tenor = quote[0].split('_')
        if inst_name == "CD":
            ratehelper = DepositRateHelper(QuoteHandle(SimpleQuote(float(quote[1]))), \
                                    misc.Period(str(inst_tenor)), 2,
                                    calendar, dayroll, False, daycount)
        elif inst_name == "IRF":
            ratehelper = FuturesRateHelper(
                QuoteHandle(SimpleQuote(100 - float(quote[1]) * 100)),
                misc.Date(str(inst_tenor)), 3, calendar, dayroll, True,
                daycount, QuoteHandle(SimpleQuote(0.0)))
        elif inst_name == "IRS":
            ratehelper = SwapRateHelper(
                QuoteHandle(SimpleQuote(float(quote[1]))),
                misc.Period(str(inst_tenor)), calendar, Semiannual,
                misc.DayRoll.Unadjusted, misc.DayCount._30360US,
                USDLibor(Period(3, Months)))
        else:
            raise NameError('The instrument name %s is not supported' %
                            inst_name)
        calib_helpers.append(ratehelper)
    #libor_fac = rate_index.LiborIndexFactory('3M', calendar, daycount)
    spotdate = today
    yield_curve = PiecewiseFlatForward(spotdate, calib_helpers, daycount)
    return yield_curve
Example #3
0
def str2tenor(input):
    if input == None:
        return None
    if '-' in input:
        tenor = misc.Date(str(input))
    else:
        tenor = misc.Period(str(input))
    return tenor
Example #4
0
 def gen_market_data(self, market_data, scen):
     if hasattr(scen[0], '__iter__'):
         crv_type = scen[0][0].split('_')[0]
     else:
         crv_type = scen[0].split('_')[0]
     md = copy.deepcopy(market_data)
     if crv_type == "MarketDate":
         md[scen[0]] = str(misc.Date(str(md[scen[0]])) + scen[1])
     else:
         if hasattr(scen[0], '__iter__'):
             data = md[scen[0][0]]
             for i in range(1, len(scen[0])):
                 data = data[scen[0][i]]
         else:
             data = md[scen[0]]
         if crv_type == 'FXFwd':
             for knot in data:
                 knot[1] = knot[1] * (1 + scen[1])
         else:
             for knot in data:
                 knot[1] = knot[1] + scen[1]
     return md
Example #5
0
 def set_market_data(self, market_data):
     self.market_data = copy.copy(market_data)
     self.value_date = misc.Date(str(market_data['MarketDate']))