public DigitalReplication(Replication.Type t = Replication.Type.Central, double gap = 1e-4) { gap_ = gap; replicationType_ = t; }
//! \name Constructors //@{ //! general constructor public DigitalCoupon(FloatingRateCoupon underlying, double? callStrike = null, Position.Type callPosition = Position.Type.Long, bool isCallATMIncluded = false, double? callDigitalPayoff = null, double? putStrike = null, Position.Type putPosition = Position.Type.Long, bool isPutATMIncluded = false, double? putDigitalPayoff = null, DigitalReplication replication = null) : base(underlying.nominal(), underlying.Date, underlying.accrualStartDate(), underlying.accrualEndDate(), underlying.fixingDays, underlying.index(), underlying.gearing(), underlying.spread(), underlying.refPeriodStart, underlying.refPeriodEnd, underlying.dayCounter(), underlying.isInArrears()) { if (replication == null) replication = new DigitalReplication(); underlying_ = underlying; callCsi_ = 0.0; putCsi_ = 0.0; isCallATMIncluded_ = isCallATMIncluded; isPutATMIncluded_ = isPutATMIncluded; isCallCashOrNothing_ = false; isPutCashOrNothing_ = false; callLeftEps_ = replication.gap() / 2.0; callRightEps_ = replication.gap() / 2.0; putLeftEps_ = replication.gap() / 2.0; putRightEps_ = replication.gap() / 2.0; hasPutStrike_ = false; hasCallStrike_ = false; replicationType_ = replication.replicationType(); if (!(replication.gap() > 0.0)) throw new ApplicationException("Non positive epsilon not allowed"); if (putStrike == null) if (!(putDigitalPayoff == null)) throw new ApplicationException("Put Cash rate non allowed if put strike is null"); if (callStrike == null) if (!(callDigitalPayoff == null)) throw new ApplicationException("Call Cash rate non allowed if call strike is null"); if (callStrike != null) { if (!(callStrike >= 0.0)) throw new ApplicationException("negative call strike not allowed"); hasCallStrike_ = true; callStrike_ = callStrike.GetValueOrDefault(); if (!(callStrike_ >= replication.gap() / 2.0)) throw new ApplicationException("call strike < eps/2"); switch (callPosition) { case Position.Type.Long: callCsi_ = 1.0; break; case Position.Type.Short: callCsi_ = -1.0; break; default: throw new ApplicationException("unsupported position type"); } if (callDigitalPayoff != null) { callDigitalPayoff_ = callDigitalPayoff.GetValueOrDefault(); isCallCashOrNothing_ = true; } } if (putStrike != null) { if (!(putStrike >= 0.0)) throw new ApplicationException("negative put strike not allowed"); hasPutStrike_ = true; putStrike_ = putStrike.GetValueOrDefault(); switch (putPosition) { case Position.Type.Long: putCsi_ = 1.0; break; case Position.Type.Short: putCsi_ = -1.0; break; default: throw new ApplicationException("unsupported position type"); } if (putDigitalPayoff != null) { putDigitalPayoff_ = putDigitalPayoff.GetValueOrDefault(); isPutCashOrNothing_ = true; } } switch (replicationType_) { case Replication.Type.Central: // do nothing break; case Replication.Type.Sub: if (hasCallStrike_) { switch (callPosition) { case Position.Type.Long: callLeftEps_ = 0.0; callRightEps_ = replication.gap(); break; case Position.Type.Short: callLeftEps_ = replication.gap(); callRightEps_ = 0.0; break; default: throw new ApplicationException("unsupported position type"); } } if (hasPutStrike_) { switch (putPosition) { case Position.Type.Long: putLeftEps_ = replication.gap(); putRightEps_ = 0.0; break; case Position.Type.Short: putLeftEps_ = 0.0; putRightEps_ = replication.gap(); break; default: throw new ApplicationException("unsupported position type"); } } break; case Replication.Type.Super: if (hasCallStrike_) { switch (callPosition) { case Position.Type.Long: callLeftEps_ = replication.gap(); callRightEps_ = 0.0; break; case Position.Type.Short: callLeftEps_ = 0.0; callRightEps_ = replication.gap(); break; default: throw new ApplicationException("unsupported position type"); } } if (hasPutStrike_) { switch (putPosition) { case Position.Type.Long: putLeftEps_ = 0.0; putRightEps_ = replication.gap(); break; case Position.Type.Short: putLeftEps_ = replication.gap(); putRightEps_ = 0.0; break; default: throw new ApplicationException("unsupported position type"); } } break; default: throw new ApplicationException("unsupported position type"); } underlying.registerWith(update); }