Skip to content

Commit

Permalink
add comparison with "moving average" purchase price in securities chart
Browse files Browse the repository at this point in the history
  • Loading branch information
mierin12 authored and buchen committed Nov 30, 2024
1 parent 9fd7ea4 commit 877b486
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ public class Messages extends NLS
public static String LabelChartDetailChartDevelopment;
public static String LabelChartDetailChartDevelopmentClosing;
public static String LabelChartDetailChartDevelopmentClosingFIFO;
public static String LabelChartDetailChartDevelopmentClosingMovingAverage;
public static String LabelChartDetailChartScaling;
public static String LabelChartDetailChartScalingLinear;
public static String LabelChartDetailChartScalingLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,8 @@ LabelChartDetailChartDevelopmentClosing = Market trend

LabelChartDetailChartDevelopmentClosingFIFO = Market trend vs. Purchase Value

LabelChartDetailChartDevelopmentClosingMovingAverage = Market trend vs. Purchase Price (moving average)

LabelChartDetailChartScaling = Scaling

LabelChartDetailChartScalingLinear = Linear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,8 @@ LabelChartDetailChartDevelopmentClosing = V\u00FDvoj na trhu

LabelChartDetailChartDevelopmentClosingFIFO = V\u00FDvoj na trhu vs po\u0159izovac\u00ED hodnota

LabelChartDetailChartDevelopmentClosingMovingAverage = V\u00FDvoj na trhu vs po\u0159izovac\u00ED hodnota (klouzav\u00FD pr\u016Fm\u011Br)

LabelChartDetailChartScaling = M\u011B\u0159\u00EDtko

LabelChartDetailChartScalingLinear = Line\u00E1rn\u00ED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Markedstrend
LabelChartDetailChartDevelopmentClosingFIFO = Markedstrend vs. K\u00F8bsv\u00E6rdi
LabelChartDetailChartDevelopmentClosingMovingAverage = Markedstrend vs. K\u00F8bsv\u00E6rdi (glidende gennemsnit)
LabelChartDetailChartScaling = Skalering
LabelChartDetailChartScalingLinear = Line\u00E6r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,8 @@ LabelChartDetailChartDevelopmentClosing = Kursentwicklung

LabelChartDetailChartDevelopmentClosingFIFO = Kursentwicklung zum Einstandspreis

LabelChartDetailChartDevelopmentClosingMovingAverage = Kursentwicklung zum Einstandspreis (gleitender Durchschnitt)

LabelChartDetailChartScaling = Skalierung

LabelChartDetailChartScalingLinear = Linear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Evoluci\u00F3n de la cotizaci\u00F3n

LabelChartDetailChartDevelopmentClosingFIFO = Evoluci\u00F3n respecto al precio de compra

LabelChartDetailChartDevelopmentClosingMovingAverage = Evoluci\u00F3n respecto al precio de compra (media m\u00F3vil)

LabelChartDetailChartScaling = Escala

LabelChartDetailChartScalingLinear = Lineal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,8 @@ LabelChartDetailChartDevelopmentClosing = \u00C9volution du cours

LabelChartDetailChartDevelopmentClosingFIFO = \u00C9volution du cours vs. Prix d'achat

LabelChartDetailChartDevelopmentClosingMovingAverage = \u00C9volution du cours vs. Prix d'achat (moyenne glissante)

LabelChartDetailChartScaling = \u00C9chelle

LabelChartDetailChartScalingLinear = Lin\u00E9aire
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Tendenza mercato
LabelChartDetailChartDevelopmentClosingFIFO = Tendenza mercato vs. Valore acquisto
LabelChartDetailChartDevelopmentClosingMovingAverage = Tendenza mercato vs. Valore acquisto (media mobile)
LabelChartDetailChartScaling = Scala
LabelChartDetailChartScalingLinear = Lineare
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Koersontwikkeling
LabelChartDetailChartDevelopmentClosingFIFO = Koersontwikkeling versus GAK (FIFO)
LabelChartDetailChartDevelopmentClosingMovingAverage = Koersontwikkeling versus GAK (SMA)
LabelChartDetailChartScaling = Schaling
LabelChartDetailChartScalingLinear = Lineair
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Trend rynkowy

LabelChartDetailChartDevelopmentClosingFIFO = Trend rynku vs. warto\u015B\u0107 kupna

LabelChartDetailChartDevelopmentClosingMovingAverage = Trend rynku vs. warto\u015B\u0107 kupna (\u015Brednia ruchoma)

