Version

Sample Stocks Data

Purpose

This topic provides sample data and data models for use with the XamDataChart™ control and its Financial Series and Financial Indicators types.

In this topic

This topic contains the following sections:

Required Namespaces

In C#:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;

namespace Infragistics.Models
{
  // TODO add data model
  // TODO add data source
}

Data Model

In C#:

public class StockPriceItem
{
    public double Volume { get; set; }
    public double Open { get; set; }
    public double Close { get; set; }
    public double High { get; set; }
    public double Low { get; set; }
    public DateTime Date { get; set; }
}

Data Source

In C#:

public class StockPriceData : List<StockPriceItem>
{
    protected internal Random Rand = new Random();

    public StockPriceData()
    {
        double open = 500, close, low, high, mod;
        double volume = 10000;
        var total = 100;
        var range = 5;
        var date = DateTime.Now.AddDays(-total);
        for (var i = 0; i < total; i++)
        {
            low = open - (Rand.NextDouble() * range);
            high = open + (Rand.NextDouble() * range);
            mod = Rand.NextDouble() - 0.4;
            close = open + (mod * range);
            var item = new StockPriceItem();
            item.Volume = volume;
            item.Open = open;
            item.Close = close;
            item.High = high;
            item.Low = low;
            item.Volume = volume;
            item.Date = date;
            this.Add(item);
            open = open + (mod * range * 2);
            volume = volume + (mod * range * 100 );
            date = date.AddDays(1);
        }
    }
}