using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using MarketData.Utils;
using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketData.Generator;
using TradeBlotter.Command;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using TradeBlotter.Model;
using TradeBlotter.UIUtils;
using TradeBlotter.Cache;

namespace TradeBlotter.ViewModels
{
  public class HistoricalViewModel : WorkspaceViewModel
  {
    private String companyName;
    private List<String> symbols;
    private List<String> watchLists;
    private String selectedWatchList;
    private String selectedSymbol;
    private RelayCommand refreshCommand;
    private TimeSeriesCollection bvpsSeries;
    private TimeSeriesCollection epsSeries;
    private TimeSeriesCollection freeCashflowSeries;
    private TimeSeriesCollection operatingCashflowSeries;
    private TimeSeriesCollection operatingIncomeSeries;
    private TimeSeriesCollection revenueSeries;
    private TimeSeriesCollection roicSeries;
    private TimeSeriesCollection roaSeries;
    private TimeSeriesCollection workingCapitalSeries;
    private TimeSeriesCollection quarterlyRevenueSeries;  
    private TimeSeriesCollection inventorySeries;
    private TimeSeriesCollection quarterlyInventorySeries;
    private TimeSeriesCollection goodwillSeries;
    private TimeSeriesCollection quarterlyGoodwillSeries;
    private TimeSeriesCollection netIncomeAvailableToCommonShareholdersSeries;
    private TimeSeriesCollection peSeries;
    private TimeSeriesCollection profitMarginSeries;
    private TimeSeriesCollection combinedSeries;
    private TimeSeriesCollection totalCashSeries;
    private DividendLoadCollection dividendLoadSeries;
    private TimeSeriesCollection debtToEquitySeries;
    private bool busyIndicator = false;

