diff --git a/Utility/CustomAggregator.cs b/Utility/CustomAggregator.cs index fb52908..745fc7a 100644 --- a/Utility/CustomAggregator.cs +++ b/Utility/CustomAggregator.cs @@ -209,6 +209,87 @@ namespace TradeBlotter.UIUtils return sb.ToString(); } } + + // ********************************************************************************************************************************** + // ********************************************************* M G S H Q U A N T U M M O M E N T U M ****************************************************** + // ********************************************************************************************************************************** + + public class MGSHMomentumPositionSumFunctionShares : AggregateFunction + { + public MGSHMomentumPositionSumFunctionShares() + { + this.AggregationExpression = items => Sum(items); + } + private String Sum(IEnumerable source) + { + double sum=(from MGSHPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Shares).Sum(); + return Utility.FormatNumber(sum,3,false); + } + } + public class MGSHMomentumPositionSumFunctionExposure : AggregateFunction + { + public MGSHMomentumPositionSumFunctionExposure() + { + this.AggregationExpression = items => Sum(items); + } + private String Sum(IEnumerable source) + { + double exposure=(from MGSHPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum(); + return Utility.FormatCurrency(exposure); + } + } + public class MGSHMomentumPositionSumFunctionMarketValue : AggregateFunction + { + public MGSHMomentumPositionSumFunctionMarketValue() + { + this.AggregationExpression = items => Sum(items); + } + private String Sum(IEnumerable source) + { + double marketValue=(from MGSHPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.MarketValue).Sum(); + return Utility.FormatCurrency(marketValue); + } + } + public class MGSHMomentumPositionSumFunctionGainLoss : AggregateFunction + { + public MGSHMomentumPositionSumFunctionGainLoss() + { + this.AggregationExpression = items => Sum(items); + } + private String Sum(IEnumerable source) + { + StringBuilder sb=new StringBuilder(); + double sum=(from MGSHPositionModel positionModel in source select positionModel.GainLoss).Sum(); + sb.Append("Total:").Append(Utility.FormatCurrency(sum)).Append("\n"); + sum=(from MGSHPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.GainLoss).Sum(); + sb.Append("Active:").Append(Utility.FormatCurrency(sum)); + return sb.ToString(); + } + } + public class MGSHMomentumPositionSumFunctionGainLossPcnt : AggregateFunction + { + public MGSHMomentumPositionSumFunctionGainLossPcnt() + { + this.AggregationExpression = items => Sum(items); + } + private String Sum(IEnumerable source) + { + StringBuilder sb=new StringBuilder(); + double marketValue=0.00; + double exposure=0.00; + double gainLossPcnt=0.00; + + double cumulativeReturn=ModelPerformanceAggregator.CalculateCumulativeReturn(source); + sb.Append("Total:").Append(Utility.FormatPercent(cumulativeReturn,2)).Append("\n"); + + marketValue=(from MGSHPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.MarketValue).Sum(); + exposure=(from MGSHPositionModel positionModel in source where Utility.IsEpoch(positionModel.SellDate) select positionModel.Exposure).Sum(); + if(0.00!=exposure)gainLossPcnt=(marketValue-exposure)/exposure; + sb.Append("Active:").Append(Utility.FormatPercent(gainLossPcnt,2)); + return sb.ToString(); + } + } + // ********************************************************************************************************************************** // ********************************************************* C M M O M E N T U M ****************************************************** // **********************************************************************************************************************************