// Basis-point sensitivity of the cash flows. // The result is the change in NPV due to a uniform 1-basis-point change in the rate paid by the cash flows. The change for each coupon is discounted according // to the given constant interest rate. The result is affected by the choice of the interest-rate compounding and the relative frequency and day counter. public static double bps(List <CashFlow> cashflows, InterestRate irr, Date settlementDate = null) { if (settlementDate == null) { settlementDate = Settings.evaluationDate(); } var flatRate = new FlatForward(settlementDate, irr.rate(), irr.dayCounter(), irr.compounding(), irr.frequency()); return(bps(cashflows, flatRate, settlementDate, settlementDate)); }
//! Basis-point sensitivity of the cash flows. // The result is the change in NPV due to a uniform // 1-basis-point change in the rate paid by the cash // flows. The change for each coupon is discounted according // to the given constant interest rate. The result is // affected by the choice of the interest-rate compounding // and the relative frequency and day counter. public static double bps(Leg leg, InterestRate yield, bool includeSettlementDateFlows, Date settlementDate = null, Date npvDate = null) { if (leg.empty()) { return(0.0); } if (settlementDate == null) { settlementDate = Settings.evaluationDate(); } if (npvDate == null) { npvDate = settlementDate; } FlatForward flatRate = new FlatForward(settlementDate, yield.rate(), yield.dayCounter(), yield.compounding(), yield.frequency()); return(bps(leg, flatRate, includeSettlementDateFlows, settlementDate, npvDate)); }
//! Basis-point sensitivity of the cash flows. // The result is the change in NPV due to a uniform // 1-basis-point change in the rate paid by the cash // flows. The change for each coupon is discounted according // to the given constant interest rate. The result is // affected by the choice of the interest-rate compounding // and the relative frequency and day counter. public static double bps(Leg leg, InterestRate yield, bool includeSettlementDateFlows, Date settlementDate = null, Date npvDate = null) { if (leg.empty()) return 0.0; if (settlementDate == null) settlementDate = Settings.evaluationDate(); if (npvDate == null) npvDate = settlementDate; FlatForward flatRate = new FlatForward(settlementDate, yield.rate(), yield.dayCounter(), yield.compounding(), yield.frequency()); return bps(leg, flatRate, includeSettlementDateFlows, settlementDate, npvDate); }
// setup public CommonVars() { // option variables nominals = new List<double>{1000000}; frequency = Frequency.Annual; // usual setup calendar = new UnitedKingdom(); convention = BusinessDayConvention.ModifiedFollowing; Date today = new Date(13, Month.August, 2007); evaluationDate = calendar.adjust(today); Settings.setEvaluationDate(evaluationDate); settlementDays = 0; fixingDays = 0; settlement = calendar.advance(today,settlementDays,TimeUnit.Days); dc = new Thirty360(); // yoy index // fixing data Date from = new Date(1, Month.January, 2005); Date to = new Date(13, Month.August, 2007); Schedule rpiSchedule = new MakeSchedule().from(from).to(to) .withConvention(BusinessDayConvention.ModifiedFollowing) .withCalendar(new UnitedKingdom()) .withTenor(new Period(1,TimeUnit.Months)).value(); double[] fixData = { 189.9, 189.9, 189.6, 190.5, 191.6, 192.0, 192.2, 192.2, 192.6, 193.1, 193.3, 193.6, 194.1, 193.4, 194.2, 195.0, 196.5, 197.7, 198.5, 198.5, 199.2, 200.1, 200.4, 201.1, 202.7, 201.6, 203.1, 204.4, 205.4, 206.2, 207.3, -999.0, -999 }; // link from yoy index to yoy TS bool interp = false; iir = new YYUKRPIr(interp, hy); for (int i=0; i<rpiSchedule.Count;i++) { iir.addFixing(rpiSchedule[i], fixData[i]); } YieldTermStructure nominalFF = new FlatForward(evaluationDate, 0.05, new ActualActual()); nominalTS.linkTo(nominalFF); // now build the YoY inflation curve Period observationLag = new Period(2,TimeUnit.Months); Datum[] yyData = { new Datum( new Date(13, Month.August, 2008), 2.95 ), new Datum( new Date(13, Month.August, 2009), 2.95 ), new Datum( new Date(13, Month.August, 2010), 2.93 ), new Datum( new Date(15, Month.August, 2011), 2.955 ), new Datum( new Date(13, Month.August, 2012), 2.945 ), new Datum( new Date(13, Month.August, 2013), 2.985 ), new Datum( new Date(13, Month.August, 2014), 3.01 ), new Datum( new Date(13, Month.August, 2015), 3.035 ), new Datum( new Date(13, Month.August, 2016), 3.055 ), // note that new Datum( new Date(13, Month.August, 2017), 3.075 ), // some dates will be on new Datum( new Date(13, Month.August, 2019), 3.105 ), // holidays but the payment new Datum( new Date(15, Month.August, 2022), 3.135 ), // calendar will roll them new Datum( new Date(13, Month.August, 2027), 3.155 ), new Datum( new Date(13, Month.August, 2032), 3.145 ), new Datum( new Date(13, Month.August, 2037), 3.145 ) }; // now build the helpers ... List<BootstrapHelper<YoYInflationTermStructure>> helpers = makeHelpers(yyData, yyData.Length, iir, observationLag, calendar, convention, dc); double baseYYRate = yyData[0].rate/100.0; PiecewiseYoYInflationCurve<Linear> pYYTS = new PiecewiseYoYInflationCurve<Linear>( evaluationDate, calendar, dc, observationLag, iir.frequency(),iir.interpolated(), baseYYRate, new Handle<YieldTermStructure>(nominalTS), helpers); pYYTS.recalculate(); yoyTS = pYYTS as YoYInflationTermStructure; // make sure that the index has the latest yoy term structure hy.linkTo(pYYTS); }
// Basis-point sensitivity of the cash flows. // The result is the change in NPV due to a uniform 1-basis-point change in the rate paid by the cash flows. The change for each coupon is discounted according // to the given constant interest rate. The result is affected by the choice of the interest-rate compounding and the relative frequency and day counter. public static double bps(List<CashFlow> cashflows, InterestRate irr, Date settlementDate = null) { if (settlementDate == null) settlementDate = Settings.evaluationDate(); var flatRate = new FlatForward(settlementDate, irr.rate(), irr.dayCounter(), irr.compounding(), irr.frequency()); return bps(cashflows, flatRate, settlementDate, settlementDate); }
public override void calculate(DateTime calcDate, FP_Parameter fp_parameter) { // master data load this.indexOptionDAO_.SelectOwn(); // market data load // index data clsHDAT_MARKETDATA_TB clstb = new clsHDAT_MARKETDATA_TB(); string calcDateStr = calcDate.ToString("yyyyMMdd"); QLNet.Settings.setEvaluationDate(calcDate); clstb.REF_DT = calcDateStr; clstb.INDEX_CD = this.indexOptionDAO_.UNDERLYING_INDEX_CD; int checkNum = clstb.SelectOwn(); if (checkNum == 0) { throw new Exception("market data does not exist : " + calcDateStr + " " + clstb.INDEX_CD); } double indexData = clstb.LAST; // curveData -------------------------------------------------- string curve_cd = "IRSKRW"; YieldCurve curveManager = new YieldCurve(); curveManager.loadCurveData(calcDate,curve_cd,clsHDAT_CURVEDATA_TB.RATE_TYP_Type.YTM); QLNet.YieldTermStructure yield_ts = curveManager.yieldCurve(); // calculate string maturityDateStr = this.indexOptionDAO_.MATURITY_DT; System.Globalization.CultureInfo us = new System.Globalization.CultureInfo("en-US"); DateTime maturityDate = DateTime.ParseExact(maturityDateStr, "yyyyMMdd", us); DayCounter dc = new Actual365Fixed(); Calendar cal = new NullCalendar(); double vol = 0.3; double strike = this.indexOptionDAO_.STRIKE; PlainVanillaPayoff strikePayoff = new PlainVanillaPayoff(Option.Type. Call, strike); Exercise exercise = new EuropeanExercise(maturityDate); VanillaOption q_option = new VanillaOption(strikePayoff,exercise); Handle<Quote> x0 = new Handle<Quote>(new SimpleQuote(indexData)); FlatForward flatForward = new FlatForward(calcDate,0.01,dc); Handle<YieldTermStructure> dividendTS = new Handle<YieldTermStructure>(flatForward); Handle<YieldTermStructure> riskFreeTS = new Handle<YieldTermStructure>(yield_ts); BlackConstantVol blackConstVol = new BlackConstantVol(calcDate,cal,vol,dc); Handle<BlackVolTermStructure> blackVolTS = new Handle<BlackVolTermStructure>(blackConstVol); GeneralizedBlackScholesProcess process =new GeneralizedBlackScholesProcess(x0 ,dividendTS,riskFreeTS,blackVolTS); AnalyticEuropeanEngine europeanEngine = new AnalyticEuropeanEngine(process); q_option.setPricingEngine(europeanEngine); double value = q_option.NPV(); double indexMultiplier = this.indexOptionDAO_.INDEX_MULTIPLIER; int quantity = this.indexOptionDAO_.QUANTITY; clsHITM_FP_GREEKRESULT_TB result_tb = new clsHITM_FP_GREEKRESULT_TB(); result_tb.FP_GREEKRESULT_ID = IDGenerator.getNewGreekResultID(this.indexOptionDAO_.INSTRUMENT_ID,calcDateStr); result_tb.CALC_DT = calcDateStr; result_tb.INSTRUMENT_ID = this.indexOptionDAO_.INSTRUMENT_ID; result_tb.INSTRUMENT_TYP = this.indexOptionDAO_.INSTRUMENT_TYP; result_tb.UNDERLYING_ID = "KOSPI200"; result_tb.UNDERLYING_VALUE = indexData; //result_tb.SEQ = 1; result_tb.DELTA = (q_option.delta() * indexData / 100) * indexMultiplier * quantity; // 1% Delta result_tb.GAMMA = 0.5 * (q_option.gamma() * indexData / 100) * indexMultiplier * quantity; // 1% Gamma result_tb.VEGA = q_option.vega() / 100 * indexMultiplier * quantity; // 1% point Vega result_tb.CALC_PRICE = value * indexMultiplier * quantity; result_tb.CALCULATED_FLAG = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATED_FLAG_Type.CALCULATED; result_tb.CALCULATED_TIME = DateTime.Now.ToString("HHmmss"); ; result_tb.CALCULATE_TYP = (int)clsHITM_FP_GREEKRESULT_TB.CALCULATE_TYP_Type.ANALYTICS; // price if (result_tb.UpdateDateResult() == 0) { throw new Exception("update result fail. no exist , calcDate : " + calcDate.ToString("yyyyMMdd") + " , inst_id : " + result_tb.INSTRUMENT_ID); } // delta // gamma and others : no exist ? }