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.Windows.Media;
using System.Windows.Input;
using System.Threading.Tasks;
using MarketData;
using MarketData.Numerical;
using MarketData.Utils;
using MarketData.MarketDataModel;
using MarketData.Generator;
using MarketData.DataAccess;
using TradeBlotter.DataAccess;
using TradeBlotter.Command;
using TradeBlotter.Model;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using MarketData.DividendRiskParity;
using TradeBlotter.UIUtils;

namespace TradeBlotter.ViewModels
{
  public class DividendRiskParityViewModel : WorkspaceViewModel
  {
    private List<String> symbols;
    private String selectedSymbol;
    private String companyName;
    private bool busyIndicator = false;
    private PortfolioTrades portfolioTrades;
    private DividendRiskParityPositionCollection dividendRiskParityPositionCollection;
    private ObservableCollection<DividendRiskParityPosition> allPositions=new ObservableCollection<DividendRiskParityPosition>();
    private DividendRiskParityPosition dividendRiskParityPositionProforma = null;
    private DividendRiskParityResult dividendRiskParityResult;
    private DividendRiskParityResult dividendRiskParityResultProforma;
    private double aum = double.NaN;
    private Price currentPrice = null;

    private RelayCommand proformaAddRiskParityPositionCommand;
    private RelayCommand proformaAddRiskParityPositionEnabledCommand;
    private RelayCommand resetCommand;

// MENU COMMANDS
    private RelayCommand bollingerBandCommand = null;
    private RelayCommand dividendHistoryCommand = null;
    private RelayCommand stickerValuationCommand = null;
    private RelayCommand displayHistoricalCommand = null;
    private RelayCommand stochasticsCommand = null;
    private RelayCommand relativeStrengthCommand = null;
    private RelayCommand macdCommand = null;
    private RelayCommand movingAverageCommand;
    private RelayCommand priceHistoryCommand = null;
    private RelayCommand dcfValuationCommand = null;
    private RelayCommand displayAnalystRatingsCommand = null;
    private RelayCommand displayHeadlinesCommand = null;

