Skip to content

Commit

Permalink
Merged Constatns.BasisPoint into Const.BASIS_POINT
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermilla committed May 6, 2019
1 parent 182c17e commit 0d0abe5
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/QLNet/Cashflows/CashFlows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public static double bps(Leg leg, YieldTermStructure discountCurve, bool include
!leg[i].tradingExCoupon(settlementDate))
leg[i].accept(calc);
}
return Constants.BasisPoint * calc.bps() / discountCurve.discount(npvDate);
return Const.BASIS_POINT * calc.bps() / discountCurve.discount(npvDate);
}
//! NPV and BPS of the cash flows.
// The NPV and BPS of the cash flows calculated together for performance reason
Expand Down Expand Up @@ -745,7 +745,7 @@ public static void npvbps(Leg leg, YieldTermStructure discountCurve, bool includ
}
double d = discountCurve.discount(npvDate);
npv /= d;
bps = Constants.BasisPoint * bps / d;
bps = Const.BASIS_POINT * bps / d;
}

// At-the-money rate of the cash flows.
Expand Down
2 changes: 1 addition & 1 deletion src/QLNet/Cashflows/ConundrumPricer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public override void initialize(FloatingRateCoupon coupon)

swapRateValue_ = swap.fairRate();

annuity_ = Math.Abs(swap.fixedLegBPS() /Constants.BasisPoint);
annuity_ = Math.Abs(swap.fixedLegBPS() /Const.BASIS_POINT);

