Add edit position, close position for MG model.
This commit is contained in:
@@ -72,7 +72,6 @@ namespace TradeBlotter.Model
|
|||||||
base.OnPropertyChanged("ActiveMarketValue");
|
base.OnPropertyChanged("ActiveMarketValue");
|
||||||
base.OnPropertyChanged("GainLoss");
|
base.OnPropertyChanged("GainLoss");
|
||||||
base.OnPropertyChanged("GainLossPcnt");
|
base.OnPropertyChanged("GainLossPcnt");
|
||||||
// base.OnPropertyChanged("RMultipleAsString");
|
|
||||||
base.OnPropertyChanged("RMultiple");
|
base.OnPropertyChanged("RMultiple");
|
||||||
base.OnPropertyChanged("EdgeRatioAsString");
|
base.OnPropertyChanged("EdgeRatioAsString");
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,15 @@ namespace TradeBlotter.Model
|
|||||||
ZacksRank=position.ZacksRank;
|
ZacksRank=position.ZacksRank;
|
||||||
SharpeRatio = position.SharpeRatio;
|
SharpeRatio = position.SharpeRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MarketData.Generator.Momentum.Position Position
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String Symbol
|
public String Symbol
|
||||||
{
|
{
|
||||||
get{return position.Symbol;}
|
get{return position.Symbol;}
|
||||||
|
|||||||
@@ -145,9 +145,15 @@
|
|||||||
<Compile Include="UIUtils\ClosePositionDialog.xaml.cs">
|
<Compile Include="UIUtils\ClosePositionDialog.xaml.cs">
|
||||||
<DependentUpon>ClosePositionDialog.xaml</DependentUpon>
|
<DependentUpon>ClosePositionDialog.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="UIUtils\ClosePositionDialogNoStop.xaml.cs">
|
||||||
|
<DependentUpon>ClosePositionDialogNoStop.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="UIUtils\EditPositionDialog.xaml.cs">
|
<Compile Include="UIUtils\EditPositionDialog.xaml.cs">
|
||||||
<DependentUpon>EditPositionDialog.xaml</DependentUpon>
|
<DependentUpon>EditPositionDialog.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="UIUtils\EditPositionDialogNoStop.xaml.cs">
|
||||||
|
<DependentUpon>EditPositionDialogNoStop.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="UIUtils\ProformaAddPositionDialog.xaml.cs">
|
<Compile Include="UIUtils\ProformaAddPositionDialog.xaml.cs">
|
||||||
<DependentUpon>ProformaAddPositionDialog.xaml</DependentUpon>
|
<DependentUpon>ProformaAddPositionDialog.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -347,10 +353,18 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="UIUtils\ClosePositionDialogNoStop.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="UIUtils\EditPositionDialog.xaml">
|
<Page Include="UIUtils\EditPositionDialog.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="UIUtils\EditPositionDialogNoStop.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="UIUtils\ProformaAddPositionDialog.xaml">
|
<Page Include="UIUtils\ProformaAddPositionDialog.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
|||||||
@@ -1119,6 +1119,7 @@ namespace TradeBlotter.ViewModels
|
|||||||
selectedPosition.Symbol,selectedPosition.PurchaseDate.ToShortDateString(),Utility.FormatCurrency(selectedPosition.PurchasePrice),Utility.FormatCurrency(selectedPosition.TrailingStopLimit));
|
selectedPosition.Symbol,selectedPosition.PurchaseDate.ToShortDateString(),Utility.FormatCurrency(selectedPosition.PurchasePrice),Utility.FormatCurrency(selectedPosition.TrailingStopLimit));
|
||||||
MessageBox.Show(strMessage,"Edit Position");
|
MessageBox.Show(strMessage,"Edit Position");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddToWatchListCommand(String symbol)
|
public void AddToWatchListCommand(String symbol)
|
||||||
{
|
{
|
||||||
if(WatchListDA.IsInWatchList(symbol))
|
if(WatchListDA.IsInWatchList(symbol))
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ using System.Windows.Threading;
|
|||||||
using MarketData.Generator.Momentum;
|
using MarketData.Generator.Momentum;
|
||||||
using TradeBlotter.UIUtils;
|
using TradeBlotter.UIUtils;
|
||||||
using MarketData.Generator.Model;
|
using MarketData.Generator.Model;
|
||||||
|
using MarketData.Generator.Interface;
|
||||||
|
using Position = MarketData.Generator.Momentum.Position;
|
||||||
|
|
||||||
namespace TradeBlotter.ViewModels
|
namespace TradeBlotter.ViewModels
|
||||||
{
|
{
|
||||||
@@ -87,6 +89,8 @@ namespace TradeBlotter.ViewModels
|
|||||||
private RelayCommand movingAverageCommandPosition;
|
private RelayCommand movingAverageCommandPosition;
|
||||||
private RelayCommand displayHistoricalCommandPosition;
|
private RelayCommand displayHistoricalCommandPosition;
|
||||||
private RelayCommand displayHeadlinesCommandPosition;
|
private RelayCommand displayHeadlinesCommandPosition;
|
||||||
|
private RelayCommand closePositionCommandPosition;
|
||||||
|
private RelayCommand editPositionCommandPosition;
|
||||||
// chart plotter
|
// chart plotter
|
||||||
private bool showAsGainLoss=true;
|
private bool showAsGainLoss=true;
|
||||||
private bool isLegendVisible=false;
|
private bool isLegendVisible=false;
|
||||||
@@ -209,6 +213,8 @@ namespace TradeBlotter.ViewModels
|
|||||||
collection.Add(new MenuItem() { Text = "Display DCF Valuation", MenuItemClickedCommand = DisplayDCFValuationPosition, StaysOpenOnClick = false });
|
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 = "Add to Watchlist", MenuItemClickedCommand = AddToWatchListPosition, StaysOpenOnClick = false });
|
||||||
collection.Add(new MenuItem() { Text = "Remove from Watchlist", MenuItemClickedCommand = RemoveFromWatchListPosition, 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;
|
return collection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -834,6 +840,37 @@ namespace TradeBlotter.ViewModels
|
|||||||
return removeFromWatchListCommandPosition;
|
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 *********************************************************
|
// ******************************************************************* I C O M M A N D S E S S I O N *********************************************************
|
||||||
// *************************************************************************************************************************************************************
|
// *************************************************************************************************************************************************************
|
||||||
@@ -1002,6 +1039,47 @@ namespace TradeBlotter.ViewModels
|
|||||||
System.Windows.MessageBox.Show("Removed '"+symbol+"'","Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
System.Windows.MessageBox.Show("Removed '"+symbol+"'","Success", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClosePositionCommand(MGPositionModel selectedPosition)
|
||||||
|
{
|
||||||
|
Position clonedPosition=Position.Clone(selectedPosition.Position);
|
||||||
|
IPurePosition changedPosition=ClosePositionDialogNoStop.Prompt("Close Position",clonedPosition);
|
||||||
|
if(null==changedPosition) return;
|
||||||
|
MomentumBacktest momentumModel = new MomentumBacktest();
|
||||||
|
if (!momentumModel.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.PurchaseDate.ToShortDateString(),
|
||||||
|
changedPosition.SellDate.ToShortDateString(),
|
||||||
|
Utility.FormatCurrency(changedPosition.CurrentPrice),
|
||||||
|
pathFileName);
|
||||||
|
MessageBox.Show(strMessage, "Close Position");
|
||||||
|
LoadSessionFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EditPositionCommand(MGPositionModel selectedPosition)
|
||||||
|
{
|
||||||
|
Position clonedPosition=Position.Clone(selectedPosition.Position);
|
||||||
|
IPurePosition changedPosition=EditPositionDialogNoStop.Prompt("Edit Position",clonedPosition);
|
||||||
|
if(null==changedPosition) return;
|
||||||
|
MomentumBacktest momentumModel = new MomentumBacktest();
|
||||||
|
if (!momentumModel.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");
|
||||||
|
}
|
||||||
// **************************************************************************************************************************************************************************
|
// **************************************************************************************************************************************************************************
|
||||||
// ********************************************************************** C O M M A N D W O R K E R S S E S S I O N ********************************************************
|
// ********************************************************************** C O M M A N D W O R K E R S S E S S I O N ********************************************************
|
||||||
// ***************************************************************************************************************************************************************************
|
// ***************************************************************************************************************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user