    public HistoricalViewModel()
    {
      base.DisplayName = "HistoricalView";
      watchLists = WatchListDA.GetWatchLists();
      watchLists.Insert(0, Constants.CONST_ALL);
      selectedWatchList = watchLists.Find(x => x.Equals("Valuations"));
      symbols = WatchListDA.GetWatchList(selectedWatchList);
      PropertyChanged += OnHistoricalViewModelPropertyChanged;
    }
    public override SaveParameters GetSaveParameters()
    {
      return null;
    }
    public override void SetSaveParameters(SaveParameters saveParameters)
    {
      try
      {
        selectedSymbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
        selectedWatchList = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedWatchList") select item).FirstOrDefault().Value;
        Referer=saveParameters.Referer;
        base.OnPropertyChanged("SelectedWatchList");
        base.OnPropertyChanged("SelectedSymbol");
      }
      catch (Exception)
      {
      }
    }
    public override bool CanPersist()
    {
      return false;
    }
    private void OnHistoricalViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
    {
      if (eventArgs.PropertyName.Equals("SelectedSymbol"))
      {
        BusyIndicator = true;
        Task workerTask = Task.Factory.StartNew(() =>
        {
          companyName = PricingDA.GetNameForSymbol(selectedSymbol);
          bvpsSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.BVPS);
          epsSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.EPS);
          freeCashflowSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.FreeCashflow);
          operatingCashflowSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.OperatingCashflow);
          operatingIncomeSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.OperatingIncome);
          revenueSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.Revenue);
          roicSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.ROIC);
          roaSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.ROA);
          workingCapitalSeries = HistoricalDA.GetTimeSeries(selectedSymbol, TimeSeriesElement.ElementType.WorkingCapital);
          netIncomeAvailableToCommonShareholdersSeries = HistoricalDA.GetTimeSeries(selectedSymbol,TimeSeriesElement.ElementType.NetIncomeAvailableToCommonShareholders);
          quarterlyRevenueSeries = IncomeStatementDA.GetRevenue(selectedSymbol, IncomeStatement.PeriodType.Quarterly);
          quarterlyInventorySeries = BalanceSheetDA.GetInventory(selectedSymbol, BalanceSheet.PeriodType.Quarterly);
          inventorySeries = BalanceSheetDA.GetInventory(selectedSymbol, BalanceSheet.PeriodType.Annual);
          quarterlyGoodwillSeries = BalanceSheetDA.GetGoodwill(selectedSymbol, BalanceSheet.PeriodType.Quarterly);
          goodwillSeries = BalanceSheetDA.GetGoodwill(selectedSymbol, BalanceSheet.PeriodType.Annual);
          peSeries = FundamentalDA.GetPERatio(selectedSymbol);
          profitMarginSeries=IncomeStatementDA.GetProfitMargin(selectedSymbol);
          combinedSeries=CreateROICWACCSeries();
          totalCashSeries=FundamentalDA.GetTotalCashMils(selectedSymbol);
          dividendLoadSeries=CompositeDA.GetDividendLoad(selectedSymbol);
          debtToEquitySeries=CompositeDA.GetDebtToEquity(selectedSymbol);
        });
        workerTask.ContinueWith((continuation) =>
        {
          BusyIndicator = false;
          base.OnPropertyChanged("BVPS");
          base.OnPropertyChanged("BVPSTitle");
          base.OnPropertyChanged("CompanyName");
          base.OnPropertyChanged("EPS");
          base.OnPropertyChanged("EPSTitle");
          base.OnPropertyChanged("FreeCashflow");
          base.OnPropertyChanged("FCFTitle");
          base.OnPropertyChanged("OperatingCashflow");
          base.OnPropertyChanged("OCFTitle");
          base.OnPropertyChanged("OperatingIncome");
          base.OnPropertyChanged("OITitle");
          base.OnPropertyChanged("Revenue");
          base.OnPropertyChanged("RevenueTitle");
          base.OnPropertyChanged("QuarterlyRevenue");
          base.OnPropertyChanged("QuarterlyRevenueTitle");
          base.OnPropertyChanged("ROIC");
          base.OnPropertyChanged("ROA");
          base.OnPropertyChanged("ROICWACC");
          base.OnPropertyChanged("NetIncomeAvailableToCommonShareholders");
          base.OnPropertyChanged("PE");
          base.OnPropertyChanged("ProfitMargin");
          base.OnPropertyChanged("TotalCash");
          base.OnPropertyChanged("DividendLoad");
          base.OnPropertyChanged("DebtToEquity");

          base.OnPropertyChanged("ROICTitle");
          base.OnPropertyChanged("ROICROATitle");
          base.OnPropertyChanged("ROATitle");
          base.OnPropertyChanged("WorkingCapital");
          base.OnPropertyChanged("WorkingCapitalTitle");
          base.OnPropertyChanged("Inventory");
          base.OnPropertyChanged("InventoryTitle");
          base.OnPropertyChanged("QuarterlyInventory");
          base.OnPropertyChanged("QuarterlyInventoryTitle");
          base.OnPropertyChanged("Goodwill");
          base.OnPropertyChanged("GoodwillTitle");
          base.OnPropertyChanged("QuarterlyGoodwill");
          base.OnPropertyChanged("QuarterlyGoodwillTitle");
          base.OnPropertyChanged("NetIncomeAvailableToCommonShareholdersTitle");
          base.OnPropertyChanged("PETitle");
          base.OnPropertyChanged("ProfitMarginTitle");
          base.OnPropertyChanged("TotalCashTitle");
          base.OnPropertyChanged("Title");
          base.OnPropertyChanged("DividendLoadTitle");
          base.OnPropertyChanged("DebtToEquityTitle");
        });
      }
      else if (eventArgs.PropertyName.Equals("SelectedWatchList"))
      {
//        if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = PricingDA.GetSymbols();
        if (selectedWatchList.Equals(Constants.CONST_ALL)) symbols = SymbolCache.GetInstance().GetSymbols();
        else symbols = WatchListDA.GetWatchList(selectedWatchList);
        base.OnPropertyChanged("Symbols");
      }
    }
