Commit Latest
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
vscode settings are in C:\Users\skess\AppData\Roaming\Code\User/settings.json
|
||||||
|
|
||||||
|
|
||||||
dotnet new avalonia.window -na EditPositionDialog -n PortfolioManager.Dialog
|
dotnet new avalonia.window -na EditPositionDialog -n PortfolioManager.Dialog
|
||||||
dotnet new avalonia.usercontrol -na [namespace] -n [name]
|
dotnet new avalonia.usercontrol -na [namespace] -n [name]
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ namespace PortfolioManager.Renderers
|
|||||||
private int selectedDayCount = int.MinValue;
|
private int selectedDayCount = int.MinValue;
|
||||||
private Price latestPrice = default;
|
private Price latestPrice = default;
|
||||||
private Price zeroPrice = default;
|
private Price zeroPrice = default;
|
||||||
private bool showLabels = true;
|
|
||||||
private bool showMarkers = true;
|
private bool showMarkers = true;
|
||||||
private bool showLegend = false;
|
private bool showLegend = false;
|
||||||
private bool showTradeLabels = true;
|
private bool showTradeLabels = true;
|
||||||
@@ -90,13 +89,7 @@ namespace PortfolioManager.Renderers
|
|||||||
|
|
||||||
private void OnBollingerBandRendererPropertyChanged(Object sender, PropertyChangedEventArgs eventArgs)
|
private void OnBollingerBandRendererPropertyChanged(Object sender, PropertyChangedEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
if (eventArgs.PropertyName.Equals("ShowLabels"))
|
if (eventArgs.PropertyName.Equals("ShowLegend"))
|
||||||
{
|
|
||||||
}
|
|
||||||
else if (eventArgs.PropertyName.Equals("ShowMarkers"))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else if (eventArgs.PropertyName.Equals("ShowLegend"))
|
|
||||||
{
|
{
|
||||||
if (!ShowLegend) Plotter.Plot.HideLegend();
|
if (!ShowLegend) Plotter.Plot.HideLegend();
|
||||||
else Plotter.Plot.ShowLegend();
|
else Plotter.Plot.ShowLegend();
|
||||||
@@ -106,10 +99,6 @@ namespace PortfolioManager.Renderers
|
|||||||
if (!ShowLegend) Plotter.Plot.HideLegend();
|
if (!ShowLegend) Plotter.Plot.HideLegend();
|
||||||
else Plotter.Plot.ShowLegend();
|
else Plotter.Plot.ShowLegend();
|
||||||
}
|
}
|
||||||
// else if (eventArgs.PropertyName.Equals("ShowInsiderTransactions"))
|
|
||||||
// {
|
|
||||||
// SetData(selectedSymbol, selectedDayCount);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render()
|
public void Render()
|
||||||
@@ -119,192 +108,197 @@ namespace PortfolioManager.Renderers
|
|||||||
base.OnPropertyChanged("ShowLegend");
|
base.OnPropertyChanged("ShowLegend");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetData(String selectedSymbol, int selectedDayCount)
|
public void SetData(String selectedSymbol, int selectedDayCount)
|
||||||
{
|
{
|
||||||
this.selectedSymbol = selectedSymbol;
|
this.selectedSymbol = selectedSymbol;
|
||||||
this.selectedDayCount = selectedDayCount;
|
this.selectedDayCount = selectedDayCount;
|
||||||
stopLimit = PortfolioDA.GetStopLimit(selectedSymbol);
|
stopLimit = PortfolioDA.GetStopLimit(selectedSymbol);
|
||||||
portfolioTrades = PortfolioDA.GetTradesSymbol(selectedSymbol);
|
portfolioTrades = PortfolioDA.GetTradesSymbol(selectedSymbol);
|
||||||
portfolioTradesLots = LotAggregator.CombineLots(portfolioTrades);
|
portfolioTradesLots = LotAggregator.CombineLots(portfolioTrades);
|
||||||
|
|
||||||
Plotter.Plot.Clear();
|
Plotter.Plot.Clear();
|
||||||
if (null != portfolioTrades && 0 != portfolioTrades.Count)
|
if (null != portfolioTrades && 0 != portfolioTrades.Count)
|
||||||
|
{
|
||||||
|
DateGenerator dateGenerator = new DateGenerator();
|
||||||
|
DateTime earliestTrade = portfolioTrades[0].TradeDate;
|
||||||
|
earliestTrade = earliestTrade.AddDays(-30);
|
||||||
|
int daysBetween = dateGenerator.DaysBetween(earliestTrade, DateTime.Now);
|
||||||
|
if (daysBetween < selectedDayCount || !syncTradeToBand) prices = PricingDA.GetPrices(selectedSymbol, selectedDayCount);
|
||||||
|
else prices = PricingDA.GetPrices(selectedSymbol, earliestTrade);
|
||||||
|
|
||||||
|
DateTime earliestInsiderTransactionDate = dateGenerator.GenerateFutureBusinessDate(prices[prices.Count - 1].Date, 30);
|
||||||
|
insiderTransactionSummaries = InsiderTransactionDA.GetInsiderTransactionSummaries(selectedSymbol, earliestInsiderTransactionDate);
|
||||||
|
|
||||||
|
// calculate the break even price on the open trades for this symbol
|
||||||
|
PortfolioTrades openTrades = portfolioTrades.GetOpenTrades();
|
||||||
|
DateTime latestPricingDate = PricingDA.GetLatestDate(selectedSymbol);
|
||||||
|
latestPrice = PricingDA.GetPrice(selectedSymbol, latestPricingDate);
|
||||||
|
zeroPrice = ParityGenerator.GenerateGainLossValue(openTrades, latestPrice);
|
||||||
|
|
||||||
|
if (!syncTradeToBand)
|
||||||
|
{
|
||||||
|
DateTime earliestPricingDate = prices[prices.Count - 1].Date;
|
||||||
|
earliestPricingDate = earliestPricingDate.AddDays(30);
|
||||||
|
IEnumerable<PortfolioTrade> tradesInRange = (from portfolioTrade in portfolioTradesLots where portfolioTrade.TradeDate >= earliestPricingDate select portfolioTrade);
|
||||||
|
portfolioTrades = new PortfolioTrades();
|
||||||
|
foreach (PortfolioTrade portfolioTrade in tradesInRange) portfolioTrades.Add(portfolioTrade);
|
||||||
|
portfolioTradesLots = portfolioTrades;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prices = PricingDA.GetPrices(selectedSymbol, selectedDayCount);
|
||||||
|
if (null != prices && 0 != prices.Count)
|
||||||
{
|
{
|
||||||
DateGenerator dateGenerator = new DateGenerator();
|
DateGenerator dateGenerator = new DateGenerator();
|
||||||
DateTime earliestTrade = portfolioTrades[0].TradeDate;
|
|
||||||
earliestTrade = earliestTrade.AddDays(-30);
|
|
||||||
int daysBetween = dateGenerator.DaysBetween(earliestTrade, DateTime.Now);
|
|
||||||
if (daysBetween < selectedDayCount || !syncTradeToBand) prices = PricingDA.GetPrices(selectedSymbol, selectedDayCount);
|
|
||||||
else prices = PricingDA.GetPrices(selectedSymbol, earliestTrade);
|
|
||||||
|
|
||||||
DateTime earliestInsiderTransactionDate = dateGenerator.GenerateFutureBusinessDate(prices[prices.Count - 1].Date, 30);
|
DateTime earliestInsiderTransactionDate = dateGenerator.GenerateFutureBusinessDate(prices[prices.Count - 1].Date, 30);
|
||||||
insiderTransactionSummaries = InsiderTransactionDA.GetInsiderTransactionSummaries(selectedSymbol, earliestInsiderTransactionDate);
|
insiderTransactionSummaries = InsiderTransactionDA.GetInsiderTransactionSummaries(selectedSymbol, earliestInsiderTransactionDate);
|
||||||
|
|
||||||
// calculate the break even price on the open trades for this symbol
|
|
||||||
PortfolioTrades openTrades = portfolioTrades.GetOpenTrades();
|
|
||||||
DateTime latestPricingDate = PricingDA.GetLatestDate(selectedSymbol);
|
|
||||||
latestPrice = PricingDA.GetPrice(selectedSymbol, latestPricingDate);
|
|
||||||
zeroPrice = ParityGenerator.GenerateGainLossValue(openTrades, latestPrice);
|
|
||||||
|
|
||||||
if (!syncTradeToBand)
|
|
||||||
{
|
|
||||||
DateTime earliestPricingDate = prices[prices.Count - 1].Date;
|
|
||||||
earliestPricingDate = earliestPricingDate.AddDays(30);
|
|
||||||
IEnumerable<PortfolioTrade> tradesInRange = (from portfolioTrade in portfolioTradesLots where portfolioTrade.TradeDate >= earliestPricingDate select portfolioTrade);
|
|
||||||
portfolioTrades = new PortfolioTrades();
|
|
||||||
foreach (PortfolioTrade portfolioTrade in tradesInRange) portfolioTrades.Add(portfolioTrade);
|
|
||||||
portfolioTradesLots = portfolioTrades;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
prices = PricingDA.GetPrices(selectedSymbol, selectedDayCount);
|
|
||||||
if (null != prices && 0 != prices.Count)
|
|
||||||
{
|
|
||||||
DateGenerator dateGenerator = new DateGenerator();
|
|
||||||
DateTime earliestInsiderTransactionDate = dateGenerator.GenerateFutureBusinessDate(prices[prices.Count - 1].Date, 30);
|
|
||||||
insiderTransactionSummaries = InsiderTransactionDA.GetInsiderTransactionSummaries(selectedSymbol, earliestInsiderTransactionDate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices);
|
|
||||||
CalculateOffsets();
|
|
||||||
GenerateBollingerBands();
|
|
||||||
GenerateZeroPoint(zeroPrice);
|
|
||||||
GenerateInsiderTransactions();
|
|
||||||
GenerateStopLimits();
|
|
||||||
GenerateTradePoints();
|
|
||||||
}
|
}
|
||||||
|
bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices);
|
||||||
|
CalculateOffsets();
|
||||||
|
GenerateBollingerBands();
|
||||||
|
GenerateInsiderTransactions();
|
||||||
|
GenerateStopLimits();
|
||||||
|
GenerateTradePoints();
|
||||||
|
GenerateZeroPoint(zeroPrice);
|
||||||
|
}
|
||||||
|
|
||||||
private void CalculateOffsets()
|
/// <summary>
|
||||||
{
|
/// These offsets are used to place markers relative to the area in which the graph occupies.
|
||||||
double maxBollingerDate = bollingerBands.Max(x => x.Date).ToOADate();
|
/// </summary>
|
||||||
double minBollingerDate = bollingerBands.Min(x => x.Date).ToOADate();
|
private void CalculateOffsets()
|
||||||
double maxBollingerValue = bollingerBands.Max(x => x.K);
|
{
|
||||||
double minBollingerValue = bollingerBands.Min(x => x.L);
|
double maxBollingerDate = bollingerBands.Max(x => x.Date).ToOADate();
|
||||||
|
double minBollingerDate = bollingerBands.Min(x => x.Date).ToOADate();
|
||||||
|
double maxBollingerValue = bollingerBands.Max(x => x.K);
|
||||||
|
double minBollingerValue = bollingerBands.Min(x => x.L);
|
||||||
|
|
||||||
offsets.Add(OffsetDictionary.OffsetType.MaxBollingerDate,maxBollingerDate);
|
offsets.Add(OffsetDictionary.OffsetType.MaxBollingerDate,maxBollingerDate);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.MinBollingerDate,minBollingerDate);
|
offsets.Add(OffsetDictionary.OffsetType.MinBollingerDate,minBollingerDate);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.MaxBollingerValue,maxBollingerValue);
|
offsets.Add(OffsetDictionary.OffsetType.MaxBollingerValue,maxBollingerValue);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.MinBollingerValue,minBollingerValue);
|
offsets.Add(OffsetDictionary.OffsetType.MinBollingerValue,minBollingerValue);
|
||||||
|
|
||||||
double spreadHorz = (maxBollingerDate - minBollingerDate);
|
double spreadHorz = (maxBollingerDate - minBollingerDate);
|
||||||
double spreadVert = (maxBollingerValue - minBollingerValue);
|
double spreadVert = (maxBollingerValue - minBollingerValue);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset1PC,spreadHorz * .01);
|
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset1PC,spreadHorz * .01);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset3PC,spreadHorz * .03);
|
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset3PC,spreadHorz * .03);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset5PC,spreadHorz * .05);
|
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset5PC,spreadHorz * .05);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset1PC,spreadVert * .01);
|
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset1PC,spreadVert * .01);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset3PC,spreadVert *.03);
|
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset3PC,spreadVert *.03);
|
||||||
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset5PC,spreadVert * .05);
|
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset5PC,spreadVert * .05);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate the ZeroPoint marker and text
|
/// Generate the ZeroPoint marker and text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="zeroPrice"></param>
|
/// <param name="zeroPrice"></param>
|
||||||
private void GenerateZeroPoint(Price zeroPrice)
|
private void GenerateZeroPoint(Price zeroPrice)
|
||||||
{
|
{
|
||||||
if (!ShowMarkers || null == zeroPrice) return;
|
if (!ShowMarkers || null == zeroPrice) return;
|
||||||
ImageMarker imageMarker = default;
|
ImageMarker imageMarker = default;
|
||||||
Coordinates coordinates = default;
|
Coordinates coordinates = default;
|
||||||
Image image = default;
|
Image image = default;
|
||||||
ZeroPoint = GainLossModel.Price(zeroPrice);
|
ZeroPoint = GainLossModel.Price(zeroPrice);
|
||||||
(DateTime[] dates, double[] values) = ZeroPoint.ToXYData(); // There is only a single value in this collection
|
(DateTime[] dates, double[] values) = ZeroPoint.ToXYData(); // There is only a single value in this collection
|
||||||
|
|
||||||
// Place the triangle marker
|
// Place the triangle marker
|
||||||
image = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.BlueTriangleUp));
|
image = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.BlueTriangleUp));
|
||||||
coordinates = new Coordinates(dates[0].ToOADate(), values[0]);
|
coordinates = new Coordinates(dates[0].ToOADate(), values[0]);
|
||||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image, SizeFactor.Normal);
|
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image, SizeFactor.Normal);
|
||||||
|
|
||||||
// Place the text marker
|
// Place the text marker
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.Append("Even ");
|
sb.Append("Even ");
|
||||||
sb.Append(Utility.FormatCurrency(zeroPrice.Close));
|
sb.Append(Utility.FormatCurrency(zeroPrice.Close));
|
||||||
double parityOffsetPercent = (latestPrice.Close - zeroPrice.Close) / zeroPrice.Close;
|
double parityOffsetPercent = (latestPrice.Close - zeroPrice.Close) / zeroPrice.Close;
|
||||||
sb.Append("(").Append(parityOffsetPercent < 0 ? "" : "+").Append(Utility.FormatPercent(parityOffsetPercent)).Append(")");
|
sb.Append("(").Append(parityOffsetPercent < 0 ? "" : "+").Append(Utility.FormatPercent(parityOffsetPercent)).Append(")");
|
||||||
image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 130, 24, FontFactor.FontSize);
|
image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 130, 24, FontFactor.FontSize);
|
||||||
coordinates = new Coordinates(dates[0].ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC), values[0] - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
coordinates = new Coordinates(dates[0].ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC), values[0] - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate Stop Limits
|
||||||
|
/// </summary>
|
||||||
|
private void GenerateStopLimits()
|
||||||
|
{
|
||||||
|
if (null == stopLimits && null == zeroPrice) return;
|
||||||
|
if (null != stopLimits)
|
||||||
|
{
|
||||||
|
StopLimits = StopLimitCompositeModel.CreateCompositeDataSource(stopLimits);
|
||||||
|
}
|
||||||
|
else if (null != stopLimit && null != zeroPrice)
|
||||||
|
{
|
||||||
|
StopLimits = GainLossModel.CreateCompositeDataSource(zeroPrice.Date, stopLimit.StopPrice);
|
||||||
|
}
|
||||||
|
(DateTime[] dates, double[] values) = StopLimits.ToXYData();
|
||||||
|
|
||||||
|
// Add the markers
|
||||||
|
Image imageStopLimitMarker = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.RedTriangleUp));
|
||||||
|
for (int index = 0; index < dates.Length; index++)
|
||||||
|
{
|
||||||
|
DateTime date = dates[index];
|
||||||
|
double value = values[index];
|
||||||
|
Coordinates coordinates = new Coordinates(date.ToOADate(), value);
|
||||||
|
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageStopLimitMarker, SizeFactor.Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// Add the text marker
|
||||||
/// Generate Stop Limits
|
if (null != stopLimits)
|
||||||
/// </summary>
|
|
||||||
private void GenerateStopLimits()
|
|
||||||
{
|
{
|
||||||
if (null == stopLimits && null == zeroPrice) return;
|
for (int index = 0; index < stopLimits.Count; index++)
|
||||||
if (null != stopLimits)
|
|
||||||
{
|
{
|
||||||
StopLimits = StopLimitCompositeModel.CreateCompositeDataSource(stopLimits);
|
StopLimit limit = stopLimits[index];
|
||||||
}
|
|
||||||
else if (null != stopLimit && null != zeroPrice)
|
|
||||||
{
|
|
||||||
StopLimits = GainLossModel.CreateCompositeDataSource(zeroPrice.Date, stopLimit.StopPrice);
|
|
||||||
}
|
|
||||||
(DateTime[] dates, double[] values) = StopLimits.ToXYData();
|
|
||||||
|
|
||||||
// Add the markers
|
|
||||||
Image imageStopLimitMarker = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.RedTriangleUp));
|
|
||||||
for (int index = 0; index < dates.Length; index++)
|
|
||||||
{
|
|
||||||
DateTime date = dates[index];
|
|
||||||
double value = values[index];
|
|
||||||
Coordinates coordinates = new Coordinates(date.ToOADate(), value);
|
|
||||||
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageStopLimitMarker, SizeFactor.Normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the text marker
|
|
||||||
if (null != stopLimits)
|
|
||||||
{
|
|
||||||
for (int index = 0; index < stopLimits.Count; index++)
|
|
||||||
{
|
|
||||||
StopLimit limit = stopLimits[index];
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.Append(limit.StopType).Append(" ");
|
|
||||||
sb.Append(Utility.FormatCurrency(limit.StopPrice));
|
|
||||||
if (index == stopLimits.Count - 1)
|
|
||||||
{
|
|
||||||
Price latestPrice = prices[0];
|
|
||||||
double percentOffsetFromLow = ((latestPrice.Low - limit.StopPrice) / limit.StopPrice);
|
|
||||||
sb.Append(" (").Append(percentOffsetFromLow > 0 ? "+" : "").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
|
||||||
}
|
|
||||||
Image image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 155, 24, FontFactor.FontSize);
|
|
||||||
Coordinates coordinates = new Coordinates(limit.EffectiveDate.ToOADate(), limit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
|
||||||
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (null == zeroPrice) return;
|
|
||||||
if (null == stopLimit || null == zeroPrice || !showTradeLabels) return;
|
|
||||||
Price latestPrice = prices[0];
|
|
||||||
double percentOffsetFromLow = ((latestPrice.Low - stopLimit.StopPrice) / stopLimit.StopPrice);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.Append(stopLimit.StopType).Append(" ");
|
sb.Append(limit.StopType).Append(" ");
|
||||||
sb.Append(Utility.FormatCurrency(stopLimit.StopPrice));
|
sb.Append(Utility.FormatCurrency(limit.StopPrice));
|
||||||
sb.Append(" (").Append(percentOffsetFromLow > 0 ? "+" : "").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
if (index == stopLimits.Count - 1)
|
||||||
|
{
|
||||||
|
Price latestPrice = prices[0];
|
||||||
|
double percentOffsetFromLow = ((latestPrice.Low - limit.StopPrice) / limit.StopPrice);
|
||||||
|
sb.Append(" (").Append(percentOffsetFromLow > 0 ? "+" : "").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
||||||
|
}
|
||||||
Image image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 155, 24, FontFactor.FontSize);
|
Image image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 155, 24, FontFactor.FontSize);
|
||||||
Coordinates coordinates = new Coordinates(latestPrice.Date.ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC), stopLimit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
Coordinates coordinates = new Coordinates(limit.EffectiveDate.ToOADate(), limit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
/// <summary>
|
|
||||||
/// Generate Trade Points
|
|
||||||
/// </summary>
|
|
||||||
private void GenerateTradePoints()
|
|
||||||
{
|
{
|
||||||
if (null == portfolioTradesLots || 0 == portfolioTradesLots.Count || !showTradeLabels) return;
|
if (null == zeroPrice) return;
|
||||||
// Here we add the image markers
|
if (null == stopLimit || null == zeroPrice) return;
|
||||||
Image tradePointMarker = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.YellowTriangleUp));
|
Price latestPrice = prices[0];
|
||||||
for (int index = 0; index < portfolioTradesLots.Count; index++)
|
double percentOffsetFromLow = ((latestPrice.Low - stopLimit.StopPrice) / stopLimit.StopPrice);
|
||||||
{
|
|
||||||
PortfolioTrade portfolioTrade = portfolioTradesLots[index];
|
|
||||||
Coordinates coordinates = new Coordinates(portfolioTrade.TradeDate.ToOADate(), portfolioTrade.Price);
|
|
||||||
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, tradePointMarker, SizeFactor.Normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append(stopLimit.StopType).Append(" ");
|
||||||
|
sb.Append(Utility.FormatCurrency(stopLimit.StopPrice));
|
||||||
|
sb.Append(" (").Append(percentOffsetFromLow > 0 ? "+" : "").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
||||||
|
Image image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 155, 24, FontFactor.FontSize);
|
||||||
|
Coordinates coordinates = new Coordinates(latestPrice.Date.ToOADate() - offsets.Offset(OffsetDictionary.OffsetType.HorizontalOffset3PC), stopLimit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
|
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate Trade Points
|
||||||
|
/// </summary>
|
||||||
|
private void GenerateTradePoints()
|
||||||
|
{
|
||||||
|
if (null == portfolioTradesLots || 0 == portfolioTradesLots.Count) return;
|
||||||
|
// Here we add the image markers
|
||||||
|
Image tradePointMarker = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.YellowTriangleUp));
|
||||||
|
for (int index = 0; index < portfolioTradesLots.Count; index++)
|
||||||
|
{
|
||||||
|
PortfolioTrade portfolioTrade = portfolioTradesLots[index];
|
||||||
|
Coordinates coordinates = new Coordinates(portfolioTrade.TradeDate.ToOADate(), portfolioTrade.Price);
|
||||||
|
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, tradePointMarker, SizeFactor.Normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showTradeLabels)
|
||||||
|
{
|
||||||
// This adds the text markers
|
// This adds the text markers
|
||||||
for (int index = 0; index < portfolioTradesLots.Count; index++)
|
for (int index = 0; index < portfolioTradesLots.Count; index++)
|
||||||
{
|
{
|
||||||
@@ -320,292 +314,293 @@ namespace PortfolioManager.Renderers
|
|||||||
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate Insider Transactions
|
/// Generate Insider Transactions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void GenerateInsiderTransactions()
|
private void GenerateInsiderTransactions()
|
||||||
|
{
|
||||||
|
if (null == prices || 0 == prices.Count || !ShowInsiderTransactions) return;
|
||||||
|
ImageMarker imageMarker = default;
|
||||||
|
Coordinates coordinates = default;
|
||||||
|
|
||||||
|
double minClose = (from Price price in prices select price.Close).Min();
|
||||||
|
|
||||||
|
// get the maximum date in the bollinger band series
|
||||||
|
DateTime maxBollingerDate = (from BollingerBandElement bollingerBandElement in bollingerBands select bollingerBandElement.Date).Max();
|
||||||
|
// ensure that the insider transactions are clipped to the bollingerband max date. There are some items in insider transaction summaries (options dated in the future) that will throw the graphic out of proportion
|
||||||
|
InsiderTransactionSummaries disposedSummaries = new InsiderTransactionSummaries((from InsiderTransactionSummary insiderTransactionSummary in insiderTransactionSummaries where insiderTransactionSummary.NumberOfSharesAcquiredDisposed < 0 && insiderTransactionSummary.TransactionDate.Date <= maxBollingerDate select insiderTransactionSummary).ToList());
|
||||||
|
InsiderTransactionSummaries acquiredSummaries = new InsiderTransactionSummaries((from InsiderTransactionSummary insiderTransactionSummary in insiderTransactionSummaries where insiderTransactionSummary.NumberOfSharesAcquiredDisposed > 0 && insiderTransactionSummary.TransactionDate.Date <= maxBollingerDate select insiderTransactionSummary).ToList());
|
||||||
|
|
||||||
|
BinCollection<InsiderTransactionSummary> disposedSummariesBin = BinHelper<InsiderTransactionSummary>.CreateBins(new BinItems<InsiderTransactionSummary>(disposedSummaries), 3);
|
||||||
|
BinCollection<InsiderTransactionSummary> acquiredSummariesBin = BinHelper<InsiderTransactionSummary>.CreateBins(new BinItems<InsiderTransactionSummary>(acquiredSummaries), 3);
|
||||||
|
|
||||||
|
InsiderTransactionPointDisposedSmall = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[2]), minClose);
|
||||||
|
InsiderTransactionPointDisposedMedium = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[1]), minClose);
|
||||||
|
InsiderTransactionPointDisposedLarge = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[0]), minClose);
|
||||||
|
InsiderTransactionPointAcquiredSmall = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[0]), minClose);
|
||||||
|
InsiderTransactionPointAcquiredMedium = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[1]), minClose);
|
||||||
|
InsiderTransactionPointAcquiredLarge = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[2]), minClose);
|
||||||
|
|
||||||
|
Image imageDisposed = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.RedTriangleDown));
|
||||||
|
Image imageAcquired = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.GreenTriangleUp));
|
||||||
|
|
||||||
|
// Disposed
|
||||||
{
|
{
|
||||||
if (null == prices || 0 == prices.Count || !ShowInsiderTransactions) return;
|
(DateTime[] dates, double[] values) = InsiderTransactionPointDisposedSmall.ToXYData();
|
||||||
ImageMarker imageMarker = default;
|
for (int index = 0; index < dates.Length; index++)
|
||||||
Coordinates coordinates = default;
|
|
||||||
|
|
||||||
double minClose = (from Price price in prices select price.Close).Min();
|
|
||||||
|
|
||||||
// get the maximum date in the bollinger band series
|
|
||||||
DateTime maxBollingerDate = (from BollingerBandElement bollingerBandElement in bollingerBands select bollingerBandElement.Date).Max();
|
|
||||||
// ensure that the insider transactions are clipped to the bollingerband max date. There are some items in insider transaction summaries (options dated in the future) that will throw the graphic out of proportion
|
|
||||||
InsiderTransactionSummaries disposedSummaries = new InsiderTransactionSummaries((from InsiderTransactionSummary insiderTransactionSummary in insiderTransactionSummaries where insiderTransactionSummary.NumberOfSharesAcquiredDisposed < 0 && insiderTransactionSummary.TransactionDate.Date <= maxBollingerDate select insiderTransactionSummary).ToList());
|
|
||||||
InsiderTransactionSummaries acquiredSummaries = new InsiderTransactionSummaries((from InsiderTransactionSummary insiderTransactionSummary in insiderTransactionSummaries where insiderTransactionSummary.NumberOfSharesAcquiredDisposed > 0 && insiderTransactionSummary.TransactionDate.Date <= maxBollingerDate select insiderTransactionSummary).ToList());
|
|
||||||
|
|
||||||
BinCollection<InsiderTransactionSummary> disposedSummariesBin = BinHelper<InsiderTransactionSummary>.CreateBins(new BinItems<InsiderTransactionSummary>(disposedSummaries), 3);
|
|
||||||
BinCollection<InsiderTransactionSummary> acquiredSummariesBin = BinHelper<InsiderTransactionSummary>.CreateBins(new BinItems<InsiderTransactionSummary>(acquiredSummaries), 3);
|
|
||||||
|
|
||||||
InsiderTransactionPointDisposedSmall = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[2]), minClose);
|
|
||||||
InsiderTransactionPointDisposedMedium = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[1]), minClose);
|
|
||||||
InsiderTransactionPointDisposedLarge = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(disposedSummariesBin[0]), minClose);
|
|
||||||
InsiderTransactionPointAcquiredSmall = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[0]), minClose);
|
|
||||||
InsiderTransactionPointAcquiredMedium = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[1]), minClose);
|
|
||||||
InsiderTransactionPointAcquiredLarge = InsiderTransactionModel.InsiderTransactionSummaries(new InsiderTransactionSummaries(acquiredSummariesBin[2]), minClose);
|
|
||||||
|
|
||||||
Image imageDisposed = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.RedTriangleDown));
|
|
||||||
Image imageAcquired = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.GreenTriangleUp));
|
|
||||||
|
|
||||||
// Disposed
|
|
||||||
{
|
{
|
||||||
(DateTime[] dates, double[] values) = InsiderTransactionPointDisposedSmall.ToXYData();
|
DateTime date = dates[index];
|
||||||
for (int index = 0; index < dates.Length; index++)
|
double value = values[index];
|
||||||
{
|
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
DateTime date = dates[index];
|
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Small);
|
||||||
double value = values[index];
|
|
||||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
|
||||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Small);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = InsiderTransactionPointDisposedMedium.ToXYData();
|
|
||||||
for (int index = 0; index < dates.Length; index++)
|
|
||||||
{
|
|
||||||
DateTime date = dates[index];
|
|
||||||
double value = values[index];
|
|
||||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
|
||||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Normal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = InsiderTransactionPointDisposedLarge.ToXYData();
|
|
||||||
for (int index = 0; index < dates.Length; index++)
|
|
||||||
{
|
|
||||||
DateTime date = dates[index];
|
|
||||||
double value = values[index];
|
|
||||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
|
||||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Large);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Acquired
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = InsiderTransactionPointAcquiredSmall.ToXYData();
|
|
||||||
for (int index = 0; index < dates.Length; index++)
|
|
||||||
{
|
|
||||||
DateTime date = dates[index];
|
|
||||||
double value = values[index];
|
|
||||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
|
||||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Small);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = InsiderTransactionPointAcquiredMedium.ToXYData();
|
|
||||||
for (int index = 0; index < dates.Length; index++)
|
|
||||||
{
|
|
||||||
DateTime date = dates[index];
|
|
||||||
double value = values[index];
|
|
||||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
|
||||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Normal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = InsiderTransactionPointAcquiredLarge.ToXYData();
|
|
||||||
for (int index = 0; index < dates.Length; index++)
|
|
||||||
{
|
|
||||||
DateTime date = dates[index];
|
|
||||||
double value = values[index];
|
|
||||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
|
||||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Large);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generate Bollinger Bands
|
|
||||||
/// </summary>
|
|
||||||
private void GenerateBollingerBands()
|
|
||||||
{
|
{
|
||||||
K = BollingerBandModel.K(bollingerBands);
|
(DateTime[] dates, double[] values) = InsiderTransactionPointDisposedMedium.ToXYData();
|
||||||
KL1 = BollingerBandModel.KL1(bollingerBands);
|
for (int index = 0; index < dates.Length; index++)
|
||||||
L = BollingerBandModel.L(bollingerBands);
|
|
||||||
LP1 = BollingerBandModel.LP1(bollingerBands);
|
|
||||||
High = BollingerBandModel.High(bollingerBands);
|
|
||||||
Low = BollingerBandModel.Low(bollingerBands);
|
|
||||||
Close = BollingerBandModel.Close(bollingerBands);
|
|
||||||
SMAN = BollingerBandModel.SMAN(bollingerBands);
|
|
||||||
Volume = BollingerBandModel.Volume(bollingerBands);
|
|
||||||
LeastSquares = BollingerBandModel.LeastSquares(bollingerBands);
|
|
||||||
|
|
||||||
Scatter scatter = default;
|
|
||||||
{
|
{
|
||||||
(DateTime[] dates, double[] values) = K.ToXYData();
|
DateTime date = dates[index];
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Green));
|
double value = values[index];
|
||||||
scatter.LegendText = "K";
|
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
scatter.LineWidth = 3;
|
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Normal);
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = KL1.ToXYData();
|
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Green));
|
|
||||||
scatter.LegendText = "KL1";
|
|
||||||
scatter.LineWidth = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = L.ToXYData();
|
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Green));
|
|
||||||
scatter.LegendText = "L";
|
|
||||||
scatter.LineWidth = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = LP1.ToXYData();
|
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Green));
|
|
||||||
scatter.LegendText = "LP1";
|
|
||||||
scatter.LineWidth = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = High.ToXYData();
|
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Blue));
|
|
||||||
scatter.LegendText = "High";
|
|
||||||
scatter.LineWidth = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = Low.ToXYData();
|
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Red));
|
|
||||||
scatter.LegendText = "Low";
|
|
||||||
scatter.LineWidth = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = Close.ToXYData();
|
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Black));
|
|
||||||
scatter.LegendText = "Close";
|
|
||||||
scatter.LineWidth = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = LeastSquares.ToXYData();
|
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Orange));
|
|
||||||
scatter.LegendText = "LeastSquares";
|
|
||||||
scatter.LineWidth = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
(DateTime[] dates, double[] values) = SMAN.ToXYData();
|
|
||||||
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Purple));
|
|
||||||
scatter.LegendText = "SMAN";
|
|
||||||
scatter.LineWidth = 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = InsiderTransactionPointDisposedLarge.ToXYData();
|
||||||
|
for (int index = 0; index < dates.Length; index++)
|
||||||
|
{
|
||||||
|
DateTime date = dates[index];
|
||||||
|
double value = values[index];
|
||||||
|
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
|
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Large);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Acquired
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = InsiderTransactionPointAcquiredSmall.ToXYData();
|
||||||
|
for (int index = 0; index < dates.Length; index++)
|
||||||
|
{
|
||||||
|
DateTime date = dates[index];
|
||||||
|
double value = values[index];
|
||||||
|
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
|
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Small);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = InsiderTransactionPointAcquiredMedium.ToXYData();
|
||||||
|
for (int index = 0; index < dates.Length; index++)
|
||||||
|
{
|
||||||
|
DateTime date = dates[index];
|
||||||
|
double value = values[index];
|
||||||
|
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
|
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = InsiderTransactionPointAcquiredLarge.ToXYData();
|
||||||
|
for (int index = 0; index < dates.Length; index++)
|
||||||
|
{
|
||||||
|
DateTime date = dates[index];
|
||||||
|
double value = values[index];
|
||||||
|
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||||
|
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Large);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate Bollinger Bands
|
||||||
|
/// </summary>
|
||||||
|
private void GenerateBollingerBands()
|
||||||
|
{
|
||||||
|
K = BollingerBandModel.K(bollingerBands);
|
||||||
|
KL1 = BollingerBandModel.KL1(bollingerBands);
|
||||||
|
L = BollingerBandModel.L(bollingerBands);
|
||||||
|
LP1 = BollingerBandModel.LP1(bollingerBands);
|
||||||
|
High = BollingerBandModel.High(bollingerBands);
|
||||||
|
Low = BollingerBandModel.Low(bollingerBands);
|
||||||
|
Close = BollingerBandModel.Close(bollingerBands);
|
||||||
|
SMAN = BollingerBandModel.SMAN(bollingerBands);
|
||||||
|
Volume = BollingerBandModel.Volume(bollingerBands);
|
||||||
|
LeastSquares = BollingerBandModel.LeastSquares(bollingerBands);
|
||||||
|
|
||||||
|
Scatter scatter = default;
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = K.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Green));
|
||||||
|
scatter.LegendText = "K";
|
||||||
|
scatter.LineWidth = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = KL1.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Green));
|
||||||
|
scatter.LegendText = "KL1";
|
||||||
|
scatter.LineWidth = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = L.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Green));
|
||||||
|
scatter.LegendText = "L";
|
||||||
|
scatter.LineWidth = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = LP1.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Green));
|
||||||
|
scatter.LegendText = "LP1";
|
||||||
|
scatter.LineWidth = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = High.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Blue));
|
||||||
|
scatter.LegendText = "High";
|
||||||
|
scatter.LineWidth = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = Low.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Red));
|
||||||
|
scatter.LegendText = "Low";
|
||||||
|
scatter.LineWidth = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = Close.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Black));
|
||||||
|
scatter.LegendText = "Close";
|
||||||
|
scatter.LineWidth = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = LeastSquares.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Orange));
|
||||||
|
scatter.LegendText = "LeastSquares";
|
||||||
|
scatter.LineWidth = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
(DateTime[] dates, double[] values) = SMAN.ToXYData();
|
||||||
|
scatter = Plotter.Plot.Add.ScatterLine(dates, values, ScottPlot.Color.FromSKColor(SKColors.Purple));
|
||||||
|
scatter.LegendText = "SMAN";
|
||||||
|
scatter.LineWidth = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// *********************************************************** P R O P E R T I E S *****************************************************
|
// *********************************************************** P R O P E R T I E S *****************************************************
|
||||||
|
|
||||||
public Prices Prices
|
public Prices Prices
|
||||||
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
get
|
return prices;
|
||||||
{
|
|
||||||
return prices;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool SyncTradeToBand
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return syncTradeToBand;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
syncTradeToBand = value;
|
|
||||||
base.OnPropertyChanged("SyncTradeToBand");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShowLabels
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return showLabels;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
showLabels = value;
|
|
||||||
base.OnPropertyChanged("ShowLabels");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShowMarkers
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return showMarkers;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
showMarkers = value;
|
|
||||||
base.OnPropertyChanged("ShowMarkers");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShowLegend
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return showLegend;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
showLegend = value;
|
|
||||||
base.OnPropertyChanged("ShowLegend");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShowInsiderTransactions
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return showInsiderTransactions;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
showInsiderTransactions = value;
|
|
||||||
base.OnPropertyChanged("ShowInsiderTransactions");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public AvaPlot Plotter { get; private set; }
|
|
||||||
|
|
||||||
private CompositeDataSource InsiderTransactionPointDisposedSmall { get; set; } = Empty();
|
|
||||||
private CompositeDataSource InsiderTransactionPointDisposedMedium { get; set; } = Empty();
|
|
||||||
private CompositeDataSource InsiderTransactionPointDisposedLarge { get; set; } = Empty();
|
|
||||||
private CompositeDataSource InsiderTransactionPointAcquiredSmall { get; set; } = Empty();
|
|
||||||
private CompositeDataSource InsiderTransactionPointAcquiredMedium { get; set; } = Empty();
|
|
||||||
private CompositeDataSource InsiderTransactionPointAcquiredLarge { get; set; } = Empty();
|
|
||||||
|
|
||||||
private CompositeDataSource K { get; set; } = Empty();
|
|
||||||
private CompositeDataSource KL1 { get; set; } = Empty();
|
|
||||||
private CompositeDataSource L { get; set; } = Empty();
|
|
||||||
private CompositeDataSource LP1 { get; set; } = Empty();
|
|
||||||
private CompositeDataSource High { get; set; } = Empty();
|
|
||||||
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();
|
|
||||||
|
|
||||||
private static CompositeDataSource Empty()
|
|
||||||
{
|
|
||||||
return new CompositeDataSource()
|
|
||||||
{
|
|
||||||
DataAdapter = new SortedDateTimeDataAdapter()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SyncTradeToBand
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return syncTradeToBand;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
syncTradeToBand = value;
|
||||||
|
base.OnPropertyChanged("SyncTradeToBand");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShowTradeLabels
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return showTradeLabels;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
showTradeLabels = value;
|
||||||
|
base.OnPropertyChanged("ShowTradeLabels");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShowMarkers
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return showMarkers;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
showMarkers = value;
|
||||||
|
base.OnPropertyChanged("ShowMarkers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShowLegend
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return showLegend;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
showLegend = value;
|
||||||
|
base.OnPropertyChanged("ShowLegend");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShowInsiderTransactions
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return showInsiderTransactions;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
showInsiderTransactions = value;
|
||||||
|
base.OnPropertyChanged("ShowInsiderTransactions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AvaPlot Plotter { get; private set; }
|
||||||
|
|
||||||
|
private CompositeDataSource InsiderTransactionPointDisposedSmall { get; set; } = Empty();
|
||||||
|
private CompositeDataSource InsiderTransactionPointDisposedMedium { get; set; } = Empty();
|
||||||
|
private CompositeDataSource InsiderTransactionPointDisposedLarge { get; set; } = Empty();
|
||||||
|
private CompositeDataSource InsiderTransactionPointAcquiredSmall { get; set; } = Empty();
|
||||||
|
private CompositeDataSource InsiderTransactionPointAcquiredMedium { get; set; } = Empty();
|
||||||
|
private CompositeDataSource InsiderTransactionPointAcquiredLarge { get; set; } = Empty();
|
||||||
|
|
||||||
|
private CompositeDataSource K { get; set; } = Empty();
|
||||||
|
private CompositeDataSource KL1 { get; set; } = Empty();
|
||||||
|
private CompositeDataSource L { get; set; } = Empty();
|
||||||
|
private CompositeDataSource LP1 { get; set; } = Empty();
|
||||||
|
private CompositeDataSource High { get; set; } = Empty();
|
||||||
|
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();
|
||||||
|
|
||||||
|
private static CompositeDataSource Empty()
|
||||||
|
{
|
||||||
|
return new CompositeDataSource()
|
||||||
|
{
|
||||||
|
DataAdapter = new SortedDateTimeDataAdapter()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,11 @@ using System.Threading.Tasks;
|
|||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
using MarketData;
|
using MarketData;
|
||||||
using MarketData.Cache;
|
|
||||||
using MarketData.DataAccess;
|
using MarketData.DataAccess;
|
||||||
using MarketData.MarketDataModel;
|
using MarketData.MarketDataModel;
|
||||||
using MarketData.Utils;
|
using MarketData.Utils;
|
||||||
using PortfolioManager.Renderers;
|
using PortfolioManager.Renderers;
|
||||||
using PortfolioManager.UIUtils;
|
using PortfolioManager.UIUtils;
|
||||||
using ScottPlot.Avalonia;
|
|
||||||
|
|
||||||
namespace PortfolioManager.ViewModels
|
namespace PortfolioManager.ViewModels
|
||||||
{
|
{
|
||||||
@@ -30,6 +28,8 @@ namespace PortfolioManager.ViewModels
|
|||||||
private String companyName = default;
|
private String companyName = default;
|
||||||
private BollingerBandRenderer bollingerBandRenderer = default;
|
private BollingerBandRenderer bollingerBandRenderer = default;
|
||||||
private bool showInsiderTransactions = true;
|
private bool showInsiderTransactions = true;
|
||||||
|
private bool showTradeLabels = true;
|
||||||
|
private bool syncTradeToBand = true;
|
||||||
|
|
||||||
public ScottPlotViewModel()
|
public ScottPlotViewModel()
|
||||||
{
|
{
|
||||||
@@ -45,252 +45,282 @@ namespace PortfolioManager.ViewModels
|
|||||||
base.OnDispose();
|
base.OnDispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override String Title
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (null == selectedSymbol) return DisplayName;
|
||||||
|
return "Bollinger " + "(" + selectedSymbol + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override String DisplayName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "Bollinger Band";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Initialize(bool executePropertyChanged = true)
|
private void Initialize(bool executePropertyChanged = true)
|
||||||
{
|
{
|
||||||
Task workerTask = Task.Factory.StartNew(() =>
|
Task workerTask = Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
MDTrace.WriteLine(LogLevel.DEBUG, $"BollingerBandViewModel::Initialize()");
|
||||||
|
watchListNames = WatchListDA.GetWatchLists();
|
||||||
|
watchListNames.Insert(0, UIConstants.CONST_ALL);
|
||||||
|
selectedWatchList = watchListNames.Find(x => x.Equals("Valuations"));
|
||||||
|
symbols.AddRange(WatchListDA.GetWatchList(selectedWatchList));
|
||||||
|
});
|
||||||
|
workerTask.ContinueWith((continuation) =>
|
||||||
|
{
|
||||||
|
if (executePropertyChanged)
|
||||||
{
|
{
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG, $"BollingerBandViewModel::Initialize()");
|
base.OnPropertyChanged("Symbols");
|
||||||
watchListNames = WatchListDA.GetWatchLists();
|
base.OnPropertyChanged("WatchListNames");
|
||||||
watchListNames.Insert(0, UIConstants.CONST_ALL);
|
base.OnPropertyChanged("SelectedWatchList");
|
||||||
selectedWatchList = watchListNames.Find(x => x.Equals("Valuations"));
|
}
|
||||||
symbols.AddRange(WatchListDA.GetWatchList(selectedWatchList));
|
});
|
||||||
});
|
|
||||||
workerTask.ContinueWith((continuation) =>
|
|
||||||
{
|
|
||||||
if (executePropertyChanged)
|
|
||||||
{
|
|
||||||
base.OnPropertyChanged("Symbols");
|
|
||||||
base.OnPropertyChanged("WatchListNames");
|
|
||||||
base.OnPropertyChanged("SelectedWatchList");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// *******************************************************************************************************************************************
|
// *******************************************************************************************************************************************
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This event will be called the first time the view is rendered and each time the view comes back into focus (i.e.) Tab activated
|
/// This event will be called the first time the view is rendered and each time the view comes back into focus (i.e.) Tab activated
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
public void PlotterLoadedEvent(object sender, PlotterLoadedEventArgs e)
|
public void PlotterLoadedEvent(object sender, PlotterLoadedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPropertyChanged("Plotter");
|
base.OnPropertyChanged("Plotter");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((eventArgs.PropertyName.Equals("SyncTradeToBand") ||
|
if ((eventArgs.PropertyName.Equals("SyncTradeToBand") ||
|
||||||
eventArgs.PropertyName.Equals("ShowTradeLabels") ||
|
eventArgs.PropertyName.Equals("ShowTradeLabels") ||
|
||||||
eventArgs.PropertyName.Equals("SelectedSymbol") ||
|
eventArgs.PropertyName.Equals("SelectedSymbol") ||
|
||||||
eventArgs.PropertyName.Equals("ShowRiskFree") ||
|
eventArgs.PropertyName.Equals("ShowRiskFree") ||
|
||||||
eventArgs.PropertyName.Equals("LeastSquaresFit") ||
|
eventArgs.PropertyName.Equals("LeastSquaresFit") ||
|
||||||
eventArgs.PropertyName.Equals("CheckBoxShowInsiderTransactions") ||
|
eventArgs.PropertyName.Equals("CheckBoxShowInsiderTransactions") ||
|
||||||
eventArgs.PropertyName.Equals("SelectedDayCount"))
|
eventArgs.PropertyName.Equals("SelectedDayCount"))
|
||||||
&& !String.IsNullOrEmpty(selectedSymbol)
|
&& !String.IsNullOrEmpty(selectedSymbol)
|
||||||
&& default != Plotter)
|
&& default != Plotter)
|
||||||
{
|
|
||||||
IsBusy = true;
|
|
||||||
Task workerTask = Task.Factory.StartNew(() =>
|
|
||||||
{
|
|
||||||
companyName = PricingDA.GetNameForSymbol(selectedSymbol);
|
|
||||||
bollingerBandRenderer = new BollingerBandRenderer(Plotter);
|
|
||||||
bollingerBandRenderer.ShowInsiderTransactions=showInsiderTransactions;
|
|
||||||
bollingerBandRenderer.SetData(selectedSymbol, selectedDayCount);
|
|
||||||
bollingerBandRenderer.Render();
|
|
||||||
});
|
|
||||||
workerTask.ContinueWith((continuation) =>
|
|
||||||
{
|
|
||||||
base.OnPropertyChanged("GraphTitle");
|
|
||||||
IsBusy = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ********************************************** P E R S I S T E N C E *************************
|
|
||||||
public override bool CanPersist()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override SaveParameters GetSaveParameters()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetSaveParameters(SaveParameters saveParameters)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// ****************************************************** P R O P E R T I E S ************************************************
|
|
||||||
|
|
||||||
// public AvaPlot Plotter { get; set; } = default;
|
|
||||||
|
|
||||||
public String GraphTitle
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (null == companyName || null == bollingerBandRenderer || null == bollingerBandRenderer.Prices) return "";
|
|
||||||
String displayCompanyName = companyName;
|
|
||||||
if (displayCompanyName.Length > 40) displayCompanyName = displayCompanyName.Substring(0, 40) + "...";
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
float change = float.NaN;
|
|
||||||
Prices prices2day = new Prices(bollingerBandRenderer.Prices.Take(2).ToList());
|
|
||||||
if (2 == prices2day.Count) change = prices2day.GetReturns()[0];
|
|
||||||
sb.Append(displayCompanyName);
|
|
||||||
sb.Append(" (").Append(selectedSymbol).Append(") ");
|
|
||||||
sb.Append(Utility.DateTimeToStringMMHDDHYYYY(bollingerBandRenderer.Prices[bollingerBandRenderer.Prices.Count - 1].Date));
|
|
||||||
sb.Append(" Thru ");
|
|
||||||
sb.Append(Utility.DateTimeToStringMMHDDHYYYY(bollingerBandRenderer.Prices[0].Date));
|
|
||||||
sb.Append(" (").Append(Utility.FormatCurrency(bollingerBandRenderer.Prices[0].Close));
|
|
||||||
sb.Append("/").Append(Utility.FormatCurrency(bollingerBandRenderer.Prices[0].Low));
|
|
||||||
if (!float.IsNaN(change))
|
|
||||||
{
|
|
||||||
sb.Append(",");
|
|
||||||
sb.Append(change >= 0.00 ? "+" : "").Append(Utility.FormatPercent((double)change));
|
|
||||||
}
|
|
||||||
sb.Append(")");
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> WatchListNames
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return watchListNames;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String SelectedWatchList
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return selectedWatchList;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
selectedWatchList = value;
|
|
||||||
base.OnPropertyChanged("SelectedWatchList");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableCollection<String> Symbols
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return symbols;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int SelectedDayCount
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return selectedDayCount;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
selectedDayCount = value;
|
|
||||||
base.OnPropertyChanged("SelectedDayCount");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<int> DayCounts
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return dayCounts;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String SelectedSymbol
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return selectedSymbol;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
selectedSymbol = value;
|
|
||||||
base.OnPropertyChanged("SelectedSymbol");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsBusy
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return isBusy;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
isBusy = value;
|
|
||||||
base.OnPropertyChanged("IsBusy");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override String Title
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (null == selectedSymbol) return DisplayName;
|
|
||||||
return "Bollinger " + "(" + selectedSymbol + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool SyncTradeToBand
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
{
|
||||||
if (null == bollingerBandRenderer) return false;
|
IsBusy = true;
|
||||||
return bollingerBandRenderer.SyncTradeToBand;
|
Task workerTask = Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
companyName = PricingDA.GetNameForSymbol(selectedSymbol);
|
||||||
|
bollingerBandRenderer = new BollingerBandRenderer(Plotter);
|
||||||
|
bollingerBandRenderer.SyncTradeToBand = syncTradeToBand;
|
||||||
|
bollingerBandRenderer.ShowInsiderTransactions = showInsiderTransactions;
|
||||||
|
bollingerBandRenderer.ShowTradeLabels = showTradeLabels;
|
||||||
|
bollingerBandRenderer.SetData(selectedSymbol, selectedDayCount);
|
||||||
|
bollingerBandRenderer.Render();
|
||||||
|
});
|
||||||
|
workerTask.ContinueWith((continuation) =>
|
||||||
|
{
|
||||||
|
base.OnPropertyChanged("GraphTitle");
|
||||||
|
base.OnPropertyChanged("Title");
|
||||||
|
IsBusy = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
set
|
}
|
||||||
{
|
|
||||||
bollingerBandRenderer.SyncTradeToBand = value;
|
|
||||||
|
|
||||||
}
|
// ********************************************** P E R S I S T E N C E *************************
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShowTradeLabels
|
public override bool CanPersist()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override SaveParameters GetSaveParameters()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
// SaveParameters saveParams = new SaveParameters();
|
||||||
|
// if (String.IsNullOrEmpty(selectedSymbol)) return null;
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("Type", GetType().Namespace + "." + GetType().Name));
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("SelectedSymbol", selectedSymbol));
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("SelectedWatchList", selectedWatchList));
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("SelectedDayCount", selectedDayCount.ToString()));
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("SyncTradeToBand", syncTradeToBand.ToString()));
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("ShowTradeLabels", showTradeLabels.ToString()));
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("UseLeastSquaresFit", useLeastSquaresFit.ToString()));
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("ShowInsiderTransactions", showInsiderTransactions.ToString()));
|
||||||
|
// if (null != stopLimits && 0 != stopLimits.Count)
|
||||||
|
// {
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>("StopHistoryCount", stopLimits.Count.ToString()));
|
||||||
|
// for (int index = 0; index < stopLimits.Count; index++)
|
||||||
|
// {
|
||||||
|
// String strItemKey = String.Format("StopHistory_{0}", index);
|
||||||
|
// StopLimit stopLimit = stopLimits[index];
|
||||||
|
// NVPCollection nvpCollection = stopLimit.ToNVPCollection();
|
||||||
|
// String strStopHistoryItem = nvpCollection.ToString();
|
||||||
|
// saveParams.Add(new KeyValuePair<String, String>(strItemKey, strStopHistoryItem));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return saveParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetSaveParameters(SaveParameters saveParameters)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// ****************************************************** P R O P E R T I E S ************************************************
|
||||||
|
|
||||||
|
public String GraphTitle
|
||||||
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
get
|
if (null == companyName || null == bollingerBandRenderer || null == bollingerBandRenderer.Prices) return "";
|
||||||
{
|
String displayCompanyName = companyName;
|
||||||
if (null == bollingerBandRenderer) return false;
|
if (displayCompanyName.Length > 40) displayCompanyName = displayCompanyName.Substring(0, 40) + "...";
|
||||||
return bollingerBandRenderer.ShowLabels;
|
StringBuilder sb = new StringBuilder();
|
||||||
}
|
float change = float.NaN;
|
||||||
set
|
Prices prices2day = new Prices(bollingerBandRenderer.Prices.Take(2).ToList());
|
||||||
{
|
if (2 == prices2day.Count) change = prices2day.GetReturns()[0];
|
||||||
bollingerBandRenderer.ShowLabels = value;
|
sb.Append(displayCompanyName);
|
||||||
|
sb.Append(" (").Append(selectedSymbol).Append(") ");
|
||||||
|
sb.Append(Utility.DateTimeToStringMMHDDHYYYY(bollingerBandRenderer.Prices[bollingerBandRenderer.Prices.Count - 1].Date));
|
||||||
|
sb.Append(" Thru ");
|
||||||
|
sb.Append(Utility.DateTimeToStringMMHDDHYYYY(bollingerBandRenderer.Prices[0].Date));
|
||||||
|
sb.Append(" (").Append(Utility.FormatCurrency(bollingerBandRenderer.Prices[0].Close));
|
||||||
|
sb.Append("/").Append(Utility.FormatCurrency(bollingerBandRenderer.Prices[0].Low));
|
||||||
|
if (!float.IsNaN(change))
|
||||||
|
{
|
||||||
|
sb.Append(",");
|
||||||
|
sb.Append(change >= 0.00 ? "+" : "").Append(Utility.FormatPercent((double)change));
|
||||||
|
}
|
||||||
|
sb.Append(")");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public List<String> WatchListNames
|
||||||
}
|
{
|
||||||
|
get
|
||||||
public Boolean CheckBoxShowInsiderTransactions
|
|
||||||
{
|
{
|
||||||
get
|
return watchListNames;
|
||||||
{
|
}
|
||||||
return showInsiderTransactions;
|
}
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
showInsiderTransactions = value;
|
|
||||||
base.OnPropertyChanged("CheckBoxShowInsiderTransactions");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public String SelectedWatchList
|
||||||
[RelayCommand]
|
{
|
||||||
public async Task Refresh()
|
get
|
||||||
{
|
{
|
||||||
base.OnPropertyChanged("SelectedSymbol");
|
return selectedWatchList;
|
||||||
await Task.FromResult(true);
|
}
|
||||||
}
|
set
|
||||||
|
{
|
||||||
|
selectedWatchList = value;
|
||||||
|
base.OnPropertyChanged("SelectedWatchList");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableCollection<String> Symbols
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return symbols;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int SelectedDayCount
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return selectedDayCount;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
selectedDayCount = value;
|
||||||
|
base.OnPropertyChanged("SelectedDayCount");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<int> DayCounts
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return dayCounts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String SelectedSymbol
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return selectedSymbol;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (String.IsNullOrEmpty(value))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectedSymbol = value;
|
||||||
|
base.OnPropertyChanged("SelectedSymbol");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsBusy
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return isBusy;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
isBusy = value;
|
||||||
|
base.OnPropertyChanged("IsBusy");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SyncTradeToBand
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return syncTradeToBand;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
syncTradeToBand = value;
|
||||||
|
base.OnPropertyChanged("SyncTradeToBand");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShowTradeLabels
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return showTradeLabels;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
showTradeLabels = value;
|
||||||
|
base.OnPropertyChanged("ShowTradeLabels");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean CheckBoxShowInsiderTransactions
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return showInsiderTransactions;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
showInsiderTransactions = value;
|
||||||
|
base.OnPropertyChanged("CheckBoxShowInsiderTransactions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
public async Task Refresh()
|
||||||
|
{
|
||||||
|
base.OnPropertyChanged("SelectedSymbol");
|
||||||
|
await Task.FromResult(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user