LabelChartDetailChartScaling = Skalowanie

LabelChartDetailChartScalingLinear = Liniowe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Gr\u00E1fico de Crescimento

LabelChartDetailChartDevelopmentClosingFIFO = Gr\u00E1fico de Crescimento versus valor de compra

LabelChartDetailChartDevelopmentClosingMovingAverage = Gr\u00E1fico de Crescimento versus valor de compra (m\u00E9dia m\u00F3vel)

LabelChartDetailChartScaling = Escala

LabelChartDetailChartScalingLinear = Linear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = Tend\u00EAncia do Mercado

LabelChartDetailChartDevelopmentClosingFIFO = Tend\u00EAnciad o Mercado vs. Valor de Compra

LabelChartDetailChartDevelopmentClosingMovingAverage = Tend\u00EAnciad o Mercado vs. Valor de Compra (m\u00E9dia m\u00F3vel)

LabelChartDetailChartScaling = Escala

LabelChartDetailChartScalingLinear = Linear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = \u0422\u0435\u043D\u0434\u0435\u043D\u

LabelChartDetailChartDevelopmentClosingFIFO = \u0420\u044B\u043D\u043E\u0447\u043D\u0430\u044F \u0442\u0435\u043D\u0434\u0435\u043D\u0446\u0438\u044F \u0438 \u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C \u043F\u043E\u043A\u0443\u043F\u043A\u0438

LabelChartDetailChartDevelopmentClosingMovingAverage = \u0420\u044B\u043D\u043E\u0447\u043D\u0430\u044F \u0442\u0435\u043D\u0434\u0435\u043D\u0446\u0438\u044F \u0438 \u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C \u043F\u043E\u043A\u0443\u043F\u043A\u0438 (\u0441\u043A\u043E\u043B\u044C\u0437\u044F\u0449\u0435\u0435 \u0441\u0440\u0435\u0434\u043D\u0435\u0435)

LabelChartDetailChartScaling = \u041C\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435

LabelChartDetailChartScalingLinear = \u041B\u0438\u043D\u0435\u0439\u043D\u043E
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = V\u00FDvoj na trhu
LabelChartDetailChartDevelopmentClosingFIFO = V\u00FDvoj na trhu vs n\u00E1kupn\u00E1 hodnota
LabelChartDetailChartDevelopmentClosingMovingAverage = V\u00FDvoj na trhu vs n\u00E1kupn\u00E1 hodnota (k\u013Azav\u00FD priemer)
LabelChartDetailChartScaling = \u0160k\u00E1lovanie
LabelChartDetailChartScalingLinear = Line\u00E1rne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = \u5E02\u573A\u8D8B\u52BF

LabelChartDetailChartDevelopmentClosingFIFO = \u5E02\u573A\u8D8B\u52BF vs. \u6210\u672C

LabelChartDetailChartDevelopmentClosingMovingAverage = \u5E02\u573A\u8D8B\u52BF vs. \u6210\u672C (\u79FB\u52A8\u5E73\u5747)

LabelChartDetailChartScaling = \u5C3A\u5EA6

