Efficient/different way to align data series
up vote
1
down vote
favorite
What are some ways to align 2 data series (i.e stock data) so that the dates match?
I can think of a few ways.
- Duplicate older data to fill in
- Throw out any missing dates from both sets
Not sure how to wrap my head around this to do it efficiently my data is stored in 2 lists.
Here is what I've tried so far. I don't like these comparer classes, though:
baseBars = baseBars.Intersect(secondaryBars, new BarDateComparer()).ToList();
secondaryBars = secondaryBars.Intersect(baseBars, new BarDateComparer()).ToList();
public class BarDateComparer : IEqualityComparer<Bar>
{
public bool Equals(Bar x, Bar y)
{
return x.Date == y.Date;
}
public int GetHashCode(Bar obj)
{
return obj.Date.GetHashCode();
}
}
c#
add a comment |
up vote
1
down vote
favorite
What are some ways to align 2 data series (i.e stock data) so that the dates match?
I can think of a few ways.
- Duplicate older data to fill in
- Throw out any missing dates from both sets
Not sure how to wrap my head around this to do it efficiently my data is stored in 2 lists.
Here is what I've tried so far. I don't like these comparer classes, though:
baseBars = baseBars.Intersect(secondaryBars, new BarDateComparer()).ToList();
secondaryBars = secondaryBars.Intersect(baseBars, new BarDateComparer()).ToList();
public class BarDateComparer : IEqualityComparer<Bar>
{
public bool Equals(Bar x, Bar y)
{
return x.Date == y.Date;
}
public int GetHashCode(Bar obj)
{
return obj.Date.GetHashCode();
}
}
c#
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
What are some ways to align 2 data series (i.e stock data) so that the dates match?
I can think of a few ways.
- Duplicate older data to fill in
- Throw out any missing dates from both sets
Not sure how to wrap my head around this to do it efficiently my data is stored in 2 lists.
Here is what I've tried so far. I don't like these comparer classes, though:
baseBars = baseBars.Intersect(secondaryBars, new BarDateComparer()).ToList();
secondaryBars = secondaryBars.Intersect(baseBars, new BarDateComparer()).ToList();
public class BarDateComparer : IEqualityComparer<Bar>
{
public bool Equals(Bar x, Bar y)
{
return x.Date == y.Date;
}
public int GetHashCode(Bar obj)
{
return obj.Date.GetHashCode();
}
}
c#
What are some ways to align 2 data series (i.e stock data) so that the dates match?
I can think of a few ways.
- Duplicate older data to fill in
- Throw out any missing dates from both sets
Not sure how to wrap my head around this to do it efficiently my data is stored in 2 lists.
Here is what I've tried so far. I don't like these comparer classes, though:
baseBars = baseBars.Intersect(secondaryBars, new BarDateComparer()).ToList();
secondaryBars = secondaryBars.Intersect(baseBars, new BarDateComparer()).ToList();
public class BarDateComparer : IEqualityComparer<Bar>
{
public bool Equals(Bar x, Bar y)
{
return x.Date == y.Date;
}
public int GetHashCode(Bar obj)
{
return obj.Date.GetHashCode();
}
}
c#
c#
edited Nov 5 at 18:04
Cœur
16.8k9101139
16.8k9101139
asked Jan 17 '11 at 23:39
Curtis White
3,530124575
3,530124575
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
How about a LINQ approach:
var combinedSeries = from record in series1
join record2 in series2
on record.Date == record2.Date into JoinedLists
from joinedRecord in JoinedLists.DefaultIfEmpty()
orderby record.Date
select (whatever you want out of both records);
Excellent thought. Linq is so powerful! See my example above (haven't tested)
– Curtis White
Jan 17 '11 at 23:55
looks my solution wont work though.. hurhm
– Curtis White
Jan 18 '11 at 0:00
Updated with some new code.. I think it may work now.
– Curtis White
Jan 18 '11 at 0:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
How about a LINQ approach:
var combinedSeries = from record in series1
join record2 in series2
on record.Date == record2.Date into JoinedLists
from joinedRecord in JoinedLists.DefaultIfEmpty()
orderby record.Date
select (whatever you want out of both records);
Excellent thought. Linq is so powerful! See my example above (haven't tested)
– Curtis White
Jan 17 '11 at 23:55
looks my solution wont work though.. hurhm
– Curtis White
Jan 18 '11 at 0:00
Updated with some new code.. I think it may work now.
– Curtis White
Jan 18 '11 at 0:03
add a comment |
up vote
0
down vote
accepted
How about a LINQ approach:
var combinedSeries = from record in series1
join record2 in series2
on record.Date == record2.Date into JoinedLists
from joinedRecord in JoinedLists.DefaultIfEmpty()
orderby record.Date
select (whatever you want out of both records);
Excellent thought. Linq is so powerful! See my example above (haven't tested)
– Curtis White
Jan 17 '11 at 23:55
looks my solution wont work though.. hurhm
– Curtis White
Jan 18 '11 at 0:00
Updated with some new code.. I think it may work now.
– Curtis White
Jan 18 '11 at 0:03
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
How about a LINQ approach:
var combinedSeries = from record in series1
join record2 in series2
on record.Date == record2.Date into JoinedLists
from joinedRecord in JoinedLists.DefaultIfEmpty()
orderby record.Date
select (whatever you want out of both records);
How about a LINQ approach:
var combinedSeries = from record in series1
join record2 in series2
on record.Date == record2.Date into JoinedLists
from joinedRecord in JoinedLists.DefaultIfEmpty()
orderby record.Date
select (whatever you want out of both records);
answered Jan 17 '11 at 23:45
Chris B. Behrens
5,20953659
5,20953659
Excellent thought. Linq is so powerful! See my example above (haven't tested)
– Curtis White
Jan 17 '11 at 23:55
looks my solution wont work though.. hurhm
– Curtis White
Jan 18 '11 at 0:00
Updated with some new code.. I think it may work now.
– Curtis White
Jan 18 '11 at 0:03
add a comment |
Excellent thought. Linq is so powerful! See my example above (haven't tested)
– Curtis White
Jan 17 '11 at 23:55
looks my solution wont work though.. hurhm
– Curtis White
Jan 18 '11 at 0:00
Updated with some new code.. I think it may work now.
– Curtis White
Jan 18 '11 at 0:03
Excellent thought. Linq is so powerful! See my example above (haven't tested)
– Curtis White
Jan 17 '11 at 23:55
Excellent thought. Linq is so powerful! See my example above (haven't tested)
– Curtis White
Jan 17 '11 at 23:55
looks my solution wont work though.. hurhm
– Curtis White
Jan 18 '11 at 0:00
looks my solution wont work though.. hurhm
– Curtis White
Jan 18 '11 at 0:00
Updated with some new code.. I think it may work now.
– Curtis White
Jan 18 '11 at 0:03
Updated with some new code.. I think it may work now.
– Curtis White
Jan 18 '11 at 0:03
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4719109%2fefficient-different-way-to-align-data-series%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password