def clean_price(self): ws = 1.0 if (self.otype[0].upper() == 'C') else -1.0 n = len(self.fixing_dates) m = len(self.past_fix) if n == m: return max((self.past_avg - self.strike) * ws, 0.0) strike = (self.strike * n - self.past_avg * m) / float(n - m) if strike < 0: return max( (self.past_avg * m + self.fwd_avg * (n - m)) / float(n) - self.strike, 0) if ws > 0 else 0.0 volnode = cmq_volgrid.Delta5VolNode( self.value_date, \ self.volmark['expiry'], \ self.fwd_avg, \ self.volmark['COMVolATM'], \ self.volmark['COMVolV90'], \ self.volmark['COMVolV75'], \ self.volmark['COMVolV25'], \ self.volmark['COMVolV10'], \ "act365") ivol = volnode.GetVolByStrike(strike, self.end) cal_str = cmq_crv_defn.COM_Curve_Map[ self.fwd_index]['calendar'] + '_Holidays' hols = getattr(misc, cal_str) tau = misc.conv_expiry_date(self.value_date + datetime.timedelta(days = int(self.eod_flag)), \ self.start - datetime.timedelta(days=1), \ self.accrual, hols) t_exp = misc.conv_expiry_date(self.value_date + datetime.timedelta(days = int(self.eod_flag)), \ self.end, self.accrual, hols) vol_adj = bsopt.asian_vol_adj(ivol, t_exp, tau) pr = bsopt.BSFwd((ws > 0), self.fwd_avg, strike, vol_adj, t_exp, 0) * self.df * float(n - m) / float(n) return pr
def calc_port_values(fwd_path, fwds, vols, exp_dates, start_date=0, end_date = 365.0, \ opt_strikes = [63.5, 45.0], a = 1, b = 0, ir = 0.02, accr = 365.0): num_steps, num_paths, num_fwds = fwd_path.shape opt_values = [] num_opt = len(opt_strikes) for i in range(num_opt): opt_values.append(np.zeros(fwd_path.shape)) for step in range(num_steps): curr_date = start_date + (end_date - start_date) / num_steps * step for path in range(num_paths): for idx, (f, v, dexp) in enumerate(zip(fwds, vols, exp_dates)): for idy, s in enumerate(opt_strikes): uv = v if idy == 0: IsCall = True else: IsCall = False uv += 0.032 if dexp <= curr_date: opt_values[idy][step, path, idx] = 0.0 else: opt_values[idy][step, path, idx] = bsopt.BSFwd( IsCall, fwd_path[step, path, idx], s, uv, (dexp - curr_date) / accr, ir) return opt_values
def clean_price(self): ws = 1.0 if (self.otype[0].upper() == 'C') else -1.0 self.volnode = cmq_volgrid.Delta5VolNode(self.value_date, \ self.end, \ self.fx_fwd, \ self.volmark['FXVolATM'], \ self.volmark['FXVolV90'], \ self.volmark['FXVolV75'], \ self.volmark['FXVolV25'], \ self.volmark['FXVolV10'], \ self.accrual) self.ivol = self.volnode.GetVolByStrike(self.strike, self.end) t_exp = misc.conv_expiry_date(self.value_date, self.end, self.accrual, []) pr = bsopt.BSFwd((ws > 0), self.fx_fwd, self.strike, self.ivol, t_exp, 0) / self.fx_fwd * self.df return pr
def clean_price(self): ws = 1.0 if (self.otype[0].upper() == 'C') else -1.0 volnode = cmq_volgrid.SamuelDelta5VolNode(self.value_date, \ self.volmark['expiry'], \ self.fwd_avg, \ self.volmark['COMVolATM'], \ self.volmark['COMVolV90'], \ self.volmark['COMVolV75'], \ self.volmark['COMVolV25'], \ self.volmark['COMVolV10'], \ self.alpha,\ self.beta, \ "act365") ivol = volnode.GetVolByStrike(self.strike, self.end) t_exp = misc.conv_expiry_date(self.value_date, self.end, self.accrual, []) pr = bsopt.BSFwd( (ws > 0), self.fwd_avg, self.strike, ivol, t_exp, 0) * self.df return pr