Blogs

Bryan Wood - DevExpress Charts Blog

information and training regarding all things DevExpress Charting.

Financial Charts Part 2–Excluding Days (Coming in v 2010 vol 2)

     

Missing-VS-Complete-FinancialChart

One of the issues when dealing with stock data is dealing with holes in the data. Weekends and holidays are usually where you will find missing data and this is easily covered with the new Exclusion tools coming in v2010.2. If the market was closed due to some reason outside of a holiday or weekend it won’t be excluded and because of that you will have a gap in your chart.

If you just want to exclude weekends and holidays there is a great video tutorial located here: http://tv.devexpress.com/#XtraChartsExcludeDays

To Summarize I am going to consider the data I get from Yahoo to be the master data and if it doesn’t have a day of data than I want to skip it on the chart and not plot anything for that day.

Include Only Valid Days

private void SetupVisibleDays(IEnumerable barsToShow)
{
    XYDiagram diagram = (XYDiagram)stockChart.Diagram;
    diagram.AxisX.WorkdaysOnly = true;

    DateTime endDate = barsToShow.First().Date;
    DateTime startDate = barsToShow.Last().Date;

    List completeDateList = new List();
            
    // Create a list that contains all of the days in the range
    for (int i = 0; i < 1 + endDate.Subtract(startDate).Days; i++)
    {
        completeDateList.Add(startDate.AddDays(i));
    }

    // using a dictionary so that I can use the ContainsKey method for quick lookup
    Dictionary availableDays = barsToShow
        .ToDictionary(val => val.Date, val => val.Date.ToShortDateString());

    // loop through the date range and add 
    // days that aren't found to the holiday list
    foreach (DateTime currentDate in completeDateList)
    {
        if ((currentDate.DayOfWeek != DayOfWeek.Saturday 
            || currentDate.DayOfWeek != DayOfWeek.Sunday)
            && availableDays.ContainsKey(currentDate) == false)
        {
            diagram.AxisX.WorkdaysOptions.Holidays.Add(
                new KnownDate(currentDate.ToShortDateString(), currentDate));
        }
    }

}

What the above code does is creates a baseline list of dates that spans all of the dates from the beginning to the ending dates from the barsToShow list.  Then we step through all the dates and if it isn’t a weekend day and we can’t find it in our source data (barsToShow) then we add it to the holidays list so that it will be excluded when the chart rendered.

Conclusion

Alternately I could have used a ScaleType.Qualitative, but that would have introduced other issues. For one I would have had to account for the X axis labeling. Second and more importantly would have been performance, the ScaleType.DateTime is an indexed scale type so it is very performant, had I used ScaleType.Qualitative I would have lost that indexing and large datasets would have increased page load time significantly.

The Weekend & Holiday Exclusion features and new features and will be included in DevExpress v2010 ver 2.

Published Nov 17 2010, 09:17 AM by Bryan Wood (DevExpress)
Filed under: , ,
Technorati tags: Charts, Stocks, Financial
Bookmark and Share

Comments

 

Sergey Butenko said:

It's very actual feature! Thank you, DevExpress!

November 18, 2010 3:04 AM
 

Bryan Wood (DevExpress) said:

Sergey, thanks for the feedback we are excited by what we are going to deliver in this next release. Stay tuned for more info.

November 18, 2010 3:54 AM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.