Fix views and view models.

This commit is contained in:
2025-02-14 19:02:17 -05:00
parent 786f5f67df
commit 9f836a09f5
5 changed files with 1171 additions and 57 deletions

View File

@@ -70,13 +70,15 @@ namespace TradeBlotter.ViewModels
private String selectedParameter=null;
private MGSHPositionModelCollection positions=null;
private MGSHPositionModel selectedPosition=null;
private RelayCommand loadFileCommand;
private RelayCommand reloadCommand;
private RelayCommand monitorCommand;
private ObservableCollection<String> monitorIntervals;
private String selectedMonitorInterval;
private bool monitorRunning=false;
private DispatcherTimer dispatcherTimer = new DispatcherTimer();
private RelayCommand loadFileCommand;
private RelayCommand reloadCommand;
private RelayCommand monitorCommand;
private RelayCommand stochasticsCommandPosition;
private RelayCommand relativeStrengthCommandPosition;
private RelayCommand macdCommandPosition;
@@ -130,6 +132,7 @@ namespace TradeBlotter.ViewModels
base.OnPropertyChanged("SelectedParameter");
base.OnPropertyChanged("ParameterValue");
}
protected override void OnDispose()
{
StopMonitor();
@@ -140,6 +143,7 @@ namespace TradeBlotter.ViewModels
{
return true;
}
public override SaveParameters GetSaveParameters()
{
SaveParameters saveParams = new SaveParameters();
@@ -148,6 +152,7 @@ namespace TradeBlotter.ViewModels
saveParams.Add(new KeyValuePair<String, String>("PathFileName", pathFileName));
return saveParams;
}
public override void SetSaveParameters(SaveParameters saveParameters)
{
try
@@ -173,6 +178,7 @@ namespace TradeBlotter.ViewModels
base.OnPropertyChanged("BusyIndicator");
}
}
public String BusyContent
{
get
@@ -207,6 +213,7 @@ namespace TradeBlotter.ViewModels
return collection;
}
}
public ObservableCollection<MenuItem> PositionsMenuItems
{
get
@@ -226,11 +233,12 @@ namespace TradeBlotter.ViewModels
collection.Add(new MenuItem() { Text = "Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuationPosition, StaysOpenOnClick = false });
collection.Add(new MenuItem() { Text = "Add to Watchlist", MenuItemClickedCommand = AddToWatchListPosition, StaysOpenOnClick = false });
collection.Add(new MenuItem() { Text = "Remove from Watchlist", MenuItemClickedCommand = RemoveFromWatchListPosition, StaysOpenOnClick = false });
collection.Add(new MenuItem() { Text="Close Position...",MenuItemClickedCommand=ClosePosition,StaysOpenOnClick=false });
collection.Add(new MenuItem() { Text="Edit Position...",MenuItemClickedCommand=EditPosition,StaysOpenOnClick=false });
collection.Add(new MenuItem() { Text = "Close Position...",MenuItemClickedCommand=ClosePosition,StaysOpenOnClick=false });
collection.Add(new MenuItem() { Text = "Edit Position...",MenuItemClickedCommand=EditPosition,StaysOpenOnClick=false });
return collection;
}
}
private void OnMomentumViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
{
}
@@ -248,6 +256,7 @@ namespace TradeBlotter.ViewModels
return "MGSHMomentum Model ("+pureFileName+")";
}
}
public override String Title
{
get
@@ -255,11 +264,13 @@ namespace TradeBlotter.ViewModels
return DisplayName;
}
}
public DateTime SelectableDateStart
{
get{return selectableDateStart;}
set{selectableDateStart=value;}
}
public DateTime SelectableDateEnd
{
get{return selectableDateEnd;}
@@ -309,6 +320,7 @@ namespace TradeBlotter.ViewModels
return sb.ToString();
}
}
public String VelocityDescription
{
get
@@ -317,6 +329,7 @@ namespace TradeBlotter.ViewModels
return "Velocity is the percentage range of the current price within the price history.";
}
}
public String BetaDescription
{
get
@@ -325,6 +338,7 @@ namespace TradeBlotter.ViewModels
return "A beta of less than 1 means that the security is theoretically less volatile than the market. A beta of greater than 1 indicates that the security's price is theoretically more volatile than the market. For example, if a stock's beta is 1.2, it's theoretically 20% more volatile than the market.";
}
}
// Position
public String CompanyDescriptionSelectedPosition
{
@@ -355,11 +369,13 @@ namespace TradeBlotter.ViewModels
base.OnPropertyChanged("SelectedItem");
}
}
public MGSHPositionModel SelectedPosition
{
get{return selectedPosition;}
set{selectedPosition=value;base.OnPropertyChanged("SelectedPosition");}
}
public String SelectedDate
{
get { return selectedDate; }
@@ -369,40 +385,49 @@ namespace TradeBlotter.ViewModels
base.OnPropertyChanged("SelectedDate");
}
}
public ObservableCollection<MGSHMomentumCandidate> AllItems
{
get{return momentumCandidates;}
}
public MGSHPositionModelCollection AllPositions
{
get{return positions;}
}
public ObservableCollection<String> Parameters
{
get{return nvpDictionaryKeys;}
}
public ObservableCollection<String> MonitorIntervals
{
get{return monitorIntervals;}
}
public bool CanMonitor
{
get{return IsTradeFileLoaded;}
}
public String MonitorStatus
{
get{return monitorRunning?"Stop Monitor":"Start Monitor";}
}
public String SelectedMonitorInterval
{
get{return selectedMonitorInterval;}
set{selectedMonitorInterval=value;base.OnPropertyChanged("SelectedMonitorInterval");}
}
public String SelectedParameter
{
get{return selectedParameter;}
set{selectedParameter=value;base.OnPropertyChanged("SelectedParameter");base.OnPropertyChanged("ParameterValue");}
}
public String ParameterValue
{
get
@@ -411,6 +436,7 @@ namespace TradeBlotter.ViewModels
return nvpDictionary[selectedParameter].Value;
}
}
public String CashBalance
{
get
@@ -419,6 +445,7 @@ namespace TradeBlotter.ViewModels
return Utility.FormatCurrency(sessionParams.CashBalance);
}
}
public String NonTradeableCash
{
get
@@ -427,6 +454,16 @@ namespace TradeBlotter.ViewModels
return Utility.FormatCurrency(sessionParams.NonTradeableCash);
}
}
public String HedgeCash
{
get
{
if(null==sessionParams) return "";
return Utility.FormatCurrency(sessionParams.HedgeCashBalance);
}
}
public String ModelExpectation
{
get
@@ -435,6 +472,7 @@ namespace TradeBlotter.ViewModels
return Utility.FormatNumber(modelStatistics.Expectancy,2);
}
}
public Brush ExpectationColor
{
get
@@ -444,6 +482,7 @@ namespace TradeBlotter.ViewModels
return UIUtils.BrushCollection.GetContextBrush(BrushCollection.BrushColor.Red);
}
}
public String ExpectationDescription
{
get
@@ -465,10 +504,11 @@ namespace TradeBlotter.ViewModels
sb.Append("The calculations are based on closed positions.");
return sb.ToString();
}
}
// *************************************************************************************************************************************************************
// *********************************************************************** I C O M M A N D ********************************************************************
// *************************************************************************************************************************************************************
}
// *************************************************************************************************************************************************************
// *********************************************************************** I C O M M A N D ********************************************************************
// *************************************************************************************************************************************************************
public ICommand DisplayHistorical
{
get
@@ -485,6 +525,7 @@ namespace TradeBlotter.ViewModels
return displayHistoricalCommand;
}
}
public ICommand RunCommand
{
get
@@ -496,6 +537,7 @@ namespace TradeBlotter.ViewModels
return runCommand;
}
}
public ICommand DisplayMovingAverage
{
get
@@ -507,6 +549,7 @@ namespace TradeBlotter.ViewModels
return movingAverageCommand;
}
}
public ICommand DisplayAnalystRatings
{
get
@@ -518,6 +561,7 @@ namespace TradeBlotter.ViewModels
return analystRatingsCommand;
}
}
public ICommand DisplayMACD
{
get
@@ -529,6 +573,7 @@ namespace TradeBlotter.ViewModels
return macdCommand;
}
}
public ICommand DisplayStochastics
{
get
@@ -540,6 +585,7 @@ namespace TradeBlotter.ViewModels
return stochasticsCommand;
}
}
public ICommand DisplayRelativeStrength
{
get
@@ -551,6 +597,7 @@ namespace TradeBlotter.ViewModels
return relativeStrengthCommand;
}
}
public ICommand DisplayStickerValuation
{
get
@@ -567,6 +614,7 @@ namespace TradeBlotter.ViewModels
return stickerValuationCommand;
}
}
public ICommand DisplayDCFValuation
{
get
@@ -583,6 +631,7 @@ namespace TradeBlotter.ViewModels
return dcfValuationCommand;
}
}
public ICommand DisplayPriceHistory
{
get
@@ -594,6 +643,7 @@ namespace TradeBlotter.ViewModels
return priceHistoryCommand;
}
}
public ICommand DisplayDividendHistory
{
get
@@ -610,12 +660,14 @@ namespace TradeBlotter.ViewModels
return dividendHistoryCommand;
}
}
public void DisplayPriceHistoryCommand()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public ICommand DisplayBollingerBand
{
get
@@ -627,6 +679,7 @@ namespace TradeBlotter.ViewModels
return bollingerBandCommand;
}
}
public ICommand AddToWatchList
{
get
@@ -644,6 +697,7 @@ namespace TradeBlotter.ViewModels
return addToWatchListCommand;
}
}
public ICommand RemoveFromWatchList
{
get
@@ -680,6 +734,7 @@ namespace TradeBlotter.ViewModels
return displayHeadlinesCommandPosition;
}
}
public ICommand DisplayHistoricalPosition
{
get
@@ -696,6 +751,7 @@ namespace TradeBlotter.ViewModels
return displayHistoricalCommandPosition;
}
}
public ICommand DisplayAnalystRatingsPosition
{
get
@@ -707,6 +763,7 @@ namespace TradeBlotter.ViewModels
return analystRatingsCommandPosition;
}
}
public ICommand DisplayMovingAveragePosition
{
get
@@ -718,6 +775,7 @@ namespace TradeBlotter.ViewModels
return movingAverageCommandPosition;
}
}
public ICommand DisplayMACDPosition
{
get
@@ -729,6 +787,7 @@ namespace TradeBlotter.ViewModels
return macdCommandPosition;
}
}
public ICommand DisplayStochasticsPosition
{
get
@@ -740,6 +799,7 @@ namespace TradeBlotter.ViewModels
return stochasticsCommandPosition;
}
}
public ICommand DisplayRelativeStrengthPosition
{
get
@@ -751,6 +811,7 @@ namespace TradeBlotter.ViewModels
return relativeStrengthCommandPosition;
}
}
public ICommand DisplayStickerValuationPosition
{
get
@@ -767,6 +828,7 @@ namespace TradeBlotter.ViewModels
return stickerValuationCommandPosition;
}
}
public ICommand DisplayDCFValuationPosition
{
get
@@ -783,6 +845,7 @@ namespace TradeBlotter.ViewModels
return dcfValuationCommandPosition;
}
}
public ICommand DisplayPriceHistoryPosition
{
get
@@ -794,6 +857,7 @@ namespace TradeBlotter.ViewModels
return priceHistoryCommandPosition;
}
}
public ICommand DisplayDividendHistoryPosition
{
get
@@ -810,6 +874,7 @@ namespace TradeBlotter.ViewModels
return dividendHistoryCommandPosition;
}
}
public ICommand DisplayBollingerBandPosition
{
get
@@ -821,6 +886,7 @@ namespace TradeBlotter.ViewModels
return bollingerBandCommandPosition;
}
}
public ICommand AddToWatchListPosition
{
get
@@ -839,6 +905,7 @@ namespace TradeBlotter.ViewModels
return addToWatchListCommandPosition;
}
}
public ICommand RemoveFromWatchListPosition
{
get
@@ -904,6 +971,7 @@ namespace TradeBlotter.ViewModels
return reloadCommand;
}
}
public bool ReloadEnabled
{
get
@@ -911,6 +979,7 @@ namespace TradeBlotter.ViewModels
return !String.IsNullOrEmpty(pathFileName);
}
}
public ICommand LoadFile
{
get
@@ -922,6 +991,7 @@ namespace TradeBlotter.ViewModels
return loadFileCommand;
}
}
public ICommand Monitor
{
get
@@ -946,24 +1016,28 @@ namespace TradeBlotter.ViewModels
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void DisplayAnalystRatingsCommand()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.AnalystRatingsViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All}");
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void DisplayStochasticsCommand()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void DisplayRelativeStrengthCommand()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.RSIViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,60,SelectedRSIDayCount,3");
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void DisplayMACDCommand()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedItem.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
@@ -1072,24 +1146,28 @@ namespace TradeBlotter.ViewModels
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void DisplayStochasticsCommandPosition()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.StochasticsViewModel,SelectedSymbol," + selectedPosition.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void DisplayRelativeStrengthCommandPosition()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.RSIViewModel,SelectedSymbol," + selectedPosition.Symbol + ",SelectedWatchList,{All},SelectedDayCount,60,SelectedRSIDayCount,3");
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void DisplayMACDCommandPosition()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.MACDViewModel,SelectedSymbol," + selectedPosition.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void DisplayPriceHistoryCommandPosition()
{
SaveParameters saveParams = SaveParameters.Parse("Type,TradeBlotter.ViewModels.PricingViewModel,SelectedSymbol," + selectedPosition.Symbol + ",SelectedWatchList,{All},SelectedDayCount,180");
@@ -1110,6 +1188,7 @@ namespace TradeBlotter.ViewModels
saveParams.Referer=this;
WorkspaceInstantiator.Invoke(saveParams);
}
public void AddToWatchListCommand(String symbol)
{
if (WatchListDA.IsInWatchList(symbol))
@@ -1126,6 +1205,7 @@ namespace TradeBlotter.ViewModels
System.Windows.MessageBox.Show("Added '"+symbol+"'","Success", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
public void RemoveFromWatchListCommand(String symbol)
{
if (!WatchListDA.IsInWatchList(symbol))
@@ -1158,6 +1238,7 @@ namespace TradeBlotter.ViewModels
monitorRunning=false;
base.OnPropertyChanged("MonitorStatus");
}
private void StartMonitor()
{
if(monitorRunning)return;
@@ -1167,12 +1248,14 @@ namespace TradeBlotter.ViewModels
DispatcherTimerTick(null,null);
base.OnPropertyChanged("MonitorStatus");
}
private void DispatcherTimerTick(object sender, EventArgs e)
{
UpdatePositionPrices(false);
UpdatePositionRSI3(true);
RunPerformance();
}
private void UpdatePositionPrices(bool change=true)
{
try
@@ -1199,6 +1282,7 @@ namespace TradeBlotter.ViewModels
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
}
}
private void UpdatePositionRSI3(bool change=true)
{
try
@@ -1222,10 +1306,12 @@ namespace TradeBlotter.ViewModels
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
}
}
public void ReloadCommand()
{
LoadSessionFile();
}
public void LoadFileCommand()
{
Forms.OpenFileDialog openFileDialog=new Forms.OpenFileDialog();
@@ -1297,6 +1383,7 @@ namespace TradeBlotter.ViewModels
base.OnPropertyChanged("CanMonitor");
base.OnPropertyChanged("CashBalance");
base.OnPropertyChanged("NonTradeableCash");
base.OnPropertyChanged("HedgeCash");
base.OnPropertyChanged("ModelExpectation");
base.OnPropertyChanged("ExpectationColor");
base.OnPropertyChanged("ExpectationDescription");
@@ -1326,6 +1413,7 @@ namespace TradeBlotter.ViewModels
base.OnPropertyChanged("LegendVisible");
}
}
public String PercentButtonText
{
get
@@ -1334,6 +1422,7 @@ namespace TradeBlotter.ViewModels
else return "Show %";
}
}
public ICommand ToggleReturnOrPercentCommand
{
get
@@ -1351,6 +1440,7 @@ namespace TradeBlotter.ViewModels
return toggleReturnOrPercentCommand;
}
}
public CompositeDataSource Data
{
get
@@ -1361,6 +1451,7 @@ namespace TradeBlotter.ViewModels
return compositeDataSource;
}
}
public String GraphTitle
{
get
@@ -1480,6 +1571,7 @@ namespace TradeBlotter.ViewModels
return sb.ToString();
}
}
public String ToolTipInitialStop
{
get
@@ -1531,6 +1623,7 @@ namespace TradeBlotter.ViewModels
{
get
{
if(null==selectedPosition)return "Please select a position by clicking on a row.";
StringBuilder sb=new StringBuilder();
sb.Append("RMultiple is based on original position setup.").Append("\n");
sb.Append("Original Exposure=").Append(Utility.FormatCurrency(selectedPosition.PurchasePrice*selectedPosition.Shares)).Append("\n");
@@ -1545,6 +1638,46 @@ namespace TradeBlotter.ViewModels
}
}
public String ToolTipSold
{
get
{
if(null==selectedPosition)return "Please select a position by clicking on a row.";
StringBuilder sb=new StringBuilder();
if(selectedPosition.IsActivePosition)
{
sb.Append($"{selectedPosition.Symbol} is currently active.");
}
else
{
sb.Append($"{selectedPosition.Symbol} {selectedPosition.Comment}.");
}
return sb.ToString();
}
}
public String ToolTipExposure
{
get
{
if(null==selectedPosition)return "Please select a position by clicking on a row.";
StringBuilder sb=new StringBuilder();
if(selectedPosition.IsActivePosition)
{
sb.Append("Exposure = PurchasePrice * Shares\n");
sb.Append($"{Utility.FormatCurrency(selectedPosition.Exposure)} = {Utility.FormatCurrency(selectedPosition.PurchasePrice)} * {Utility.FormatNumber(selectedPosition.Shares,3)}");
}
else
{
sb.Append("Original Exposure = PurchasePrice * Shares\n");
sb.Append($"{Utility.FormatCurrency(selectedPosition.PurchasePrice * selectedPosition.Shares)} = {Utility.FormatCurrency(selectedPosition.PurchasePrice)} * {Utility.FormatNumber(selectedPosition.Shares,3)}");
}
return sb.ToString();
}
}
// ************************************************************** T O O L T I P H E L P E R S **************************************************************
public MarketData.Generator.Model.StopLimits GetHistoricalStopLimits()
{