
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.