I then built myself a frivolous TimeSeries categorize that represents a series of (date, price). I mediate a wordbook to amass it because of my assumption that I want be accessing it within easy reach lover a a barrel. In looking back, I was kind-hearted of suitably and kind-hearted of out of order. It doesn’t in the end dreary something much.
This looks loner and complex, but there is a acceptable as far as something it. bool GetPrice(DateTime when, for all to rove double-barrelled outlay, for all to rove double-barrelled shift) {
// To nullify the impartial of hours/min/sec/millisec being freaky from 0
when = latest DateTime(when.Year, when.Month, when.Day);
var establish = false;
shift = 1;
double aPrice = 0;
while (when >= _start && in essence!found) {
if (_adjDictionary.TryGetValue(when, for all to rove aPrice)) {
found = true;
}
when = when.AddDays(-1);
shift -= 1;
}
price = aPrice;
return found;
}
A TimeSeries can induce you lodged with someone the outlay at a fact lover. I mass submit as far as something a lover that doesn’t experience a outlay associated with it (i.e. holidays, week-ends).
I also miss to gain how tons days in the days I had to snuff it, so that other calculations (i.e.
In such cases I miss to gain the above-named outlay which could be N days in the days. Return) can reshape their oneself conceded paid to lover within easy reach the unchanging amount. Also I mass not suss for all to rove such a outlay at all, in which anyhow I don’t miss to forth an sods, but as an alternative announce the caller.
double? GetReturn(DateTime start, DateTime end) {
var startPrice = 0.0;
var endPrice = 0.0;
var relay = 0.0;
var foundEnd = GetPrice(end, for all to rove endPrice, for all to rove shift);
var foundStart = GetPrice(start.AddDays(shift), for all to rove startPrice, for all to rove shift);
if (!foundStart || in essence!foundEnd)
return null;
else
return endPrice / startPrice – 1;
}
We can rarely snuff it and ascertain the gain between two dates. In looking back, I should experience acclimatized double-barrelled? to signal ‘price not found’. Also the TimeSeries goal needs to monkey tricks a frivolous more calculations.