// **********************************************************************************************
    public bool BusyIndicator
    {
      get { return busyIndicator; }
      set
      {
        busyIndicator = value;
        base.OnPropertyChanged("BusyIndicator");
      }
    }
    public String TotalCashTitle
    {
      get
      {
        if (null == companyName || null == totalCashSeries || 0 == totalCashSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(totalCashSeries[totalCashSeries.Count-1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(totalCashSeries[0].AsOf);
      }
    }
    public String ProfitMarginTitle
    {
      get
      {
        if (null == companyName || null == profitMarginSeries || 0 == profitMarginSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(profitMarginSeries[profitMarginSeries.Count-1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(profitMarginSeries[0].AsOf);
      }
    }
    public String PETitle
    {
      get
      {
        if (null == companyName || null == peSeries || 0 == peSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(peSeries[peSeries.Count-1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(peSeries[0].AsOf);
      }
    }
    public String BVPSTitle
    {
      get
      {
        if (null == companyName || null == bvpsSeries || 0 == bvpsSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(bvpsSeries[bvpsSeries.Count-1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(bvpsSeries[0].AsOf);
      }
    }
    public String EPSTitle
    {
      get
      {
        if (null == companyName || null == epsSeries || 0 == epsSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(epsSeries[epsSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(epsSeries[0].AsOf);
      }
    }
    public String FCFTitle
    {
      get
      {
        if (null == companyName || null == freeCashflowSeries || 0 == freeCashflowSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(freeCashflowSeries[freeCashflowSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(freeCashflowSeries[0].AsOf);
      }
    }
    public String OCFTitle
    {
      get
      {
        if (null == companyName || null == operatingCashflowSeries || 0 == operatingCashflowSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(operatingCashflowSeries[operatingCashflowSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(operatingCashflowSeries[0].AsOf);
      }
    }
    public String OITitle
    {
      get
      {
        if (null == companyName || null == operatingIncomeSeries || 0 == operatingIncomeSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(operatingIncomeSeries[operatingIncomeSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(operatingIncomeSeries[0].AsOf);
      }
    }
    public String RevenueTitle
    {
      get
      {
        if (null == companyName || null == revenueSeries || 0 == revenueSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(revenueSeries[revenueSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(revenueSeries[0].AsOf);
      }
    }
    public String QuarterlyRevenueTitle
    {
      get
      {
        if (null == companyName || null == quarterlyRevenueSeries || 0 == quarterlyRevenueSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(quarterlyRevenueSeries[quarterlyRevenueSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(quarterlyRevenueSeries[0].AsOf);
      }
    }
    public String InventoryTitle
    {
      get
      {
        if (null == companyName || null == inventorySeries || 0 == inventorySeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(inventorySeries[inventorySeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(inventorySeries[0].AsOf);
      }
    }
    public String QuarterlyInventoryTitle
    {
      get
      {
        if (null == companyName || null == quarterlyInventorySeries || 0 == quarterlyInventorySeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(quarterlyInventorySeries[quarterlyInventorySeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(quarterlyInventorySeries[0].AsOf);
      }
    }
    public String GoodwillTitle
    {
      get
      {
        if (null == companyName || null == goodwillSeries || 0 == goodwillSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(goodwillSeries[goodwillSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(goodwillSeries[0].AsOf);
      }
    }
    public String QuarterlyGoodwillTitle
    {
      get
      {
        if (null == companyName || null == quarterlyGoodwillSeries || 0 == quarterlyGoodwillSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(quarterlyGoodwillSeries[quarterlyGoodwillSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(quarterlyGoodwillSeries[0].AsOf);
      }
    }
    public String ROICTitle
    {
      get
      {
        if (null == companyName || null == roicSeries || 0 == roicSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(roicSeries[roicSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(roicSeries[0].AsOf);
      }
    }
    public String WorkingCapitalTitle
    {
      get
      {
        if (null == companyName || null == workingCapitalSeries || 0 == workingCapitalSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(workingCapitalSeries[workingCapitalSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(workingCapitalSeries[0].AsOf);
      }
    }
    public String ROICROATitle
    {
      get
      {
        if (null == companyName || null == roicSeries || 0 == roicSeries.Count || null==roaSeries || 0==roaSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(roicSeries[roicSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(roicSeries[0].AsOf);
      }
    }
    public String ROATitle
    {
      get
      {
        if (null == companyName || null==roaSeries || 0==roaSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(roicSeries[roaSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(roaSeries[0].AsOf);
      }
    }
    public String NetIncomeAvailableToCommonShareholdersTitle
    {
      get
      {
        if (null == companyName || null == netIncomeAvailableToCommonShareholdersSeries || 0 == netIncomeAvailableToCommonShareholdersSeries.Count) return "";
        return Utility.DateTimeToStringMMHDDHYYYY(netIncomeAvailableToCommonShareholdersSeries[netIncomeAvailableToCommonShareholdersSeries.Count - 1].AsOf) + " Thru " + Utility.DateTimeToStringMMHDDHYYYY(netIncomeAvailableToCommonShareholdersSeries[0].AsOf);
      }
    }
    public String DividendLoadTitle
    {
      get
      {
        if (null == companyName || null == dividendLoadSeries || 0 == dividendLoadSeries.Count) return "";
        return dividendLoadSeries[dividendLoadSeries.Count - 1].Year.ToString() + " Thru " + dividendLoadSeries[0].Year.ToString();
      }
    }
    public String DebtToEquityTitle
    {
      get
      {
        if (null == companyName || null == debtToEquitySeries || 0 == debtToEquitySeries.Count) return "";
        return debtToEquitySeries[debtToEquitySeries.Count - 1].AsOf.ToString() + " Thru " + debtToEquitySeries[0].AsOf.ToString();
      }
    }
    //**********************************C O M P O S I T E  D A T A  S O U R C E****************************************************************************
    public CompositeDataSource TotalCash
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(totalCashSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource ProfitMargin
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(profitMarginSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource PE
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(peSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource BVPS
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(bvpsSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource EPS
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(epsSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource FreeCashflow
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(freeCashflowSeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource OperatingCashflow
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(operatingCashflowSeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource OperatingIncome
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(operatingIncomeSeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource Revenue
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(revenueSeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource QuarterlyRevenue
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(quarterlyRevenueSeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource Inventory
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(inventorySeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource QuarterlyInventory
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(quarterlyInventorySeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource Goodwill
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(goodwillSeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource QuarterlyGoodwill
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(quarterlyGoodwillSeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource ROIC
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(roicSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource ROA
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(roaSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource ROICWACC
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(combinedSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource WorkingCapital
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(workingCapitalSeries, new ValueConverter(MilsConverter));
        return compositeDataSource;
      }
    }
    public CompositeDataSource NetIncomeAvailableToCommonShareholders
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(netIncomeAvailableToCommonShareholdersSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource DividendLoad
    {
      get
      {
        CompositeDataSource compositeDataSource = DividendLoadModel.GenerateCompositeDataSource(dividendLoadSeries);
        return compositeDataSource;
      }
    }
    public CompositeDataSource DebtToEquity
    {
      get
      {
        CompositeDataSource compositeDataSource = TimeSeriesModel.GenerateCompositeDataSource(debtToEquitySeries);
        return compositeDataSource;
      }
    }
// **************************************************************************************************
    private TimeSeriesCollection CreateROICWACCSeries()
    {
      TimeSeriesCollection combinedSeriesCollection=new TimeSeriesCollection();
      if(null==roicSeries||0==roicSeries.Count)return combinedSeriesCollection;
      foreach(TimeSeriesElement roicSeriesElement in roicSeries)
      {
        double wacc=DCFGenerator.CalculateWACC(roicSeriesElement.Symbol,roicSeriesElement.AsOf);
        if(double.IsNaN(wacc))continue;
        TimeSeriesElement timeSeriesElement=new TimeSeriesElement();
        timeSeriesElement.Symbol=roicSeriesElement.Symbol;
        timeSeriesElement.AsOf=roicSeriesElement.AsOf;
        timeSeriesElement.Value=roicSeriesElement.Value-(wacc*100.00);
        combinedSeriesCollection.Add(timeSeriesElement);
      }
      return combinedSeriesCollection;
    }
    public double MilsConverter(double value)
    {
      return value / 1000000;
    }
    // **********************************************************************************************
    public String CompanyName
    {
      get { return companyName; }
    }
    public override String Title
    {
      get
      {
        if (null == CompanyName || null == SelectedSymbol) return "";
        return CompanyName + " (" + SelectedSymbol + " )"; 
      }
    }
    // **********************************************************************************************
    public List<String> Symbols
    {
      get
      {
        return symbols;
      }
    }
//**************************************************************************************************************
    public String SelectedSymbol
    {
      get { return selectedSymbol; }
      set
      {
        if (value == selectedSymbol || String.IsNullOrEmpty(value)) return;
        selectedSymbol = value;
        base.OnPropertyChanged("SelectedSymbol");
      }
    }
    public List<String> WatchListNames
    {
      get
      {
        return watchLists;
      }
      set { ;}
    }
    public String SelectedWatchList
    {
      get { return selectedWatchList; }
      set { selectedWatchList = value; base.OnPropertyChanged("SelectedWatchList"); }
    }
//**************************************************************************************************************
    private void Refresh()
    {
      base.OnPropertyChanged("SelectedSymbol");
    }
    private bool CanRefresh
    {
      get { return true; }
    }
    public ICommand RefreshCommand
    {
      get
      {
        if (refreshCommand == null)
        {
          refreshCommand = new RelayCommand(param => this.Refresh(), param => this.CanRefresh);
 //         portfolioHoldings.ForEach(portfolioHolding => new Action(delegate() { portfolioHolding.WeightExp = portfolioHolding.Exposure / totalPortfolioExposure; }).Invoke());

          //if (movingAverageCommand == null)
          //{
          //  movingAverageCommand = new RelayCommand(param => this.DisplayMovingAverageCommand(), param => { return null != selectedGainLossSummaryItem && null != selectedGainLossSummaryItem.Symbol; });
          //}


        }
        return refreshCommand;
      }
    }
  }
}
