Skip to content

Commit

Permalink
More code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Drawaes committed Apr 29, 2022
1 parent c953124 commit 907ea69
Show file tree
Hide file tree
Showing 375 changed files with 1,155 additions and 2,023 deletions.
12 changes: 6 additions & 6 deletions src/Qwack.Core/Basic/BarrierType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ namespace Qwack.Core.Basic
{
public enum BarrierType
{
KO=0,
KnockOut=0,
Out=0,
KI=1,
KnockIn=1,
In=1
KO = 0,
KnockOut = 0,
Out = 0,
KI = 1,
KnockIn = 1,
In = 1
}

public enum BarrierObservationType
Expand Down
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/BaseMetrics.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum BaseMetric
Expand Down
8 changes: 2 additions & 6 deletions src/Qwack.Core/Basic/BaselMethods.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum BaselMethods
{
Basel_II_Standardized = 0,
II_SM =0,
II_SM = 0,
Basel_II_InternalModel = 1,
II_IMM = 1,
Basel_III_Standardized= 2,
Basel_III_Standardized = 2,
III_SM = 2,
Basel_III_InternalModel = 3,
III_IMM = 3,
Expand Down
4 changes: 1 addition & 3 deletions src/Qwack.Core/Basic/BasketDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using Qwack.Transport.BasicTypes;

namespace Qwack.Core.Basic
{
public class BasketDefinition
{
public Dictionary<string,double> BasketWeights { get; set; }
public Dictionary<string, double> BasketWeights { get; set; }
public BasketType BasketType { get; set; }
public int NthModifier { get; set; } //for Nth BestOf/WorstOf use

Expand Down
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/BasketType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Qwack.Core/Basic/Capital/SaCcrParameters.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Qwack.Transport.BasicTypes;

namespace Qwack.Core.Basic.Capital
Expand Down
12 changes: 4 additions & 8 deletions src/Qwack.Core/Basic/CompositeVolType.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum CompositeVolType
{
Margrabe=0,
Black=0,
AssetSkewOnly=1,
FxSkewOnly=2,
Margrabe = 0,
Black = 0,
AssetSkewOnly = 1,
FxSkewOnly = 2,

}
}
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/Consts.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public static class Consts
Expand Down
3 changes: 0 additions & 3 deletions src/Qwack.Core/Basic/Correlation/CorrelationMatrix.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Qwack.Core.Models;
using Qwack.Transport.BasicTypes;
using Qwack.Transport.TransportObjects.MarketData.Correlations;

namespace Qwack.Core.Basic.Correlation
Expand Down
14 changes: 5 additions & 9 deletions src/Qwack.Core/Basic/Correlation/CorrelationMatrixCollection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Qwack.Core.Models;
using Qwack.Transport.BasicTypes;
using Qwack.Transport.TransportObjects.MarketData.Correlations;

namespace Qwack.Core.Basic.Correlation
Expand All @@ -21,14 +17,14 @@ public class CorrelationMatrixCollection : ICorrelationMatrix

public double GetCorrelation(string label1, string label2, double t = 0)
{
foreach(var m in Matrices)
foreach (var m in Matrices)
{
if (m.TryGetCorrelation(label1, label2, out var correl, t))
return correl;
}
return 0;
}

public bool TryGetCorrelation(string label1, string label2, out double correl, double t = 0)
{
foreach (var m in Matrices)
Expand All @@ -44,15 +40,15 @@ public bool TryGetCorrelation(string label1, string label2, out double correl, d
return false;
}

public ICorrelationMatrix Clone() => new CorrelationMatrixCollection(Matrices.Select(x=>x.Clone()).ToArray());
public ICorrelationMatrix Clone() => new CorrelationMatrixCollection(Matrices.Select(x => x.Clone()).ToArray());

public ICorrelationMatrix Bump(double epsilon) => new CorrelationMatrixCollection(Matrices.Select(x => x.Bump(epsilon)).ToArray());


public TO_CorrelationMatrix GetTransportObject() =>
new()
{
Children = Matrices.Select(x=>GetTransportObject()).ToArray(),
Children = Matrices.Select(x => GetTransportObject()).ToArray(),
};
}
}
10 changes: 4 additions & 6 deletions src/Qwack.Core/Basic/Correlation/CorrelationMatrixFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Qwack.Core.Models;
using Qwack.Transport.TransportObjects.MarketData.Correlations;

Expand All @@ -10,11 +8,11 @@ namespace Qwack.Core.Basic.Correlation
public static class CorrelationMatrixFactory
{
public static ICorrelationMatrix GetCorrelationMatrix(this TO_CorrelationMatrix transportObject) =>
transportObject.Children!=null?
(ICorrelationMatrix) new CorrelationMatrixCollection(transportObject.Children.Select(x=>x.GetCorrelationMatrix()).ToArray()) :
transportObject.Children != null ?
(ICorrelationMatrix)new CorrelationMatrixCollection(transportObject.Children.Select(x => x.GetCorrelationMatrix()).ToArray()) :
transportObject.IsTimeVector ?
(ICorrelationMatrix) new CorrelationTimeVector(transportObject.LabelsX[0], transportObject.LabelsY, transportObject.Correlations, transportObject.Times, transportObject.InterpolatorType) :
(ICorrelationMatrix) new CorrelationMatrix(transportObject.LabelsX, transportObject.LabelsY, transportObject.Correlations);
(ICorrelationMatrix)new CorrelationTimeVector(transportObject.LabelsX[0], transportObject.LabelsY, transportObject.Correlations, transportObject.Times, transportObject.InterpolatorType) :
(ICorrelationMatrix)new CorrelationMatrix(transportObject.LabelsX, transportObject.LabelsY, transportObject.Correlations);

public static TO_CorrelationMatrix GetTransportObject(this ICorrelationMatrix matrix) => matrix switch
{
Expand Down
2 changes: 0 additions & 2 deletions src/Qwack.Core/Basic/Correlation/CorrelationTimeVector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Qwack.Core.Models;
using Qwack.Math;
using Qwack.Math.Interpolation;
Expand Down
8 changes: 4 additions & 4 deletions src/Qwack.Core/Basic/Currency.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class Currency
private readonly ICalendarProvider _calendarProvider;

public Currency(ICalendarProvider calendarProvider) => _calendarProvider = calendarProvider;
public string Ccy { get; set;}
public DayCountBasis DayCount { get; set;}

public string Ccy { get; set; }
public DayCountBasis DayCount { get; set; }
public Calendar SettlementCalendar => _calendarProvider.Collection[SettlementCalendarName];
public string SettlementCalendarName { get;set;}
public string SettlementCalendarName { get; set; }

public override bool Equals(object x)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/DateGenerationType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum DateGenerationType
Expand Down
7 changes: 3 additions & 4 deletions src/Qwack.Core/Basic/FixingDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Qwack.Core.Models;
using Qwack.Transport.BasicTypes;
using Qwack.Transport.TransportObjects.MarketData.Models;
Expand All @@ -25,8 +24,8 @@ public class FixingDictionary : Dictionary<DateTime, double>, IFixingDictionary
base(source)
{
}
public FixingDictionary(TO_FixingDictionary transportObject)
: base(transportObject.Fixings==null?new Dictionary<DateTime, double>():transportObject.Fixings.ToDictionary(x=>DateTime.ParseExact(x.Key, "s",CultureInfo.InvariantCulture), x=>x.Value))
public FixingDictionary(TO_FixingDictionary transportObject)
: base(transportObject.Fixings == null ? new Dictionary<DateTime, double>() : transportObject.Fixings.ToDictionary(x => DateTime.ParseExact(x.Key, "s", CultureInfo.InvariantCulture), x => x.Value))
{
Name = transportObject.Name;
AssetId = transportObject.AssetId;
Expand Down Expand Up @@ -55,7 +54,7 @@ public IFixingDictionary Clone()
Name = Name,
FxPair = FxPair,
FixingDictionaryType = FixingDictionaryType,
Fixings = this.ToDictionary(x=>x.Key.ToString("s"),x=>x.Value)
Fixings = this.ToDictionary(x => x.Key.ToString("s"), x => x.Value)
};
}
}
14 changes: 7 additions & 7 deletions src/Qwack.Core/Basic/FxMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FxMatrix : IFxMatrix
{
private readonly ICurrencyProvider _currencyProvider;

public FxMatrix(TO_FxMatrix transportObject, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider):this(currencyProvider)
public FxMatrix(TO_FxMatrix transportObject, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider) : this(currencyProvider)
{
BaseCurrency = currencyProvider.GetCurrency(transportObject.BaseCurrency);
BuildDate = transportObject.BuildDate;
Expand Down Expand Up @@ -54,7 +54,7 @@ public FxMatrix(ICurrencyProvider currencyProvider)
public FxPair GetFxPair(string pair)
{
var leftCCy = _currencyProvider[pair.Substring(0, 3)];
var rightCcy = _currencyProvider[pair.Substring(pair.Length-3, 3)];
var rightCcy = _currencyProvider[pair.Substring(pair.Length - 3, 3)];
return GetFxPair(leftCCy, rightCcy);
}

Expand All @@ -65,7 +65,7 @@ public FxPair GetFxPair(string pair)

public FxPair GetFxPair(Currency domesticCcy, Currency foreignCcy)
{
if(domesticCcy==foreignCcy)
if (domesticCcy == foreignCcy)
return new FxPair { Domestic = domesticCcy, Foreign = foreignCcy, PrimaryCalendar = new Calendar(), SpotLag = 0.Day() };

var pair = FxPairDefinitions.SingleOrDefault(x => x.Domestic == domesticCcy && x.Foreign == foreignCcy);
Expand All @@ -74,8 +74,8 @@ public FxPair GetFxPair(Currency domesticCcy, Currency foreignCcy)

pair = FxPairDefinitions.SingleOrDefault(x => x.Foreign == domesticCcy && x.Domestic == foreignCcy);
if (pair != null)
return new FxPair { Domestic = domesticCcy, Foreign = foreignCcy, PrimaryCalendar = pair.PrimaryCalendar, SecondaryCalendar = pair.SecondaryCalendar, SpotLag = pair.SpotLag };
return new FxPair { Domestic = domesticCcy, Foreign = foreignCcy, PrimaryCalendar = pair.PrimaryCalendar, SecondaryCalendar = pair.SecondaryCalendar, SpotLag = pair.SpotLag };

return new FxPair { Domestic = domesticCcy, Foreign = foreignCcy, PrimaryCalendar = foreignCcy.SettlementCalendar.Merge(domesticCcy.SettlementCalendar), SpotLag = 2.Bd() };
}

Expand All @@ -86,7 +86,7 @@ public IFxMatrix Clone()
return o;
}

public IFxMatrix Rebase(DateTime newBuildDate, Dictionary<Currency,double> newSpotRates)
public IFxMatrix Rebase(DateTime newBuildDate, Dictionary<Currency, double> newSpotRates)
{
var o = new FxMatrix(_currencyProvider);
o.Init(BaseCurrency, newBuildDate, newSpotRates, new List<FxPair>(FxPairDefinitions), new Dictionary<Currency, string>(DiscountCurveMap));
Expand All @@ -102,7 +102,7 @@ public IFxMatrix Rebase(DateTime newBuildDate, Dictionary<Currency,double> newSp
BuildDate = BuildDate,
DiscountCurveMap = DiscountCurveMap.ToDictionary(x => x.Key.Ccy, x => x.Value),
SpotRates = SpotRates.ToDictionary(x => x.Key.Ccy, x => x.Value),
FxPairDefinitions = FxPairDefinitions.Select(x=>x.GetTransportObject()).ToList()
FxPairDefinitions = FxPairDefinitions.Select(x => x.GetTransportObject()).ToList()
};
}
}
6 changes: 3 additions & 3 deletions src/Qwack.Core/Basic/FxPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public class FxPair
public Calendar PrimaryCalendar { get; set; }
public Calendar SecondaryCalendar { get; set; }

public FxPair()
public FxPair()
{
PrimaryCalendar = new Calendar() { Name = "Empty" };
SecondaryCalendar = new Calendar() { Name = "Empty" };
}

public FxPair(TO_FxPair transportObject, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider):base()
public FxPair(TO_FxPair transportObject, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider) : base()
{
Foreign = currencyProvider.GetCurrency(transportObject.Foreign);
Domestic = currencyProvider.GetCurrency(transportObject.Domestic);
Expand Down Expand Up @@ -82,7 +82,7 @@ public static FxPair FxPairFromString(this string pair, ICurrencyProvider curren
public static DateTime OptionExpiry(this FxPair pair, DateTime valDate, Frequency tenor)
{
var spot = pair.SpotDate(valDate);
var roll = tenor.PeriodType == DatePeriodType.M || tenor.PeriodType == DatePeriodType.Y ? RollType.MF : RollType.F;
var roll = tenor.PeriodType is DatePeriodType.M or DatePeriodType.Y ? RollType.MF : RollType.F;
var delivery = spot.AddPeriod(roll, pair.PrimaryCalendar, tenor);
delivery = delivery.IfHolidayRoll(roll, pair.SecondaryCalendar);
var expiry = delivery.SubtractPeriod(RollType.P, pair.PrimaryCalendar, pair.SpotLag);
Expand Down
5 changes: 0 additions & 5 deletions src/Qwack.Core/Basic/ICurrencyProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Qwack.Core.Basic
{
public interface ICurrencyProvider
Expand Down
5 changes: 1 addition & 4 deletions src/Qwack.Core/Basic/IVolSurface.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Qwack.Math.Interpolation;
using Qwack.Math;
using Qwack.Dates;
using Qwack.Math;

namespace Qwack.Core.Basic
{
Expand Down
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/McModelType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum McModelType
Expand Down
7 changes: 1 addition & 6 deletions src/Qwack.Core/Basic/MtmSwapType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Qwack.Core.Basic
namespace Qwack.Core.Basic
{
public enum MTMSwapType
{
Expand Down
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/MutationType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum MutationType
Expand Down
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/PFERegressorType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum PFERegressorType
Expand Down
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/RandomGeneratorType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum RandomGeneratorType
Expand Down
4 changes: 0 additions & 4 deletions src/Qwack.Core/Basic/RiskMetric.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Qwack.Core.Basic
{
public enum RiskMetric
Expand Down

0 comments on commit 907ea69

Please sign in to comment.