From 3cf1d0d51e38b51daa68012decffed87410ad14d Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 11 Feb 2025 19:24:15 -0500 Subject: [PATCH] Add aggregator to MGSHPositionSumFunctionRisk. Add RMultipleValueConverter so that we can represent RMultiple as numeric in the grid while at the same time preserving the "R" which is appended to it. --- Utility/CustomAggregator.cs | 16 ++++++++++++++++ Utility/UIUtils.cs | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Utility/CustomAggregator.cs b/Utility/CustomAggregator.cs index 745fc7a..2824f0a 100644 --- a/Utility/CustomAggregator.cs +++ b/Utility/CustomAggregator.cs @@ -290,6 +290,22 @@ namespace TradeBlotter.UIUtils } } + public class MGSHPositionSumFunctionRisk:AggregateFunction + { + public MGSHPositionSumFunctionRisk() + { + this.AggregationExpression=items => Sum(items); + } + private String Sum(IEnumerable source) + { + StringBuilder sb=new StringBuilder(); + List activePositions=source.Where(x => x.IsActivePosition).ToList(); + double sum=activePositions.Sum(x => x.TotalRiskExposure); + return Utility.FormatCurrency(sum); + } + } + + // ********************************************************************************************************************************** // ********************************************************* C M M O M E N T U M ****************************************************** // ********************************************************************************************************************************** diff --git a/Utility/UIUtils.cs b/Utility/UIUtils.cs index 426c1bc..551c3ea 100644 --- a/Utility/UIUtils.cs +++ b/Utility/UIUtils.cs @@ -10,6 +10,20 @@ using MarketData.Utils; namespace TradeBlotter.UIUtils { + public class RMultipleValueConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + double doubleValue = (double)value; + if (double.IsNaN(doubleValue)) return Constants.CONST_DASHES; + return Utility.FormatNumber(doubleValue,2)+"R"; + } + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return null; + } + } + public class DoubleValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)