return PerformanceIndex.forClient(pseudoClient, reportInterval, warnings);
}
private static void addSecurity(Client pseudoClient, Client client, Security security, int weight)
{
Account pseudoAccount = new Account();
pseudoAccount.setName(""); //$NON-NLS-1$
pseudoClient.addAccount(pseudoAccount);
Portfolio pseudoPortfolio = new Portfolio();
pseudoPortfolio.setReferenceAccount(pseudoAccount);
pseudoClient.addPortfolio(pseudoPortfolio);
pseudoClient.addSecurity(security);
for (Portfolio p : client.getPortfolios())
{
for (PortfolioTransaction t : p.getTransactions())
{
if (t.getSecurity().equals(security))
{
long shares = value(t.getShares(), weight);
long amount = value(t.getAmount(), weight);
long fees = value(t.getFees(), weight);
long taxes = value(t.getTaxes(), weight);
switch (t.getType())
{
case BUY:
case TRANSFER_IN:
{
pseudoPortfolio.addTransaction(new PortfolioTransaction(t.getDate(), t.getSecurity(),
PortfolioTransaction.Type.DELIVERY_INBOUND, shares, amount, fees, taxes));
break;
}
case SELL:
case TRANSFER_OUT:
pseudoPortfolio.addTransaction(new PortfolioTransaction(t.getDate(), t.getSecurity(),
PortfolioTransaction.Type.DELIVERY_OUTBOUND, shares, amount, fees, taxes));
break;
case DELIVERY_INBOUND:
case DELIVERY_OUTBOUND:
pseudoPortfolio.addTransaction(new PortfolioTransaction(t.getDate(), t.getSecurity(), t
.getType(), shares, amount, fees, taxes));
break;
default:
throw new UnsupportedOperationException();
}
}
}
}
for (Account a : client.getAccounts())
{
for (AccountTransaction t : a.getTransactions())
{
if (security.equals(t.getSecurity()))
{
switch (t.getType())
{
case DIVIDENDS:
long amount = value(t.getAmount(), weight);
pseudoAccount.addTransaction(new AccountTransaction(t.getDate(), t.getSecurity(),
AccountTransaction.Type.DIVIDENDS, amount));
pseudoAccount.addTransaction(new AccountTransaction(t.getDate(), t.getSecurity(),
AccountTransaction.Type.REMOVAL, amount));
break;
case BUY:
case TRANSFER_IN:
case SELL: