internal static List <EntryPointHistory> GetExchangeRateHistory(ConnectionContextSQLite ctx, long?RateId, DateTime?settlementDate) { List <EntryPointHistory> outExchangeRateHistoryList = new List <EntryPointHistory>(); var command = SqlHelperSQLite.SelectExchangeRateHistoryCommand(ctx, RateId, null); using (var reader = command.ExecuteReader()) { Dictionary <long, HashSet <HistoricValue> > tmpExchangeRateListDic = new Dictionary <long, HashSet <HistoricValue> >(); while (reader.Read()) { var d = new EntryPointHistory { Id = reader.GetInt32(reader.GetOrdinal("Id")), DataProviderId = reader.IsDBNull(reader.GetOrdinal("DataProviderId")) ? 0 : reader.GetInt32(reader.GetOrdinal("DataProviderId")), DataReference = reader.IsDBNull(reader.GetOrdinal("DataReference")) ? null : reader.GetString(reader.GetOrdinal("DataReference")), epValueHistory = null }; if (!tmpExchangeRateListDic.ContainsKey(d.Id)) { tmpExchangeRateListDic[d.Id] = new HashSet <HistoricValue>(new HistoricValueComparer()); outExchangeRateHistoryList.Add(d); } tmpExchangeRateListDic[d.Id].Add(new HistoricValue { Value = reader.GetDouble(reader.GetOrdinal("Value")), Date = reader.GetDateTime(reader.GetOrdinal("Date")) }); } foreach (EntryPointHistory y in outExchangeRateHistoryList) { y.epValueHistory = tmpExchangeRateListDic[y.Id]; } outExchangeRateHistoryList.Sort(new EntryPointHistoryCompare()); } return(outExchangeRateHistoryList); }
internal static List <EntryPointHistory> GetYieldCurveEntryPointHistory(ConnectionContextSQLite ctx, long?idYc, DateTime?settlementDate) { List <EntryPointHistory> outEntryPointHistoryList = new List <EntryPointHistory>(); var command = SqlHelperSQLite.SelectYieldCurveEntryPointHistoryCommand(ctx, idYc, null); using (var reader = command.ExecuteReader()) { Dictionary <long, HashSet <HistoricValue> > tmpEntryPointListDic = new Dictionary <long, HashSet <HistoricValue> >(); while (reader.Read()) { var d = new EntryPointHistory { YieldCurveId = reader.GetInt32(reader.GetOrdinal("YieldCurveId")), Id = reader.GetInt32(reader.GetOrdinal("Id")), Type = reader.GetString(reader.GetOrdinal("Type")), Length = reader.IsDBNull(reader.GetOrdinal("Length")) ? 0 : reader.GetInt32(reader.GetOrdinal("Length")), TimeUnit = reader.IsDBNull(reader.GetOrdinal("TimeUnit")) ? null : reader.GetString(reader.GetOrdinal("TimeUnit")), DataProviderId = reader.GetInt32(reader.GetOrdinal("DataProviderId")), DataReference = reader.GetString(reader.GetOrdinal("DataReference")), ValidDateBegin = reader.GetDateTime(reader.GetOrdinal("ValidDateBegin")), ValidDateEnd = reader.GetDateTime(reader.GetOrdinal("ValidDateEnd")), Enabled = true, epValueHistory = null }; d.Instrument = (d.Type == "bond" ? (Instrument)GetBond(reader.GetInt32(reader.GetOrdinal("RateId")), ctx) : (Instrument)GetRate(reader.GetInt32(reader.GetOrdinal("RateId")), ctx) ); if (d.Type == "bond" && (d.Instrument as Bond).MaturityDate <= settlementDate) { continue; // skip if bond and maturity date is not in future } // entry point is read 1st time (1st historic entry) => create new entry in output list + create history hashset if (!tmpEntryPointListDic.ContainsKey(d.Id)) { tmpEntryPointListDic[d.Id] = new HashSet <HistoricValue>(new HistoricValueComparer()); outEntryPointHistoryList.Add(d); } // add new historic value to the hashset tmpEntryPointListDic[d.Id].Add(new HistoricValue { Value = reader.GetDouble(reader.GetOrdinal("Value")), Date = reader.GetDateTime(reader.GetOrdinal("Date")) }); } // entryPointSet of output entry points is still null - assign historic values from tmp dictionary constructed foreach (EntryPointHistory y in outEntryPointHistoryList) { y.epValueHistory = tmpEntryPointListDic[y.Id]; y.epValue = y.epValueHistory.LastOrDefault(i => i.Date <= settlementDate); } // sort by durations outEntryPointHistoryList.Sort(new EntryPointHistoryCompare()); } return(outEntryPointHistoryList); }