Search in sources :

Example 6 with LatestSecurityPrice

use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.

the class YahooFinanceQuoteFeedTest method testParsingHistoricalQuotes.

@Test
public void testParsingHistoricalQuotes() throws IOException {
    String responseBody = null;
    try (Scanner scanner = new Scanner(getClass().getResourceAsStream("response_yahoo_historical.txt"), "UTF-8")) {
        responseBody = scanner.useDelimiter("\\A").next();
    }
    Security security = new Security();
    security.setTickerSymbol("DAI.DE");
    YahooFinanceQuoteFeed feed = new YahooFinanceQuoteFeed();
    List<LatestSecurityPrice> prices = feed.getHistoricalQuotes(responseBody, new ArrayList<Exception>());
    Collections.sort(prices, new SecurityPrice.ByDate());
    assertThat(prices.size(), is(2257));
    LatestSecurityPrice price = new // 
    LatestSecurityPrice(// 
    LocalDate.of(2003, Month.JANUARY, 1), // 
    Values.Quote.factorize(29.35), // 
    Values.Quote.factorize(29.35), // 
    Values.Quote.factorize(29.35), 0);
    assertThat(prices.get(0), equalTo(price));
    price = new // 
    LatestSecurityPrice(// 
    LocalDate.of(2011, Month.SEPTEMBER, 22), // 
    Values.Quote.factorize(32.74), // 
    Values.Quote.factorize(34.16), // 
    Values.Quote.factorize(32.35), 10825200);
    assertThat(prices.get(prices.size() - 1), equalTo(price));
}
Also used : LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) Scanner(java.util.Scanner) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with LatestSecurityPrice

use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.

the class SecuritiesTable method addDeltaColumn.

private // NOSONAR
void addDeltaColumn() {
    Column column;
    // $NON-NLS-1$
    column = new Column("5", Messages.ColumnChangeOnPrevious, SWT.RIGHT, 60);
    column.setMenuLabel(Messages.ColumnChangeOnPrevious_MenuLabel);
    column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, element -> {
        SecurityPrice price = ((Security) element).getSecurityPrice(LocalDate.now());
        if (!(price instanceof LatestSecurityPrice))
            return null;
        LatestSecurityPrice latest = (LatestSecurityPrice) price;
        if (latest.getPreviousClose() == LatestSecurityPrice.NOT_AVAILABLE)
            return null;
        return (latest.getValue() - latest.getPreviousClose()) / (double) latest.getPreviousClose();
    }));
    column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
        // NOSONAR
        SecurityPrice p1 = ((Security) o1).getSecurityPrice(LocalDate.now());
        SecurityPrice p2 = ((Security) o2).getSecurityPrice(LocalDate.now());
        if (!(p1 instanceof LatestSecurityPrice))
            p1 = null;
        if (!(p2 instanceof LatestSecurityPrice))
            p2 = null;
        if (p1 == null)
            return p2 == null ? 0 : -1;
        if (p2 == null)
            return 1;
        LatestSecurityPrice l1 = (LatestSecurityPrice) p1;
        LatestSecurityPrice l2 = (LatestSecurityPrice) p2;
        double v1 = ((double) (l1.getValue() - l1.getPreviousClose())) / l1.getPreviousClose() * 100;
        double v2 = ((double) (l2.getValue() - l2.getPreviousClose())) / l2.getPreviousClose() * 100;
        return Double.compare(v1, v2);
    }));
    support.addColumn(column);
}
Also used : ReportingPeriodColumnOptions(name.abuchen.portfolio.ui.util.viewers.ReportingPeriodColumnOptions) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) BiFunction(java.util.function.BiFunction) DND(org.eclipse.swt.dnd.DND) SecurityDragListener(name.abuchen.portfolio.ui.dnd.SecurityDragListener) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) SecurityTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransactionDialog) StockSplitWizard(name.abuchen.portfolio.ui.wizards.splits.StockSplitWizard) Composite(org.eclipse.swt.widgets.Composite) AbstractFinanceView(name.abuchen.portfolio.ui.AbstractFinanceView) KeyEvent(org.eclipse.swt.events.KeyEvent) Factory(name.abuchen.portfolio.online.Factory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Separator(org.eclipse.jface.action.Separator) SecurityTransferDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransferDialog) MenuManager(org.eclipse.jface.action.MenuManager) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) Transfer(org.eclipse.swt.dnd.Transfer) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) OptionLabelProvider(name.abuchen.portfolio.ui.util.viewers.OptionLabelProvider) List(java.util.List) UpdateQuotesJob(name.abuchen.portfolio.ui.UpdateQuotesJob) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) Colors(name.abuchen.portfolio.ui.util.Colors) EditSecurityDialog(name.abuchen.portfolio.ui.wizards.security.EditSecurityDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) Watchlist(name.abuchen.portfolio.model.Watchlist) AccountTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.AccountTransactionDialog) SecurityTransfer(name.abuchen.portfolio.ui.dnd.SecurityTransfer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed) BooleanEditingSupport(name.abuchen.portfolio.ui.util.viewers.BooleanEditingSupport) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) Function(java.util.function.Function) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Messages(name.abuchen.portfolio.ui.Messages) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Taxonomy(name.abuchen.portfolio.model.Taxonomy) NumberColorLabelProvider(name.abuchen.portfolio.ui.util.viewers.NumberColorLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Shell(org.eclipse.swt.widgets.Shell) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) Dialog(org.eclipse.jface.dialogs.Dialog) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Menu(org.eclipse.swt.widgets.Menu) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice)

