Class AccountLedgerService
java.lang.Object
com.bluebell.greenhouse.radicle.services.AbstractGenericEntityService<Account, AccountRepository>
com.bluebell.greenhouse.radicle.services.account.AccountLedgerService
@Service
@Transactional(readOnly=true)
public class AccountLedgerService
extends AbstractGenericEntityService<Account, AccountRepository>
Service-layer for building and reading account ledger entries from positions and transactions.
- Version:
- 3.0.6
- Author:
- Stephen Prizio
-
Constructor Summary
ConstructorsConstructorDescriptionAccountLedgerService(AccountLedgerRepository accountLedgerRepository, AccountRepository accountRepository, PositionRepository positionRepository, TransactionRepository transactionRepository) Creates the service. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculateFundedCapital(Account account) Calculates the account's net funded capital from its initial balance, deposits, and withdrawals.doublecalculateFundedCapital(Account account, List<AccountLedgerEntry> entries) Calculates funded capital from ledger entries already loaded by an enclosing computation.doublecalculateNetProfit(Account account) Calculates an account's closed position net profit.doublecalculatePercentageReturn(Account account) Calculates an account's closed position net profit percentage return against its funded capital.doublecalculateProfitPercentage(Position position) Calculates a position's realized profit percentage from its ledger entry.voiddeleteEntriesForAccount(Account account) Deletes all ledger entries for the givenAccount.voiddeleteEntriesForTransaction(Transaction transaction) Removes the ledger entries linked to the givenTransaction.findEntriesForAccount(Account account) Finds all ledger entries for the givenAccount.findEntriesForAccounts(List<Account> accounts) Finds all ledger entries for the givenAccounts.findEntryForPosition(Position position) Finds the ledger entry linked to the givenPosition.rebuildLedger(Account account) Rebuilds the ledger for the givenAccountfrom persisted account events.recordManualBalanceAdjustment(Account account, double targetBalance) Records a manual balance adjustment when the requested balance differs from the latest ledger balance.Calculates an account's net profit and percentage return together.Summarises an account from collections already loaded by an enclosing computation.summariseAll(Collection<Account> accounts) Calculates theAccountLedgerSummaryfor every givenAccountin two queries.Methods inherited from class AbstractGenericEntityService
refreshEntity, resolveEntity, resolveEntity, resolveEntity
-
Constructor Details
-
AccountLedgerService
public AccountLedgerService(AccountLedgerRepository accountLedgerRepository, AccountRepository accountRepository, PositionRepository positionRepository, TransactionRepository transactionRepository) Creates the service.- Parameters:
accountLedgerRepository-AccountLedgerRepositoryaccountRepository-AccountRepositorypositionRepository-PositionRepositorytransactionRepository-TransactionRepository
-
-
Method Details
-
rebuildLedger
-
recordManualBalanceAdjustment
@Transactional public Optional<AccountLedgerEntry> recordManualBalanceAdjustment(Account account, double targetBalance) Records a manual balance adjustment when the requested balance differs from the latest ledger balance. -
deleteEntriesForAccount
-
deleteEntriesForTransaction
Removes the ledger entries linked to the givenTransaction. Must be called before the transaction itself is deleted, otherwise the entries are left referencing a row that no longer exists and the flush fails on the dangling association.- Parameters:
transaction-Transaction
-
calculateProfitPercentage
-
calculateNetProfit
-
calculateFundedCapital
Calculates the account's net funded capital from its initial balance, deposits, and withdrawals. Legacy accounts without capital ledger entries fall back to their recorded initial balance.- Parameters:
account-Account- Returns:
- net funded capital
-
calculateFundedCapital
Calculates funded capital from ledger entries already loaded by an enclosing computation.- Parameters:
account-Accountentries- that account's ledger entries- Returns:
- net funded capital
-
calculatePercentageReturn
-
summariseAll
Calculates theAccountLedgerSummaryfor every givenAccountin two queries.- Parameters:
accounts-CollectionofAccounts- Returns:
- summaries keyed by account id
-
summarise
Calculates an account's net profit and percentage return together.- Parameters:
account-Account- Returns:
AccountLedgerSummary
-
summarise
public AccountLedgerSummary summarise(Account account, List<Position> closedPositions, List<AccountLedgerEntry> entries) Summarises an account from collections already loaded by an enclosing computation.- Parameters:
account-AccountclosedPositions- that account's closed positionsentries- that account's ledger entries- Returns:
AccountLedgerSummary
-
findEntryForPosition
Finds the ledger entry linked to the givenPosition.- Parameters:
position-Position- Returns:
OptionalAccountLedgerEntry
-
findEntriesForAccount
Finds all ledger entries for the givenAccount.- Parameters:
account-Account- Returns:
ListofAccountLedgerEntry
-
findEntriesForAccounts
Finds all ledger entries for the givenAccounts.- Parameters:
accounts-ListofAccounts- Returns:
ListofAccountLedgerEntry
-