/// <summary> /// Updates the Element Order in the list based on the drag drop parameters /// </summary> /// <param name="dataContext">List of MorningSnapshotData binded to the grid</param> /// <param name="dragBenchmarkDetails">Preference details of the dragged Item</param> /// <param name="dropBenchmarkDetails">Preference details of the next to drop location</param> /// <param name="isDropLastOfSameGroup">True if the drop location is last within the drag item group</param> private void UpdateParametersForSameGroupReordering(List <MarketSnapshotPerformanceData> dataContext, MarketSnapshotPreference dragBenchmarkDetails, MarketSnapshotPreference dropBenchmarkDetails, bool isDropLastOfSameGroup) { //dropped at group end with the next group empty if (dropBenchmarkDetails.EntityOrder == null) { dropBenchmarkDetails.EntityOrder = GetEntityCountInGroup(dataContext, dragBenchmarkDetails.GroupPreferenceID) + 1; } //dropped at group end within the same group if (isDropLastOfSameGroup) { if (dragBenchmarkDetails.GroupPreferenceID != dropBenchmarkDetails.GroupPreferenceID) { dropBenchmarkDetails.EntityOrder = GetEntityCountInGroup(dataContext, dragBenchmarkDetails.GroupPreferenceID) + 1; } } //check drop flow - top ot bottom or vice versa bool isDropLocationExceedingDragLocation = dropBenchmarkDetails.EntityOrder > dragBenchmarkDetails.EntityOrder; foreach (MarketSnapshotPerformanceData record in dataContext) { //no consideration of records in other groups if (record.MarketSnapshotPreferenceInfo.GroupPreferenceID != dragBenchmarkDetails.GroupPreferenceID) { continue; } //check if the record is between drag and drop location bool isRecordBetweenDragDropLocation = isDropLocationExceedingDragLocation ? record.MarketSnapshotPreferenceInfo.EntityOrder > dragBenchmarkDetails.EntityOrder && record.MarketSnapshotPreferenceInfo.EntityOrder < dropBenchmarkDetails.EntityOrder : record.MarketSnapshotPreferenceInfo.EntityOrder < dragBenchmarkDetails.EntityOrder && record.MarketSnapshotPreferenceInfo.EntityOrder >= dropBenchmarkDetails.EntityOrder; //shift record order between drag and drop location based on drop flow if (isRecordBetweenDragDropLocation) { record.MarketSnapshotPreferenceInfo.EntityOrder = isDropLocationExceedingDragLocation ? record.MarketSnapshotPreferenceInfo.EntityOrder - 1 : record.MarketSnapshotPreferenceInfo.EntityOrder + 1; continue; } //check if the record is the drag element bool isRecordDragLocation = record.MarketSnapshotPreferenceInfo.EntityOrder == dragBenchmarkDetails.EntityOrder; //change record order if the record element is the drag element if (isRecordDragLocation) { record.MarketSnapshotPreferenceInfo.EntityOrder = isDropLocationExceedingDragLocation ? dropBenchmarkDetails.EntityOrder - 1 : dropBenchmarkDetails.EntityOrder; } } }
/// <summary> /// Method to update parameters for reordering inter group /// </summary> /// <param name="dataContext">List of MorningSnapshotData binded to the grid</param> /// <param name="dragBenchmarkDetails">Preference details of the dragged Item</param> /// <param name="dropBenchmarkDetails">Preference details of the next to drop location</param> /// <param name="isDropLastOfOtherGroup">true if the drop is done at location last of drop location group</param> private void UpdateParametersForDiffGroupReordering(List <MarketSnapshotPerformanceData> dataContext, MarketSnapshotPreference dragBenchmarkDetails, MarketSnapshotPreference dropBenchmarkDetails, bool isDropLastOfOtherGroup) { bool isDropLocationExceedingDragLocation = isDropLastOfOtherGroup ? dropBenchmarkDetails.GroupPreferenceID - 1 > dragBenchmarkDetails.GroupPreferenceID : dropBenchmarkDetails.GroupPreferenceID > dragBenchmarkDetails.GroupPreferenceID; //true if insertion is done after an element and false if it's done before the element bool isDropPositionAfter = DragDropPosition.Value == DropPosition.After; foreach (MarketSnapshotPerformanceData record in dataContext) { bool isDragGroupRecordShifted = record.MarketSnapshotPreferenceInfo.EntityOrder > dragBenchmarkDetails.EntityOrder && record.MarketSnapshotPreferenceInfo.GroupPreferenceID == dragBenchmarkDetails.GroupPreferenceID; if (isDragGroupRecordShifted) { record.MarketSnapshotPreferenceInfo.EntityOrder--; continue; } bool isDropGroupRecordShifted = record.MarketSnapshotPreferenceInfo.EntityOrder > dropBenchmarkDetails.EntityOrder && record.MarketSnapshotPreferenceInfo.GroupPreferenceID == dropBenchmarkDetails.GroupPreferenceID; if (isDropGroupRecordShifted && !isDropLastOfOtherGroup) { record.MarketSnapshotPreferenceInfo.EntityOrder++; continue; } bool isRecordDragLocation = record.MarketSnapshotPreferenceInfo.EntityOrder == dragBenchmarkDetails.EntityOrder && record.MarketSnapshotPreferenceInfo.GroupPreferenceID == dragBenchmarkDetails.GroupPreferenceID; if (isRecordDragLocation) { record.MarketSnapshotPreferenceInfo.EntityOrder = isDropLastOfOtherGroup ? GetEntityCountInGroup(dataContext, GetLastGroupPreferenceId(dataContext, dropBenchmarkDetails.GroupPreferenceID)) + 1 : dropBenchmarkDetails.EntityOrder; record.MarketSnapshotPreferenceInfo.GroupName = isDropLastOfOtherGroup ? GetLastGroupName(dataContext, dropBenchmarkDetails.GroupPreferenceID) : dropBenchmarkDetails.GroupName; record.MarketSnapshotPreferenceInfo.GroupPreferenceID = isDropLastOfOtherGroup ? GetLastGroupPreferenceId(dataContext, dropBenchmarkDetails.GroupPreferenceID) : dropBenchmarkDetails.GroupPreferenceID; continue; } bool isRecordDropLocation = record.MarketSnapshotPreferenceInfo.EntityOrder == dropBenchmarkDetails.EntityOrder && record.MarketSnapshotPreferenceInfo.GroupPreferenceID == dropBenchmarkDetails.GroupPreferenceID; if (isRecordDropLocation && !isDropLastOfOtherGroup) { record.MarketSnapshotPreferenceInfo.EntityOrder++; continue; } } }
/// <summary> /// OK button Click Event Handler /// </summary> /// <param name="sender">Sender</param> /// <param name="e">RoutedEventArgs</param> private void OKButton_Click(object sender, RoutedEventArgs e) { InsertedMarketSnapshotPreference = (this.DataContext as ChildViewModelInsertEntity).SelectedMarketSnapshotPreference; InsertedMarketSnapshotPreference.GroupName = this.txtGroupName.Text; if (groupNames != null) { if (groupNames.Contains(InsertedMarketSnapshotPreference.GroupName)) { this.txtMessage.Text = "*Group name '" + InsertedMarketSnapshotPreference.GroupName + "' is already present in this snapshot. Please input a different group name"; this.txtMessage.Visibility = System.Windows.Visibility.Visible; return; } } this.DialogResult = true; }
/// <summary> /// Gets return value for a preference between two specific dates /// </summary> /// <param name="entity">dimension service instance</param> /// <param name="preference">MarketSnapshotPreference object</param> /// <param name="fromDate">start date</param> /// <param name="toDate">end date</param> /// <returns>security return value</returns> private static Decimal?GetReturn(DimensionEntities entity, MarketSnapshotPreference preference, DateTime fromDate, DateTime toDate) { try { List <GreenField.DAL.GF_PRICING_BASEVIEW> datedRecords = entity.GF_PRICING_BASEVIEW .Where(record => record.INSTRUMENT_ID == preference.EntityId && record.TYPE == preference.EntityType && record.ISSUE_NAME == preference.EntityName && record.FROMDATE >= fromDate && record.FROMDATE <= toDate) .ToList(); Decimal result = -1; foreach (GreenField.DAL.GF_PRICING_BASEVIEW record in datedRecords) { Decimal?returnValue = preference.EntityReturnType == "Price" ? (record.DAILY_PRICE_RETURN != null ? record.DAILY_PRICE_RETURN : 0) : (record.DAILY_GROSS_RETURN != null ? record.DAILY_GROSS_RETURN : 0); if (result == -1) { result = (1 + ((returnValue == null ? 0 : Convert.ToDecimal(returnValue)) / 100)); } else { result = result * (1 + ((returnValue == null ? 0 : Convert.ToDecimal(returnValue)) / 100)); } } if (result == -1) { return(null); } return((result - 1) * 100); } catch (Exception) { throw; } }
/// <summary> /// ReorderBehavior Reordering Event Handler - Adjusts Entity Order and GroupPreferenceId of entities after reordering /// </summary> /// <param name="sender">Sender</param> /// <param name="e">ReorderingEventArgs</param> private void ReorderBehavior_Reordering(object sender, ReorderingEventArgs e) { //if there are no dragged Items reordering is redundant if (e.DraggedItems.Count().Equals(0)) { return; } #region Get Dragged Element //dragged Element MarketSnapshotPerformanceData draggedElement = e.DraggedItems.FirstOrDefault() as MarketSnapshotPerformanceData; //null Exception Handling if (draggedElement == null) { return; } #endregion #region Get Data Context //collection of MorningSnapshotData binded to the grid List <MarketSnapshotPerformanceData> dataContext = (e.SourceGrid.ItemsSource as ObservableCollection <MarketSnapshotPerformanceData>).ToList(); //null Exception Handling if (dataContext == null) { return; } #endregion #region Get Drag Drop Details //drag drop Indexes int dragIndex = dataContext.IndexOf(draggedElement); int dropIndex = e.DropIndex; //true if insertion is done after an element and False if it's done before the element bool isDropPositionAfter = DragDropPosition.Value == DropPosition.After; //check if the drop Index exceed the Count of List - item dropped after the last element bool isDropIndexExceedingCount = dropIndex >= dataContext.Count; #endregion #region Drag Location Parameters MarketSnapshotPreference dragBenchmarkDetails = new MarketSnapshotPreference() { EntityName = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.EntityName, EntityReturnType = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.EntityReturnType, EntityOrder = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.EntityOrder, GroupName = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.GroupName, GroupPreferenceID = dataContext.ElementAt(dragIndex).MarketSnapshotPreferenceInfo.GroupPreferenceID }; #endregion #region Drop Location Parameters MarketSnapshotPreference dropBenchmarkDetails = new MarketSnapshotPreference() { EntityName = isDropIndexExceedingCount ? null : dataContext.ElementAt(dropIndex).MarketSnapshotPreferenceInfo.EntityName, EntityReturnType = isDropIndexExceedingCount ? null : dataContext.ElementAt(e.DropIndex).MarketSnapshotPreferenceInfo.EntityReturnType, EntityOrder = isDropIndexExceedingCount ? dataContext.ElementAt(dropIndex - 1).MarketSnapshotPreferenceInfo.EntityOrder + 1 : dataContext.ElementAt(dropIndex).MarketSnapshotPreferenceInfo.EntityOrder, GroupName = isDropIndexExceedingCount ? dataContext.ElementAt(dropIndex - 1).MarketSnapshotPreferenceInfo.GroupName : dataContext.ElementAt(dropIndex).MarketSnapshotPreferenceInfo.GroupName, GroupPreferenceID = isDropIndexExceedingCount ? dataContext.ElementAt(dropIndex - 1).MarketSnapshotPreferenceInfo.GroupPreferenceID : dataContext.ElementAt(dropIndex).MarketSnapshotPreferenceInfo.GroupPreferenceID }; #endregion #region Managing discrepancies in drop location //if drop location is after the last element of same or another group the behavior picks the next element nevertheless bool isDragdropGroupSame = dragBenchmarkDetails.GroupPreferenceID == dropBenchmarkDetails.GroupPreferenceID; bool isDropEntityMisread = dropBenchmarkDetails.EntityOrder == 1 && isDropPositionAfter; bool isDropLastOfSameGroup = GetLastGroupPreferenceId(dataContext, dropBenchmarkDetails.GroupPreferenceID) == dragBenchmarkDetails.GroupPreferenceID && isDropEntityMisread; bool isDropLastOfOtherGroup = (!isDropLastOfSameGroup) && isDropEntityMisread; #endregion bool isDragWithinGroup = isDragdropGroupSame ? (!isDropLastOfOtherGroup) : isDropLastOfSameGroup; if (isDragWithinGroup) { UpdateParametersForSameGroupReordering(dataContext, dragBenchmarkDetails, dropBenchmarkDetails, isDropLastOfSameGroup); } else { UpdateParametersForDiffGroupReordering(dataContext, dragBenchmarkDetails, dropBenchmarkDetails, isDropLastOfOtherGroup); } }
/// <summary> /// Gets performance data for a specific snapshot preference where entity type is benchmark /// </summary> /// <param name="entity">Dimension service entity instance</param> /// <param name="preference">MarketSnapshotPreference object</param> /// <returns>MarketSnapshotPerformanceData</returns> public static MarketSnapshotPerformanceData GetBenchmarkPerformanceData(DimensionEntities entity, MarketSnapshotPreference preference) { MarketSnapshotPerformanceData result = new MarketSnapshotPerformanceData(); try { List <GreenField.DAL.GF_PERF_DAILY_ATTRIBUTION> benchmarkRecords = entity.GF_PERF_DAILY_ATTRIBUTION .Where(record => record.NODE_NAME == (preference.EntityNodeType == "Country" ? "Country" : "GICS Level 1") && record.AGG_LVL_1 == (preference.EntityNodeType == null ? "Undefined" : preference.EntityNodeValueCode) && record.AGG_LVL_1_LONG_NAME == (preference.EntityNodeType == null ? "-" : preference.EntityNodeValueName) && record.BM == preference.EntityId.ToUpper() && record.BMNAME == preference.EntityName && record.TO_DATE != null && record.POR_INCEPTION_DATE != null) .OrderByDescending(record => record.TO_DATE).ToList(); GreenField.DAL.GF_PERF_DAILY_ATTRIBUTION lastRecord = benchmarkRecords.FirstOrDefault(); GreenField.DAL.GF_PERF_DAILY_ATTRIBUTION benchmarkRecord = lastRecord != null?GetMinInceptionDateRecord <GreenField.DAL.GF_PERF_DAILY_ATTRIBUTION>(benchmarkRecords .Where(record => record.TO_DATE == lastRecord.TO_DATE).ToList()) : null; result.DateToDateReturn = benchmarkRecord != null ? (preference.EntityNodeType == null ? benchmarkRecord.BM1_TOP_RC_TWR_1D * Convert.ToDecimal(100) : benchmarkRecord.BM1_RC_TWR_1D * Convert.ToDecimal(100)) : null; result.WeekToDateReturn = benchmarkRecord != null ? (preference.EntityNodeType == null ? benchmarkRecord.BM1_TOP_RC_TWR_1W * Convert.ToDecimal(100) : benchmarkRecord.BM1_RC_TWR_1W * Convert.ToDecimal(100)) : null; result.MonthToDateReturn = benchmarkRecord != null ? (preference.EntityNodeType == null ? benchmarkRecord.BM1_TOP_RC_TWR_MTD * Convert.ToDecimal(100) : benchmarkRecord.BM1_RC_TWR_MTD * Convert.ToDecimal(100)) : null; result.QuarterToDateReturn = benchmarkRecord != null ? (preference.EntityNodeType == null ? benchmarkRecord.BM1_TOP_RC_TWR_QTD * Convert.ToDecimal(100) : benchmarkRecord.BM1_RC_TWR_QTD * Convert.ToDecimal(100)) : null; result.YearToDateReturn = benchmarkRecord != null ? (preference.EntityNodeType == null ? benchmarkRecord.BM1_TOP_RC_TWR_YTD * Convert.ToDecimal(100) : benchmarkRecord.BM1_RC_TWR_YTD * Convert.ToDecimal(100)) : null; if (preference.EntityNodeType == null) { GreenField.DAL.GF_PERF_TOPLEVELYEAR benchmarkLastYearRecord = GetMinInceptionDateRecord <GreenField.DAL.GF_PERF_TOPLEVELYEAR>(entity.GF_PERF_TOPLEVELYEAR .Where(g => g.CURRENCY.ToUpper() == "USD" && g.RETURN_TYPE.ToUpper() == "NET" && g.TO_DATE == "31/12/" + (DateTime.Today.Year - 1).ToString() && g.BM1ID.ToUpper() == preference.EntityId.ToUpper() && g.BM1NAME.ToUpper() == preference.EntityName.ToUpper() && g.POR_INCEPTION_DATE != null) .ToList()); result.LastYearReturn = preference.EntityNodeType == null ? (benchmarkLastYearRecord != null ? benchmarkLastYearRecord.BM1_RC_TWR_YTD * Convert.ToDecimal(100) : null) : null; GreenField.DAL.GF_PERF_TOPLEVELYEAR benchmarkSecondLastYearRecord = GetMinInceptionDateRecord <GreenField.DAL.GF_PERF_TOPLEVELYEAR>(entity.GF_PERF_TOPLEVELYEAR .Where(g => g.CURRENCY.ToUpper() == "USD" && g.RETURN_TYPE.ToUpper() == "NET" && g.TO_DATE == "31/12/" + (DateTime.Today.Year - 2).ToString() && g.BM1ID.ToUpper() == preference.EntityId.ToUpper() && g.BM1NAME.ToUpper() == preference.EntityName.ToUpper() && g.POR_INCEPTION_DATE != null) .ToList()); result.SecondLastYearReturn = preference.EntityNodeType == null ? (benchmarkSecondLastYearRecord != null ? benchmarkSecondLastYearRecord.BM1_RC_TWR_YTD * Convert.ToDecimal(100) : null) : null; GreenField.DAL.GF_PERF_TOPLEVELYEAR benchmarkThirdLastYearRecord = GetMinInceptionDateRecord <GreenField.DAL.GF_PERF_TOPLEVELYEAR>(entity.GF_PERF_TOPLEVELYEAR .Where(g => g.CURRENCY.ToUpper() == "USD" && g.RETURN_TYPE.ToUpper() == "NET" && g.TO_DATE == "31/12/" + (DateTime.Today.Year - 3).ToString() && g.BM1ID.ToUpper() == preference.EntityId.ToUpper() && g.BM1NAME.ToUpper() == preference.EntityName.ToUpper() && g.POR_INCEPTION_DATE != null) .ToList()); result.ThirdLastYearReturn = preference.EntityNodeType == null ? (benchmarkThirdLastYearRecord != null ? benchmarkThirdLastYearRecord.BM1_RC_TWR_YTD * Convert.ToDecimal(100) : null) : null; } } catch (Exception) { throw; } return(result); }
/// <summary> /// Gets performance data for a specific snapshot preference where entity type is security, index or commodity /// </summary> /// <param name="entity">Dimension service entity instance</param> /// <param name="preference">MarketSnapshotPreference object</param> /// <returns>MarketSnapshotPerformanceData</returns> public static MarketSnapshotPerformanceData GetSecurityCommodityIndexPerformanceData(DimensionEntities entity, MarketSnapshotPreference preference) { MarketSnapshotPerformanceData result = new MarketSnapshotPerformanceData(); try { DateTime TrackDate = DateTime.Today; GreenField.DAL.GF_PRICING_BASEVIEW lastDateToDateRecord = entity.GF_PRICING_BASEVIEW .Where(record => record.INSTRUMENT_ID == preference.EntityId && record.TYPE == preference.EntityType && record.ISSUE_NAME == preference.EntityName && record.FROMDATE != null) .OrderByDescending(record => record.FROMDATE) .Take(1).FirstOrDefault(); if (lastDateToDateRecord == null) { return(result); } GreenField.DAL.GF_PRICING_BASEVIEW firstRecord = entity.GF_PRICING_BASEVIEW .Where(record => record.INSTRUMENT_ID == preference.EntityId && record.TYPE == preference.EntityType && record.ISSUE_NAME == preference.EntityName && record.FROMDATE != null) .OrderBy(record => record.FROMDATE) .Take(1).FirstOrDefault(); DateTime firstRecordDateTime = DateTime.Today.AddYears(-5); if (firstRecord != null) { firstRecordDateTime = Convert.ToDateTime(firstRecord.FROMDATE); } DateTime lastBusinessDateTime = TrackDate = Convert.ToDateTime(lastDateToDateRecord.FROMDATE); result.DateToDateReturn = lastDateToDateRecord != null ? (preference.EntityReturnType == "Price" ? lastDateToDateRecord.DAILY_PRICE_RETURN != null ? lastDateToDateRecord.DAILY_PRICE_RETURN : 0 : lastDateToDateRecord.DAILY_GROSS_RETURN != null ? lastDateToDateRecord.DAILY_GROSS_RETURN : 0) : null; result.WeekToDateReturn = GetReturn(entity, preference, lastBusinessDateTime.AddDays(-6) > firstRecordDateTime ? lastBusinessDateTime.AddDays(-6) : firstRecordDateTime, lastBusinessDateTime); result.MonthToDateReturn = GetReturn(entity, preference, new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1) > firstRecordDateTime ? new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1) : firstRecordDateTime, lastBusinessDateTime); result.QuarterToDateReturn = GetReturn(entity, preference , new DateTime(DateTime.Today.Year, (DateTime.Today.Month - ((DateTime.Today.Month - 1) % 3)), 1) > firstRecordDateTime ? new DateTime(DateTime.Today.Year, (DateTime.Today.Month - ((DateTime.Today.Month - 1) % 3)), 1) : firstRecordDateTime, lastBusinessDateTime); result.YearToDateReturn = GetReturn(entity, preference, new DateTime(DateTime.Today.Year, 1, 1) > firstRecordDateTime ? new DateTime(DateTime.Today.Year, 1, 1) : firstRecordDateTime, lastBusinessDateTime); result.LastYearReturn = GetReturn(entity, preference, new DateTime(DateTime.Today.Year - 1, 1, 1) > firstRecordDateTime ? new DateTime(DateTime.Today.Year - 1, 1, 1) : firstRecordDateTime, new DateTime(DateTime.Today.Year - 1, 12, 31)); result.SecondLastYearReturn = GetReturn(entity, preference, new DateTime(DateTime.Today.Year - 2, 1, 1) > firstRecordDateTime ? new DateTime(DateTime.Today.Year - 2, 1, 1) : firstRecordDateTime, new DateTime(DateTime.Today.Year - 2, 12, 31)); result.ThirdLastYearReturn = GetReturn(entity, preference, new DateTime(DateTime.Today.Year - 3, 1, 1) > firstRecordDateTime ? new DateTime(DateTime.Today.Year - 3, 1, 1) : firstRecordDateTime, new DateTime(DateTime.Today.Year - 3, 12, 31)); } catch (Exception) { throw; } return(result); }