Example 8 with LatestSecurityPrice

use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.

the class YahooFinanceQuoteFeedTest method testParsingHistoricalAdjustedCloseQuotes.

@Test
public void testParsingHistoricalAdjustedCloseQuotes() throws IOException {
    String responseBody = null;
    try (Scanner scanner = new Scanner(getClass().getResourceAsStream("response_yahoo_historical.txt"), "UTF-8")) {
        responseBody = scanner.useDelimiter("\\A").next();
    }
    Security security = new Security();
    security.setTickerSymbol("DAI.DE");
    YahooFinanceAdjustedCloseQuoteFeed feed = new YahooFinanceAdjustedCloseQuoteFeed();
    List<LatestSecurityPrice> prices = feed.getHistoricalQuotes(responseBody, new ArrayList<Exception>());
    Collections.sort(prices, new SecurityPrice.ByDate());
    assertThat(prices.size(), is(2257));
    LatestSecurityPrice price = new // 
    LatestSecurityPrice(// 
    LocalDate.of(2003, Month.JANUARY, 1), // 
    Values.Quote.factorize(22.55), // 
    Values.Quote.factorize(29.35), // 
    Values.Quote.factorize(29.35), 0);
    assertThat(prices.get(0), equalTo(price));
    price = new // 
    LatestSecurityPrice(// 
    LocalDate.of(2011, Month.SEPTEMBER, 22), // 
    Values.Quote.factorize(32.74), // 
    Values.Quote.factorize(34.16), // 
    Values.Quote.factorize(32.35), 10825200);
    assertThat(prices.get(prices.size() - 1), equalTo(price));
}
Also used : LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) Scanner(java.util.Scanner) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with LatestSecurityPrice

use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.

the class ImportQuotesWizard method performFinish.

@Override
public boolean performFinish() {
    List<LatestSecurityPrice> quotes = reviewPage.getQuotes();
    for (LatestSecurityPrice p : quotes) {
        SecurityPrice quote = new SecurityPrice(p.getDate(), p.getValue());
        security.addPrice(quote);
    }
    return true;
}
Also used : LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice)

Example 10 with LatestSecurityPrice

use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.

the class HTMLTableQuoteFeed method updateHistoricalQuotes.

@Override
public boolean updateHistoricalQuotes(Security security, List<Exception> errors) {
    List<LatestSecurityPrice> quotes = internalGetQuotes(security, security.getFeedURL(), errors);
    boolean isUpdated = false;
    for (LatestSecurityPrice quote : quotes) {
        boolean isAdded = security.addPrice(new SecurityPrice(quote.getDate(), quote.getValue()));
        isUpdated = isUpdated || isAdded;
    }
    return isUpdated;
}
Also used : LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice)

Aggregations

LatestSecurityPrice (name.abuchen.portfolio.model.LatestSecurityPrice)16 IOException (java.io.IOException)8 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)6 ParseException (java.text.ParseException)5 Scanner (java.util.Scanner)5 ArrayList (java.util.ArrayList)4 LocalDate (java.time.LocalDate)3 DateTimeParseException (java.time.format.DateTimeParseException)3 Security (name.abuchen.portfolio.model.Security)3 HttpURLConnection (java.net.HttpURLConnection)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)2 RateLimitExceededException (name.abuchen.portfolio.util.RateLimitExceededException)2 Elements (org.jsoup.select.Elements)2 File (java.io.File)1 MessageFormat (java.text.MessageFormat)1 List (java.util.List)1 BiFunction (java.util.function.BiFunction)1