Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #3237: dividend yoc #3248

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ workspace
.metadata/*
.recommenders/*
.DS_Store
**/.classpath
**/.metadata/**
.classpath

### IntelliJ IDEA ###
.idea
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package name.abuchen.portfolio.junit;

import java.time.LocalDateTime;
import java.util.Objects;

import name.abuchen.portfolio.model.AccountTransaction;
import name.abuchen.portfolio.model.AccountTransaction.Type;
import name.abuchen.portfolio.model.Security;

public class AccountTransactionBuilder
{
private Type txType;
private LocalDateTime dateTime;
private String currencyCode;
private long amount;
private Security security;

public AccountTransactionBuilder(Type txType)
{
this.txType = txType;
}

public AccountTransactionBuilder transactionAt(LocalDateTime dateTime)
{
this.dateTime = dateTime;
return this;
}

public AccountTransactionBuilder withCurrency(String currencyCode)
{
this.currencyCode = currencyCode;
return this;
}

public AccountTransactionBuilder withAmountOf(long amount)
{
this.amount = amount;
return this;
}

public AccountTransactionBuilder forSecurity(Security security)
{
this.security = security;
return this;
}

public AccountTransaction build()
{
Objects.requireNonNull(dateTime);
Objects.requireNonNull(currencyCode);
Objects.requireNonNull(amount);
Objects.requireNonNull(security);
return new AccountTransaction(dateTime, currencyCode, amount, security, txType);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package name.abuchen.portfolio.junit;

import java.time.LocalDateTime;
import java.util.Objects;

import name.abuchen.portfolio.model.PortfolioTransaction;
import name.abuchen.portfolio.model.PortfolioTransaction.Type;
import name.abuchen.portfolio.model.Security;

public class PortfolioTransactionBuilder
{
private Type txType;
private LocalDateTime datetime;
private String currencyCode;
private long amount = 0;
private long shares = 0;
private Security security;
private long fees = 0;
private long taxes = 0;

public PortfolioTransactionBuilder(Type txType)
{
this.txType = txType;
}

public PortfolioTransactionBuilder transactionAt(LocalDateTime dateTime)
{
datetime = dateTime;
return this;
}

public PortfolioTransactionBuilder withCurrency(String code)
{
currencyCode = code;
return this;
}

public PortfolioTransactionBuilder withAmountOf(long amount)
{
this.amount = amount;
return this;
}

public PortfolioTransactionBuilder numberOfShares(long shares)
{
this.shares = shares;
return this;
}

public PortfolioTransactionBuilder forSecurity(Security security)
{
this.security = security;
return this;
}

public PortfolioTransactionBuilder withCostsOf(long fees)
{
this.fees = fees;
return this;
}

public PortfolioTransactionBuilder withTaxAmountOf(long taxes)
{
this.taxes = taxes;
return this;
}

public PortfolioTransaction build()
{
Objects.requireNonNull(datetime);
Objects.requireNonNull(currencyCode);
Objects.requireNonNull(amount);
Objects.requireNonNull(security);
Objects.requireNonNull(shares);
return new PortfolioTransaction(datetime, currencyCode, amount, security, shares, txType, fees, taxes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class TestCurrencyConverter implements CurrencyConverter
{
private static ExchangeRateTimeSeriesImpl EUR_USD = null; // NOSONAR
private static InverseExchangeRateTimeSeries USD_EUR = null; // NOSONAR
private static ExchangeRateTimeSeriesImpl EUR_CHF = null; // NOSONAR
private static InverseExchangeRateTimeSeries CHF_EUR = null; // NOSONAR

static
{
Expand All @@ -35,6 +37,25 @@ public class TestCurrencyConverter implements CurrencyConverter
EUR_USD.addRate(new ExchangeRate(LocalDate.parse("2015-01-16"), BigDecimal.valueOf(1.1588).setScale(10)));

USD_EUR = new InverseExchangeRateTimeSeries(EUR_USD);

EUR_CHF = new ExchangeRateTimeSeriesImpl(null, CurrencyUnit.EUR, "CHF"); //$NON-NLS-1$
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2014-12-31"), new BigDecimal("1.2024")));
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-02"), new BigDecimal("1.2022")));

EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-05"), new BigDecimal("1.2016")));
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-06"), new BigDecimal("1.2014")));
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-07"), new BigDecimal("1.2011")));
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-08"), new BigDecimal("1.2010")));
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-09"), new BigDecimal("1.2010")));

EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-12"), new BigDecimal("1.2010")));
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-13"), new BigDecimal("1.2010")));
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-14"), new BigDecimal("1.2010")));
// 'Francogeddon': the SNB abandons its EUR/CHF cap on 2015-01-15
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-15"), new BigDecimal("1.0280")));
EUR_CHF.addRate(new ExchangeRate(LocalDate.parse("2015-01-16"), new BigDecimal("1.0128")));

CHF_EUR = new InverseExchangeRateTimeSeries(EUR_CHF);
}

private final String termCurrency;
Expand Down Expand Up @@ -66,6 +87,10 @@ public ExchangeRate getRate(LocalDate date, String currencyCode)
series = USD_EUR;
else if (currencyCode.equals("EUR") && termCurrency.equals("USD"))
series = EUR_USD;
else if (currencyCode.equals("CHF") && termCurrency.equals("EUR"))
series = CHF_EUR;
else if (currencyCode.equals("EUR") && termCurrency.equals("CHF"))
series = EUR_CHF;
else
// testing: any other currency will be converted 1:1
return new ExchangeRate(date, BigDecimal.ONE);
Expand All @@ -80,7 +105,8 @@ public CurrencyConverter with(String currencyCode)
return this;

if (currencyCode.equals(CurrencyUnit.EUR)
|| currencyCode.equals(CurrencyUnit.USD))
|| currencyCode.equals(CurrencyUnit.USD)
|| currencyCode.equals("CHF"))
return new TestCurrencyConverter(currencyCode);

return null;
Expand Down
Loading