diff --git a/ViewModels/GainLossViewModel.cs b/ViewModels/GainLossViewModel.cs index a03ecf2..2fec680 100644 --- a/ViewModels/GainLossViewModel.cs +++ b/ViewModels/GainLossViewModel.cs @@ -45,6 +45,8 @@ namespace TradeBlotter.ViewModels private bool suspendUpdate=false; private String selectedAccounts; private List accounts=null; + private DateTime latestMarketDate=Utility.Epoch; +// RelayCommands private RelayCommand refreshCommand=null; private RelayCommand toggleReturnOrPercentCommand=null; private RelayCommand toggleActiveOrTotalCommand=null; @@ -77,6 +79,7 @@ namespace TradeBlotter.ViewModels public GainLossViewModel() { + latestMarketDate=PremarketDA.GetLatestMarketDate(); semaphorePool.Add(Tasks.SelectedSymbol,new Semaphore(1,1)); semaphorePool.Add(Tasks.SelectedAccounts,new Semaphore(1,1)); semaphorePool.Add(Tasks.LeastSquaresFit,new Semaphore(1,1)); @@ -556,6 +559,7 @@ namespace TradeBlotter.ViewModels } private void Refresh() { + latestMarketDate = PremarketDA.GetLatestMarketDate(); base.OnPropertyChanged("SelectedSymbol"); } public ICommand RefreshCommand @@ -666,9 +670,9 @@ namespace TradeBlotter.ViewModels base.OnPropertyChanged("SelectedGainLossSummaryItem"); } } -// ************************************************************************************************************************************************************************************ -// ************************************************************************************************************************************************************************************ -// ************************************************************************************************************************************************************************************ + // ************************************************************************************************************************************************************************************ + // ************************************************************************************************************************************************************************************ + // ************************************************************************************************************************************************************************************ public ObservableCollection MenuItems { get @@ -680,7 +684,7 @@ namespace TradeBlotter.ViewModels 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 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 }); @@ -691,6 +695,7 @@ namespace TradeBlotter.ViewModels return collection; } } + public ICommand DisplayBollingerBand { get @@ -890,12 +895,21 @@ namespace TradeBlotter.ViewModels }, param => { if(null == selectedGainLossSummaryItem || null==selectedGainLossSummaryItem.Symbol)return false; - DateTime latestDate=PremarketDA.GetLatestMarketDate(); - DateTime latestDateSymbol=PricingDA.GetLatestDate(selectedGainLossSummaryItem.Symbol); - if(latestDate.Equals(latestDateSymbol))return false; + Price symbolPrice=GBPriceCache.GetInstance().GetPriceOrLatestAvailable(selectedGainLossSummaryItem.Symbol,latestMarketDate); + if(null==symbolPrice)return false; + if(symbolPrice.Date.Equals(latestMarketDate))return false; DateGenerator dateGenerator=new DateGenerator(); - DateTime prevBusinessDay=dateGenerator.FindPrevBusinessDay(latestDate); - if(!latestDateSymbol.Equals(prevBusinessDay))return false; + DateTime prevBusinessDay=dateGenerator.FindPrevBusinessDay(latestMarketDate); + if(!symbolPrice.Date.Equals(prevBusinessDay))return false; + + // This method was slowing things down quite considerably as it was constantly hitting the pricingDA.GetLatestDate() + // Refactored to the above code and seeing how that works out. + //DateTime latestDate=PremarketDA.GetLatestMarketDate(); + //DateTime latestDateSymbol=PricingDA.GetLatestDate(selectedGainLossSummaryItem.Symbol); + //if(latestDate.Equals(latestDateSymbol))return false; + //DateGenerator dateGenerator=new DateGenerator(); + //DateTime prevBusinessDay=dateGenerator.FindPrevBusinessDay(latestDate); + //if(!latestDateSymbol.Equals(prevBusinessDay))return false; return true; }); } @@ -1019,6 +1033,7 @@ namespace TradeBlotter.ViewModels sb.Append("\n"); double change=(p1.Close-p2.Close)/p2.Close; sb.Append(String.Format("Latest Price {0} {1} ({2}{3})",Utility.DateTimeToStringMMSDDSYYYY(p1.Date),Utility.FormatCurrency(p1.Close),change<0?"-":"+",Utility.FormatPercent(Math.Abs(change)))); + if(companyProfile.FreezePricing)sb.Append(" ").Append("**Frozen**"); sb.Append("\n").Append(String.Format("Source: {0}",p1.SourceAsString())); return sb.ToString(); }