    public DividendRiskParityViewModel()
    {
      base.DisplayName = "Dividend Risk Parity";
      symbols=PortfolioDA.GetOpenSymbols();
      PortfolioTrades allTrades = PortfolioDA.GetOpenTrades();
      aum= allTrades.Sum(x => x.Exposure());
      base.OnPropertyChanged("Aum");
      selectedSymbol = null;
      PropertyChanged += OnDividendRiskParityViewModelPropertyChanged;
      base.OnPropertyChanged("SelectedSymbol");
    }
    // ******************************************************************************************** P E R S I S T E N C E ********************************************************************************************
    public override bool CanPersist()
    {
      return true;
    }
    public override SaveParameters GetSaveParameters()
    {
      //return null;
      SaveParameters saveParams = new SaveParameters();
      if (null == selectedSymbol) return null;
      saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
      saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", selectedSymbol));
      saveParams.Add(new KeyValuePair<String, String>("Aum", aum.ToString()));
      if(null!=currentPrice)
      {
        saveParams.Add((new KeyValuePair<String, String>("CurrentPrice", currentPrice.Close.ToString())));
        saveParams.Add((new KeyValuePair<String, String>("PricingDate", Utility.DateTimeToStringMMHDDHYYYY(currentPrice.Date))));
      }
      if (null != dividendRiskParityPositionProforma) saveParams.Add(new KeyValuePair<String, String>("DividendRiskParityPositionProforma", dividendRiskParityPositionProforma.ToString()));
      return saveParams;
    }
    public override void SetSaveParameters(SaveParameters saveParameters)
    {
      try
      {
        dividendRiskParityResult = null;
        dividendRiskParityResultProforma = null;
        dividendRiskParityPositionProforma = null;
        selectedSymbol = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("SelectedSymbol") select item).FirstOrDefault().Value;
        aum = double.NaN;
        String strAum=(from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("Aum") select item).FirstOrDefault().Value;
        if(null!=strAum)aum=double.Parse(strAum);
        else
        {
          PortfolioTrades allTrades = PortfolioDA.GetOpenTrades();
          aum= allTrades.Sum(x => x.Exposure());
        }
        String strCurrentPrice = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("CurrentPrice") select item).FirstOrDefault().Value;
        String strPricingDate= (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("PricingDate") select item).FirstOrDefault().Value;
        if (null != strCurrentPrice && null != strPricingDate)
        {
          currentPrice = new Price();
          currentPrice.Close = double.Parse(strCurrentPrice);
          currentPrice.Date = DateTime.Parse(strPricingDate);
        }
        String strDividendRiskParityPositionProforma = (from KeyValuePair<String, String> item in saveParameters where item.Key.Equals("DividendRiskParityPositionProforma") select item).FirstOrDefault().Value;
        if (null != strDividendRiskParityPositionProforma && !"".Equals(strDividendRiskParityPositionProforma))
        {
          dividendRiskParityPositionProforma = DividendRiskParityPosition.FromString(strDividendRiskParityPositionProforma);
        }
        Referer = saveParameters.Referer;
        companyName = PricingDA.GetNameForSymbol(selectedSymbol);
        portfolioTrades = PortfolioDA.GetOpenTradesSymbol(selectedSymbol);
        dividendRiskParityPositionCollection = new DividendRiskParityPositionCollection(portfolioTrades);
        if(null==currentPrice)currentPrice = PricingDA.GetPrice(portfolioTrades.Take(1).FirstOrDefault().Symbol);
        dividendRiskParityResult = DividendRiskParityGenerator.GenerateDividendRiskParity(currentPrice, aum, dividendRiskParityPositionCollection);
        foreach (DividendRiskParityPosition dividendRiskParityPosition in dividendRiskParityPositionCollection) allPositions.Add(dividendRiskParityPosition);
        if (null != dividendRiskParityPositionProforma)
        {
          dividendRiskParityPositionProforma.PurchasePrice = currentPrice.Close;    // must be taken from the stored pricing data 
          dividendRiskParityPositionProforma.TradeDate = currentPrice.Date;
          dividendRiskParityPositionCollection.Add(dividendRiskParityPositionProforma);
          dividendRiskParityResultProforma = DividendRiskParityGenerator.GenerateDividendRiskParity(currentPrice, aum, dividendRiskParityPositionCollection);
          allPositions = new ObservableCollection<DividendRiskParityPosition>();
          foreach (DividendRiskParityPosition dividendRiskParityPosition in dividendRiskParityPositionCollection) allPositions.Add(dividendRiskParityPosition);
        }
        base.OnPropertyChanged("AllPositions");
        base.OnPropertyChanged("Title");
        base.OnPropertyChanged("Aum");
        base.OnPropertyChanged("ProformaAddRiskParityPositionEnabled");
        UpdateDividendRiskParityResultProforma();
        UpdateDividendRiskParityResult();
      }
      catch (Exception exception)
      {
        MDTrace.WriteLine(String.Format("Exception:{0}",exception.ToString()));
      }
    }
    // ******************************************************************************************************************************************************
    public bool BusyIndicator
    {
      get { return busyIndicator; }
      set
      {
        busyIndicator = value;
        base.OnPropertyChanged("BusyIndicator");
      }
    }
    public ObservableCollection<DividendRiskParityPosition> AllPositions
    {
      get
      {
        return allPositions;
      }
      set
      {
        allPositions = value;
        base.OnPropertyChanged("AllPositions");
      }
    }
    private void OnDividendRiskParityViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
    {
      if (eventArgs.PropertyName.Equals("SelectedSymbol"))
      {
        base.DisplayName = "Dividend Risk Parity(" + selectedSymbol + ")";
        base.OnPropertyChanged("DisplayName");
        HandleSelectedSymbol();
      }
    }
    private void HandleSelectedSymbol()
    {
      BusyIndicator = true;
      Task workerTask = Task.Factory.StartNew(() =>
      {
        if (null != selectedSymbol)
        {
          companyName = PricingDA.GetNameForSymbol(SelectedSymbol);
          dividendRiskParityResult = null;
          dividendRiskParityResultProforma = null;
          dividendRiskParityPositionProforma = null;
          portfolioTrades = PortfolioDA.GetOpenTradesSymbol(selectedSymbol);
          dividendRiskParityPositionCollection= new DividendRiskParityPositionCollection(portfolioTrades);
          allPositions=new ObservableCollection<DividendRiskParityPosition>();
          currentPrice=PricingDA.GetPrice(portfolioTrades.Take(1).FirstOrDefault().Symbol);
          dividendRiskParityResult = DividendRiskParityGenerator.GenerateDividendRiskParity(currentPrice, aum, dividendRiskParityPositionCollection);
          foreach (DividendRiskParityPosition dividendRiskParityPosition in dividendRiskParityPositionCollection) allPositions.Add(dividendRiskParityPosition);
        }
      });
      workerTask.ContinueWith((continuation) =>
      {
        BusyIndicator = false;
        base.OnPropertyChanged("AllPositions");
        base.OnPropertyChanged("Title");
        base.OnPropertyChanged("CurrentPrice");
        base.OnPropertyChanged("PricingDate");
        base.OnPropertyChanged("ProformaAddRiskParityPositionEnabled");
        UpdateDividendRiskParityResult();
        UpdateDividendRiskParityResultProforma();
      });
    }
    public void OnErrorItemHandler(String symbol, String message)
    {
    }
    public void UpdateDividendRiskParityResult()
    {
      base.OnPropertyChanged("Parity");
      base.OnPropertyChanged("ParityPercent");
      base.OnPropertyChanged("CostBasis");
      base.OnPropertyChanged("Aum");
      base.OnPropertyChanged("AllocationPercent");
      base.OnPropertyChanged("AnnualDividend");
      base.OnPropertyChanged("DividendYearsToParity");
      base.OnPropertyChanged("DaysSinceLastTraded");
      base.OnPropertyChanged("CurrentDividendPercent");
      base.OnPropertyChanged("AdditionalDividendPerYear");
      base.OnPropertyChanged("YieldPercent");
    }
    public void UpdateDividendRiskParityResultProforma()
    {
      base.OnPropertyChanged("ParityProforma");
      base.OnPropertyChanged("ParityPercentProforma");
      base.OnPropertyChanged("CostBasisProforma");
      base.OnPropertyChanged("AumProforma");
      base.OnPropertyChanged("AllocationPercentProforma");
      base.OnPropertyChanged("AnnualDividendProforma");
      base.OnPropertyChanged("DividendYearsToParityProforma");
      base.OnPropertyChanged("DaysSinceLastTradedProforma");
      base.OnPropertyChanged("CurrentDividendPercentProforma");
      base.OnPropertyChanged("AdditionalDividendPerYearProforma");
      base.OnPropertyChanged("YieldPercentProforma");
    }
