// Constructor 2 : Interest Rate Line public myFrame_old(List <InterestRate_Line> databaseLine) { // 1. Perform checks on number of series @TODO if (databaseLine.Count() != 0) { // 2. Extract fields from any DB line List <string> fieldsList = databaseLine.FirstOrDefault().GetDataFields(); // 3. Initialize the dict foreach (string field in fieldsList) { data[field] = new mySeries(); } // 4. Fill the dict foreach (InterestRate_Line line in databaseLine) { foreach (string field in fieldsList) { data[field].pushback(line.Date, (double)line[field]); } } } }
// ************************************************************ // LOAD-RELATED METHODS // ************************************************************ #region // LOAD THE OBJECT FROM A DICT OF DICT public void fromDictOfDict(SortedDictionary <string, SortedDictionary <DateTime, double> > argDictOfDict) { foreach (string mySeriesName in argDictOfDict.Keys) { mySeries mymySeries = new mySeries(argDictOfDict[mySeriesName]); this.add(mySeriesName, mymySeries); } }
// REPLACE mySeries WITHIN EXISTING FRAME public void replace(string argmySeriesName, mySeries argmySeries) { if (this.data.ContainsKey(argmySeriesName)) { this.remove(argmySeriesName); this.add(argmySeriesName, argmySeries); } }
// ADD FRAME TO FRAME public void add(string argmySeriesName, mySeries argmySeries) { // Perform sanity checks // @TODO : to be implemented // Add to frame this.data[argmySeriesName] = argmySeries; }
// MERGE INDEX public SortedSet <DateTime> mergeIndex(mySeries argmySeries) // previously hashset { // http://www.dotnetperls.com/combine-keys SortedSet <DateTime> ans = new SortedSet <DateTime>(this.data.Keys); ans.UnionWith(argmySeries.data.Keys); return(ans); }
// POWERS public mySeries Power(double argExp) { mySeries answer = new mySeries(); foreach (DateTime dt in this.data.Keys) { answer[dt] = Math.Pow(this[dt], argExp); } return(answer); }
// LOGARITHM LN public mySeries LN(double argExp) { mySeries answer = new mySeries(); foreach (DateTime dt in this.data.Keys) { answer[dt] = Math.Log(argExp * this[dt]); } return(answer); }
public static mySeries operator -(double num, mySeries den) { mySeries answer = new mySeries(); foreach (DateTime dt in den.data.Keys) { answer[dt] = num - den[dt]; } return(answer); }
public static mySeries operator -(mySeries num, double den) { mySeries answer = new mySeries(); foreach (DateTime dt in num.data.Keys) { answer[dt] = num[dt] - den; } return(answer); }
// CONCAT mySeries public mySeries concat(mySeries argmySeries) { SortedDictionary <DateTime, double> ans = new SortedDictionary <DateTime, double>(this.data); foreach (DateTime dt in argmySeries.data.Keys.Where(x => !this.data.Keys.Contains(x))) { ans.Add(dt, argmySeries.data[dt]); } return(new mySeries(ans)); }
// SWAP FRAME WITHIN FRAME public mySeries swap(string argmySeriesName, mySeries argmySeries) { mySeries ans = new mySeries(); if (this.data.ContainsKey(argmySeriesName)) { ans = this.pop(argmySeriesName); this.add(argmySeriesName, argmySeries); } return(ans); }
// POP FRAME FROM FRAME public mySeries pop(string argmySeriesName) { mySeries ans = new mySeries(); if (this.data.ContainsKey(argmySeriesName)) { ans = this.data[argmySeriesName]; this.remove(argmySeriesName); } return(ans); }
// SUBTRACTION public static mySeries operator -(mySeries num, mySeries den) { mySeries ansNum = num.merge(den); mySeries ansDen = den.merge(num); mySeries answer = new mySeries(); foreach (DateTime dt in ansNum.data.Keys) { answer[dt] = ansNum[dt] - ansDen[dt]; } return(answer); }