public void Create(ConstructGenGen<string,double> series_, int xIndex_=0, int yIndex_=1) { ultraChart.FillSceneGraph -= handleFillSceneGraph; ultraChart.FillSceneGraph += handleFillSceneGraph; if (dt == null) dt = new DataTable(); dt.Columns.Clear(); dt.Columns.Add("Label", typeof(string)); dt.Columns.Add(series_.ColumnHeadings[xIndex_], typeof(double)); if (dt.Columns.Contains(series_.ColumnHeadings[yIndex_])) dt.Columns.Add(string.Format("{0}_1", series_.ColumnHeadings[yIndex_]), typeof(double)); else dt.Columns.Add(series_.ColumnHeadings[yIndex_], typeof(double)); m_datasource = series_; m_xIndex = xIndex_; m_yIndex = yIndex_; refreshData(); EstablishDefaultTooltip(mytooltipCallback); }
/// <summary> /// /// </summary> /// <param name="field"></param> /// <returns>Each Column is a different. Each Row is a different index point</returns> public ConstructGenGen<int, double> GetCombined(DataAroundEventField field) { if (m_cache.ContainsKey(field)) return m_cache[field]; if (DataInterEvents == null || DataInterEvents.Length == 0) return null; var allEvents = DataInterEvents.Where(x => x.HasProcessedData).ToArray(); var allindexes = allEvents.Select(x => x[field].Select(p => p.Index).ToArray()).SelectMany(x => x).OrderBy(x => x).ToArray(); var minIndex = allindexes[0]; var maxIndex = allindexes[allindexes.Length - 1]; var combined = new ConstructGenGen<int, double>(allEvents.Select(x => x.EventSpan.ToString()).ToArray()); for (int i = minIndex; i <= maxIndex; ++i) combined.SetValues(i, ExtensionMethods.CreateArrayRep(double.NaN, combined.ArrayLength)); for (int eventIndex = 0; eventIndex < allEvents.Length; ++eventIndex) { foreach (var point in allEvents[eventIndex][field]) combined.SetValue(point.Index, eventIndex, point.Value); } m_cache[field] = combined; //m_combined.DisplayInGrid("title", "span"); return combined; }
public LiveDayComparison(Day currentRoll_, Day priorRoll_) { m_priorRoll = priorRoll_; m_currentRoll = currentRoll_; m_data = new ConstructGenGen<RelativeDate, Line>(new[] {"Current", "PriorRoll"}); }
public void Create(DatedDataCollectionGen<double> x_, DatedDataCollectionGen<double> y_, string xName_, string yName_) { var con = new ConstructGenGen<string,double>(2); con.ColumnHeadings = new string[] { xName_, yName_ }; var ds = new DatedDataCollectionGen<double>[] { x_, y_ }; for (int y = 0; y < ds.Length; ++y) for (int i = 0; i < ds[y].Length; ++i) con.SetValue(ds[y].Dates[i].ToString("dd-MMM-yyyy"), y, ds[y].Data[i]); Create(con); }
public ConstructGenGen<RelativeDate, OIValue> BackOIAsRelativeDatesConstruct() { if (m_con_OI_to != null) return m_con_OI_to; m_con_OI_to = new ConstructGenGen<RelativeDate, OIValue>(1); foreach (var dateIndex in IndexedDates) { // create a RelativeDate for the IndexDates var rd = new RelativeDate(IndexedDates, dateIndex.Date, DispTimeZone); // shift it to the following morning (which is where we want to stamp the closing OI for the day) rd = rd.GetNextDayStart(); m_con_OI_to.SetValue( key_: rd, index_: 0, value_: new OIValue(OI_Back==null ? double.NaN : OI_Back.ValueOnExactDate_Else(dateIndex.Date, double.NaN), OIStatus.Actual)); } m_con_OI_to.SortKeys(); return m_con_OI_to; }
public ConstructGenGen<RelativeDate, double> GenerateHourlyPoints(DayField field_) { Func<RelativeDate, RelativeDate, bool> areSameHour = (a, b) => a.UnderlyingDate.IsSameHourAs(b.UnderlyingDate); try { var data = LinesAsRelativeDates(); m_lock.EnterReadLock(); var con = new ConstructGenGen<RelativeDate, double>(1); if (data == null) return null; var hour = data.Keys[0]; con.SetValue(new RelativeDate(hour.IndexDates, hour.UnderlyingDate.StartOfHour(),DispTimeZone), 0, data.GetValue(hour, 0).GetValue(field_)); foreach (var rd in data.Keys) { if (areSameHour(hour, rd)) continue; hour = rd; con.SetValue(new RelativeDate(hour.IndexDates, hour.UnderlyingDate.StartOfHour(),DispTimeZone), 0, data.GetValue(rd, 0).GetValue(field_)); } return con; } finally { m_lock.ExitReadLock(); } }
private void reload2CMTSpread_TopLeftChart() { lcdCurveSpread_TopLeft.ClearSeries(); if (m_source.Primary == BondMarket.None || m_source.Secondary == BondMarket.None || m_source.Primary == m_source.Secondary) return; lblCurveSpread.Text = string.Format("{0} {1} CMT Spread", m_source.Primary, m_source.Secondary); // first for the history... var histSpread = CMTHelper.GetHistoricalSpreads(m_source.Primary, m_source.Secondary, m_source.Focus) .TakeEndValues(m_source.HistWinLength); // if we've got enough hsitory if (histSpread.Keys.Count == m_source.HistWinLength) { var con = new ConstructGenGen<string, double>(new[] {"high", "low", "avg"}); for (int i = 0; i < CMTLine.DisplayPoints.Length; ++i) { var point = (int) CMTLine.DisplayPoints[i]; var spreadOfPoint = histSpread.GetColumnValues(point - 1); con.SetValues(point.ToString(), new[] {spreadOfPoint.Max()*10000d, spreadOfPoint.Min()*10000d, spreadOfPoint.Average()*10000d}); } lcdCurveSpread_TopLeft.AddBoxSeries("range", con, 0, 1, 2, 2, 2, null, Color.White); } var chart = lcdCurveSpread_TopLeft.AddSeries<CMTLineDiff>( source_: getSpreadObject(), xAxisValues_: CMTLine.DisplayPoints.Select(x => string.Format("{0}", x)).ToArray(), valueFields_: CMTLine.DisplayPoints.Select(x => string.Format("Y{0}", x)).ToArray(), desc_: "cmtspread", yAxisExtent_:40, color_: Color.Red, yLabelFormat_: "###0.0", lineThickness_: 0); lcdCurveSpread_TopLeft.Chart.Data.ZeroAligned = true; var lcapp = (LineChartAppearance)chart.ChartTypeAppearance; lcapp.MidPointAnchors = true; var la = new LineAppearance(); la.IconAppearance.Icon = Infragistics.UltraChart.Shared.Styles.SymbolIcon.Diamond; la.IconAppearance.IconSize = Infragistics.UltraChart.Shared.Styles.SymbolIconSize.Medium; la.Thickness = 0; lcapp.LineAppearances.Add(la); }
public ConstructGenGen<RelativeDate, double> GenerateHourlySums(DayField field_) { Func<RelativeDate, RelativeDate, bool> areSameHour = (a, b) => a.UnderlyingDate.IsSameHourAs(b.UnderlyingDate); try { var data = LinesAsRelativeDates(); m_lock.EnterReadLock(); var con = new ConstructGenGen<RelativeDate, double>(1); if (data == null) return null; var hour = data.Keys[0]; var sum = 0d; foreach (var rd in data.Keys) { if (areSameHour(hour, rd)) sum += data.GetValue(rd, 0).GetValue(field_); else { con.SetValue(new RelativeDate(hour.IndexDates, hour.UnderlyingDate.StartOfHour(),DispTimeZone), 0, sum); sum = 0; hour = rd; } } // do we need to commit last value var lastHour = new RelativeDate(hour.IndexDates, hour.UnderlyingDate.StartOfHour(),DispTimeZone); if (con.LastKey() != lastHour) con.SetValue(lastHour, 0, sum); return con; } finally { m_lock.ExitReadLock(); } }
private static ConstructGenGen<string, double> toYears(DatedDataCollectionGen<double> monthlyValues_) { var ret = new ConstructGenGen<string, double>(new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }); for (int i = 0; i < monthlyValues_.Length; ++i) { var date = monthlyValues_.Dates[i]; if (date.Year == DateTime.Today.Year) break; ret.SetValue(date.Year.ToString(), date.Month - 1, monthlyValues_.Data[i]); } return ret; }
private static async Task populateKnown(CarbonClient cc_) { var knownMonikers = AssetClassMonikerRoots.Roots.Select(x => string.Format("{0}.secmaster", x)); m_list = new ConstructGenGen<string, SecMasterEntry>(new[] {"Value"}); foreach (var moniker in knownMonikers) { Logger.Info(string.Format("Loading secmaster document [{0}]...", moniker), typeof (SecMasters)); var s = await DataFrameHelper.GetDataFrameByColumn( name_: moniker, keyExtractor_: x => x.ToString(), valueExtractor_: (idx,col) => { var invertValue = col[idx["invert"]]; bool invert; if (invertValue is bool) invert = (bool) col[idx["invert"]]; else bool.TryParse(invertValue.ToString(), out invert); var method = (string) col[idx["method"]]; PnlMethod mthd = PnlMethod.Arithmetic; switch(method.ToLower()) { case "arithmetic": mthd = PnlMethod.Arithmetic;break; case "geometric": mthd = PnlMethod.Geometric;break; case "swaps": mthd = PnlMethod.Swap;break; case "credit": mthd = PnlMethod.Credit;break; default: Logger.Warn(string.Format("Unknown pricing method of '{0}'. Will default to arithmetic.", method), typeof (SecMasters)); break; } return new SecMasterEntry { Invert = invert, Method = mthd }; }, cc_: cc_); if(s!=null) foreach (var key in s.Keys) { var val = s.GetValue(key, 0); val.Name = key; if (m_list.HasKey(key)) { var currentValue = m_list.GetValue(key, 0); if (!currentValue.Equals(val)) { Logger.Error( string.Format( "Entry for {0} is being overwritten with different values from another list. PriorSettings={1}. NewSettings={2}", val.Name, currentValue, val), typeof (SecMasters)); } } m_list.SetValue(key, 0, val); } } }
internal static void Reset() { m_list = null; }
public ConstructGenGen<RelativeDate, double> GetOIFrontBackOpenInterestValues(RollGeneration generation_) { if (m_oiInterestValues != null) return m_oiInterestValues; var day = GetDay(generation_); var hour = day.DispTimeZone == DisplayTimeZone.NYK ? 15 : 16; var ret = new ConstructGenGen<RelativeDate, double>(new[] { "Front", "Back" }); foreach (var date in day.Dates) { var relDate = new RelativeDate(day.Dates, date.AddHours(hour)); ret.SetValue(relDate, 0, day.OI_From.ValueOnDate(date)); ret.SetValue(relDate, 1, day.OI_To.ValueOnDate(date)); } return m_oiInterestValues = ret; }
public ConstructGenGen<RelativeDate,double> GetMinuteFrontBackOpenInterestValues(RollGeneration generation_) { var day = GetDay(generation_); var hour = day.DispTimeZone == DisplayTimeZone.NYK ? 15 : 16; var oiDates = day.Dates.Select(x => new Tuple<DateTime, RelativeDate>(x, new RelativeDate(day.Dates, x.AddHours(hour)))); var ret = new ConstructGenGen<RelativeDate, double>(new[] {"Front", "Back"}); try { m_lock.EnterReadLock(); var startDate = day.Dates.Min(); var frontStartingValue = day.OI_From.ValueOnDate(startDate, -1); var backStartingValue = day.OI_To.ValueOnDate(startDate, -1); double priorValueFront = frontStartingValue; double priorValueBack = backStartingValue; for (int i = 0; i < m_data.Keys.Count; ++i) { var key = m_data.Keys[i]; if (i == 0) { ret.SetValue(key, 0, frontStartingValue, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AddEveryTime); ret.SetValue(key, 1, backStartingValue, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AssumeKeyAlreadyThere); continue; } var matchOnExactOI = oiDates.FirstOrDefault(x => x.Item2 == key); bool handled = false; if (matchOnExactOI!=null) { var frontOI = priorValueFront = day.OI_From.ValueOnExactDate(matchOnExactOI.Item1); var backOI = priorValueBack = day.OI_To.ValueOnExactDate(matchOnExactOI.Item1); if (!frontOI.IsZero() || !backOI.IsZero()) { ret.SetValue(key, 0, frontOI, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AddEveryTime); ret.SetValue(key, 1, backOI, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AssumeKeyAlreadyThere); handled = true; } } if(!handled) { var line = m_data.GetValue(key, (int)generation_); double increment = line == null ? 0d : line.SpreadVolume; ret.SetValue(key, 0, priorValueFront - increment, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AddEveryTime); ret.SetValue(key, 1, priorValueBack + increment, ConstructGenGen<RelativeDate, double>.KeyOptionsWhenAdding.AssumeKeyAlreadyThere); priorValueFront -= increment; priorValueBack += increment; } } } finally { m_lock.ExitReadLock(); } return ret; }
public ConstructGenGen<RelativeDate, Line> LinesAsRelativeDates() { if (m_data != null ) return m_data; try { m_lock.EnterWriteLock(); m_data = new ConstructGenGen<RelativeDate, Line>(1); if(Lines!=null) foreach (var item in Lines) { item.CalcSeriesValue(DefaultTail); m_data.SetValue(new RelativeDate(IndexedDates, item.GmtDateAsDate().ToTZfromGMT(DispTimeZone),DispTimeZone), 0, item, ConstructGenGen<RelativeDate, Line>.KeyOptionsWhenAdding.AddEveryTime); } return m_data; } finally { m_lock.ExitWriteLock(); } }
public void ReRead() { ConstructGenGen<string, double> con = new ConstructGenGen<string, double>(2); con.ColumnHeadings = new string[] { EnumDescriptionAttribute.GetDescription(m_args.XAxis), EnumDescriptionAttribute.GetDescription(m_args.YAxis) }; foreach (var v in m_func()) { con.SetValues(v.Inst, new double[] { v.GetRawStat(m_args.XAxis), v.GetRawStat(m_args.YAxis) }); } m_scatter.Create(con); }
public ConstructGenGen<RelativeDate, Line> GetSubLinesAsRelativeDates(Func<RelativeDate, bool> shouldIncludeFunction_) { var data = LinesAsRelativeDates(); var ret = new ConstructGenGen<RelativeDate, Line>(1); try { m_lock.EnterReadLock(); foreach (var v in data.Keys.Where(x => shouldIncludeFunction_(x))) ret.SetValues(v, data.GetValues(v),ConstructGenGen<RelativeDate,Line>.KeyOptionsWhenAdding.AddEveryTime); } finally { m_lock.ExitReadLock(); } return ret; }
public SysTimeSeries MultiplyOut(DatedDataCollectionGen<double> allocation_, int offset_) { if (!HasData || allocation_==null) return null; var con = new ConstructGenGen<DateTime, double>(Data.ColumnHeadings); foreach (var date in Data.Keys) con.SetValues(date, Data.GetValues(date).MultiplyBy(allocation_.ValueOnDate(date,offset_))); return new SysTimeSeries {Data = con}; }
public async Task<PortfolioPnlCache> GetCurrentAllocatedExposureHistPnl(CarbonClient cc_, bool forcerefresh_ = false) { if (m_currentExpBackwards != null && !forcerefresh_) return m_currentExpBackwards.Value; var exp = await GetLatestAllocatedExposure(cc_, forcerefresh_); // if we haven't got exposure if (exp == null || exp.Item2 == null) { m_currentExpBackwards = new TriedObject<PortfolioPnlCache>(); return null; } var listOfColumns = new List<string>(); var listOfDailyReturns = new List<DatedDataCollectionGen<double>>(); for (int i = 0; i < exp.Item2.Length; ++i) { var exposureName = exp.Item1[i]; var exposure = exp.Item2[i]; if (exposure.IsZero()) continue; listOfColumns.Add(exposureName); // get the security master var secMaster = await SecMasters.Get(exposureName, cc_); // find equivalent TRS object var trInstrument = (secMaster == null) ? null : await secMaster.TRInstrument(cc_); // get TRS object's history var series = trInstrument == null ? null : await trInstrument.GetTimeSeries(cc_); if (series == null) { Logger.Error(string.Format("Could not find total return series for [{0}]", exposureName), typeof(Portfolio)); continue; } var dailyIncrements = series.ToReturns(); if (secMaster.Invert) dailyIncrements = dailyIncrements.MultiplyBy(-1d); listOfDailyReturns.Add(dailyIncrements.MultiplyBy(exposure)); } var con = new ConstructGenGen<DateTime, double>(listOfColumns.ToArray()); for (int i = 0; i < con.ArrayLength; ++i) con.SetColumnValues(i, listOfDailyReturns[i].Dates, listOfDailyReturns[i].Data); con.Keys.Sort((a, b) => a.CompareTo(b)); m_currentExpBackwards = new TriedObject<PortfolioPnlCache>(new PortfolioPnlCache(new SysTimeSeries { Data = con })); return m_currentExpBackwards.Value; }
private void analyse() { if (m_lastApplied == null) return; seasAverageNormalized.ClearSeries(); seasProbability.ClearSeries(); var allLevels = m_lastApplied.GetCombined(DataAroundEventField.Filled_Level); var allDiffs = m_lastApplied.GetCombined(DataAroundEventField.Filled_Daily_Diff); var subsetLevels = new ConstructGenGen<int, double>(allLevels.ColumnHeadings); var subsetDiffs = new ConstructGenGen<int, double>(allLevels.ColumnHeadings); // // get all the values for the subset that's been defined // foreach (var indexPoint in allLevels.Keys) { if (indexPoint < m_args.AnalysisStartIndex) continue; if (indexPoint > m_args.AnalysisEndIndex) break; subsetLevels.SetValues(indexPoint, allLevels.GetValues(indexPoint)); subsetDiffs.SetValues(indexPoint, allDiffs.GetValues(indexPoint)); } // // calculate and apply probabilities // var probType = ProbabilityCalcType.UpsMinusDownsOverNumber; var probabilities = new double[subsetDiffs.Keys.Count]; for (int i = 0; i < subsetDiffs.Keys.Count; ++i) { var valsForIndexPoint = allDiffs.GetValues(allDiffs.Keys[i]); probabilities[i] = ProbabilityCalc.CalcProb(valsForIndexPoint, probType); } // add probability column chart seasProbability.AddColumnChart("Probability", subsetLevels.Keys.Select(x => x.ToString()).ToArray(), probabilities, ProbabilityCalc.GetMaxValue(probType)); seasProbability.AddLegend(); // // calculate normlized series on subset // var normdValues = new ConstructGenGen<int, double>(allLevels.ColumnHeadings); var keys = subsetLevels.Keys.Select(x => x.ToString()).ToArray(); for(int i=0;i<subsetLevels.ArrayLength;++i) { var normd = subsetLevels.GetColumnValues(i).Normalize(); normdValues.SetColumnValues(i, subsetLevels.Keys.ToArray(), normd); } // // calculate average normalized series // var averageNorms = new double[normdValues.Keys.Count]; //var dispersionMeasure = new double[normdValues.Keys.Count]; for (int i = 0; i < averageNorms.Length; ++i) { var valuesToUse = normdValues.GetValues(normdValues.Keys[i]).Where(x => double.IsNaN(x) == false).ToArray(); averageNorms[i] = valuesToUse.Average(); //dispersionMeasure[i] = Statistics.Stdev(valuesToUse.Select(x=>x-averageNorms[i]).ToArray()); } // // normalize the average and display // averageNorms = averageNorms.Normalize(); seasAverageNormalized.AddLineChart("Seasonal pattern", keys, averageNorms); //seasAverageNormalized.AddColumnChart("stdev", keys, dispersionMeasure, dispersionMeasure.Max()); seasAverageNormalized.AddLegend(); }