|
|
|
|
@@ -24,15 +24,15 @@ using Microsoft.Research.DynamicDataDisplay.DataSources;
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
using MarketData.Generator.CMMomentum;
|
|
|
|
|
using Position = MarketData.Generator.CMMomentum.Position;
|
|
|
|
|
|
|
|
|
|
using TradeBlotter.UIUtils;
|
|
|
|
|
using MarketData.Generator.Model;
|
|
|
|
|
using MarketData.CNNProcessing;
|
|
|
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
|
|
|
using MarketData.Generator.Interface;
|
|
|
|
|
|
|
|
|
|
namespace TradeBlotter.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class CMMomentumViewModel : WorkspaceViewModel
|
|
|
|
|
public class CMMomentumViewModel : WorkspaceViewModel
|
|
|
|
|
{
|
|
|
|
|
// generic section
|
|
|
|
|
private const String DISPLAY_NAME = "Momentum Model";
|
|
|
|
|
@@ -92,6 +92,8 @@ namespace TradeBlotter.ViewModels
|
|
|
|
|
private RelayCommand movingAverageCommandPosition;
|
|
|
|
|
private RelayCommand displayHistoricalCommandPosition;
|
|
|
|
|
private RelayCommand displayHeadlinesCommandPosition;
|
|
|
|
|
private RelayCommand closePositionCommandPosition;
|
|
|
|
|
private RelayCommand editPositionCommandPosition;
|
|
|
|
|
// chart plotter
|
|
|
|
|
private bool showAsGainLoss=true;
|
|
|
|
|
private bool isLegendVisible=false;
|
|
|
|
|
@@ -217,6 +219,8 @@ 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 });
|
|
|
|
|
return collection;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -845,6 +849,38 @@ namespace TradeBlotter.ViewModels
|
|
|
|
|
return removeFromWatchListCommandPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand ClosePosition
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if(closePositionCommandPosition==null)
|
|
|
|
|
{
|
|
|
|
|
closePositionCommandPosition=new RelayCommand(param => this.ClosePositionCommand(selectedPosition),param =>
|
|
|
|
|
{
|
|
|
|
|
if(null==selectedPosition||null==selectedPosition.Symbol) return false;
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return closePositionCommandPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand EditPosition
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if(editPositionCommandPosition==null)
|
|
|
|
|
{
|
|
|
|
|
editPositionCommandPosition=new RelayCommand(param => this.EditPositionCommand(selectedPosition),param =>
|
|
|
|
|
{
|
|
|
|
|
if(null==selectedPosition||null==selectedPosition.Symbol||!Utility.IsEpoch(selectedPosition.SellDate)) return false;
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return editPositionCommandPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// *************************************************************************************************************************************************************
|
|
|
|
|
// ******************************************************************* I C O M M A N D S E S S I O N *********************************************************
|
|
|
|
|
// *************************************************************************************************************************************************************
|
|
|
|
|
@@ -981,6 +1017,7 @@ namespace TradeBlotter.ViewModels
|
|
|
|
|
saveParams.Referer = this;
|
|
|
|
|
WorkspaceInstantiator.Invoke(saveParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddToWatchListCommand(String symbol)
|
|
|
|
|
{
|
|
|
|
|
if (WatchListDA.IsInWatchList(symbol))
|
|
|
|
|
@@ -997,6 +1034,7 @@ namespace TradeBlotter.ViewModels
|
|
|
|
|
System.Windows.MessageBox.Show("Added '" + symbol + "'", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveFromWatchListCommand(String symbol)
|
|
|
|
|
{
|
|
|
|
|
if (!WatchListDA.IsInWatchList(symbol))
|
|
|
|
|
@@ -1013,6 +1051,47 @@ namespace TradeBlotter.ViewModels
|
|
|
|
|
System.Windows.MessageBox.Show("Removed '"+symbol+"'","Success",MessageBoxButton.OK,MessageBoxImage.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClosePositionCommand(CMPositionModel selectedPosition)
|
|
|
|
|
{
|
|
|
|
|
Position clonedPosition=Position.Clone(selectedPosition.Position);
|
|
|
|
|
IPurePosition changedPosition=ClosePositionDialogNoStop.Prompt("Close Position",clonedPosition);
|
|
|
|
|
if(null==changedPosition) return;
|
|
|
|
|
CMMomentumBacktest cmMomentumModel = new CMMomentumBacktest();
|
|
|
|
|
if (!cmMomentumModel.ClosePosition(changedPosition.Symbol, changedPosition.PurchaseDate, changedPosition.SellDate, changedPosition.CurrentPrice, pathFileName))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Failed to close the position, check log for details.", "Close Position");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String strMessage = String.Format("Closed position for {0}, Purchase Date:{1}, Sell Date{2}, Current Price:{3}. Saved to {4}. A backup was created.",
|
|
|
|
|
changedPosition.Symbol,
|
|
|
|
|
changedPosition.SellDate.ToShortDateString(),
|
|
|
|
|
Utility.FormatCurrency(changedPosition.CurrentPrice),
|
|
|
|
|
pathFileName);
|
|
|
|
|
MessageBox.Show(strMessage, "Close Position");
|
|
|
|
|
LoadSessionFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EditPositionCommand(CMPositionModel selectedPosition)
|
|
|
|
|
{
|
|
|
|
|
Position clonedPosition=Position.Clone(selectedPosition.Position);
|
|
|
|
|
IPurePosition changedPosition=EditPositionDialogNoStop.Prompt("Edit Position",clonedPosition);
|
|
|
|
|
if(null==changedPosition) return;
|
|
|
|
|
CMMomentumBacktest cmMomentumModel = new CMMomentumBacktest();
|
|
|
|
|
if (!cmMomentumModel.EditPosition(changedPosition.Symbol, changedPosition.PurchaseDate, changedPosition.PurchasePrice, pathFileName))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Failed to edit the position, check log for details.", "Edit Position");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
selectedPosition.PurchaseDate = changedPosition.PurchaseDate;
|
|
|
|
|
selectedPosition.PurchasePrice = changedPosition.PurchasePrice;
|
|
|
|
|
String strMessage = String.Format("Edited Position for {0} Purchase Date:{1} Purchase Price:{2}. A backup was created.",
|
|
|
|
|
selectedPosition.Symbol,
|
|
|
|
|
selectedPosition.PurchaseDate.ToShortDateString(),
|
|
|
|
|
Utility.FormatCurrency(selectedPosition.PurchasePrice));
|
|
|
|
|
MessageBox.Show(strMessage, "Edit Position");
|
|
|
|
|
LoadSessionFile();
|
|
|
|
|
}
|
|
|
|
|
// **************************************************************************************************************************************************************************
|
|
|
|
|
// ********************************************************************** C O M M A N D W O R K E R S S E S S I O N ********************************************************
|
|
|
|
|
// ***************************************************************************************************************************************************************************
|
|
|
|
|
|