// *****************************************************************************************************************************************************************
// ****************************************************************************** C O N T E X T  M E N U   *********************************************************
// *****************************************************************************************************************************************************************

    public ObservableCollection<MenuItem> MenuItems
    {
      get
      {
        ObservableCollection<MenuItem> collection = new ObservableCollection<MenuItem>();
        collection.Add(new MenuItem() { Text = "Display Bollinger Band", MenuItemClickedCommand = DisplayBollingerBand, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Dividend History", MenuItemClickedCommand = DisplayDividendHistory, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Sticker Valuation", MenuItemClickedCommand = DisplayStickerValuation, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Historical", MenuItemClickedCommand = DisplayHistorical, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Stochastics", MenuItemClickedCommand = DisplayStochastic, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Relative Strength", MenuItemClickedCommand = DisplayRelativeStrength, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display MACD", MenuItemClickedCommand = DisplayMACD, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Moving Average", MenuItemClickedCommand = DisplayMovingAverage, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Price History", MenuItemClickedCommand = DisplayPriceHistory, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuation, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Analyst Ratings", MenuItemClickedCommand = DisplayAnalystRatings, StaysOpenOnClick = false });
        collection.Add(new MenuItem() { Text = "Display Headlines", MenuItemClickedCommand = DisplayHeadlines, StaysOpenOnClick = false });
        return collection;
      }
    }
    public ICommand DisplayBollingerBand
    {
      get
      {
        if (bollingerBandCommand == null)
        {
          bollingerBandCommand = new RelayCommand(param => this.DisplayBollingerBandCommand(),
            param => { return null != selectedSymbol ; });
        }
        return bollingerBandCommand;
      }
    }
    public ICommand DisplayDividendHistory
    {
      get
      {
        if (dividendHistoryCommand == null)
        {
          dividendHistoryCommand = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DividendHistoryViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
            saveParams.Referer = this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => { return null != selectedSymbol; });
        }
        return dividendHistoryCommand;
      }
    }
    public ICommand DisplayStickerValuation
    {
      get
      {
        if (null == stickerValuationCommand)
        {
          stickerValuationCommand = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StickerPriceViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
            saveParams.Referer = this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => { return null != selectedSymbol && null != selectedSymbol; });
        }
        return stickerValuationCommand;
      }
    }
    public ICommand DisplayHistorical
    {
      get
      {
        if (displayHistoricalCommand == null)
        {
          displayHistoricalCommand = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HistoricalViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
            saveParams.Referer = this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => { return null != selectedSymbol && null != selectedSymbol; });
        }
        return displayHistoricalCommand;
      }
    }
    public ICommand DisplayStochastic
    {
      get
      {
        if (stochasticsCommand == null)
        {
          stochasticsCommand = new RelayCommand(param => this.DisplayStochasticCommand(),
            param => { return null != selectedSymbol; });
        }
        return stochasticsCommand;
      }
    }
    public ICommand DisplayRelativeStrength
    {
      get
      {
        if (relativeStrengthCommand == null)
        {
          relativeStrengthCommand = new RelayCommand(param => this.DisplayRelativeStrengthCommand(),
            param => { return null != selectedSymbol; });
        }
        return relativeStrengthCommand;
      }
    }
    public ICommand DisplayMACD
    {
      get
      {
        if (macdCommand == null)
        {
          macdCommand = new RelayCommand(param => this.DisplayMACDCommand(),
            param => { return null != selectedSymbol; });
        }
        return macdCommand;
      }
    }
    public ICommand DisplayMovingAverage
    {
      get
      {
        if (movingAverageCommand == null)
        {
          movingAverageCommand = new RelayCommand(param => this.DisplayMovingAverageCommand(), param => { return null != selectedSymbol; });
        }
        return movingAverageCommand;
      }
    }
    public ICommand DisplayPriceHistory
    {
      get
      {
        if (priceHistoryCommand == null)
        {
          priceHistoryCommand = new RelayCommand(param => this.DisplayPriceHistoryCommand(),
            param => { return null != selectedSymbol; });
        }
        return priceHistoryCommand;
      }
    }
    public ICommand DisplayDCFValuation
    {
      get
      {
        if (null == dcfValuationCommand)
        {
          dcfValuationCommand = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.DCFValuationViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
            saveParams.Referer = this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => { return null != selectedSymbol; });
        }
        return dcfValuationCommand;
      }
    }
    public ICommand DisplayAnalystRatings
    {
      get
      {
        if (null == displayAnalystRatingsCommand)
        {
          displayAnalystRatingsCommand = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.AnalystRatingsViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All}");
            saveParams.Referer = this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => { return null != selectedSymbol; });
        }
        return displayAnalystRatingsCommand;
      }
    }
    public ICommand DisplayHeadlines
    {
      get
      {
        if (null == displayHeadlinesCommand)
        {
          displayHeadlinesCommand = new RelayCommand(param =>
          {
            SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.HeadlinesViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,Valuations");
            saveParams.Referer = this;
            WorkspaceInstantiator.Invoke(saveParams);
          }, param => { return null != selectedSymbol; });
        }
        return displayHeadlinesCommand;
      }
    }
    // **************************************************************************************************************************************************************************************
    // ******************************************************************************** C O M M A N D S *************************************************************************************
    // **************************************************************************************************************************************************************************************
    public void DisplayBollingerBandCommand()
    {
      SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.BollingerBandViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,180,SyncTradeToBand,FALSE");
      saveParams.Referer = this;
      WorkspaceInstantiator.Invoke(saveParams);
    }
    public void DisplayStochasticCommand()
    {
      SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,90");
      saveParams.Referer = this;
      WorkspaceInstantiator.Invoke(saveParams);
    }
    public void DisplayRelativeStrengthCommand()
    {
      SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.RSIViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,60,SelectedRSIDayCount,3");
      saveParams.Referer = this;
      WorkspaceInstantiator.Invoke(saveParams);
    }
    public void DisplayMACDCommand()
    {
      SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,90");
      saveParams.Referer = this;
      WorkspaceInstantiator.Invoke(saveParams);
    }
    public void DisplayMovingAverageCommand()
    {
      SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MovingAverageViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,360");
      saveParams.Referer = this;
      WorkspaceInstantiator.Invoke(saveParams);
    }
    public void DisplayPriceHistoryCommand()
    {
      SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedSymbol + ",SelectedWatchList,{All},SelectedDayCount,90");
      saveParams.Referer = this;
      WorkspaceInstantiator.Invoke(saveParams);
    }
