Skip to content

Commit

Permalink
Mc VaR improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Sep 21, 2022
1 parent 38417d3 commit 5947503
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Qwack.Models/Risk/McVaRCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class McVaRCalculator
private readonly IFutureSettingsProvider _futureSettingsProvider;
private readonly List<IAssetFxModel> _bumpedModels = new();
private readonly Dictionary<string, double> _spotFactors = new();

private int _ciIx = 0;

public int CIIX => _ciIx;

public McVaRCalculator(IAssetFxModel model, Portfolio portfolio, ILogger logger, ICurrencyProvider currencyProvider,
ICalendarProvider calendarProvider, IFutureSettingsProvider futureSettingsProvider)
Expand Down Expand Up @@ -117,6 +119,7 @@ public double CalculateVaR(double ci, Currency ccy, string[] excludeTradeIds)
var results = _resultsCache.ToDictionary(x => x.Key, x => x.Value.Filter(filterDict, true).SumOfAllRows);
var sortedResults = results.OrderBy(kv => kv.Value).ToList();
var ixCi = (int)System.Math.Floor(sortedResults.Count() * (1.0 - ci));
_ciIx = ixCi;
var ciResult = sortedResults[System.Math.Min(System.Math.Max(ixCi, 0), sortedResults.Count - 1)];
var basePvForSet = _basePvCube.Filter(filterDict, true).SumOfAllRows;
return ciResult.Value - basePvForSet;
Expand Down

0 comments on commit 5947503

Please sign in to comment.