Commit Latest
This commit is contained in:
@@ -33,8 +33,30 @@ namespace PortfolioManager.Renderers
|
||||
|
||||
public class OffsetDictionary
|
||||
{
|
||||
enum OffsetType {VerticalOffset5PC, VerticalOffset3PC, VerticalOffset1PC,HorizontalOffset5PC,HorizontalOffset3PC,HorizontalOffset1PC};
|
||||
private Dictionary<int, double> offsetDictionary;
|
||||
public enum OffsetType
|
||||
{
|
||||
VerticalOffset5PC, VerticalOffset3PC, VerticalOffset1PC, HorizontalOffset5PC, HorizontalOffset3PC, HorizontalOffset1PC,
|
||||
MinBollingerDate, MaxBollingerDate, MinBollingerValue, MaxBollingerValue
|
||||
};
|
||||
|
||||
private Dictionary<OffsetType, double> offsetDictionary = new Dictionary<OffsetType, double>();
|
||||
|
||||
public void Add(OffsetType offsetType, double value)
|
||||
{
|
||||
if (offsetDictionary.ContainsKey(offsetType))
|
||||
{
|
||||
offsetDictionary[offsetType] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
offsetDictionary.Add(offsetType, value);
|
||||
}
|
||||
}
|
||||
|
||||
public double Offset(OffsetType offsetType)
|
||||
{
|
||||
return offsetDictionary[offsetType];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,14 +80,7 @@ namespace PortfolioManager.Renderers
|
||||
private BollingerBands bollingerBands;
|
||||
private InsiderTransactionSummaries insiderTransactionSummaries = null;
|
||||
|
||||
// double maxBollingerDate = 0.00;
|
||||
// double minBollingerDate = 0.00;
|
||||
//double spread = 0.00;
|
||||
double percentShiftHorz3PC = 0.00;
|
||||
double percentShiftHorz1PC = 0.00;
|
||||
double percentShiftVert3PC = 0.00;
|
||||
double percentShiftVert1PC = 0.00;
|
||||
double percentShiftVert5PC = 0.00;
|
||||
private OffsetDictionary offsets = new OffsetDictionary();
|
||||
|
||||
public BollingerBandRenderer(AvaPlot plotter)
|
||||
{
|
||||
@@ -91,10 +106,10 @@ namespace PortfolioManager.Renderers
|
||||
if (!ShowLegend) Plotter.Plot.HideLegend();
|
||||
else Plotter.Plot.ShowLegend();
|
||||
}
|
||||
else if (eventArgs.PropertyName.Equals("ShowInsiderTransactions"))
|
||||
{
|
||||
SetData(selectedSymbol, selectedDayCount);
|
||||
}
|
||||
// else if (eventArgs.PropertyName.Equals("ShowInsiderTransactions"))
|
||||
// {
|
||||
// SetData(selectedSymbol, selectedDayCount);
|
||||
// }
|
||||
}
|
||||
|
||||
public void Render()
|
||||
@@ -152,20 +167,7 @@ namespace PortfolioManager.Renderers
|
||||
}
|
||||
}
|
||||
bollingerBands = BollingerBandGenerator.GenerateBollingerBands(prices);
|
||||
|
||||
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);
|
||||
|
||||
double spreadHorz = (maxBollingerDate - minBollingerDate);
|
||||
double spreadVert = (maxBollingerValue - minBollingerValue);
|
||||
percentShiftHorz3PC = spreadHorz * .03;
|
||||
percentShiftHorz1PC = spreadHorz * .01;
|
||||
percentShiftVert3PC = spreadVert * .03;
|
||||
percentShiftVert1PC = spreadVert * .01;
|
||||
percentShiftVert5PC = spreadVert * .05;
|
||||
|
||||
CalculateOffsets();
|
||||
GenerateBollingerBands();
|
||||
GenerateZeroPoint(zeroPrice);
|
||||
GenerateInsiderTransactions();
|
||||
@@ -173,6 +175,28 @@ namespace PortfolioManager.Renderers
|
||||
GenerateTradePoints();
|
||||
}
|
||||
|
||||
private void CalculateOffsets()
|
||||
{
|
||||
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.MinBollingerDate,minBollingerDate);
|
||||
offsets.Add(OffsetDictionary.OffsetType.MaxBollingerValue,maxBollingerValue);
|
||||
offsets.Add(OffsetDictionary.OffsetType.MinBollingerValue,minBollingerValue);
|
||||
|
||||
double spreadHorz = (maxBollingerDate - minBollingerDate);
|
||||
double spreadVert = (maxBollingerValue - minBollingerValue);
|
||||
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset1PC,spreadHorz * .01);
|
||||
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset3PC,spreadHorz * .03);
|
||||
offsets.Add(OffsetDictionary.OffsetType.HorizontalOffset5PC,spreadHorz * .05);
|
||||
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset1PC,spreadVert * .01);
|
||||
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset3PC,spreadVert *.03);
|
||||
offsets.Add(OffsetDictionary.OffsetType.VerticalOffset5PC,spreadVert * .05);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate the ZeroPoint marker and text
|
||||
/// </summary>
|
||||
@@ -184,21 +208,21 @@ namespace PortfolioManager.Renderers
|
||||
Coordinates coordinates = default;
|
||||
Image image = default;
|
||||
ZeroPoint = GainLossModel.Price(zeroPrice);
|
||||
(DateTime[] dates, double[] values) = ZeroPoint.ToXYData();
|
||||
|
||||
Scatter scatter = Plotter.Plot.Add.Scatter(dates, values, ScottPlot.Color.FromSKColor(SKColors.Blue));
|
||||
(DateTime[] dates, double[] values) = ZeroPoint.ToXYData(); // There is only a single value in this collection
|
||||
|
||||
// Place the triangle marker
|
||||
image = TextMarkerImageGenerator.ToSPImage(ImageCache.GetInstance().GetImage(ImageCache.ImageType.BlueTriangleUp));
|
||||
coordinates = new Coordinates(dates[0].ToOADate(), values[0]);
|
||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image, SizeFactor.Normal);
|
||||
|
||||
// Place the text marker
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("Even ");
|
||||
sb.Append(Utility.FormatCurrency(zeroPrice.Close));
|
||||
double parityOffsetPercent = (latestPrice.Close - zeroPrice.Close) / zeroPrice.Close;
|
||||
sb.Append("(").Append(parityOffsetPercent < 0 ? "" : "+").Append(Utility.FormatPercent(parityOffsetPercent)).Append(")");
|
||||
image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 130, 24, FontFactor.FontSize);
|
||||
coordinates = new Coordinates(dates[0].ToOADate(), values[0] - 5.00);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -245,8 +269,7 @@ namespace PortfolioManager.Renderers
|
||||
sb.Append(" (").Append(percentOffsetFromLow > 0 ? "+" : "").Append(Utility.FormatPercent(percentOffsetFromLow)).Append(")");
|
||||
}
|
||||
Image image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 155, 24, FontFactor.FontSize);
|
||||
// Coordinates coordinates = new Coordinates(dates[0].ToOADate()-1, values[0] - 5.00);
|
||||
Coordinates coordinates = new Coordinates(limit.EffectiveDate.ToOADate(), limit.StopPrice - 5.00);
|
||||
Coordinates coordinates = new Coordinates(limit.EffectiveDate.ToOADate(), limit.StopPrice - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
||||
}
|
||||
}
|
||||
@@ -261,10 +284,8 @@ namespace PortfolioManager.Renderers
|
||||
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()/(1+onePercent), stopLimit.StopPrice - 5.00);
|
||||
Coordinates coordinates = new Coordinates(latestPrice.Date.ToOADate() - percentShiftHorz3PC, stopLimit.StopPrice - 5.00);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -295,7 +316,7 @@ namespace PortfolioManager.Renderers
|
||||
sb.Append(Utility.FormatCurrency(portfolioTrade.Price));
|
||||
|
||||
Image image = TextMarkerImageGenerator.GenerateImage(sb.ToString(), 150, 24, FontFactor.FontSize);
|
||||
Coordinates coordinates = new Coordinates(portfolioTrade.TradeDate.ToOADate(), portfolioTrade.Price - percentShiftVert5PC);
|
||||
Coordinates coordinates = new Coordinates(portfolioTrade.TradeDate.ToOADate(), portfolioTrade.Price - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||
ImageMarker imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, image);
|
||||
}
|
||||
}
|
||||
@@ -337,7 +358,7 @@ namespace PortfolioManager.Renderers
|
||||
{
|
||||
DateTime date = dates[index];
|
||||
double value = values[index];
|
||||
coordinates = new Coordinates(date.ToOADate(), value);
|
||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Small);
|
||||
}
|
||||
}
|
||||
@@ -348,7 +369,7 @@ namespace PortfolioManager.Renderers
|
||||
{
|
||||
DateTime date = dates[index];
|
||||
double value = values[index];
|
||||
coordinates = new Coordinates(date.ToOADate(), value);
|
||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Normal);
|
||||
}
|
||||
}
|
||||
@@ -359,7 +380,7 @@ namespace PortfolioManager.Renderers
|
||||
{
|
||||
DateTime date = dates[index];
|
||||
double value = values[index];
|
||||
coordinates = new Coordinates(date.ToOADate(), value);
|
||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageDisposed, SizeFactor.Large);
|
||||
}
|
||||
}
|
||||
@@ -371,7 +392,7 @@ namespace PortfolioManager.Renderers
|
||||
{
|
||||
DateTime date = dates[index];
|
||||
double value = values[index];
|
||||
coordinates = new Coordinates(date.ToOADate(), value);
|
||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Small);
|
||||
}
|
||||
}
|
||||
@@ -382,7 +403,7 @@ namespace PortfolioManager.Renderers
|
||||
{
|
||||
DateTime date = dates[index];
|
||||
double value = values[index];
|
||||
coordinates = new Coordinates(date.ToOADate(), value);
|
||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Normal);
|
||||
}
|
||||
}
|
||||
@@ -393,7 +414,7 @@ namespace PortfolioManager.Renderers
|
||||
{
|
||||
DateTime date = dates[index];
|
||||
double value = values[index];
|
||||
coordinates = new Coordinates(date.ToOADate(), value);
|
||||
coordinates = new Coordinates(date.ToOADate(),offsets.Offset(OffsetDictionary.OffsetType.MinBollingerValue) - offsets.Offset(OffsetDictionary.OffsetType.VerticalOffset5PC));
|
||||
imageMarker = Plotter.Plot.Add.ImageMarker(coordinates, imageAcquired, SizeFactor.Large);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user