public double[] getInstrumentReturns(string instrumentID, DateTime startDate, DateTime endDate) { double[] returnsArray = null; try { Series <DateTime, double> instrumentPricesColumn = instrumentPricesHistory.GetColumn <double>(instrumentID); Series <DateTime, double> instrumentPrices = instrumentPricesColumn.Between(startDate, endDate); Series <DateTime, double> instrumentReturns = (instrumentPrices.Diff(1) / instrumentPrices).DropMissing(); returnsArray = new double[instrumentReturns.ValueCount]; int i = 0; foreach (double instrumentReturn in instrumentReturns.Values) { returnsArray[i] = instrumentReturn; i++; } } catch (Exception ex) { throw new DAOException(DAOException.UNKNOWN_ERROR, "Unknown error occurred when trying to obatain returns", ex); } return(returnsArray); }
public static Series <DateTime, MarketDataElement> getLastNMarketData(Series <DateTime, MarketDataElement> series, int n) { MarketDataElement lastItem = series.GetAt(series.KeyCount - 1); DateTime tempStartTime = lastItem.time.AddMinutes(-n + 1); Series <DateTime, MarketDataElement> tempSeries = series.Between(tempStartTime, lastItem.time); if (tempSeries.KeyCount == n) { return(tempSeries); } //bool found=false; while (true) { //log.Info("testing 3"); tempStartTime = tempStartTime.AddMinutes(-1); tempSeries = series.Between(tempStartTime, lastItem.time); if (tempSeries.KeyCount == n) { return(tempSeries); } } }
public DeedleControl() { var xx = dict[nameof(Data)] .CombineLatest( dict[nameof(Date)].StartWith("Date"), dict[nameof(Value)].StartWith("Value"), (data, date, value) => Task.Run(() => GetData(data, (string)date, (string)value))) .Subscribe(async _ => { data = await _; await ChangePlotModel(data); }); var xx2 = dict[nameof(Upper)].CombineLatest(dict[nameof(Lower)], (upper, lower) => Task.Run(() => data?.Between((DateTime)lower, (DateTime)upper))) .Subscribe(async _ => await ChangePlotModel(await _)); var xx3 = dict[nameof(DiffIndex)].Select(_ => Task.Run(() => data?.Diff((int)_))) .Subscribe(async _ => await ChangePlotModel(await _)); }