using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Finance.Data
{
public class StockDataSource : Finance.Common.BindableBase
{
public StockDataSource()
{
LoadSampleData();
}
private ObservableCollection<StockSymbol> _symbols = newObservableCollection<StockSymbol>();
public ObservableCollection<StockSymbol> Symbols
{
get { return this._symbols; }
}
private StockSymbol _selectedSymbol;
public StockSymbol SelectedSymbol
{
get { return this._selectedSymbol; }
set { this.SetProperty(ref this._selectedSymbol, value); }
}
private string[] symbols = new string[] { “MSFT”, “DOW”, “AAPL”, “NASDAQ”,“GOOG”,“YHOO” };
privatestring[] names = new string[] { “Microsoft”, “Dow Jones”, “Apple”, “NASDAQ”,“Google”,“YAHOO” };
private constint NUMPOINTS = 2555;
private DateTime date;
private void LoadSampleData()
{
Random rnd = newRandom();
_symbols.Clear();
for (int i = 0; i < symbols.Length; i++)
{
StockSymbol ss1 = newStockSymbol();
ss1.Name = names[i];
ss1.Symbol = symbols[i];
ss1.Change = rnd.Next(500, 1500) + rnd.NextDouble();
ss1.ChangePercent = rnd.NextDouble();
ss1.Open = rnd.Next(100, 500);
if (rnd.Next(10) % 2 == 0)
{
ss1.Change = 0 – ss1.Change;
ss1.ChangePercent = 0 – ss1.Change;
ss1.Close = rnd.Next(100, ( int)ss1.Open);
}
else
{
ss1.Close = rnd.Next((int)ss1.Open, 500);
}
ss1.Date = DateTime.Now;
int previous = rnd.Next(50, 100);
date = newDateTime(DateTime.Now.Subtract(newTimeSpan(NUMPOINTS / 7, NUMPOINTS % 7, 0, 0)).Ticks);
for (int j = 0; j < NUMPOINTS; j++)
{
var value = rnd.Next(previous – 5, previous + 6);
StockHistoricalData shd = newStockHistoricalData();
shd.Volume = value;
shd.Date = date;
UpdateDate();
ss1.Items.Add(shd);
previous = value;
}
_symbols.Add(ss1);
}
}
private void UpdateDate()
{
date = date.AddHours(1);
if (date.Hour > 16)
{
date = date.AddDays(1);
date = date.Subtract(newTimeSpan(7, 0, 0));
}
}
}
public class StockSymbol : Finance.Common.BindableBase
{
public StockSymbol()
{
}
private string _name = string.Empty;
public string Name
{
get { return this._name; }
set { this.SetProperty(ref this._name, value); }
}
private string _symbol = string.Empty;
public string Symbol
{
get { return this._symbol; }
set { this.SetProperty(ref this._symbol, value); }
}
private double _change = double.NaN;
public double Change
{
get { return this._change; }
set { this.SetProperty(ref this._change, value); }
}
public double _changePercent = double.NaN;
public double ChangePercent
{
get { return this._changePercent; }
set { this.SetProperty(ref this._changePercent, value); }
}
private float _open = float.NaN;
public float Open
{
get { return this._open; }
set { this.SetProperty(ref this._open, value); }
}
private float _close = float.NaN;
public float Close
{
get { return this._close; }
set { this.SetProperty(ref this._close, value); }
}
private bool _isPositive = true;
public bool IsPositive
{
get { return this._isPositive; }
set { this.SetProperty(ref this._isPositive, value); }
}
private DateTime _date = DateTime.Now;
public DateTime Date
{
get { return this._date; }
set { this.SetProperty(ref this._date, value); }
}
private ObservableCollection<StockHistoricalData> _items = newObservableCollection<StockHistoricalData>();
public ObservableCollection<StockHistoricalData> Items
{
get { return this._items; }
}
}
public class StockHistoricalData : Finance.Common.BindableBase
{
public StockHistoricalData()
{
}
private DateTime _date = DateTime.Now;
public DateTime Date
{
get { return this._date; }
set { this.SetProperty(ref this._date, value); }
}
private float _open = float.NaN;
public float Open
{
get { return this._open; }
set { this.SetProperty(ref this._open, value); }
}
private float _close = float.NaN;
public float Close
{
get { return this._close; }
set { this.SetProperty(ref this._close, value); }
}
private float _high = float.NaN;
public float High
{
get { return this._high; }
set { this.SetProperty(ref this._high, value); }
}
private float _low = float.NaN;
public float Low
{
get { return this._low; }
set { this.SetProperty(ref this._low, value); }
}
private float _volume = float.NaN;
public float Volume
{
get { return this._volume; }
set { this.SetProperty(refthis._volume, value); }
}
}
}
You must be logged in to post a comment.