LabelChartDetailChartScalingLinear = \u7EBF\u6027
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ LabelChartDetailChartDevelopmentClosing = \u5E02\u5834\u8DA8\u52E2
LabelChartDetailChartDevelopmentClosingFIFO = \u5E02\u5834\u8DA8\u52E2\u8207\u8CFC\u8CB7\u50F9\u503C
LabelChartDetailChartDevelopmentClosingMovingAverage = \u5E02\u5834\u8DA8\u52E2\u8207\u8CFC\u8CB7\u50F9\u503C \uFF08\u79FB\u52D5\u5E73\u5747\u6CD5\uFF09
LabelChartDetailChartScaling = \u7E2E\u653E
LabelChartDetailChartScalingLinear = \u7DDA\u6027
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private enum ChartDetails
SCALING_LOG(Messages.LabelChartDetailChartScalingLog), //
CLOSING(Messages.LabelChartDetailChartDevelopmentClosing), //
PURCHASEPRICE(Messages.LabelChartDetailChartDevelopmentClosingFIFO), //
PURCHASEPRICE_MA(Messages.LabelChartDetailChartDevelopmentClosingMovingAverage), //
INVESTMENT(Messages.LabelChartDetailMarkerInvestments), //
SHARES_HELD(Messages.ColumnSharesOwned), //
DIVIDENDS(Messages.LabelChartDetailMarkerDividends), //
Expand Down Expand Up @@ -727,6 +728,7 @@ private void chartConfigAboutToShow(IMenuManager manager)
subMenuChartScaling.add(addMenuAction(ChartDetails.SCALING_LOG));
subMenuChartDevelopment.add(addMenuAction(ChartDetails.CLOSING));
subMenuChartDevelopment.add(addMenuAction(ChartDetails.PURCHASEPRICE));
subMenuChartDevelopment.add(addMenuAction(ChartDetails.PURCHASEPRICE_MA));
subMenuChartMarker.add(addMenuAction(ChartDetails.INVESTMENT));
subMenuChartMarker.add(addMenuAction(ChartDetails.SHARES_HELD));
subMenuChartMarker.add(addMenuAction(ChartDetails.DIVIDENDS));
Expand Down Expand Up @@ -792,15 +794,23 @@ private Action addMenuAction(ChartDetails detail)
case SCALING_LOG:
chartConfig.remove(ChartDetails.SCALING_LINEAR);
chartConfig.remove(ChartDetails.PURCHASEPRICE);
chartConfig.remove(ChartDetails.PURCHASEPRICE_MA);
chartConfig.remove(ChartDetails.CLOSING);
break;
case CLOSING:
chartConfig.remove(ChartDetails.PURCHASEPRICE);
chartConfig.remove(ChartDetails.PURCHASEPRICE_MA);
chartConfig.remove(ChartDetails.SCALING_LOG);
break;
case PURCHASEPRICE:
chartConfig.remove(ChartDetails.CLOSING);
chartConfig.remove(ChartDetails.SCALING_LOG);
chartConfig.remove(ChartDetails.PURCHASEPRICE_MA);
break;
case PURCHASEPRICE_MA:
chartConfig.remove(ChartDetails.CLOSING);
chartConfig.remove(ChartDetails.SCALING_LOG);
chartConfig.remove(ChartDetails.PURCHASEPRICE);
break;
case SHOW_MAIN_HORIZONTAL_LINES:
chartConfig.remove(ChartDetails.SHOW_PERCENTAGE_HORIZONTAL_LINES);
Expand Down Expand Up @@ -905,13 +915,15 @@ private void updateChart()
swtAntialias = range.size > 1000 ? SWT.OFF : SWT.ON;

boolean showAreaRelativeToFirstQuote = chartConfig.contains(ChartDetails.CLOSING)
|| chartConfig.contains(ChartDetails.PURCHASEPRICE);
if (!chartConfig.contains(ChartDetails.PURCHASEPRICE))
|| chartConfig.contains(ChartDetails.PURCHASEPRICE)
|| chartConfig.contains(ChartDetails.PURCHASEPRICE_MA);
if (!chartConfig.contains(ChartDetails.PURCHASEPRICE)
&& !chartConfig.contains(ChartDetails.PURCHASEPRICE_MA))
{
SecurityPrice p2 = prices.get(range.start);
firstQuote = (p2.getValue() / Values.Quote.divider());
}
else
else if (chartConfig.contains(ChartDetails.PURCHASEPRICE))
{
Optional<Double> purchasePrice = getLatestPurchasePrice();

Expand All @@ -920,6 +932,15 @@ private void updateChart()
else
showAreaRelativeToFirstQuote = false;
}
else if (chartConfig.contains(ChartDetails.PURCHASEPRICE_MA))
{
Optional<Double> purchasePrice = getLatestMovingAveragePurchasePrice();

if (purchasePrice.isPresent())
firstQuote = purchasePrice.get();
else
showAreaRelativeToFirstQuote = false;
}

addChartMarkerBackground(chartInterval, range);

Expand Down Expand Up @@ -1894,6 +1915,17 @@ private Optional<Double> getLatestPurchasePrice()
converter.with(security.getCurrencyCode()), LocalDate.now());
}

private Optional<Double> getLatestMovingAveragePurchasePrice()
{
// securities w/o currency (e.g. index) cannot be bought and hence have
// no purchase price
if (security.getCurrencyCode() == null)
return Optional.empty();

return getMovingAveragePurchasePrice(new ClientSecurityFilter(security).filter(client),
converter.with(security.getCurrencyCode()), LocalDate.now());
}

private Optional<Double> getPurchasePrice(Client filteredClient, CurrencyConverter currencyConverter,
LocalDate date)
{
Expand Down

0 comments on commit 877b486

Please sign in to comment.