diff --git a/PortfolioManager/Dialogs/ClosePositionDialogViewModel.cs b/PortfolioManager/Dialogs/ClosePositionDialogViewModel.cs index bdddea1..25814cd 100644 --- a/PortfolioManager/Dialogs/ClosePositionDialogViewModel.cs +++ b/PortfolioManager/Dialogs/ClosePositionDialogViewModel.cs @@ -26,7 +26,7 @@ namespace PortfolioManager.Dialogs sourcePosition = clonedPosition; if (Utility.IsEpoch(sourcePosition.SellDate)) { - sourcePosition.SellDate = DateTime.Now; + sourcePosition.SellDate = DateTime.Now.Date; } OkEnabled = Validate(); DisplayName = "Close Position"; diff --git a/PortfolioManager/Renderers/BollingerBandRenderer.cs b/PortfolioManager/Renderers/BollingerBandRenderer.cs index d613475..ce04a82 100644 --- a/PortfolioManager/Renderers/BollingerBandRenderer.cs +++ b/PortfolioManager/Renderers/BollingerBandRenderer.cs @@ -24,77 +24,6 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; namespace PortfolioManager.Renderers { - -// ******************************************************************************************************************************** - // public class TextPlot - // { - // public TextPlot() - // { - // } - // public TextPlot(String markerText,SKRect boundingRect,Pixel screenCoordinates) - // { - // BoundingRect = boundingRect; - // ScreenCoordinates = screenCoordinates; - // MarkerText = markerText; - // } - // public Pixel ScreenCoordinates { get; set; } - // public SKRect BoundingRect { get; set; } - // public String MarkerText { get; set; } - // } - - // public class TextPlots : List - // { - // public TextPlots() - // { - // } - - // /// - // /// The coordinate system is based on (0,0) in the upper left - // /// - // /// - // /// - // public bool PointInRects(String markerText,Pixel screenCoordinates,ref Pixel adjustedScreenCoordinates,float factor) - // { - // MDTrace.WriteLine(LogLevel.DEBUG,$"Searching for rectangles in X:{screenCoordinates.X}Y:{screenCoordinates.Y}"); - // foreach(TextPlot textPlot in this) - // { - // if(Math.Round(screenCoordinates.X,2) >= Math.Round(textPlot.BoundingRect.Left,2) && - // Math.Round(screenCoordinates.X,2) <= Math.Round(textPlot.BoundingRect.Right,2) && - // Math.Round(screenCoordinates.Y,2) >= Math.Round(textPlot.BoundingRect.Top,2) && - // Math.Round(screenCoordinates.Y,2) <= Math.Round(textPlot.BoundingRect.Bottom,2)) - // { - // MDTrace.WriteLine(LogLevel.DEBUG,$"The text {markerText} at Point:X:{screenCoordinates.X}:Y:{screenCoordinates.Y} is within Rect:L({textPlot.BoundingRect.Left}),T({textPlot.BoundingRect.Top}),R({textPlot.BoundingRect.Right}),B({textPlot.BoundingRect.Bottom}) with text {textPlot.MarkerText} which is plotted at Coordinates:X:{textPlot.ScreenCoordinates.X} Y:{textPlot.ScreenCoordinates.Y}"); - // SKRect lowestRect = FindLowestAdjacentRect(textPlot.BoundingRect); - // adjustedScreenCoordinates.Y = textPlot.ScreenCoordinates.Y - factor; - // adjustedScreenCoordinates.X = screenCoordinates.X; - // return true; - // } - // } - // return false; - // } - - // public void Summary() - // { - // MDTrace.WriteLine(LogLevel.DEBUG,$"TextPlots:{Count}"); - // foreach(TextPlot textPlot in this) - // { - // MDTrace.WriteLine(LogLevel.DEBUG,$"Rect:L({textPlot.BoundingRect.Left}),T({textPlot.BoundingRect.Top}),R({textPlot.BoundingRect.Right}),B({textPlot.BoundingRect.Bottom}) with text {textPlot.MarkerText} is plotted at Coordinates:X:{textPlot.ScreenCoordinates.X} Y:{textPlot.ScreenCoordinates.Y}"); - // } - // } - - // /// - // /// Find the Rectangle with the highest Bottom that lies within the X-plane - // /// - // /// - // private SKRect FindLowestAdjacentRect(SKRect rect) - // { - // List adjacentRects = this.Where(x=> rect.Left >= x.BoundingRect.Left && rect.Right <= x.BoundingRect.Right).Select(x=>x.BoundingRect).ToList(); - // if(null == adjacentRects || 0==adjacentRects.Count)return new SKRect(){Left=0,Top=0,Right=0,Bottom=0}; - // adjacentRects = adjacentRects.OrderByDescending(x=>x.Bottom).ToList(); - // return adjacentRects[0]; - // } - // } - public class MarkerItem { public MarkerItem(double markerDate, double markerPrice) @@ -131,11 +60,6 @@ namespace PortfolioManager.Renderers { double markerItemDate = markerItem.MarkerDate; double markerItemPrice = markerItem.MarkerPrice; - // double minDate = markerItemDate/(1.00+DATE_SPREAD_PCNT/100.0); - // double maxDate = markerItemDate*(1.00+DATE_SPREAD_PCNT/100.0); - // double minPrice = markerItemPrice/(1.00+PRICE_SPREAD_PCNT/100.0); - // double maxPrice = markerItemPrice*(1.00+PRICE_SPREAD_PCNT/100.0); - double minDate = markerItemDate - offsetDictionary.HorizontalSpread*(DATE_SPREAD_PCNT/100.0); double maxDate = markerItemDate + offsetDictionary.HorizontalSpread*(DATE_SPREAD_PCNT/100.0); double minPrice = markerItemPrice - offsetDictionary.VerticalSpread*(PRICE_SPREAD_PCNT/100.0); @@ -172,9 +96,7 @@ namespace PortfolioManager.Renderers private Prices prices = default; private BollingerBands bollingerBands; private InsiderTransactionSummaries insiderTransactionSummaries = null; - // private TextPlots textPlots = new TextPlots(); private TextMarkerManager textMarkerManager = new TextMarkerManager(); - private OffsetDictionary offsets = new OffsetDictionary(); public BollingerBandRenderer(AvaPlot plotter) @@ -268,7 +190,6 @@ namespace PortfolioManager.Renderers } } bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices); - // textPlots.Clear(); textMarkerManager.Clear(); CalculateOffsets(); GenerateBollingerBands(); @@ -358,19 +279,8 @@ namespace PortfolioManager.Renderers coordinates = new Coordinates(dates[0].ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC), values[0] - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - coordinates = textMarkerManager.GetBestMarkerLocation(coordinates.X, coordinates.Y, offsets, offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates); - // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates); - // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) - // { - // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC); - // } - // screenCoordinates = Plotter.Plot.GetPixel(coordinates); - // SKRect markerRect = new SKRect(){Left=(float)screenCoordinates.X,Top=(float)screenCoordinates.Y,Right=(float)screenCoordinates.X+image.Width,Bottom=(float)screenCoordinates.Y+image.Height}; - // textPlots.Add(new TextPlot(sb.ToString(),markerRect,screenCoordinates)); - imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image); } @@ -423,15 +333,6 @@ namespace PortfolioManager.Renderers limit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); coordinates = textMarkerManager.GetBestMarkerLocation(coordinates.X, coordinates.Y,offsets, offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates); - // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates); - // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) - // { - // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC); - // } - // screenCoordinates = Plotter.Plot.GetPixel(coordinates); - // SKRect markerRect = new SKRect(){Left=(float)screenCoordinates.X,Top=(float)screenCoordinates.Y,Right=(float)screenCoordinates.X+image.Width,Bottom=(float)screenCoordinates.Y+image.Height}; - // textPlots.Add(new TextPlot(sb.ToString(),markerRect,screenCoordinates)); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image); } @@ -452,15 +353,6 @@ namespace PortfolioManager.Renderers stopLimit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); coordinates = textMarkerManager.GetBestMarkerLocation(coordinates.X, coordinates.Y,offsets, offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates); - // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates); - // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) - // { - // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC); - // } - // screenCoordinates = Plotter.Plot.GetPixel(coordinates); - // SKRect markerRect = new SKRect(){Left=(float)screenCoordinates.X,Top=(float)screenCoordinates.Y,Right=(float)screenCoordinates.X+image.Width,Bottom=(float)screenCoordinates.Y+image.Height}; - // textPlots.Add(new TextPlot(sb.ToString(),markerRect,screenCoordinates)); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image); } @@ -498,15 +390,6 @@ namespace PortfolioManager.Renderers portfolioTrade.Price - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); coordinates = textMarkerManager.GetBestMarkerLocation(coordinates.X, coordinates.Y,offsets, offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC)); - // Pixel screenCoordinates = Plotter.Plot.GetPixel(coordinates); - // Pixel adjScreenCoordinates = Plotter.Plot.GetPixel(coordinates); - // if(textPlots.PointInRects(sb.ToString(),screenCoordinates,ref adjScreenCoordinates,(float)offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC))) - // { - // coordinates.Y-=offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset6P5PC); - // } - // screenCoordinates = Plotter.Plot.GetPixel(coordinates); - // SKRect markerRect = new SKRect(){Left=(float)screenCoordinates.X,Top=(float)screenCoordinates.Y,Right=(float)screenCoordinates.X+image.Width,Bottom=(float)screenCoordinates.Y+image.Height}; - // textPlots.Add(new TextPlot(sb.ToString(),markerRect,screenCoordinates)); ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image); } @@ -625,7 +508,6 @@ namespace PortfolioManager.Renderers Low = BollingerBandModel.Low(bollingerBands); Close = BollingerBandModel.Close(bollingerBands); SMAN = BollingerBandModel.SMAN(bollingerBands); -// Volume = BollingerBandModel.Volume(bollingerBands); Scatter scatter = default; { @@ -803,7 +685,6 @@ namespace PortfolioManager.Renderers private CompositeDataSource Low { get; set; } = Empty(); private CompositeDataSource Close { get; set; } = Empty(); private CompositeDataSource SMAN { get; set; } = Empty(); - private CompositeDataSource Volume { get; set; } = Empty(); private CompositeDataSource LeastSquares { get; set; } = Empty(); private CompositeDataSource ZeroPoint { get; set; } = Empty(); private CompositeDataSource StopLimits { get; set; } = Empty(); diff --git a/PortfolioManager/ViewModels/BollingerBandViewModel.cs b/PortfolioManager/ViewModels/BollingerBandViewModel.cs index 478ad27..de02f22 100644 --- a/PortfolioManager/ViewModels/BollingerBandViewModel.cs +++ b/PortfolioManager/ViewModels/BollingerBandViewModel.cs @@ -148,8 +148,6 @@ namespace PortfolioManager.ViewModels bollingerBandRenderer.ExternalStopLimits = stopLimits; bollingerBandRenderer.SetData(selectedSymbol, selectedDayCount); bollingerBandRenderer.Render(); - // bollingerBandRenderer.SetData(selectedSymbol, selectedDayCount); // do it twice. The second render will figure out the text image overlaps - // bollingerBandRenderer.Render(); }); workerTask.ContinueWith((continuation) => { diff --git a/PortfolioManager/ViewModels/MGSHMomentumViewModel.cs b/PortfolioManager/ViewModels/MGSHMomentumViewModel.cs index 55250b4..07d5721 100644 --- a/PortfolioManager/ViewModels/MGSHMomentumViewModel.cs +++ b/PortfolioManager/ViewModels/MGSHMomentumViewModel.cs @@ -680,7 +680,8 @@ namespace PortfolioManager.ViewModels sb.Append(showAsGainLoss ? "$ GainLoss" : "% Return"); sb.Append(" "); sb.Append("(").Append(minDate.ToShortDateString()).Append("-").Append(maxDate.ToShortDateString()).Append(")"); - sb.Append(showAsGainLoss ? Utility.FormatCurrency(modelPerformanceSeries[modelPerformanceSeries.Count - 1].CumulativeGainLoss) : Utility.FormatPercent(modelPerformanceSeries[modelPerformanceSeries.Count - 1].CumProdMinusOne)); + sb.Append(showAsGainLoss ? Utility.FormatCurrency(modelPerformanceSeries[modelPerformanceSeries.Count - 1].CumulativeGainLoss) : + Utility.FormatPercent(modelPerformanceSeries[modelPerformanceSeries.Count - 1].CumProdMinusOne)); return sb.ToString(); } if (showAsGainLoss)