diff --git a/src/QLNet/Handle.cs b/src/QLNet/Handle.cs
index c845a91ce..c3ba38cf3 100644
--- a/src/QLNet/Handle.cs
+++ b/src/QLNet/Handle.cs
@@ -24,7 +24,7 @@ namespace QLNet
pointer is relinked to another observable, the change will be propagated to all the copies.
registerAsObserver is not needed since C# does automatic garbage collection */
- public class Handle where T : IObservable
+ public class Handle where T : class, IObservable
{
protected Link link_;
@@ -41,7 +41,7 @@ public Handle(T h, bool registerAsObserver)
public T currentLink() { return link; }
// this one is instead of c++ -> and () operators overload
- public static implicit operator T(Handle ImpliedObject) { return ImpliedObject.link; }
+ public static implicit operator T(Handle impliedObject) { return impliedObject.link; }
public T link
{
@@ -153,7 +153,7 @@ protected void notifyObservers()
/*! An instance of this class can be relinked so that it points to another observable. The change will be propagated to all
handles that were created as copies of such instance. */
- public class RelinkableHandle : Handle where T : IObservable
+ public class RelinkableHandle : Handle where T : class, IObservable
{
public RelinkableHandle() : base(default(T), true) { }
diff --git a/src/QLNet/Math/Interpolations/MixedInterpolation.cs b/src/QLNet/Math/Interpolations/MixedInterpolation.cs
index 424501522..27de435d1 100644
--- a/src/QLNet/Math/Interpolations/MixedInterpolation.cs
+++ b/src/QLNet/Math/Interpolations/MixedInterpolation.cs
@@ -32,8 +32,8 @@ interpolation over the second part. */
}
public class MixedInterpolationImpl : Interpolation.templateImpl
- where Interpolator1 : IInterpolationFactory, new ()
- where Interpolator2 : IInterpolationFactory, new ()
+ where Interpolator1 : class, IInterpolationFactory, new ()
+ where Interpolator2 : class, IInterpolationFactory, new ()
{
public MixedInterpolationImpl(List xBegin, int xEnd,
List yBegin, int n,
@@ -41,8 +41,8 @@ public MixedInterpolationImpl(List xBegin, int xEnd,
Interpolator1 factory1 = default(Interpolator1),
Interpolator2 factory2 = default(Interpolator2))
: base(xBegin, xEnd, yBegin,
- Math.Max(factory1 == null ? (factory1 = new Interpolator1()).requiredPoints : factory1.requiredPoints,
- factory2 == null ? (factory2 = new Interpolator2()).requiredPoints : factory2.requiredPoints))
+ Math.Max(factory1?.requiredPoints ?? (factory1 = new Interpolator1()).requiredPoints,
+ factory2?.requiredPoints ?? (factory2 = new Interpolator2()).requiredPoints))
{
n_ = n;
diff --git a/src/QLNet/Math/Interpolations/SABRInterpolation.cs b/src/QLNet/Math/Interpolations/SABRInterpolation.cs
index 530c90b34..4838f00fd 100644
--- a/src/QLNet/Math/Interpolations/SABRInterpolation.cs
+++ b/src/QLNet/Math/Interpolations/SABRInterpolation.cs
@@ -111,7 +111,7 @@ public Vector inverse(Vector y, List b, List < double? > c, double d)
Vector x = new Vector(4);
x[0] = y[0] < 25.0 + eps1() ? Math.Sqrt(Math.Max(eps1(), y[0]) - eps1())
: (y[0] - eps1() + 25.0) / 10.0;
- x[1] = y[1] == 0.0 ? 0.0 : Math.Sqrt(-Math.Log(y[1]));
+ x[1] = y[1].IsEqual(0.0) ? 0.0 : Math.Sqrt(-Math.Log(y[1]));
x[2] = y[2] < 25.0 + eps1() ? Math.Sqrt(y[2] - eps1())
: (y[2] - eps1() + 25.0) / 10.0;
x[3] = Math.Asin(y[3] / eps2());
@@ -123,7 +123,7 @@ public Vector direct(Vector x, List b, List < double? > c, double d)
y[0] = Math.Abs(x[0]) < 5.0
? x[0] * x[0] + eps1()
: (10.0 * Math.Abs(x[0]) - 25.0) + eps1();
- y[1] = Math.Abs(x[1]) < Math.Sqrt(-Math.Log(eps1())) && x[1] != 0.0
+ y[1] = Math.Abs(x[1]) < Math.Sqrt(-Math.Log(eps1())) && x[1].IsNotEqual(0.0)
? Math.Exp(-(x[1] * x[1]))
: (volatilityType_ == VolatilityType.ShiftedLognormal ? eps1() : 0.0);
y[2] = Math.Abs(x[2]) < 5.0
@@ -142,7 +142,7 @@ public IWrapper instance(double t, double forward, List < double? > param, List
}
public double weight(double strike, double forward, double stdDev, List < double? > addParams)
{
- if (Convert.ToDouble(addParams[1]) == 0.0)
+ if (Convert.ToDouble(addParams[1]).IsEqual(0.0))
return Utils.blackFormulaStdDevDerivative(strike, forward, stdDev, 1.0, addParams[0].Value);
else
return Utils.bachelierBlackFormulaStdDevDerivative(strike, forward, stdDev, 1.0);
diff --git a/src/QLNet/Math/randomnumbers/RNGTraits.cs b/src/QLNet/Math/randomnumbers/RNGTraits.cs
index 5e54997f5..8401e5de8 100644
--- a/src/QLNet/Math/randomnumbers/RNGTraits.cs
+++ b/src/QLNet/Math/randomnumbers/RNGTraits.cs
@@ -34,7 +34,7 @@ public interface IRSG
}
// random number traits
- public class GenericPseudoRandom : IRSG where URNG : IRNGTraits, new () where IC : IValue, new ()
+ public class GenericPseudoRandom : IRSG where URNG : IRNGTraits, new () where IC : class, IValue, new ()
{
// data
private static IC icInstance_ = FastActivator.Create();
diff --git a/src/QLNet/Methods/Finitedifferences/FiniteDifferenceModel.cs b/src/QLNet/Methods/Finitedifferences/FiniteDifferenceModel.cs
index 40aefc94d..090cd7841 100644
--- a/src/QLNet/Methods/Finitedifferences/FiniteDifferenceModel.cs
+++ b/src/QLNet/Methods/Finitedifferences/FiniteDifferenceModel.cs
@@ -66,7 +66,7 @@ private void rollbackImpl(ref object o, double from, double to, int steps, IStep
double dt = (from - to) / steps, t = from;
evolver_.setStep(dt);
- if (!stoppingTimes_.empty() && stoppingTimes_.Last() == from)
+ if (!stoppingTimes_.empty() && stoppingTimes_.Last().IsEqual(from))
{
if (condition != null)
condition.applyTo(o, from);
diff --git a/src/QLNet/Methods/Finitedifferences/Operators/TripleBandLinearOp.cs b/src/QLNet/Methods/Finitedifferences/Operators/TripleBandLinearOp.cs
index 4b2012f07..636c0d656 100644
--- a/src/QLNet/Methods/Finitedifferences/Operators/TripleBandLinearOp.cs
+++ b/src/QLNet/Methods/Finitedifferences/Operators/TripleBandLinearOp.cs
@@ -130,9 +130,9 @@ public Vector solve_splitting(Vector r, double a, double b = 1.0)
{
List coordinates = iter.coordinates();
Utils.QL_REQUIRE(coordinates[direction_] != 0
- || lower_[iter.index()] == 0, () => "removing non zero entry!");
+ || lower_[iter.index()].IsEqual(0), () => "removing non zero entry!");
Utils.QL_REQUIRE(coordinates[direction_] != layout.dim()[direction_] - 1
- || upper_[iter.index()] == 0, () => "removing non zero entry!");
+ || upper_[iter.index()].IsEqual(0), () => "removing non zero entry!");
}
Vector retVal = new Vector(r.size()), tmp = new Vector(r.size());
@@ -142,7 +142,7 @@ public Vector solve_splitting(Vector r, double a, double b = 1.0)
// changed to fit for the triple band operator.
int rim1 = reverseIndex_[0];
double bet = 1.0 / (a * diag_[rim1] + b);
- Utils.QL_REQUIRE(bet != 0.0, () => "division by zero");
+ Utils.QL_REQUIRE(bet.IsNotEqual(0.0), () => "division by zero");
retVal[reverseIndex_[0]] = r[rim1] * bet;
for (int j = 1; j <= layout.size() - 1; j++)
@@ -151,7 +151,7 @@ public Vector solve_splitting(Vector r, double a, double b = 1.0)
tmp[j] = a * upper_[rim1] * bet;
bet = b + a * (diag_[ri] - tmp[j] * lower_[ri]);
- Utils.QL_REQUIRE(bet != 0.0, () => "division by zero"); //QL_ENSURE
+ Utils.QL_REQUIRE(bet.IsNotEqual(0.0), () => "division by zero"); //QL_ENSURE
bet = 1.0 / bet;
retVal[ri] = (r[ri] - a * lower_[ri] * retVal[rim1]) * bet;
diff --git a/src/QLNet/Methods/Finitedifferences/Schemes/CrankNicolsonScheme.cs b/src/QLNet/Methods/Finitedifferences/Schemes/CrankNicolsonScheme.cs
index 19d78ca96..505b174ee 100644
--- a/src/QLNet/Methods/Finitedifferences/Schemes/CrankNicolsonScheme.cs
+++ b/src/QLNet/Methods/Finitedifferences/Schemes/CrankNicolsonScheme.cs
@@ -59,10 +59,10 @@ public IMixedScheme factory(object L, object bcs, object[] additionalInputs = nu
public void step(ref object a, double t, double theta = 1.0)
{
Utils.QL_REQUIRE(t - dt_ > -1e-8, () => "a step towards negative time given");
- if (theta_ != 1.0)
+ if (theta_.IsNotEqual(1.0))
explicit_.step(ref a, t, 1.0 - theta_);
- if (theta_ != 0.0)
+ if (theta_.IsNotEqual(0.0))
implicit_.step(ref a, t, theta_);
}
diff --git a/src/QLNet/Methods/Finitedifferences/StepConditions/FdmSnapshotCondition.cs b/src/QLNet/Methods/Finitedifferences/StepConditions/FdmSnapshotCondition.cs
index 751d7bf79..5f19c992c 100644
--- a/src/QLNet/Methods/Finitedifferences/StepConditions/FdmSnapshotCondition.cs
+++ b/src/QLNet/Methods/Finitedifferences/StepConditions/FdmSnapshotCondition.cs
@@ -32,7 +32,7 @@ public FdmSnapshotCondition(double t)
public void applyTo(object o, double t)
{
- if (t == t_)
+ if (t.IsEqual(t_))
values_ = (Vector)o;
}
diff --git a/src/QLNet/Methods/Finitedifferences/Utilities/FdmInnerValueCalculator.cs b/src/QLNet/Methods/Finitedifferences/Utilities/FdmInnerValueCalculator.cs
index 6d00c844a..561bc0088 100644
--- a/src/QLNet/Methods/Finitedifferences/Utilities/FdmInnerValueCalculator.cs
+++ b/src/QLNet/Methods/Finitedifferences/Utilities/FdmInnerValueCalculator.cs
@@ -89,8 +89,7 @@ protected double avgInnerValueCalc(FdmLinearOpIterator iter, double t)
double retVal;
try
{
- double acc
- = ((f(a) != 0.0 || f(b) != 0.0) ? (f(a) + f(b)) * 5e-5 : 1e-4);
+ double acc = ((f(a).IsNotEqual(0.0) || f(b).IsNotEqual(0.0)) ? (f(a) + f(b)) * 5e-5 : 1e-4);
retVal = new SimpsonIntegral(acc, 8).value(f, a, b) / (b - a);
}
catch
diff --git a/src/QLNet/Pricingengines/Bond/TreeCallableBondEngine.cs b/src/QLNet/Pricingengines/Bond/TreeCallableBondEngine.cs
index 5d2853b81..fa418a7f7 100644
--- a/src/QLNet/Pricingengines/Bond/TreeCallableBondEngine.cs
+++ b/src/QLNet/Pricingengines/Bond/TreeCallableBondEngine.cs
@@ -77,7 +77,7 @@ private void calculateWithSpread(double s)
lattice = model_.link.tree(timeGrid);
}
- if (s != 0.0)
+ if (s.IsNotEqual(0.0))
{
var sr = lattice as OneFactorModel.ShortRateTree;
Utils.QL_REQUIRE(sr != null, () => "Spread is not supported for trees other than OneFactorModel");
diff --git a/src/QLNet/Pricingengines/GenericModelEngine.cs b/src/QLNet/Pricingengines/GenericModelEngine.cs
index 09fcee7df..8717851c4 100644
--- a/src/QLNet/Pricingengines/GenericModelEngine.cs
+++ b/src/QLNet/Pricingengines/GenericModelEngine.cs
@@ -25,7 +25,7 @@ public class GenericModelEngine
: GenericEngine
where ArgumentsType : IPricingEngineArguments, new ()
where ResultsType : IPricingEngineResults, new ()
- where ModelType : IObservable
+ where ModelType : class,IObservable
{
public GenericModelEngine() { }
public GenericModelEngine(Handle model)
diff --git a/src/QLNet/Pricingengines/vanilla/FDMultiPeriodEngine.cs b/src/QLNet/Pricingengines/vanilla/FDMultiPeriodEngine.cs
index 4b1c0a013..022554bb0 100644
--- a/src/QLNet/Pricingengines/vanilla/FDMultiPeriodEngine.cs
+++ b/src/QLNet/Pricingengines/vanilla/FDMultiPeriodEngine.cs
@@ -168,7 +168,7 @@ public override void calculate(IPricingEngineResults r)
if (firstDateIsZero)
executeIntermediateStep(0);
- results.value = prices_.valueAtCenter();
+ results!.value = prices_.valueAtCenter();
results.delta = prices_.firstDerivativeAtCenter();
results.gamma = prices_.secondDerivativeAtCenter();
results.additionalResults["priceCurve"] = prices_;
diff --git a/src/QLNet/Termstructures/Bootstraphelper.cs b/src/QLNet/Termstructures/Bootstraphelper.cs
index 7ab2efd8a..a39993fe4 100644
--- a/src/QLNet/Termstructures/Bootstraphelper.cs
+++ b/src/QLNet/Termstructures/Bootstraphelper.cs
@@ -38,6 +38,7 @@ public enum Choice
* class to ensure consistancy between the algorithms used during bootstrapping
and later instrument pricing. This is not yet fully enforced in the available rate helpers. */
public class BootstrapHelper : IObservable, IObserver
+ where TS : class
{
protected Handle quote_;
protected TS termStructure_;
diff --git a/src/QLNet/Termstructures/Credit/InterpolatedHazardRateCurve.cs b/src/QLNet/Termstructures/Credit/InterpolatedHazardRateCurve.cs
index a622f9b10..bcb3a28be 100644
--- a/src/QLNet/Termstructures/Credit/InterpolatedHazardRateCurve.cs
+++ b/src/QLNet/Termstructures/Credit/InterpolatedHazardRateCurve.cs
@@ -23,7 +23,7 @@ under the terms of the QLNet license. You should have received a
namespace QLNet
{
public class InterpolatedHazardRateCurve : HazardRateStructure, InterpolatedCurve
- where Interpolator : IInterpolationFactory, new ()
+ where Interpolator : class, IInterpolationFactory, new ()
{
public InterpolatedHazardRateCurve(List dates, List hazardRates, DayCounter dayCounter, Calendar cal = null,
List> jumps = null, List jumpDates = null, Interpolator interpolator = default(Interpolator))
diff --git a/src/QLNet/Termstructures/Curve.cs b/src/QLNet/Termstructures/Curve.cs
index 9aa5863b1..c28530ec9 100644
--- a/src/QLNet/Termstructures/Curve.cs
+++ b/src/QLNet/Termstructures/Curve.cs
@@ -21,6 +21,7 @@ under the terms of the QLNet license. You should have received a
namespace QLNet
{
public interface Curve : ITraits, InterpolatedCurve
+ where T : class
{
#region ITraits
@@ -44,4 +45,4 @@ public interface Curve : ITraits, InterpolatedCurve
double initialValue();
}
-}
\ No newline at end of file
+}
diff --git a/src/QLNet/Termstructures/Inflation/PiecewiseYoYInflationCurve.cs b/src/QLNet/Termstructures/Inflation/PiecewiseYoYInflationCurve.cs
index 0b455765a..776783c1b 100644
--- a/src/QLNet/Termstructures/Inflation/PiecewiseYoYInflationCurve.cs
+++ b/src/QLNet/Termstructures/Inflation/PiecewiseYoYInflationCurve.cs
@@ -210,8 +210,8 @@ public PiecewiseYoYInflationCurve()
public class PiecewiseYoYInflationCurve : PiecewiseYoYInflationCurve
where Traits : ITraits, new ()
- where Interpolator : IInterpolationFactory, new ()
- where Bootstrap : IBootStrap, new ()
+ where Interpolator : class, IInterpolationFactory, new ()
+ where Bootstrap : class, IBootStrap, new ()
{
public PiecewiseYoYInflationCurve(Date referenceDate,
@@ -288,7 +288,7 @@ public override Dictionary nodes()
// Allows for optional 3rd generic parameter defaulted to IterativeBootstrap
public class PiecewiseYoYInflationCurve : PiecewiseYoYInflationCurve
- where Interpolator : IInterpolationFactory, new ()
+ where Interpolator : class, IInterpolationFactory, new ()
{
public PiecewiseYoYInflationCurve(Date referenceDate,
Calendar calendar,
diff --git a/src/QLNet/Termstructures/Inflation/PiecewiseZeroInflationCurve.cs b/src/QLNet/Termstructures/Inflation/PiecewiseZeroInflationCurve.cs
index 292201a05..63bbe187e 100644
--- a/src/QLNet/Termstructures/Inflation/PiecewiseZeroInflationCurve.cs
+++ b/src/QLNet/Termstructures/Inflation/PiecewiseZeroInflationCurve.cs
@@ -217,8 +217,8 @@ public PiecewiseZeroInflationCurve()
public class PiecewiseZeroInflationCurve : PiecewiseZeroInflationCurve
where Traits : ITraits, new ()
- where Interpolator : IInterpolationFactory, new ()
- where Bootstrap : IBootStrap, new ()
+ where Interpolator : class, IInterpolationFactory, new ()
+ where Bootstrap : class, IBootStrap, new ()
{
public PiecewiseZeroInflationCurve(Date referenceDate,
@@ -296,7 +296,7 @@ public override Dictionary nodes()
// Allows for optional 3rd generic parameter defaulted to IterativeBootstrap
public class PiecewiseZeroInflationCurve : PiecewiseZeroInflationCurve
- where Interpolator : IInterpolationFactory, new ()
+ where Interpolator : class, IInterpolationFactory, new ()
{
public PiecewiseZeroInflationCurve(Date referenceDate,
Calendar calendar,
diff --git a/src/QLNet/Utils.cs b/src/QLNet/Utils.cs
index 76d041218..5d909d233 100644
--- a/src/QLNet/Utils.cs
+++ b/src/QLNet/Utils.cs
@@ -174,7 +174,7 @@ public static MethodInfo GetMethodInfo(Object t, String function, Type[] types
// this is a redefined collection class to emulate array-type behaviour at initialisation
// if T is a class then the list is initilized with default constructors instead of null
- public class InitializedList : List where T : new ()
+ public class InitializedList : List where T : new ()
{
public InitializedList() : base() { }
public InitializedList(int size) : base(size)