public static Dictionary<string, CTDItem[]> GetCTDOverrideFromFile(string ctdOverridePath) { Log.InfoFormat("Reading ctd override from {0}", ctdOverridePath); string[] lines = System.IO.File.ReadAllLines(ctdOverridePath); var overrides = new Dictionary<string, CTDItem[]>(); foreach (string line in lines) { // Use a tab to indent each line of the file. Log.Info("\t" + line); var items = line.Split('\t'); if (items.Length > 2) { CTDItem ctdItem = null; var ctdEffectiveDate = DateTime.ParseExact(items[2], "yyyy-MM-dd", CultureInfo.InvariantCulture); ctdItem = new CTDItem() { Ticker = items[0], Isin = items[1], EffFrom = ctdEffectiveDate, EffTo = DateTime.MaxValue, }; if (items.Length > 3) { var ctdToDate = DateTime.ParseExact(items[3], "yyyy-MM-dd", CultureInfo.InvariantCulture); ctdItem = new CTDItem() { Ticker = items[0], Isin = items[1], EffFrom = ctdEffectiveDate, EffTo = ctdToDate, }; } overrides.AddOrAppendDictionaryValueArray(items[0], ctdItem); } } return overrides; }
public ChartData GetDataFromCarbonFrame() { var enabled = Components.Where(x => x.IsReady()).ToList(); if (!enabled.Any()) return null; var listofAllRollDates = new Dictionary<CTCTDType, Tuple<string, DateTime>[]>(); var listOfAllOldDates = new Dictionary<CTCTDType, Tuple<string, DateTime>[]>(); ConstructGen<double> con = new ConstructGen<double>(enabled.Count()); ConstructGen<double> conOld = new ConstructGen<double>(enabled.Count()); ConstructGen<double> conOldOld = new ConstructGen<double>(enabled.Count()); ConstructGen<double> conSmoothed = new ConstructGen<double>(enabled.Count()); for (int i = 0; i < con.ArrayLength; ++i) { var curDataTuple = ChartComponentCarbonMediator.GetItemsFromCarbonFrame(enabled[i], g => g.CurrentResult, r => r.TrueSpread); con.SetColumnValues(i, curDataTuple.Item2); var oDataTuple = ChartComponentCarbonMediator.GetItemsFromCarbonFrame(enabled[i], g => g.OResult, r => r.TrueSpread); conOld.SetColumnValues(i, oDataTuple.Item2); var ooDataTuple = ChartComponentCarbonMediator.GetItemsFromCarbonFrame(enabled[i], g => g.OOResult, r => r.TrueSpread); conOldOld.SetColumnValues(i, ooDataTuple.Item2); var smoothDataTuple = ChartComponentCarbonMediator.GetItemsFromCarbonFrame(enabled[i], g => g.SmoothResult, r => r.TrueSpread); conSmoothed.SetColumnValues(i, smoothDataTuple.Item2); for (int j = 1; j < con.Dates.Count; ++j) { // if the bond hasn't changed, then just adjust the previous value by change in the bond if (j < curDataTuple.Item1.Data.Length) { if (String.CompareOrdinal(curDataTuple.Item1.Data[j], curDataTuple.Item1.Data[j - 1]) != 0) { listofAllRollDates.AddOrAppendDictionaryValueArray(enabled[i].CTCTDType, new Tuple<string, DateTime>(enabled[i].Component + "\n" + curDataTuple.Item1.Data[j], curDataTuple.Item1.Dates[j])); listOfAllOldDates.AddOrAppendDictionaryValueArray(enabled[i].CTCTDType, new Tuple<string, DateTime>(enabled[i].Component + "\n" + curDataTuple.Item1.Data[j - 1], curDataTuple.Item1.Dates[j - 1])); } } } } return new ChartData { OriginalData = con.SumRows(), OldData = conOld.SumRows(), OldOldData = conOldOld.SumRows(), SmoothedData = conSmoothed.SumRows(), NewDates = listofAllRollDates.SelectMany(d => d.Value.Select(v => v.Item2)).Distinct().OrderBy(x => x).ToArray(), OldDates = listOfAllOldDates.SelectMany(d => d.Value.Select(v => v.Item2)).Distinct().OrderBy(x => x).ToArray(), OldRollTypeDates = listOfAllOldDates.Select(k => new {k.Key, v = k.Value.Distinct().OrderBy(x => x).ToArray() } ).ToDictionary(k => k.Key, k => k.v), NewRollTypeDates = listofAllRollDates.Select(k => new { k.Key, v = k.Value.Distinct().OrderBy(x => x).ToArray() }).ToDictionary(k => k.Key, k => k.v), }; }
public ChartData GetData2() { var enabled = Components.Where(x => x.IsReady()).ToList(); if (!enabled.Any()) return null; Dictionary<CTCTDType, Tuple<string, DateTime>[]> oldDates, rollDates; DatedDataCollectionGen<double> primary, old, smthd, oldsmthd; { ConstructGen<double> con = new ConstructGen<double>(enabled.Count()); ConstructGen<double> conOld = new ConstructGen<double>(enabled.Count()); ConstructGen<double> conOldOld = new ConstructGen<double>(enabled.Count()); ConstructGen<double> conSmoothed = new ConstructGen<double>(enabled.Count()); ConstructGen<double> conOldSmoothed = new ConstructGen<double>(enabled.Count()); var listofAllRollDates = new Dictionary<CTCTDType, Tuple<string, DateTime>[]>(); var listOfAllOldDates = new Dictionary<CTCTDType, Tuple<string, DateTime>[]>(); for (int i = 0; i < con.ArrayLength; ++i) { var currentTuple = getItems(enabled[i], CTDValueGeneration.Current); var oldTuple = getItems(enabled[i], CTDValueGeneration.Old); var oldOldTuple = getItems(enabled[i], CTDValueGeneration.OldOld); con.SetColumnValues(i, currentTuple.Item2); conOld.SetColumnValues(i, oldTuple.Item2); conOldOld.SetColumnValues(i, oldOldTuple.Item2); { var smoothed = new double[con.Dates.Count]; var oldSmoothed = new double[con.Dates.Count]; smoothed[0] = currentTuple.Item2.Data[0]; oldSmoothed[0] = oldTuple.Item2.Data[0]; for (int j = 1; j < smoothed.Length; ++j) { // if the bond hasn't changed, then just adjust the previous value by change in the bond if (String.CompareOrdinal(currentTuple.Item1.Data[j].SymmetryCode, currentTuple.Item1.Data[j - 1].SymmetryCode) == 0) { smoothed[j] = smoothed[j - 1] + (currentTuple.Item2.Data[j] - currentTuple.Item2.Data[j - 1]); oldSmoothed[j] = oldSmoothed[j - 1] + (oldTuple.Item2.Data[j] - oldTuple.Item2.Data[j - 1]); } // the bond has changed... yesterday's [current bond] has become the new [old bond], so adjust previous value by [old bond] value today - the [current bond] value yesterday else { smoothed[j] = smoothed[j - 1] + (oldTuple.Item2.Data[j] - currentTuple.Item2.Data[j - 1]); oldSmoothed[j] = oldSmoothed[j - 1] + (oldOldTuple.Item2.Data[j] - oldTuple.Item2.Data[j - 1]); listofAllRollDates.AddOrAppendDictionaryValueArray(enabled[i].CTCTDType, new Tuple<string, DateTime>(currentTuple.Item1.Data[j].SymmetryCode, currentTuple.Item1.Dates[j])); listOfAllOldDates.AddOrAppendDictionaryValueArray(enabled[i].CTCTDType, new Tuple<string, DateTime>(currentTuple.Item1.Data[j-1].SymmetryCode, currentTuple.Item1.Dates[j - 1])); } } conSmoothed.SetColumnValues(i, new DatedDataCollectionGen<double>(currentTuple.Item2.Dates, smoothed)); conOldSmoothed.SetColumnValues(i, new DatedDataCollectionGen<double>(currentTuple.Item2.Dates, oldSmoothed)); } } primary = con.SumRows(); old = conOld.SumRows(); smthd = conSmoothed.SumRows(); oldsmthd = conOldSmoothed.SumRows(); oldDates = listOfAllOldDates.Select(k => new {k.Key, v = k.Value.Distinct().OrderBy(x => x).ToArray() } ).ToDictionary(k => k.Key, k => k.v); rollDates = listofAllRollDates.Select(k => new { k.Key, v = k.Value.Distinct().OrderBy(x => x).ToArray() }).ToDictionary(k => k.Key, k => k.v); } return new ChartData() { OriginalData = primary, OldData = old, SmoothedData = smthd, OldSmoothedData = oldsmthd, NewRollTypeDates = rollDates, OldRollTypeDates = oldDates }; }