public class CapitalGainBuy extends java.lang.Object implements java.lang.Comparable<CapitalGainBuy>
Even though you include all unsold shares of a fund in a single category to compute average basis, you may have both short-term and long-term gains or losses when you sell these shares. To determine your holding period, the shares disposed of are considered to be those acquired first.This class tracks how many shares of a particular buy transaction has already been allotted by one or more sale transactions, and also helps track the remaining average cost basis. Note that these objects should always be processed in date order. If the date provided to methods
allot(long, int)
, getRemainingShares(int)
or
setRemainingBasis(double, int)
were ever to go backwards in time, this
could give incorrect results because of stock splits.Constructor and Description |
---|
CapitalGainBuy(Account securityAccount,
int date,
long totalAmount,
long sharesPurchased)
Constructor to allow most fields to be final.
|
Modifier and Type | Method and Description |
---|---|
long |
allot(long sharesRequested,
int asofDate)
Allocate the requested number of shares from the total amount, if possible.
|
int |
compareTo(CapitalGainBuy other) |
int |
getDateInt() |
long |
getRemainingBasis() |
long |
getRemainingShares(int asofDate)
Compute the remaining shares for a buy transaction
|
long |
getSharesPurchased() |
long |
getTotalAmount() |
boolean |
isAllocated() |
void |
setRemainingBasis(double averageCost,
int asofDate)
Compute the remaining basis for this buy transaction, given a particular average cost.
|
public CapitalGainBuy(Account securityAccount, int date, long totalAmount, long sharesPurchased)
securityAccount
- The associated security account.date
- The date of the buy transaction.totalAmount
- The total buy amount, in the investment account's currency.sharesPurchased
- The number of shares purchased in the buy transaction.public int getDateInt()
public long getTotalAmount()
public long getSharesPurchased()
public boolean isAllocated()
getTotalAmount()
to get the cost basis.public long allot(long sharesRequested, int asofDate)
sharesRequested
- The number of shares requested to be allotted.asofDate
- The date of the allotment.public long getRemainingShares(int asofDate)
asofDate
- The date the remaining shares should be computed for, adjusting for any
splits previous.public void setRemainingBasis(double averageCost, int asofDate)
averageCost
- The current average cost, computed for a particular sale transaction.asofDate
- The date the remaining basis is valid for. The shares remaining are
brought forward to this date, adjusting for splits.public long getRemainingBasis()
public int compareTo(CapitalGainBuy other)
compareTo
in interface java.lang.Comparable<CapitalGainBuy>