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.




  1. Duplicate older data to fill in

  2. 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();
}

}









share|improve this question




























    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.




    1. Duplicate older data to fill in

    2. 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();
    }

    }









    share|improve this question


























      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.




      1. Duplicate older data to fill in

      2. 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();
      }

      }









      share|improve this question















      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.




      1. Duplicate older data to fill in

      2. 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#






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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
























          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);





          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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
































          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);





          share|improve this answer





















          • 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















          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);





          share|improve this answer





















          • 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













          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);





          share|improve this answer












          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);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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




















































































          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()