int q = (int)swapIndex.fixedLegTenor().frequency();
Schedule schedule = swap.fixedSchedule();
Expand Down
8 changes: 0 additions & 8 deletions src/QLNet/Constants.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/QLNet/Instruments/AssetSwap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public double fairSpread()
}
else if (legBPS_.Count > 1 && legBPS_[1] != null)
{
fairSpread_ = spread_ - NPV_ / legBPS_[1] * Constants.BasisPoint;
fairSpread_ = spread_ - NPV_ / legBPS_[1] * Const.BASIS_POINT;
return fairSpread_.Value;
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Instruments/BMASwap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ public double liborLegNPV()

public double fairLiborFraction()
{
double spreadNPV = (liborSpread_ / Constants.BasisPoint) * liborLegBPS();
double spreadNPV = (liborSpread_ / Const.BASIS_POINT) * liborLegBPS();
double pureLiborNPV = liborLegNPV() - spreadNPV;
Utils.QL_REQUIRE(pureLiborNPV.IsNotEqual(0.0), () => "result not available (null libor NPV)");
return -liborFraction_ * (bmaLegNPV() + spreadNPV) / pureLiborNPV;
}

public double fairLiborSpread()
{
return liborSpread_ - NPV() / (liborLegBPS() / Constants.BasisPoint);
return liborSpread_ - NPV() / (liborLegBPS() / Const.BASIS_POINT);
}

public double bmaLegBPS()
Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Instruments/BasisSwap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ public override void fetchResults(IPricingEngineResults r)
// Long fair spread should be fine - no averaging or compounding
if (fairLongSpread_ == null && legBPS_[longNo_] != null)
{
fairLongSpread_ = longSpread_ - NPV_ / (legBPS_[longNo_] / Constants.BasisPoint);
fairLongSpread_ = longSpread_ - NPV_ / (legBPS_[longNo_] / Const.BASIS_POINT);
}

/* Short fair spread calculation ok if no averaging/compounding OR
if there is averaging/compounding and the spread is added after */
if (fairShortSpread_ == null && legBPS_[shortNo_] != null)
{
fairShortSpread_ = shortSpread_ - NPV_ / (legBPS_[shortNo_] / Constants.BasisPoint);
fairShortSpread_ = shortSpread_ - NPV_ / (legBPS_[shortNo_] / Const.BASIS_POINT);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Instruments/CPISwap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ public override void fetchResults(IPricingEngineResults r)
{
// calculate it from other results
if (legBPS_[0] != null)
fairRate_ = fixedRate_ - NPV_ / (legBPS_[0] / Constants.BasisPoint);
fairRate_ = fixedRate_ - NPV_ / (legBPS_[0] / Const.BASIS_POINT);
}
if (fairSpread_ == null)
{
// ditto
if (legBPS_[1] != null)
fairSpread_ = spread_ - NPV_ / (legBPS_[1] / Constants.BasisPoint);
fairSpread_ = spread_ - NPV_ / (legBPS_[1] / Const.BASIS_POINT);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Instruments/OvernightIndexedSwap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ public OvernightIndexedSwap(Type type,
public double? fairRate()
{
calculate();
return fixedRate_ - NPV_ / (fixedLegBPS() / Constants.BasisPoint);
return fixedRate_ - NPV_ / (fixedLegBPS() / Const.BASIS_POINT);
}

public double? fairSpread()
{
calculate();
return spread_ - NPV_ / (overnightLegBPS() / Constants.BasisPoint);
return spread_ - NPV_ / (overnightLegBPS() / Const.BASIS_POINT);
}

public double? fixedLegBPS()
Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Instruments/VanillaSwap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ public override void fetchResults(IPricingEngineResults r)
{
// calculate it from other results
if (legBPS_[0] != null)
fairRate_ = fixedRate_ - NPV_.GetValueOrDefault() / (legBPS_[0] / Constants.BasisPoint);
fairRate_ = fixedRate_ - NPV_.GetValueOrDefault() / (legBPS_[0] / Const.BASIS_POINT);
}
if (fairSpread_ == null)
{
// ditto
if (legBPS_[1] != null)
fairSpread_ = spread_ - NPV_.GetValueOrDefault() / (legBPS_[1] / Constants.BasisPoint);
fairSpread_ = spread_ - NPV_.GetValueOrDefault() / (legBPS_[1] / Const.BASIS_POINT);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Instruments/YearOnYearInflationSwap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ public override void fetchResults(IPricingEngineResults r)
{
// calculate it from other results
if (legBPS_[0] != null)
fairRate_ = fixedRate_ - NPV_ / (legBPS_[0] / Constants.BasisPoint);
fairRate_ = fixedRate_ - NPV_ / (legBPS_[0] / Const.BASIS_POINT);
}
if (fairSpread_ == null)
{
// ditto
if (legBPS_[1] != null)
fairSpread_ = spread_ - NPV_ / (legBPS_[1] / Constants.BasisPoint);
fairSpread_ = spread_ - NPV_ / (legBPS_[1] / Const.BASIS_POINT);
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Pricingengines/credit/IntegralCdsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public override void calculate()
if (arguments_.spread.IsNotEqual(0.0))
{
results_.couponLegBPS =
results_.couponLegNPV * Constants.BasisPoint / arguments_.spread;
results_.couponLegNPV * Const.BASIS_POINT / arguments_.spread;
}
else
{
Expand All @@ -187,7 +187,7 @@ public override void calculate()
if (arguments_.upfront.HasValue && arguments_.upfront.IsNotEqual(0.0))
{
results_.upfrontBPS =
results_.upfrontNPV * Constants.BasisPoint / (arguments_.upfront.Value);
results_.upfrontNPV * Const.BASIS_POINT / (arguments_.upfront.Value);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Pricingengines/credit/IsdaCdsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public override void calculate()
if (arguments_.spread.IsNotEqual(0.0))
{
results_.couponLegBPS =
results_.couponLegNPV * Constants.BasisPoint / arguments_.spread;
results_.couponLegNPV * Const.BASIS_POINT / arguments_.spread;
}
else
{
Expand All @@ -411,7 +411,7 @@ public override void calculate()
if (arguments_.upfront != null && arguments_.upfront.IsNotEqual(0.0))
{
results_.upfrontBPS =
results_.upfrontNPV * Constants.BasisPoint / (arguments_.upfront);
results_.upfrontNPV * Const.BASIS_POINT / (arguments_.upfront);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Pricingengines/credit/MidPointCdsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public override void calculate()
if (arguments_.spread.IsNotEqual(0.0))
{
results_.couponLegBPS =
results_.couponLegNPV * Constants.BasisPoint / arguments_.spread.Value;
results_.couponLegNPV * Const.BASIS_POINT / arguments_.spread.Value;
}
else
{
Expand All @@ -178,7 +178,7 @@ public override void calculate()
if (arguments_.upfront.HasValue && arguments_.upfront.IsNotEqual(0.0))
{
results_.upfrontBPS =
results_.upfrontNPV * Constants.BasisPoint / (arguments_.upfront.Value);
results_.upfrontNPV * Const.BASIS_POINT / (arguments_.upfront.Value);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Pricingengines/swaption/BlackSwaptionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public override void calculate()
(arguments_.settlementType == Settlement.Type.Cash &&
arguments_.settlementMethod == Settlement.Method.CollateralizedCashPrice))
{
annuity = Math.Abs(swap.fixedLegBPS()) / Constants.BasisPoint;
annuity = Math.Abs(swap.fixedLegBPS()) / Const.BASIS_POINT;
}
else if (arguments_.settlementType == Settlement.Type.Cash &&
arguments_.settlementMethod == Settlement.Method.ParYieldCurve)
Expand All @@ -157,7 +157,7 @@ public override void calculate()
new InterestRate(atmForward, dayCount, Compounding.Compounded, Frequency.Annual), false,
discountDate);

annuity = Math.Abs(fixedLegCashBPS / Constants.BasisPoint) * discountCurve_.link.discount(discountDate);
annuity = Math.Abs(fixedLegCashBPS / Const.BASIS_POINT) * discountCurve_.link.discount(discountDate);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/QLNet/Termstructures/Yield/Ratehelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,9 @@ public override double impliedQuote()
// weak implementation... to be improved
double floatingLegNPV = swap_.floatingLegNPV();
double spread = this.spread();
double spreadNPV = swap_.floatingLegBPS() / Constants.BasisPoint * spread;
double spreadNPV = swap_.floatingLegBPS() / Const.BASIS_POINT * spread;
double totNPV = -(floatingLegNPV + spreadNPV);
double result = totNPV / (swap_.fixedLegBPS() / Constants.BasisPoint);
double result = totNPV / (swap_.fixedLegBPS() / Const.BASIS_POINT);
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions src/QLNet/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public struct Const
public const double M_PI = 3.141592653589793238462643383280;
public const double M_PI_2 = 1.57079632679489661923;
public const double M_2_PI = 0.636619772367581343076;

public static double BASIS_POINT = 1.0e-4;
}

public class TimeSeries<T> : IDictionary<Date, T>
Expand Down
2 changes: 1 addition & 1 deletion src/QLNet/legacy/libormarketmodels/LfmSwaptionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override void calculate()
Option.Type.Call : Option.Type.Put;
double vol = volatility.volatility(exercise, swapLength,
fairRate, true);
results_.value = (swap.fixedLegBPS() / Constants.BasisPoint) *
results_.value = (swap.fixedLegBPS() / Const.BASIS_POINT) *
Utils.blackFormula(w, fixedRate, fairRate, vol * Math.Sqrt(exercise));
}
}
Expand Down

0 comments on commit 0d0abe5

Please sign in to comment.