// *****************************************************************************************************************************************************************
// ****************************************************************************** I C O M M A N D  ****************************************************************
// *****************************************************************************************************************************************************************
    public ICommand ProformaAddRiskParityPositionCommand
    {
      get
      {
        if (null == proformaAddRiskParityPositionCommand)
        {
          proformaAddRiskParityPositionCommand = new RelayCommand(param =>
          {
            if (null != dividendRiskParityPositionCollection && 0 != dividendRiskParityPositionCollection.Count)
            {
              String symbol = dividendRiskParityPositionCollection.Take(1).FirstOrDefault().Symbol;
              DateTime pricingDate=PricingDA.GetLatestDate();
              ProformaAddRiskDividendParityPositionDialogResult proformaAddRiskDividendParityPositionDialogResult=ProformaAddRiskDividendParityPositionDialog.Prompt("Proforma Add Risk Parity Position", symbol, pricingDate, dividendRiskParityPositionCollection);
              if (true == proformaAddRiskDividendParityPositionDialogResult.Success)
              {
                dividendRiskParityPositionProforma = proformaAddRiskDividendParityPositionDialogResult.DividendRiskParityPositionProforma;
                dividendRiskParityPositionCollection = proformaAddRiskDividendParityPositionDialogResult.DividendRiskParityPositionCollection;
                currentPrice = PricingDA.GetPrice(dividendRiskParityPositionCollection.Take(1).FirstOrDefault().Symbol);
                dividendRiskParityResultProforma = DividendRiskParityGenerator.GenerateDividendRiskParity(currentPrice, aum, dividendRiskParityPositionCollection);
                allPositions = new ObservableCollection<DividendRiskParityPosition>();
                foreach (DividendRiskParityPosition dividendRiskParityPosition in dividendRiskParityPositionCollection) allPositions.Add(dividendRiskParityPosition);
                base.OnPropertyChanged("AllPositions");
                base.OnPropertyChanged("CurrentPrice");
                base.OnPropertyChanged("PricingDate");
                base.OnPropertyChanged("ProformaAddRiskParityPositionEnabled");
                UpdateDividendRiskParityResultProforma();
              }
            }
          }, param => { return true; });
        }
        return proformaAddRiskParityPositionCommand;
      }
    }
    public bool ProformaAddRiskParityPositionEnabled
    {
      get
      {
        if(null==dividendRiskParityPositionCollection)return false;
        int proformaRecords=dividendRiskParityPositionCollection.Where(x=>x.TypeOfPosition.Equals(DividendRiskParityPosition.PositionType.Proforma)).Count();
        return proformaRecords>0?false:true;
      }
    }
    public ICommand ResetCommand
    {
      get
      {
        if (null == resetCommand)
        {
          resetCommand = new RelayCommand(param =>
          {
            dividendRiskParityResult = null;
            dividendRiskParityResultProforma = null;
            base.OnPropertyChanged("SelectedSymbol");
          }, param => { return true; });
        }
        return resetCommand;
      }
    }
    // ************************************************************************************************************************************************************************
    // ************************************************************** D I V I D E N D  R I S K  P A R I T Y  R E S U L T  ******************************************************
    // ************************************************************************************************************************************************************************
    // ************************************************************************************************************************************************************************
    public String Parity
    {
      get
      {
        return null==dividendRiskParityResult?Constants.CONST_DASHES:Utility.FormatCurrency(dividendRiskParityResult.ParityPrice.Close, 2);
      }
    }
    public String ParityPercent
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResult.ParityPercent/100.00);
      }
    }
    public String YieldPercent
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResult.YieldPercent / 100.00);
      }
    }
    public String CostBasis
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResult.CostBasis, 2);
      }
    }
    public String Aum
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResult.Aum, 2);
      }
    }
    public String AllocationPercent
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResult.AllocationPercent / 100.00);
      }
    }
    public String AnnualDividend
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResult.AnnualDividend, 2);
      }
    }
    public String DividendYearsToParity
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatNumber(dividendRiskParityResult.DividendYearsToParity, 2);
      }
    }
    public String DaysSinceLastTraded
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatNumber(dividendRiskParityResult.DaysSinceLastTraded,0,true);
      }
    }
    public String CurrentDividendPercent
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResult.CurrentDividendPercent/100.00);
      }
    }
    public String AdditionalDividendPerYear
    {
      get
      {
        return null == dividendRiskParityResult ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResult.AdditionalDividendPerYer);
      }
    }
    // ************************************************************************************************************************************************************************
    // ********************************************************* D I V I D E N D  R I S K  P A R I T Y  R E S U L T  P R O F O R A ******************************************
    // ************************************************************************************************************************************************************************
    // ************************************************************************************************************************************************************************
    public String ParityProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.ParityPrice.Close, 2);
      }
    }
    public String ParityPercentProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResultProforma.ParityPercent / 100.00);
      }
    }
    public String YieldPercentProforma
    {
      get
      {
        if (null == dividendRiskParityResultProforma) return Constants.CONST_DASHES;
        StringBuilder sb = new StringBuilder();
        double yieldDifferenceBasisPoints = ((dividendRiskParityResultProforma.YieldPercent - dividendRiskParityResult.YieldPercent)*100.00);
        sb.Append(Utility.FormatPercent(dividendRiskParityResultProforma.YieldPercent / 100.00)).Append("(").Append(yieldDifferenceBasisPoints < 0 ? "" : "+").Append(Utility.FormatNumber(yieldDifferenceBasisPoints,2)).Append("bps)");
        return sb.ToString();
      }
    }
    public String CostBasisProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.CostBasis, 2);
      }
    }
    public String AumProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.Aum, 2);
      }
    }
    public String AllocationPercentProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResultProforma.AllocationPercent / 100.00);
      }
    }
    public String AnnualDividendProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.AnnualDividend, 2);
      }
    }
    public String DividendYearsToParityProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatNumber(dividendRiskParityResultProforma.DividendYearsToParity, 2);
      }
    }
    public String DaysSinceLastTradedProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatNumber(dividendRiskParityResultProforma.DaysSinceLastTraded,0,true);
      }
    }
    public String CurrentDividendPercentProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatPercent(dividendRiskParityResultProforma.CurrentDividendPercent / 100.00);
      }
    }
    public String AdditionalDividendPerYearProforma
    {
      get
      {
        return null == dividendRiskParityResultProforma ? Constants.CONST_DASHES : Utility.FormatCurrency(dividendRiskParityResultProforma.AdditionalDividendPerYer);
      }
    }
// ***********************************************************************************************************************************************************************************
    public String CurrentPrice
    {
      get 
      {
        if (null == currentPrice) return Constants.CONST_DASHES;
        return Utility.FormatCurrency(currentPrice.Close); 
      }
    }
    public String PricingDate
    {
      get
      {
        if (null == currentPrice) return Constants.CONST_DASHES;
        return Utility.DateTimeToStringMMHDDHYYYY(currentPrice.Date);
      }
    }
    public String TotalAum
    {
      get { return Utility.FormatCurrency(aum); }
    }
    public List<String> Symbols
    {
      get
      {
        return symbols;
      }
    }
    public override String Title
    {
      get
      {
        if (null != companyName && null != selectedSymbol) return "Dividend Risk Parity - (" + selectedSymbol + ") " + companyName;
        return "Dividend Risk Parity";
      }
    }
    public String SelectedSymbol
    {
      get
      {
        return selectedSymbol;
      }
      set
      {
        if (value == selectedSymbol || String.IsNullOrEmpty(value)) return;
        selectedSymbol = value;
        base.OnPropertyChanged("SelectedSymbol");
      }
    }
  }
}


