using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using MarketData.MarketDataModel;

namespace TradeBlotter.Model
{
  public class PricesModel
  {
    private PricesModel()
    {
    }
    public static CompositeDataSource Close(Prices prices)
    {
      if (null == prices) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(prices.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(prices.Select(y => y.Close));
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
    public static CompositeDataSource LeastSquares(Prices prices)
    {
      if (null == prices) return null;
      CompositeDataSource compositeDataSource;
      var xData = new EnumerableDataSource<DateTime>(prices.Select(x => x.Date.Date));
      xData.SetXMapping(x => (x.Ticks / 10000000000.0));
      var yData = new EnumerableDataSource<double>(prices.GetLeastSquaresFit());
      yData.SetYMapping(y => y);
      compositeDataSource = xData.Join(yData);
      return compositeDataSource;
    }
  }
  public class PriceModel
  {
    private Price price;
    private float return1d;
    private float return5d;
    private float return10d;
    private float return15d;
    private float return30d;
    private float return60d;
    private float return200d;
    private String companyName;
    public PriceModel(Price price,float return1d,float return5d,float return10d,float return15d,float return30d,float return60d,float return200d,String companyName)
    {
      this.price = price;
      this.return1d = return1d;
      this.return5d = return5d;
      this.return10d = return10d;
      this.return15d = return15d;
      this.return30d=return30d;
      this.return60d=return60d;
      this.return200d=return200d;
      this.companyName = companyName;
    }
    public String CompanyName
    {
      get { return companyName; }
    }
    public String Symbol
    {
      get { return price.Symbol; }
    }
    public String Source
    {
      get {return price.SourceAsString();}
    }
    public DateTime Date
    {
      get { return price.Date; }
    }
    public double Open
    {
      get { return price.Open; }
    }
    public double High
    {
      get { return price.High; }
    }
    public double Low
    {
      get { return price.Low; }
    }
    public double Close
    {
      get { return price.Close; }
    }
    public long Volume
    {
      get { return price.Volume; }
    }
    public double AdjClose
    {
      get { return price.AdjClose; }
    }
    public float Return1D
    {
      get { return return1d; }
    }
    public float Return5D
    {
      get { return return5d; }
    }
    public float Return10D
    {
      get { return return10d; }
    }
    public float Return15D
    {
      get { return return15d; }
    }
    public float Return30D
    {
      get{return return30d;}
    }
    public float Return60D
    {
      get{return return60d;}
    }
    public float Return200D
    {
      get{return return200d;}
    }
  }
}
