text: /*! json_risk 29-07-2021 */
  
  !function(e,t){"object"==typeof module&&"undefined"!=typeof exports?module.exports=t():e.JsonRisk=t()}(this,function(){var e={valuation_date:null,require_vd:function(){if(!(e.valuation_date instanceof Date))throw new Error("JsonRisk: valuation_date must be set")}};return e}),function(l){l.callable_fixed_income=function(e){if(!l.get_safe_number_vector(e.fixed_rate))throw new Error("callable_fixed_income: must provide valid fixed_rate.");var t=l.get_safe_date(e.first_exercise_date);if(null===t)throw new Error("callable_fixed_income: must provide first call date");if(this.base=new l.fixed_income(e),t.getTime()<=this.base.schedule[0].getTime())throw new Error("callable_fixed_income: first call date before issue date");if(!this.base.notional_exchange)throw new Error("callable_fixed_income: callable instruments must exchange notionals");var r=l.get_safe_natural(e.call_tenor);this.call_schedule=l.schedule(t,l.get_safe_date(e.maturity),r||0,this.base.adj),this.call_schedule.pop(),this.opportunity_spread=l.get_safe_number(e.opportunity_spread)||0,this.exclude_base=l.get_safe_bool(e.exclude_base),this.simple_calibration=l.get_safe_bool(e.simple_calibration);for(var a,n=this.base.get_cash_flows(),i=n.current_principal.length-1;0===n.current_principal[i];)i--;for(;this.call_schedule[this.call_schedule.length-1]>=n.date_pmt[i];)this.call_schedule.pop();for(this.basket=new Array(this.call_schedule.length),i=0;i<this.call_schedule.length;i++)!this.base.is_amortizing&&1===this.base.fixed_rate.length||this.simple_calibration?this.basket[i]=new l.swaption({is_payer:!1,maturity:e.maturity,first_exercise_date:this.call_schedule[i],notional:e.notional,fixed_rate:this.base.fixed_rate[0]-this.opportunity_spread-this.base.excl_margin,tenor:12,float_spread:0,float_tenor:e.float_tenor||6,float_current_rate:0,calendar:e.calendar,bdc:e.bdc,float_bdc:e.bdc,dcc:e.dcc,float_dcc:e.dcc}):((a=l.create_equivalent_regular_swaption(this.base.get_cash_flows(),this.call_schedule[i],{tenor:12,float_spread:0,float_tenor:e.float_tenor||6,calendar:e.calendar,bdc:e.bdc})).fixed_rate-=this.opportunity_spread,this.basket[i]=new l.swaption(a))},l.callable_fixed_income.prototype.present_value=function(e,t,r,a){var n,i=0;l.require_vd();var s,o=[];for(n=0;n<this.call_schedule.length;n++)1/512<(s=l.time_from_now(this.call_schedule[n]))&&o.push(s);if("object"!=typeof e||null===e)throw new Error("callable_fixed_income.present_value: must provide discount curve");if("object"!=typeof r||null===r)throw new Error("callable_fixed_income.present_value: must provide forward curve for calibration");if("object"!=typeof a||null===a)throw new Error("callable_fixed_income.present_value: must provide valid surface");var _=l.lgm_calibrate(this.basket,e,r,a);return 1===_.length?i=-l.lgm_european_call_on_cf(this.base.get_cash_flows(),o[0],e,_[0],t,this.base.residual_spread,this.opportunity_spread):1<_.length&&(i=-l.lgm_bermudan_call_on_cf(this.base.get_cash_flows(),o,e,_,t,this.base.residual_spread,this.opportunity_spread)),this.exclude_base||(i+=this.base.present_value(e,t,null)),i},l.pricer_callable_bond=function(e,t,r,a,n){return new l.callable_fixed_income(e).present_value(t,r,a,n)}}(this.JsonRisk||module.exports),function(l){var r=null;function u(e,t){if(e.times)return e.times[t];if(e.days)return e.days[t]/365;if(e.dates)return(r=r||l.year_fraction_factory("a/365"))(l.get_safe_date(e.dates[0]),l.get_safe_date(e.dates[t]));if(e.labels)return l.period_str_to_time(e.labels[t]);throw new Error("get_time_at: invalid curve, cannot derive times")}function f(e,t){if(Array.isArray(e.dfs))return e.dfs[t];if(Array.isArray(e.zcs))return Math.pow(1+e.zcs[t],-u(e,t));throw new Error("get_df: invalid curve, must provide dfs or zcs")}l.get_const_curve=function(e,t){if("number"!=typeof e)throw new Error("get_const_curve: input must be number.");if(e<=-1)throw new Error("get_const_curve: invalid input.");return{type:t||"yield",times:[1],dfs:[1/(1+e)]}},l.get_curve_times=function(e){var t=(e.times||e.days||e.dates||e.labels||[]).length;if(!t)throw new Error("get_curve_times: invalid curve, need to provide valid times, days, dates, or labels");for(var r=new Array(t);0<t;)r[--t]=u(e,t);return r},l.get_safe_curve=function(e){return e?{type:"yield",times:l.get_curve_times(e),dfs:function(e){var t=(e.times||e.days||e.dates||e.labels||[]).length;if(!t)throw new Error("get_curve_dfs: invalid curve, need to provide valid times, days, dates, or labels");if(e.dfs){if(e.dfs.length!==t)throw new Error("get_curve_dfs: invalid curve, dfs length must match times length")}else if(e.zcs.length!==t)throw new Error("get_curve_dfs: invalid curve, zcs length must match times length");for(var r=new Array(t);0<t;)if(r[--t]=e.dfs?e.dfs[t]:f(e,t),"number"!=typeof r[t])throw new Error("get_curve_dfs: invalid curve, must provide numeric zcs or dfs");return r}(e)}:l.get_const_curve(0)},l.get_df=function(e,t){var r=0,a=(e.times||e.days||e.dates||e.labels).length-1;if(t<1/512)return 1;var n=u(e,r);if(r===a)return t===n?f(e,r):Math.pow(f(e,r),t/n);var i,s,o=u(e,a);if(t<n)return Math.pow(f(e,r),t/n);if(o<t)return Math.pow(f(e,a),t/o);for(;r+1!==a;)(s=u(e,i=(r+a)/2|0))<t?(n=s,r=i):(o=s,a=i);if(o-n<1/512)throw new Error("get_df_internal: invalid curve, support points must be increasing and differ at least one day");var _=1/(o-n);return(f(e,r)*(o-t)+f(e,a)*(t-n))*_},l.get_rate=function(e,t){return t<1/512?0:Math.pow(l.get_df(e,t),-1/t)-1},l.get_fwd_rate=function(e,t,r){return r-t<1/512?0:Math.pow(l.get_df(e,r)/l.get_df(e,t),-1/(r-t))-1},l.add_curves=function(e,t){for(var r,a=l.get_curve_times(e),n=l.get_curve_times(t),i=[],s=0,o=0,_=[];r=Number.POSITIVE_INFINITY,s<a.length&&(r=Math.min(a[s],r)),o<n.length&&(r=Math.min(n[o],r)),i.push(r),_.push(l.get_rate(e,r)+l.get_rate(t,r)),r===a[s]&&s<a.length&&s++,r===n[o]&&o<n.length&&o++,s!==a.length||o!==n.length;);return{times:i,zcs:_}}}(this.JsonRisk||module.exports),function(c){c.dcf=function(e,t,r,a,n){c.require_vd(),"number"!=typeof a&&(a=0),t=t||c.get_const_curve(0);var i=c.get_safe_date(n);i||(i=c.valuation_date);var s=c.time_from_now(i);if(void 0===e.t_pmt||void 0===e.pmt_total)throw new Error("dcf: invalid cashflow object");if(e.t_pmt.length!==e.pmt_total.length)throw new Error("dcf: invalid cashflow object");for(var o,_,l=0,u=0,f=!r&&0===a;e.t_pmt[u]<=s;)u++;for(;u<e.t_pmt.length;)o=f?c.get_df(t,e.t_pmt[u]):(_=a+c.get_rate(t,e.t_pmt[u]),r&&(_+=c.get_rate(r,e.t_pmt[u])),Math.pow(1+_,-e.t_pmt[u])),l+=e.pmt_total[u]*o,u++;return l},c.irr=function(t,r,a){c.require_vd(),a||(a=0);var n=c.time_from_now(r);return c.find_root_secant(function(e){return c.dcf(t,null,null,e,r)+a*Math.pow(1+e,-n)},0,1e-4)}}(this.JsonRisk||module.exports),function(b){b.fixed_income=function(e){var t=b.get_safe_date(e.maturity);if(!t)throw new Error("fixed_income: must provide maturity date.");var r=b.get_safe_date(e.effective_date);if("number"!=typeof e.notional)throw new Error("fixed_income: must provide valid notional.");this.notional=e.notional,this.notional_exchange=!1!==e.notional_exchange;var a=b.get_safe_natural(e.tenor);if(null===a)throw new Error("fixed_income: must provide valid tenor.");var n=b.get_safe_date(e.first_date),i=b.get_safe_date(e.next_to_last_date),s=b.get_safe_bool(e.stub_end),o=b.get_safe_bool(e.stub_long);this.excl_margin=b.get_safe_number(e.excl_margin)||0,this.type="string"==typeof e.type?e.type:"unknown",this.is_holiday_func=b.is_holiday_factory(e.calendar||""),this.year_fraction_func=b.year_fraction_factory(e.dcc||""),this.bdc=e.bdc||"",this.adjust_accrual_periods=b.get_safe_bool(e.adjust_accrual_periods),this.adj=function(e){return b.adjust(e,this.bdc,this.is_holiday_func)};var _=b.get_safe_natural(e.repay_tenor);null===_&&(_=a);var l=e.linear_amortization||!1;this.repay_amount=b.get_safe_number_vector(e.repay_amount)||[0],this.interest_capitalization=b.get_safe_bool_vector(e.interest_capitalization);var u=b.get_safe_date(e.repay_first_date)||this.first_date,f=b.get_safe_date(e.repay_next_to_last_date)||this.next_to_last_date,c=e.stub_end||!1,d=e.stub_long||!1;if(this.conditions_valid_until=b.get_safe_date_vector(e.conditions_valid_until),this.conditions_valid_until){if(this.conditions_valid_until[this.conditions_valid_until.length-1].getTime()!==t.getTime())throw new Error("fixed_income: last date provided under conditions_valid_until must match maturity")}else this.conditions_valid_until=[t];var h=b.get_safe_natural(e.settlement_days)||0;this.settlement_date=b.get_safe_date(e.settlement_date)||b.add_business_days(b.valuation_date,h,this.is_holiday_func),this.residual_spread="number"==typeof e.residual_spread?e.residual_spread:0;e.currency;if(this.schedule=b.schedule(r,t,a,this.adj,n,i,s,o),e.fixed_rate||0===e.fixed_rate)this.is_float=!1,this.fixed_rate=b.get_safe_number_vector(e.fixed_rate),this.float_spread=0,this.cap_rate=[0],this.floor_rate=[0],this.fixing_schedule=[this.schedule[0],t];else{if(this.is_float=!0,this.fixed_rate=null,this.float_spread=b.get_safe_number_vector(e.float_spread)||[0],this.float_current_rate=b.get_safe_number(e.float_current_rate),null===this.float_current_rate)throw new Error("fixed_income: must provide valid float_current_rate.");var p=b.get_safe_natural(e.fixing_tenor);null===p&&(p=a);var m=b.get_safe_date(e.fixing_first_date)||this.first_date,g=b.get_safe_date(e.fixing_next_to_last_date)||this.next_to_last_date;e.fixing_stub_end,e.fixing_stub_long;this.cap_rate="number"==typeof e.cap_rate?[e.cap_rate]:[Number.POSITIVE_INFINITY],this.floor_rate="number"==typeof e.floor_rate?[e.floor_rate]:[Number.POSITIVE_INFINITY],this.fixing_schedule=b.schedule(this.schedule[0],t,p,this.adj,m,g)}this.is_amortizing=0<this.repay_amount.reduce(function(e,t){return Math.max(e*e,t*t)},0)||this.interest_capitalization.reduce(function(e,t){return e||t},!1)||l,this.is_amortizing?this.repay_schedule=b.schedule(this.schedule[0],t,_,this.adj,u,f,c,d):this.repay_schedule=[this.schedule[0],t],l&&(this.repay_amount=[Math.abs(this.notional)/(this.repay_schedule.length-1)]),this.cash_flows=this.initialize_cash_flows(),this.is_float||(this.cash_flows=this.finalize_cash_flows(null))},b.fixed_income.prototype.initialize_cash_flows=function(){b.require_vd();var e=new Array(this.schedule.length),t=new Array(this.schedule.length),r=new Array(this.schedule.length),a=new Array(this.schedule.length),n=new Array(this.schedule.length),i=new Array(this.schedule.length);e[0]=this.schedule[0],t[0]=this.schedule[0],r[0]=!1,a[0]=!1,n[0]=!0,i[0]=!1;for(var s=1,o=1,_=1,l=1,u=0;e[s]=t[s-1],t[s]=new Date(Math.min(this.schedule[o],this.repay_schedule[_],this.fixing_schedule[l],this.conditions_valid_until[u])),o<this.schedule.length&&t[s].getTime()===this.schedule[o].getTime()?(r[s]=!0,o++):r[s]=!1,_<this.repay_schedule.length&&t[s].getTime()===this.repay_schedule[_].getTime()?(a[s]=!0,_++):a[s]=!1,l<this.fixing_schedule.length&&t[s].getTime()===this.fixing_schedule[l].getTime()?(n[s]=!0,l++):n[s]=!1,u<this.conditions_valid_until.length&&t[s].getTime()===this.conditions_valid_until[u].getTime()?(i[s]=!0,u++):i[s]=!1,o!==this.schedule.length||_!==this.repay_schedule.length||l!==this.fixing_schedule.length;)s++;var f=new Array(e.length),c=new Array(e.length),d=new Array(e.length),h=new Array(e.length),p=(new Array(e.length),new Array(e.length));new Array(e.length),new Array(e.length),new Array(e.length),new Array(e.length),new Array(e.length);for(s=0;s<e.length;s++)this.adjust_accrual_periods&&(e[s]=this.adj(e[s]),t[s]=this.adj(t[s])),f[s]=this.adj(t[s]),h[s]=b.time_from_now(f[s]),c[s]=b.time_from_now(e[s]),d[s]=b.time_from_now(t[s]),p[s]=0===s?0:this.year_fraction_func(e[s],t[s]);return{date_accrual_start:e,date_accrual_end:t,date_pmt:f,t_accrual_start:c,t_accrual_end:d,t_pmt:h,is_interest_date:r,is_repay_date:a,is_fixing_date:n,is_condition_date:i,accrual_factor:p}},b.fixed_income.prototype.finalize_cash_flows=function(e,t){b.require_vd();b.year_fraction_factory(null);for(var r=this.cash_flows,a=r.date_accrual_start.length,n=new Array(a),i=new Array(a),s=new Array(a),o=new Array(a),_=new Array(a),l=new Array(a),u=new Array(a),f=0<=this.notional?1:-1,c=0;this.conditions_valid_until[c]<r.date_accrual_start[0];)c++;var d,h,p,m=this.repay_amount[Math.min(c,this.repay_amount.length-1)],g=this.interest_capitalization[Math.min(c,this.interest_capitalization.length-1)],v=(this.cap_rate[Math.min(c,this.cap_rate.length-1)],this.floor_rate[Math.min(c,this.floor_rate.length-1)],this.is_float?this.float_spread:this.fixed_rate);p="number"==typeof t?function(){return t}:function(){return v[Math.min(c,v.length-1)]},_[o[s[i[n[0]=0]=0]=0]=0]=-this.notional,u[l[0]=0]=this.notional_exchange?-this.notional:0;var w,y=0;for(w=1;w<a;w++){if(n[w]=n[w-1]-_[w-1],r.is_repay_date[w]?_[w]=m*f:_[w]=0,this.is_float)if(r.t_accrual_start[w]<=0)i[w]=this.float_current_rate;else if(r.is_fixing_date[w-1]){for(h=0;!r.is_fixing_date[w+h]&&w+h<r.is_fixing_date.length;)h++;i[w]=b.get_fwd_rate(e,r.t_accrual_start[w],r.t_accrual_end[w+h])}else i[w]=i[w-1];else i[w]=0;d=i[w]+p(),s[w]=n[w]*(d-this.excl_margin)*r.accrual_factor[w],0!==this.excl_margin&&(y+=n[w]*this.excl_margin*r.accrual_factor[w]),o[w]=(0<w?o[w-1]:0)+s[w],r.is_interest_date[w]?(l[w]=o[w],o[w]=0,g&&(_[w]=_[w]-l[w],0!==this.excl_margin&&(_[w]=_[w]-y)),y=0):l[w]=0,(w<a-1&&_[w]*f>n[w]*f||w===a-1)&&(_[w]=n[w]),u[w]=l[w],this.notional_exchange&&(u[w]+=_[w]),r.is_condition_date[w]&&(c++,m=this.repay_amount[Math.min(c,this.repay_amount.length-1)],g=this.interest_capitalization[Math.min(c,this.interest_capitalization.length-1)],this.cap_rate[Math.min(c,this.cap_rate.length-1)],this.floor_rate[Math.min(c,this.floor_rate.length-1)])}return{date_accrual_start:r.date_accrual_start,date_accrual_end:r.date_accrual_end,date_pmt:r.date_pmt,t_accrual_start:r.t_accrual_start,t_accrual_end:r.t_accrual_end,t_pmt:r.t_pmt,is_interest_date:r.is_interest_date,is_repay_date:r.is_repay_date,is_fixing_date:r.is_fixing_date,is_condition_date:r.is_condition_date,accrual_factor:r.accrual_factor,current_principal:n,fwd_rate:i,interest_current_period:s,accrued_interest:o,pmt_principal:_,pmt_interest:l,pmt_total:u}},b.fixed_income.prototype.get_cash_flows=function(e){if(this.is_float){if("object"!=typeof e||null===e)throw new Error("fixed_income.get_cash_flows: Must provide forward curve when evaluating floating rate interest stream");return this.finalize_cash_flows(e)}return this.cash_flows},b.fixed_income.prototype.present_value=function(e,t,r){if("object"!=typeof e||null===e)throw new Error("fixed_income.present value: Must provide discount curve when evaluating interest stream");if(this.is_float&&("object"!=typeof r||null===r))throw new Error("fixed_income.present value: Must provide forward curve when evaluating floating rate interest stream");return b.dcf(this.get_cash_flows(b.get_safe_curve(r)||null),b.get_safe_curve(e),t?b.get_safe_curve(t):null,this.residual_spread,this.settlement_date)},b.fixed_income.prototype.fair_rate_or_spread=function(e,t,r){b.require_vd();for(var a,n=b.get_safe_curve(r)||b.get_const_curve(0),i=this.finalize_cash_flows(n),s=0;i.date_pmt[s]<=b.valuation_date;)s++;a=i.current_principal[s];var o=new Array(i.pmt_total.length),_=0;for(s=0;s<o.length;s++)o[s]=i.pmt_principal[s],_+=i.current_principal[s]*i.accrual_factor[s]*i.fwd_rate[s],i.is_interest_date[s]&&(o[s]+=_,_=0);var l=a-b.dcf({date_pmt:i.date_pmt,t_pmt:i.t_pmt,pmt_total:o},e,t,this.residual_spread,this.settlement_date);return l/=this.annuity(e,t,n)},b.fixed_income.prototype.annuity=function(e,t,r){var a,n=this.get_cash_flows(b.get_safe_curve(r)||b.get_const_curve(0)),i=new Array(n.pmt_total.length),s=0;for(a=0;a<i.length;a++)i[a]=0,s+=n.current_principal[a]*n.accrual_factor[a],n.is_interest_date[a]&&(i[a]+=s,s=0);return b.dcf({date_pmt:n.date_pmt,t_pmt:n.t_pmt,pmt_total:i},b.get_safe_curve(e),b.get_safe_curve(t),this.residual_spread,this.settlement_date)},b.pricer_bond=function(e,t,r){return new b.fixed_income(e).present_value(t,r,null)},b.pricer_floater=function(e,t,r,a){return new b.fixed_income(e).present_value(t,r,a)}}(this.JsonRisk||module.exports),function(r){r.fxterm=function(e){this.near_leg=new r.fixed_income({notional:e.notional,maturity:e.maturity,fixed_rate:0,tenor:0}),"number"==typeof e.notional_2&&r.get_safe_date(e.maturity_2)?this.far_leg=new r.fixed_income({notional:e.notional_2,maturity:e.maturity_2,fixed_rate:0,tenor:0}):this.far_leg=null},r.fxterm.prototype.present_value=function(e){var t=0;return t+=this.near_leg.present_value(e,null,null),this.far_leg&&(t+=this.far_leg.present_value(e,null,null)),t},r.pricer_fxterm=function(e,t){return new r.fxterm(e).present_value(t)}}(this.JsonRisk||module.exports),function(A){"use strict";function y(e){return e}function j(e,t,r,a,n){var i,s=new Array(e.t_pmt.length+1),o=0;"number"!=typeof n&&(n=0);for(var _=!a&&0===n;e.t_pmt[o]<=0;)o++;for(;o<e.t_pmt.length;)_?s[o]=A.get_df(r,e.t_pmt[o]):(i=A.get_rate(r,e.t_pmt[o]),a&&(i+=A.get_rate(a,e.t_pmt[o])),i+=n,s[o]=Math.pow(1+i,-e.t_pmt[o])),o++;return _?s[o]=A.get_df(r,t):(i=A.get_rate(r,t),a&&(i+=A.get_rate(a,t)),i+=n,s[o]=Math.pow(1+i,-t)),s}function b(e,t,r,a){if(!a)return 0;for(var n=0,i=0;e.t_pmt[n]<=t;)n++;for(;n<e.t_pmt.length;)i+=e.current_principal[n]*r[n]*a*(e.t_pmt[n]-Math.max(e.t_pmt[n-1],t)),n++;return i/=r[r.length-1]}A.lgm_dcf=function(e,t,r,a,n,i){if(!n.length)throw new Error("lgm_dcf: state variable must be an array of numbers");for(var s,o,_,l,u=0,f=new Float64Array(n.length),c=e.t_pmt,d=e.pmt_total;c[u]<=t;)u++;var h=0;e.pmt_interest&&(h=0===u?0:e.pmt_interest[u]*(t-c[u-1])/(c[u]-c[u-1]));var p=b(e,t,r,i);for(_=-(e.current_principal[u]+h+p)*r[r.length-1],s=0;s<n.length;s++)f[s]=_;for(;u<c.length;){if(o=y(e.t_pmt[u])-y(t),0!==(_=d[u]*r[u]))for(l=o*o*a*.5,s=0;s<n.length;s++)f[s]+=_*Math.exp(-o*n[s]-l);u++}return f},A.lgm_european_call_on_cf=function(t,r,a,n,i,s,o,e){var _=e||j(t,r,a,i,s);if(r<0)return 0;if(r<1/512||n<1e-10)return Math.max(0,A.lgm_dcf(t,r,_,0,[0],o)[0]);var l,u=Math.sqrt(n),f=y(r+1/365)-y(r);function c(e){return A.lgm_dcf(t,r,_,n,[e],o)[0]}if(20/f<u)l=-10*(u=20/f);else{var d,h;if(0<=c(0)){if((d=0)<c(h=u*D))return A.lgm_dcf(t,r,_,0,[0],o)[0]}else if(h=0,c(d=-u*D)<0)return 0;try{l=A.find_root_ridders(c,h,d,20)}catch(e){return A.lgm_bermudan_call_on_cf(t,[r],a,[n],i,s,o)}}for(var p=0,m=1/u;t.t_pmt[p]<=r;)p++;var g=0;t.pmt_interest&&(g=0===p?0:t.pmt_interest[p]*(r-t.t_pmt[p-1])/(t.t_pmt[p]-t.t_pmt[p-1]));for(var v=b(t,r,_,o),w=-(t.current_principal[p]+g+v)*_[_.length-1]*A.cndf(l*m);p<t.t_pmt.length;)f=y(t.t_pmt[p])-y(r),w+=t.pmt_total[p]*_[p]*A.cndf(l*m+f*u),p++;return w},A.lgm_european_swaption_adjusted_cashflow=function(e,t,r,a){var n,i=e.swap.fair_rate(t,t);if(a)n=i;else{var s=e.swap.fair_rate(t,r);n=e.swap.fixed_rate-s+i}var o=e.swap.fixed_leg.finalize_cash_flows(null,n);return o.pmt_total[0]-=o.current_principal[1],o.pmt_total[o.pmt_total.length-1]+=o.current_principal[o.pmt_total.length-1],o},A.lgm_european_swaption=function(e,t,r,a,n){var i=A.lgm_european_swaption_adjusted_cashflow(e,r,n);return A.lgm_european_call_on_cf(i,t,r,a,null,null,null)},A.lgm_calibrate=function(e,t,r,a){A.require_vd();var n,i,s,o,_,l,u,f,c,d,h,p,m,g=[],v=function(e){return A.lgm_european_call_on_cf(i,_,t,e,null,null,null,s)-u};for(c=0;c<e.length;c++)if(A.time_from_now(e[c].first_exercise_date)>1/512){for(_=A.time_from_now(e[c].first_exercise_date),A.time_from_now(e[c].maturity),i=A.lgm_european_swaption_adjusted_cashflow(e[c],t,r,!1),s=j(i,_,t,null,null),d=l=0;d<i.t_pmt.length;d++)l+=i.pmt_total[d]*s[d]*(y(i.t_pmt[d])-y(_));if(u=e[c].present_value(t,r,a),o=e[c].std_dev,n=Math.pow(o*e[c].swap.annuity(t)/l,2),p=(h=A.lgm_dcf(i,_,s,0,[0],null)[0])+e[c].swap.fixed_leg.notional*s[s.length-1],h<0&&(h=0),(u=e[c].present_value(t,r,a))<=h+(m=1e-7*u+1e-7)||0===n)n=0;else{for(p<u&&(u=p),f=v(n),d=10;f<0&&0<d;)d--,f=v(n*=2);try{n=A.find_root_ridders(v,0,n,20,m)}catch(e){Math.abs(u-h)<Math.abs(f)&&(n=0)}}0<g.length&&g[g.length-1]>n&&(n=g[g.length-1]),g.push(n)}return g};var D=4;A.lgm_bermudan_call_on_cf=function(e,t,r,a,n,i,s){if(t[t.length-1]<0)return 0;if(t[t.length-1]<1/512)return A.lgm_european_call_on_cf(e,t[t.length-1],r,0,n,i,s);function o(){var e=new Float64Array(2*D*15+1);for(e[0]=-D*h,f=1;f<b;f++)e[f]=e[f-1]+p;return e}function _(){var e=0;for(f=0;f<b;f++)E[f]=Math.max(M[f],w[f],0),!e&&0<f&&(w[f]-M[f])*(w[f-1]-M[f-1])<0&&(e=f);if(e){var t=E[e-1],r=E[e],a=Math.min(w[e-1],M[e-1]),n=Math.min(w[e],M[e]),i=(t-a)/(r-n+t-a),s=.25*(i*(r-n)+(1-i)*(t-a));E[e]-=i*s,E[e-1]-=(1-i)*s}}function l(e){if(x-d<1e-12)return E[e];for(var t,r=0,a=0,n=1/Math.sqrt(x-d),i=m*n,s=0,o=(v[0]-g[e]+.5*m)*n;o<-D;)o+=i,s+=1;for(;o<D&&!(b<=s);)t=A.fast_cndf(o),r+=E[s]*(t-a),a=t,o+=i,s++;return r}var u,f,c,d,h,p,m,g,v,w,y,b=2*D*15+1,x=0,E=new Float64Array(b),M=new Float64Array(b);for(c=a.length-1;0<=c;){if(d=a[c],h=Math.sqrt(d),p=h/15,g=o(),y=j(e,t[c],r,n,i),w=A.lgm_dcf(e,t[c],y,d,g,s),c<a.length-1)for(u=0;u<b;u++)M[u]=l(u);else for(u=0;u<b;u++)M[u]=0;_(),x=d,v=g,m=p,c--}return g=[0],M=l(d=0)}}(this.JsonRisk||module.exports),function(a){"use strict";var n=Math.sqrt(4*Math.acos(0));a.get_safe_number=function(e){if("number"==typeof e)return e;if("string"!=typeof e)return null;e=e.trim();var t=parseFloat(e);return isNaN(t)?null:("%"===e.charAt(e.length-1)&&(t*=.01),t)},a.get_safe_positive=function(e){var t=a.get_safe_number(e);return t<=0?null:t},a.get_safe_natural=function(e){var t=a.get_safe_number(e);return t<0||t!==Math.floor(t)?null:t},a.get_safe_number_vector=function(e){if("number"==typeof e)return[e];var t;if("string"==typeof e)t=e.split(/\s+/);else{if(!Array.isArray(e))return null;t=e.slice()}for(var r=0;r<t.length;r++)if(t[r]=a.get_safe_number(t[r]),null===t[r])throw new Error("get_safe_number_vector: invalid input");return t},a.get_safe_bool=function(e){if("boolean"==typeof e)return e;if("number"==typeof e)return 0!==e;if("string"!=typeof e)return!1;var t=e.trim().toLowerCase();return"true"===t||"yes"===t||"y"===t},a.get_safe_bool_vector=function(e){if("boolean"==typeof e)return[e];if("number"==typeof e)return[0!==e];var t;if("string"==typeof e)t=e.split(/\s+/);else{if(!Array.isArray(e))return[!1];t=e.slice()}for(var r=0;r<t.length;r++)t[r]=a.get_safe_bool(t[r]);return t},a.ndf=function(e){return Math.exp(-e*e/2)/n},a.cndf=function(e){var t,r=Math.abs(e);if(r<=37){var a=Math.exp(-r*r/2);if(r<7.07106781186547)t=a*((((((.0352624965998911*r+.700383064443688)*r+6.37396220353165)*r+33.912866078383)*r+112.079291497871)*r+221.213596169931)*r+220.206867912376)/(((((((.0883883476483184*r+1.75566716318264)*r+16.064177579207)*r+86.7807322029461)*r+296.564248779674)*r+637.333633378831)*r+793.826512519948)*r+440.413735824752);else t=a/(n*(r+1/(r+2/(r+3/(r+4/(r+.65))))))}else{if(!(37<r))throw new Error("cndf: invalid input.");t=0}return e<=0?t:1-t};a.fast_cndf=function(e){var t=0<e?e:-e,r=1+t*(.049867347+t*(.0211410061+t*(.0032776263+t*(380036e-10+t*(488906e-10+5383e-9*t)))));return r*=r,r*=r,r*=r,r=.5/(r*=r),0<=e?1-r:r},a.find_root_secant=function(e,t,r,a,n){var i=t,s=r,o=0,_=a||20,l=n||1e-8,u=e(i),f=e(s);for(Math.abs(f)>Math.abs(u)&&(o=i,i=s,s=o,o=u,u=f,f=o);Math.abs(f)>l&&0<_;)o=(i-s)*f/(f-u),u=f,f=e(s=(i=s)+o),_--;if(_<=0)throw new Error("find_root_secant: failed, too many iterations");if(isNaN(s))throw new Error("find_root_secant: failed, invalid result");return s},a.find_root_ridders=function(e,t,r,a,n){var i,s,o,_=t,l=r,u=0,f=0,c=0,d=a||20,h=n||1e-8,p=e(_),m=e(l);if(0<p*m)throw new Error("find_root_ridders: start values do not bracket the root");if(Math.abs(p)<h)return _;if(Math.abs(m)<h)return l;for(;0<d;){if(d--,u=.5*(_+l),Math.abs(_-l)<1e-15)return u;if(i=e(u),Math.abs(i)<h)return u;if(0===(c=Math.sqrt(i*i-m*p)))return u;if(f=(u-_)*(0<(o=p-m)?1:o<0?-1:0)*i/c+u,isNaN(f)&&(f=u),s=e(f),Math.abs(s)<h)return f;i*s<0?(_=f,p=s,l=u,m=i):p*s<0?(l=f,m=s):m*s<0&&(_=f,p=s)}if(d<=0)throw new Error("find_root_ridders: failed, too many iterations")}}(this.JsonRisk||module.exports),function(l){"use strict";var u=function(e,t,r,a){for(var n=[e],i=1,s=l.add_months(e,r);s.getTime()<t.getTime();)n.push(s),i++,s=l.add_months(e,i*r);return a(t).getTime()<=a(n[n.length-1]).getTime()&&n.pop(),n},f=function(e,t,r,a){for(var n=[t],i=1,s=l.add_months(t,-r);s.getTime()>e.getTime();)n.unshift(s),i++,s=l.add_months(t,-i*r);return a(e).getTime()>=a(n[0]).getTime()&&n.shift(),n};l.schedule=function(e,t,r,a,n,i,s,o){if(!(t instanceof Date))throw new Error("schedule: maturity must be provided");if(!(e instanceof Date)){if(null===l.valuation_date)throw new Error("schedule: if valuation_date is unset, effective date must be provided");if(n instanceof Date)throw new Error("schedule: if first date is provided, effective date must be provided");if(!(i instanceof Date)&&s)throw new Error("schedule: if next to last date is not provided and stub in the end is specified, effective date must be provided")}if(e instanceof Date&&t<e||l.valuation_date instanceof Date&&t<l.valuation_date)throw new Error("schedule: maturity is before valuation date or effective date.");if("number"!=typeof r)throw new Error("schedule: tenor must be a nonnegative integer, e.g., 6 for semiannual schedule, 0 for zerobond/iam schedule");if(r<0||Math.floor(r)!==r)throw new Error("schedule: tenor must be a nonnegative integer, e.g., 6 for semiannual schedule, 0 for zerobond/iam schedule");return 0===r?[e instanceof Date?e:l.valuation_date,t]:(n instanceof Date&&!(i instanceof Date)?((_=u(n,t,r,a)).push(t),e.getTime()!==n.getTime()&&_.unshift(e)):i instanceof Date&&!(n instanceof Date)?(_=f(e instanceof Date?e:l.valuation_date,i,r,a),t.getTime()!==i.getTime()&&_.push(t),e instanceof Date&&_.unshift(e),e instanceof Date||_.unshift(l.add_months(_[0],-r))):n instanceof Date&&i instanceof Date?(_=f(n,i,r,a),t.getTime()!==i.getTime()&&_.push(t),_.unshift(n),_.unshift(e)):s?(_=u(e,t,r,a),o&&1<_.length&&_.pop(),_.push(t)):(_=f(e instanceof Date?e:l.valuation_date,t,r,a),o&&1<_.length&&_.shift(),e instanceof Date&&_.unshift(e),e instanceof Date||_.unshift(l.add_months(_[0],-r))),_);var _}}(this.JsonRisk||module.exports),function(c){function f(e,t){if(e.terms)return e.terms[t];if(e.labels_term)return c.period_str_to_time(e.labels_term[t]);throw new Error("get_term_at: invalid surface, cannot derive terms")}function u(e,t){if(e.expiries)return e.expiries[t];if(e.labels_expiry)return c.period_str_to_time(e.labels_expiry[t]);throw new Error("get_expiry_at: invalid surface, cannot derive expiries")}function d(e,t,r){var a=0,n=(e.terms||e.labels_term||[]).length-1,i=e.values[t];if(!Array.isArray(i))throw new Error("get_slice_rate: invalid surface, values property must be an array of arrays");if(a===n)return i[a];var s,o,_=f(e,a),l=f(e,n);if(r<f(e,a))return i[a];if(r>f(e,n))return i[n];for(;a+1!==n;)(o=f(e,s=(a+n)/2|0))<r?(_=o,a=s):(l=o,n=s);if(l-_<1/512)throw new Error("get_slice_rate: invalid curve, support points must be increasing and differ at least one day");var u=1/(l-_);return(i[a]*(l-r)+i[n]*(r-_))*u}c.get_const_surface=function(e,t){if("number"!=typeof e)throw new Error("get_const_surface: input must be number.");return{type:t||"",expiries:[1],terms:[1],values:[[e]]}},c.get_safe_surface=function(e){return e?{type:e.type||"",expiries:function(e){var t=(e.expiries||e.labels_expiry||[]).length;if(!t)throw new Error("get_surface_terms: invalid surface, need to provide valid expiries or labels_expiry");for(var r=new Array(t);0<t;)r[--t]=u(e,t);return r}(e),terms:function(e){var t=(e.terms||e.labels_term||[]).length;if(!t)throw new Error("get_surface_terms: invalid surface, need to provide valid terms or labels_term");for(var r=new Array(t);0<t;)r[--t]=f(e,t);return r}(e),values:e.values}:c.get_const_surface(0)},c.get_surface_rate=function(e,t,r){var a=0,n=(e.expiries||e.labels_expiry||[]).length-1;if(a===n)return d(e,a,r);var i,s,o=u(e,a),_=u(e,n);if(t<o)return d(e,a,r);if(_<t)return d(e,n,r);for(;a+1!==n;)(s=u(e,i=(a+n)/2|0))<t?(o=s,a=i):(_=s,n=i);if(_-o<1/512)throw new Error("get_surface_rate: invalid curve, support points must be increasing and differ at least one day");var l=1/(_-o);return(d(e,a,r)*(_-t)+d(e,n,r)*(t-o))*l},c.get_cube_rate=function(e,t,r,a){var n=c.get_surface_rate(e,t,r);if(e.moneyness&&e.smile){if(!e.moneyness.length||!e.smile.length)throw new Error("get_cube_rate: invalid cube, moneyness and smile must be arrays");var i=0,s=e.moneyness.length-1;if(i===s)return n+c.get_surface_rate(e.smile[i],t,r);var o,_,l=e.moneyness[i],u=e.moneyness[s];if(a<l)return n+c.get_surface_rate(e.smile[i],t,r);if(u<a)return n+c.get_surface_rate(e.smile[s],t,r);for(;i+1!==s;)o=(i+s)/2|0,(_=e.moneyness[o])<a?(l=_,i=o):(u=_,s=o);if(u-l<1e-15)throw new Error("get_cube_rate: invalid cube, moneyness must be nondecreasing");var f=1/(u-l);return n+(c.get_surface_rate(e.smile[i],t,r)*(u-a)+c.get_surface_rate(e.smile[s],t,r)*(a-l))*f}return n}}(this.JsonRisk||module.exports),function(a){a.swap=function(e){this.phi=e.is_payer?-1:1,this.fixed_rate=e.fixed_rate,this.fixed_leg=new a.fixed_income({notional:e.notional*this.phi,notional_exchange:!1,maturity:e.maturity,fixed_rate:e.fixed_rate,tenor:e.tenor,effective_date:e.effective_date,calendar:e.calendar,bdc:e.bdc,dcc:e.dcc}),this.float_leg=new a.fixed_income({notional:-e.notional*this.phi,notional_exchange:!1,maturity:e.maturity,float_spread:e.float_spread,tenor:e.float_tenor,effective_date:e.effective_date,calendar:e.calendar,bdc:e.float_bdc,dcc:e.float_dcc,float_current_rate:e.float_current_rate})},a.swap.prototype.fair_rate=function(e,t){var r=this.float_leg.present_value(e,null,t);return 0===r?0:-this.phi*r/this.annuity(e)},a.swap.prototype.annuity=function(e){return this.fixed_leg.annuity(e)*this.phi},a.swap.prototype.present_value=function(e,t){var r=0;return r+=this.fixed_leg.present_value(e,null,null),r+=this.float_leg.present_value(e,null,t)},a.swap.prototype.get_cash_flows=function(e){return{fixed_leg:this.fixed_leg.get_cash_flows(),float_leg:this.float_leg.get_cash_flows(e)}},a.pricer_swap=function(e,t,r){return new a.swap(e).present_value(t,r)}}(this.JsonRisk||module.exports),function(b){b.swaption=function(e){if(this.sign=e.is_short?-1:1,this.maturity=b.get_safe_date(e.maturity),!this.maturity)throw new Error("swaption: must provide valid maturity date.");if(this.first_exercise_date=b.get_safe_date(e.first_exercise_date),!this.first_exercise_date)throw new Error("swaption: must provide valid first_exercise_date date.");this.swap=new b.swap({is_payer:e.is_payer,notional:e.notional,effective_date:this.first_exercise_date,maturity:e.maturity,fixed_rate:e.fixed_rate,tenor:e.tenor,calendar:e.calendar,bdc:e.bdc,dcc:e.dcc,float_spread:e.float_spread,float_tenor:e.float_tenor,float_bdc:e.float_bdc,float_dcc:e.float_dcc,float_current_rate:e.float_current_rate})},b.swaption.prototype.present_value=function(e,t,r){b.require_vd();var a,n=b.time_from_now(this.maturity),i=b.time_from_now(this.first_exercise_date),s=n-i;if(s<1/512)return 0;if(this.fair_rate=this.swap.fair_rate(e,t),this.moneyness=this.swap.fixed_rate-this.fair_rate,"object"!=typeof r||null===r)throw new Error("swaption.present_value: must provide valid surface");if(this.vol=b.get_cube_rate(r,i,s,this.moneyness),this.std_dev=this.vol*Math.sqrt(i),i<0)return 0;if(i<1/512||this.std_dev<1e-4)a=Math.max(this.swap.phi*this.moneyness,0);else{var o=this.moneyness/this.std_dev;a=this.swap.phi*this.moneyness*b.cndf(this.swap.phi*o)+this.std_dev*b.ndf(o)}return a*=this.swap.annuity(e),a*=this.sign},b.pricer_swaption=function(e,t,r,a){return new b.swaption(e).present_value(t,r,a)},b.create_equivalent_regular_swaption=function(e,t,r){if(void 0===e.date_pmt||void 0===e.pmt_total||void 0===e.current_principal)throw new Error("create_equivalent_regular_swaption: invalid cashflow object");if(e.t_pmt.length!==e.pmt_total.length||e.t_pmt.length!==e.current_principal.length)throw new Error("create_equivalent_regular_swaption: invalid cashflow object");b.require_vd(),r||(r={});for(var a,n=r.tenor||6,i=r.bdc||"unadjusted",s=r.calendar||"",o=0;e.date_pmt[o]<=t;)o++;if(0===(a=e.current_principal[o]))throw new Error("create_equivalent_regular_swaption: invalid cashflow object or first_exercise_date, zero outstanding principal");var _=b.irr(e,t,-a);_=12/n*(Math.pow(1+_,n/12)-1);var l=b.time_from_now(t),u=b.get_const_curve(_+1e-4),f=b.get_const_curve(_-1e-4),c=b.dcf(e,u,null,null,t);c/=b.get_df(u,l);for(var d=b.dcf(e,f,null,null,t),h=1e4*((d/=b.get_df(f,l))-c)/(d+c),p=function(e){var t=new b.fixed_income(e);return c=t.present_value(u),c/=b.get_df(u,l),d=t.present_value(f),1e4*((d/=b.get_df(f,l))-c)/(d+c)},m=Math.abs(_)<1e-8?h:-Math.log(1-h*_)/_,g=b.add_days(t,Math.round(365*m)),v={maturity:g,effective_date:t,settlement_date:b.adjust(t,i,b.is_holiday_factory(s)),notional:a,fixed_rate:_,tenor:n,calendar:s,bdc:i},w=p(v),y=10;Math.abs(w-h)>1/512&&0<y;)m=m*h/w,g=b.add_days(t,Math.round(365*m)),v.maturity=g,w=p(v),y--;return{is_payer:!1,maturity:g,first_exercise_date:t,effective_date:t,settlement_date:t,notional:a,fixed_rate:_,tenor:n,float_spread:0,float_tenor:r.float_tenor||6,float_current_rate:0,calendar:s,bdc:i,float_bdc:i}}}(this.JsonRisk||module.exports),function(_){"use strict";var l=1/864e5;function i(e){return e%4==0&&(2e3===e||e%100!=0)}function s(e,t){return new Date(e,t+1,0).getDate()}function o(e,t){return Math.round((t-e)*l)}function r(e,t){return o(e,t)/365}function a(e,t){return o(e,t)/360}function n(e,t){return(360*(t.getFullYear()-e.getFullYear())+30*(t.getMonth()-e.getMonth())+(Math.min(t.getDate(),30)-Math.min(e.getDate(),30)))/360}function u(e,t){if(e-t==0)return 0;if(t<e)return-u(t,e);var r=e.getFullYear(),a=t.getFullYear();if(r===a)return o(e,t)/(i(r)?366:365);var n=a-r-1;return n+=o(e,new Date(r+1,0,1))/(i(r)?366:365),n+=o(new Date(a,0,1),t)/(i(a)?366:365)}function f(e){var t=e.getDay();return 0===t||6===t}function c(e){if(f(e))return!0;var t=e.getDate(),r=e.getMonth();if(1===t&&0===r)return!0;if(25===t&&11===r)return!0;var a=e.getFullYear();if((1998===a||1999===a||2001===a)&&31===t&&11===r)return!0;if(2e3<a){if(1===t&&4===r||26===t&&11===r)return!0;var n=function(e){var t=Math.floor,r=t(e/100),a=e-19*t(e/19),n=t((r-17)/25),i=r-t(r/4)-t((r-n)/3)+19*a+15;i-=30*t(i/30),i-=t(i/28)*(1-t(i/28)*t(29/(i+1))*t((21-a)/11));var s=e+t(e/4)+i+2-r+t(r/4),o=i-(s-=7*t(s/7)),_=3+t((o+40)/44),l=o+28-31*t(_/4);return new Date(e,_-1,l)}(a);if(e.getTime()===_.add_days(n,-2).getTime())return!0;if(e.getTime()===_.add_days(n,1).getTime())return!0}return!1}_.period_str_to_time=function(e){var t=parseInt(e,10);if(isNaN(t))throw new Error("period_str_to_time(str) - Invalid time period string: "+e);var r=e.charAt(e.length-1);if("Y"===r||"y"===r)return t;if("M"===r||"m"===r)return t/12;if("W"===r||"w"===r)return t/52;if("D"===r||"d"===r)return t/365;throw new Error("period_str_to_time(str) - Invalid time period string: "+e)},_.date_str_to_date=function(e){var t,r,a,n=null;if(null!==(n=/^([1-2][0-9]{3})[\/-]([0-9]{1,2})[\/-]([0-9]{1,2})/.exec(e))?(a=parseInt(n[1],10),r=parseInt(n[2],10)-1,t=parseInt(n[3],10)):null!==(n=/^([0-9]{1,2})\.([0-9]{1,2})\.([1-2][0-9]{3})/.exec(e))&&(a=parseInt(n[3],10),r=parseInt(n[2],10)-1,t=parseInt(n[1],10)),null===n)throw new Error("date_str_to_time(str) - Invalid date string: "+e);if(r<0||11<r)throw new Error("date_str_to_time(str) - Invalid month in date string: "+e);if(t<0||t>s(a,r))throw new Error("date_str_to_time(str) - Invalid day in date string: "+e);return new Date(a,r,t)},_.get_safe_date=function(e){if(!e)return null;if(e instanceof Date)return e;if(e instanceof String||"string"==typeof e)return _.date_str_to_date(e);throw new Error("get_safe_date: invalid input.")},_.get_safe_date_vector=function(e){if(e instanceof Date)return[e];var t;if("string"==typeof e)t=e.split(/\s+/);else{if(!Array.isArray(e))return null;t=e.slice()}for(var r=0;r<t.length;r++)if(t[r]=_.get_safe_date(t[r]),null===t[r])throw new Error("get_safe_date_vector: invalid input");return t},_.year_fraction_factory=function(e){if(!(e instanceof String)&&"string"!=typeof e)return r;var t=e.toLowerCase();if("a"===t.charAt(0)){if("actual/365"===t||"act/365"===t||"a/365"===t||"act/365 (fixed)"===t||"actual/365 (fixed)"===t)return r;if("act/360"===t||"a/360"===t)return a;if("act/act"===t||"a/a"===t)return u}return"3"===t.charAt(0)&&"30e/360"===t?n:r},_.time_from_now=function(e){return _.require_vd(),r(_.valuation_date,e)},_.add_days=function(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)},_.add_months=function(e,t,r){for(var a,n=e.getFullYear(),i=e.getMonth()+t;12<=i;)i-=12,n+=1;for(;i<0;)i+=12,n-=1;return a=r||e.getDate(),new Date(n,i,Math.min(a,s(n,i)))},_.add_period=function(e,t){var r=parseInt(t,10);if(isNaN(r))throw new Error("period_str_to_time(str) - Invalid time period string: "+t);var a=t.charAt(t.length-1);if("Y"===a||"y"===a)return _.add_months(e,12*r);if("M"===a||"m"===a)return _.add_months(e,r);if("W"===a||"w"===a)return _.add_days(e,7*r);if("D"===a||"d"===a)return _.add_days(e,r);throw new Error("period_str_to_time(str) - Invalid time period string: "+t)};var d={};_.add_calendar=function(e,t){if(!(e instanceof String||"string"==typeof e))throw new Error("add_calendar: invalid input.");if(!Array.isArray(t))throw new Error("add_calendar: invalid input.");var r,a,n,i=t.length,s=[];for(r=0;r<i;r++)(n=_.get_safe_date(t[r]))&&(f(n)||s.push(n));for(i=s.length,r=1;r<41&&!(i/10<=(a=r*r-r+41));)r++;var o=new Array(a);for(r=0;r<a;r++)o[r]=[];for(r=0;r<i;r++)o[Math.floor(s[r].getTime()*l)%a].push(s[r].getTime());return d[e.toLowerCase()]=o,a},_.is_holiday_factory=function(e){var t=e.toLowerCase();if("target"===t)return c;if(Array.isArray(d[t])){var n=d[t];return function(e){if(f(e))return!0;for(var t=e.getTime(),r=Math.floor(t*l)%n.length,a=0;a<n[r].length;a++)if(t===n[r][a])return!0;return!1}}if(""===t)return f;throw new Error("is_holiday_factory: calendar not found")},_.adjust=function(e,t,r){var a,n=(t||"u").charAt(0).toLowerCase(),i=new Date(e);if("u"===n)return i;if("m"===n&&(a=i.getMonth()),"m"===n||"f"===n)for(;r(i);)i=_.add_days(i,1);if("f"===n)return i;if("m"===n&&a===i.getMonth())return i;for("m"===n&&(i=_.add_days(i,-1));r(i);)i=_.add_days(i,-1);return i},_.add_business_days=function(e,t,r){for(var a=e,n=t;0<n;)a=_.adjust(_.add_days(a,1),"f",r),n--;return a}}(this.JsonRisk||module.exports),function(d){var h=null,f=function(e){var t=d.get_curve_times(e),r=e.dfs?Array.isArray(e.dfs[0])?e.dfs:[e.dfs]:null,a=e.zcs?Array.isArray(e.zcs[0])?e.zcs:[e.zcs]:null;if(!r){r=new Array(a.length);for(var n=0;n<a.length;n++){r[n]=new Array(a[n].length);for(var i=0;i<a[n].length;i++)r[n][i]=Math.pow(1+a[n][i],-t[i])}}return{times:t,dfs:r}},c=function(e){if(1!==e)if(1!==h.vector_length){if(e!==h.vector_length)throw new Error("vector_pricing: provided parameters need to have the same length or length one")}else h.vector_length=e};function i(e){var t=e.toLowerCase();if(t.endsWith("atm"))return 0;var r=t.match(/([+-][0-9]+)bp$/);return r.length<2?null:r[1]/1e4}function p(e,t){for(var r,a=[],n=0;n<t.length;n++)t[n].startsWith(e)&&t[n].length!==e.length&&null!==(r=i(t[n]))&&a.push({name:t[n],moneyness:r});return a.sort(function(e,t){return e.moneyness-t.moneyness}),a}d.store_params=function(e){var t,r,a,n,i,s,o,_,l,u;if((h={vector_length:1,scalars:{},curves:{},surfaces:{}}).valuation_date=d.get_safe_date(e.valuation_date),"object"==typeof e.scalars)for(t=Object.keys(e.scalars),r=0;r<t.length;r++)h.scalars[t[r]]=(a=e.scalars[t[r]],Array.isArray(a.value)?{value:a.value}:{value:[a.value]}),c(h.scalars[t[r]].value.length);if("object"==typeof e.curves)for(t=Object.keys(e.curves),r=0;r<t.length;r++)n=f(e.curves[t[r]]),i=(h.curves[t[r]]=n).dfs?n.dfs.length:n.zcs.length,c(i);if("object"==typeof e.surfaces){for(t=Object.keys(e.surfaces),r=0;r<t.length;r++)h.surfaces[t[r]]=(_=e.surfaces[t[r]],void 0,{expiries:(l=d.get_safe_surface(_)).expiries,terms:l.terms,values:Array.isArray(_.values[0][0])?_.values:[_.values]}),c(h.surfaces[t[r]].values.length);for(r=0;r<t.length;r++)if(0<(s=p(t[r],t)).length)for(h.surfaces[t[r]].smile=[],h.surfaces[t[r]].moneyness=[],o=0;o<s.length;o++)h.surfaces[t[r]].smile.push(h.surfaces[s[o].name]),h.surfaces[t[r]].moneyness.push(s[o].moneyness)}if("object"==typeof e.calendars)for(t=Object.keys(e.calendars),r=0;r<t.length;r++)u=e.calendars[t[r]],d.add_calendar(t[r],u.dates)},d.get_params=function(){return h},d.set_params=function(e){if("object"!=typeof e)throw new Error("vector_pricing: try to hard set invalid parameters. Use store_params to normalize and store params.");if("number"!=typeof e.vector_length)throw new Error("vector_pricing: try to hard set invalid parameters. Use store_params to normalize and store params.");h=e};var m=function(e,t){return e?{times:e.times,dfs:e.dfs?e.dfs[1<e.dfs.length?t:0]:null}:null},g=function(e,t,r){if(!e)return null;var a,n=e.expiries,i=e.terms,s=e.values[1<e.values.length?t:0],o=null,_=null;if(!0!==r&&Array.isArray(e.smile)&&Array.isArray(e.moneyness))for(_=e.moneyness,o=[],a=0;a<e.smile.length;a++)o.push(g(e.smile[a],t,!0));return{expiries:n,terms:i,values:s,moneyness:_,smile:o}};d.get_internal_object=function(e){switch(e.type.toLowerCase()){case"bond":case"floater":return new d.fixed_income(e);case"swap":return new d.swap(e);case"swaption":return new d.swaption(e);case"fxterm":return new d.fxterm(e);case"callable_bond":return new d.callable_fixed_income(e);default:throw new Error("get_internal_object: invalid instrument type")}},d.vector_pricer=function(e){if("string"!=typeof e.type)throw new Error("vector_pricer: instrument object must contain valid type");d.valuation_date=h.valuation_date;for(var t,r,a,n,i=d.get_internal_object(e),s=h.curves[e.disc_curve||""]||null,o=h.curves[e.spread_curve||""]||null,_=h.curves[e.fwd_curve||""]||null,l=h.surfaces[e.surface||""]||null,u=h.scalars[e.currency||""]||null,f=new Array(h.vector_length),c=0;c<h.vector_length;c++){switch(t=m(s,c),r=m(o,c),a=m(_,c),n=g(l,c),e.type.toLowerCase()){case"bond":case"floater":case"fxterm":case"irregular_bond":f[c]=i.present_value(t,r,a);break;case"swap":case"swaption":f[c]=i.present_value(t,a,n);break;case"callable_bond":f[c]=i.present_value(t,r,a,n)}if(e.currency&&"EUR"!==e.currency){if(!u)throw new Error("vector_pricer: cannot convert currency, scalar parameter not provided");f[c]/=u.value[1<u.value.length?c:0]}}return f}}(this.JsonRisk||module.exports);