Documentation ¶
Index ¶
- Constants
- Variables
- func CircularBootstrap(timeSeries []float64, blockSize int, n int, m int) [][]float64
- func DynamicWithdrawalRate(mc [][]float64, inflation float64) float64
- func PerpetualWithdrawalRate(mc [][]float64, inflation float64) float64
- func SafeWithdrawalRate(mc [][]float64, inflation float64) float64
- type Activity
- type AnnualReturn
- type ColferError
- type ColferMax
- type ColferTail
- type DrawDown
- func (o *DrawDown) MarshalBinary() (data []byte, err error)
- func (o *DrawDown) MarshalLen() (int, error)
- func (o *DrawDown) MarshalTo(buf []byte) int
- func (o *DrawDown) MarshalZerologObject(e *zerolog.Event)
- func (o *DrawDown) Unmarshal(data []byte) (int, error)
- func (o *DrawDown) UnmarshalBinary(data []byte) error
- type Holding
- type Justification
- type Metrics
- func (o *Metrics) MarshalBinary() (data []byte, err error)
- func (o *Metrics) MarshalLen() (int, error)
- func (o *Metrics) MarshalTo(buf []byte) int
- func (metrics *Metrics) MarshalZerologObject(e *zerolog.Event)
- func (o *Metrics) Unmarshal(data []byte) (int, error)
- func (o *Metrics) UnmarshalBinary(data []byte) error
- type Model
- func (pm *Model) AddActivity(date time.Time, msg string, tags []string)
- func (pm *Model) FillCorporateActions(ctx context.Context, through time.Time) error
- func (pm *Model) LoadTransactionsFromDB(ctx context.Context) error
- func (pm *Model) NotificationsForDate(ctx context.Context, forDate time.Time, perf *Performance) []*Notification
- func (pm *Model) RebalanceTo(ctx context.Context, allocation *data.SecurityAllocation, ...) error
- func (pm *Model) RequestedNotificationsForDate(forDate time.Time) []NotificationFrequency
- func (pm *Model) Save(ctx context.Context, userID string) error
- func (pm *Model) SaveActivities(ctx context.Context) error
- func (pm *Model) SaveWithTransaction(ctx context.Context, trx pgx.Tx, userID string, permanent bool) error
- func (pm *Model) SetStatus(ctx context.Context, msg string) error
- func (pm *Model) Table() string
- func (pm *Model) TargetPortfolio(ctx context.Context, target data.PortfolioPlan) error
- func (pm *Model) UpdateTransactions(ctx context.Context, through time.Time) error
- type Notification
- type NotificationFrequency
- type Performance
- func (perf *Performance) ActiveReturn(periods uint) float64
- func (perf *Performance) AllDrawDowns(periods uint, kind string) []*DrawDown
- func (perf *Performance) Alpha(periods uint) float64
- func (perf *Performance) AverageDrawDown(periods uint, kind string) float64
- func (perf *Performance) AvgUlcerIndex(periods uint) float64
- func (perf *Performance) Beta(periods uint) float64
- func (perf *Performance) CalculateThrough(ctx context.Context, pm *Model, through time.Time) error
- func (perf *Performance) CalmarRatio(periods uint, kind string) float64
- func (perf *Performance) DownsideDeviation(periods uint, kind string) float64
- func (perf *Performance) ExcessKurtosis(periods uint) float64
- func (perf *Performance) InformationRatio(periods uint) float64
- func (perf *Performance) KRatio(periods uint) float64
- func (perf *Performance) KellerRatio(periods uint, kind string) float64
- func (perf *Performance) LoadMeasurementsFromDB(ctx context.Context, userID string) error
- func (perf *Performance) LogSummary()
- func (perf *Performance) MWRR(periods uint, kind string) float64
- func (perf *Performance) MWRRYtd(kind string) float64
- func (o *Performance) MarshalBinary() (data []byte, err error)
- func (o *Performance) MarshalLen() (int, error)
- func (o *Performance) MarshalTo(buf []byte) int
- func (perf *Performance) MaxDrawDown(periods uint, kind string) *DrawDown
- func (perf *Performance) NetProfit() float64
- func (perf *Performance) NetProfitPercent() float64
- func (perf *Performance) Save(ctx context.Context, userID string) error
- func (perf *Performance) SaveWithTransaction(ctx context.Context, trx pgx.Tx, userID string) error
- func (perf *Performance) SharpeRatio(periods uint, kind string) float64
- func (perf *Performance) Skew(periods uint, kind string) float64
- func (perf *Performance) SortinoRatio(periods uint, kind string) float64
- func (perf *Performance) StdDev(periods uint, kind string) float64
- func (perf *Performance) TWRR(periods uint, kind string) float64
- func (perf *Performance) TWRRYtd(kind string) float64
- func (perf *Performance) Top10DrawDowns(periods uint, kind string) []*DrawDown
- func (perf *Performance) TrackingError(periods uint) float64
- func (perf *Performance) TreynorRatio(periods uint) float64
- func (perf *Performance) UlcerIndex() float64
- func (perf *Performance) UlcerIndexPercentile(periods uint, percentile float64) float64
- func (o *Performance) Unmarshal(data []byte) (int, error)
- func (o *Performance) UnmarshalBinary(data []byte) error
- func (perf *Performance) ValueAtYearStart(dt time.Time) float64
- type PerformanceMeasurement
- func (o *PerformanceMeasurement) MarshalBinary() (data []byte, err error)
- func (o *PerformanceMeasurement) MarshalLen() (int, error)
- func (o *PerformanceMeasurement) MarshalTo(buf []byte) int
- func (o *PerformanceMeasurement) Unmarshal(data []byte) (int, error)
- func (o *PerformanceMeasurement) UnmarshalBinary(data []byte) error
- type PerformanceMeasurementItem
- func (o *PerformanceMeasurementItem) MarshalBinary() (data []byte, err error)
- func (o *PerformanceMeasurementItem) MarshalLen() (int, error)
- func (o *PerformanceMeasurementItem) MarshalTo(buf []byte) int
- func (o *PerformanceMeasurementItem) Unmarshal(data []byte) (int, error)
- func (o *PerformanceMeasurementItem) UnmarshalBinary(data []byte) error
- type PerformanceMeasurementItemList
- func (o *PerformanceMeasurementItemList) MarshalBinary() (data []byte, err error)
- func (o *PerformanceMeasurementItemList) MarshalLen() (int, error)
- func (o *PerformanceMeasurementItemList) MarshalTo(buf []byte) int
- func (o *PerformanceMeasurementItemList) Unmarshal(data []byte) (int, error)
- func (o *PerformanceMeasurementItemList) UnmarshalBinary(data []byte) error
- type Period
- type Portfolio
- type PortfolioHoldingItem
- func (o *PortfolioHoldingItem) MarshalBinary() (data []byte, err error)
- func (o *PortfolioHoldingItem) MarshalLen() (int, error)
- func (o *PortfolioHoldingItem) MarshalTo(buf []byte) int
- func (o *PortfolioHoldingItem) Unmarshal(data []byte) (int, error)
- func (o *PortfolioHoldingItem) UnmarshalBinary(data []byte) error
- type PortfolioHoldingItemList
- func (o *PortfolioHoldingItemList) MarshalBinary() (data []byte, err error)
- func (o *PortfolioHoldingItemList) MarshalLen() (int, error)
- func (o *PortfolioHoldingItemList) MarshalTo(buf []byte) int
- func (o *PortfolioHoldingItemList) Unmarshal(data []byte) (int, error)
- func (o *PortfolioHoldingItemList) UnmarshalBinary(data []byte) error
- type PortfolioTransactionList
- func (o *PortfolioTransactionList) MarshalBinary() (data []byte, err error)
- func (o *PortfolioTransactionList) MarshalLen() (int, error)
- func (o *PortfolioTransactionList) MarshalTo(buf []byte) int
- func (o *PortfolioTransactionList) Unmarshal(data []byte) (int, error)
- func (o *PortfolioTransactionList) UnmarshalBinary(data []byte) error
- type ReportableHolding
- func (o *ReportableHolding) MarshalBinary() (data []byte, err error)
- func (o *ReportableHolding) MarshalLen() (int, error)
- func (o *ReportableHolding) MarshalTo(buf []byte) int
- func (o *ReportableHolding) Unmarshal(data []byte) (int, error)
- func (o *ReportableHolding) UnmarshalBinary(data []byte) error
- type Returns
- type TaxLot
- func (o *TaxLot) MarshalBinary() (data []byte, err error)
- func (o *TaxLot) MarshalLen() (int, error)
- func (o *TaxLot) MarshalTo(buf []byte) int
- func (o *TaxLot) MarshalZerologObject(e *zerolog.Event)
- func (t *TaxLot) Security() *data.Security
- func (o *TaxLot) Unmarshal(data []byte) (int, error)
- func (o *TaxLot) UnmarshalBinary(data []byte) error
- type TaxLotInfo
- func (t *TaxLotInfo) AdjustForSplit(security *data.Security, splitFactor float64)
- func (t *TaxLotInfo) CheckIfDividendIsQualified(trx *Transaction) bool
- func (t *TaxLotInfo) Copy() *TaxLotInfo
- func (t *TaxLotInfo) LinkTransactionsWithTaxLots(sell *Transaction) []*Transaction
- func (t *TaxLotInfo) LinkWithFIFOMethod(sell *Transaction) []*Transaction
- func (o *TaxLotInfo) MarshalBinary() (data []byte, err error)
- func (o *TaxLotInfo) MarshalLen() (int, error)
- func (o *TaxLotInfo) MarshalTo(buf []byte) int
- func (o *TaxLotInfo) Unmarshal(data []byte) (int, error)
- func (o *TaxLotInfo) UnmarshalBinary(data []byte) error
- func (t *TaxLotInfo) Update(date time.Time, buys []*Transaction, sells []*Transaction) []*Transaction
- type Transaction
- func (o *Transaction) MarshalBinary() (data []byte, err error)
- func (o *Transaction) MarshalLen() (int, error)
- func (o *Transaction) MarshalTo(buf []byte) int
- func (o *Transaction) MarshalZerologObject(e *zerolog.Event)
- func (trx *Transaction) Security() *data.Security
- func (trx *Transaction) SplitFactor() float64
- func (o *Transaction) Unmarshal(data []byte) (int, error)
- func (o *Transaction) UnmarshalBinary(data []byte) error
Constants ¶
const ( STRATEGY = "STRATEGY" BENCHMARK = "BENCHMARK" RISKFREE = "RISKFREE" )
const ( SellTransaction = "SELL" BuyTransaction = "BUY" InterestTransaction = "INTEREST" DividendTransaction = "DIVIDEND" SplitTransaction = "SPLIT" DepositTransaction = "DEPOSIT" WithdrawTransaction = "WITHDRAW" )
const ( Roth = "ROTH" TaxDeferred = "DEFERRED" Taxable = "TAXABLE" )
account types
const ( LTC = "LTC" STC = "STC" QualifiedDividend = "QUALIFIED" NonQualifiedDividend = "NON-QUALIFIED" )
capital gains
const (
SourceName = "PV"
)
const (
SplitFactor = "SplitFactor"
)
const (
TaxLotFIFOMethod = "TaxLotFIFO"
)
Variables ¶
var ( ErrInvalidTransactionType = errors.New("unrecognized transaction type") ErrNoTransactions = errors.New("portfolio has no transactions") ErrSerialize = errors.New("could not serialize data") ErrNoMeasurementFound = errors.New("no measurement found") )
var ( ErrEmptyUserID = errors.New("user id empty") ErrStrategyNotFound = errors.New("strategy not found") ErrHoldings = errors.New("holdings are out of sync, cannot rebalance portfolio") ErrInvalidSell = errors.New("refusing to sell 0 shares - cannot rebalance portfolio; target allocation broken") ErrTimeInverted = errors.New("start date occurs after through date") ErrPortfolioNotFound = errors.New("could not find portfolio ID in database") ErrGenerateHash = errors.New("could not create a new hash") ErrTransactionsOutOfOrder = errors.New("transactions would be out-of-order if executed") ErrRebalancePercentWrong = errors.New("rebalance total must equal 1.0") ErrSecurityPriceNotAvailable = errors.New("security price not available for date") ErrNoTickerColumn = errors.New("no ticker column present") ErrInvalidDateRange = errors.New("invalid date range") )
var ( // ColferSizeMax is the upper limit for serial byte sizes. ColferSizeMax = 16 * 1024 * 1024 // ColferListMax is the upper limit for the number of elements in a list. ColferListMax = 4 * 1024 * 1024 )
Colfer configuration attributes
var (
ErrDidNotConverge = errors.New("did not converge")
)
Functions ¶
func CircularBootstrap ¶
CircularBootstrap returns n arrays if length m of bootstrapped values from timeSeries
func DynamicWithdrawalRate ¶
DynamicWithdrawalRate calculates the maximum % that can be withdrawn per year and expect the balance to be greater than or equal to the inflation adjusted starting balance. Inflation should be provided as an annual rate.
func PerpetualWithdrawalRate ¶
PerpetualWithdrawalRate
func SafeWithdrawalRate ¶
SafeWithdrawalRate
Types ¶
type AnnualReturn ¶
func (*AnnualReturn) MarshalBinary ¶
func (o *AnnualReturn) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*AnnualReturn) MarshalLen ¶
func (o *AnnualReturn) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*AnnualReturn) MarshalTo ¶
func (o *AnnualReturn) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*AnnualReturn) Unmarshal ¶
func (o *AnnualReturn) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*AnnualReturn) UnmarshalBinary ¶
func (o *AnnualReturn) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type DrawDown ¶
type DrawDown struct { Begin time.Time End time.Time Recovery time.Time LossPercent float64 Active bool }
func (*DrawDown) MarshalBinary ¶
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*DrawDown) MarshalLen ¶
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*DrawDown) MarshalTo ¶
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*DrawDown) MarshalZerologObject ¶ added in v0.5.0
func (*DrawDown) Unmarshal ¶
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*DrawDown) UnmarshalBinary ¶
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type Holding ¶
func (*Holding) MarshalBinary ¶
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*Holding) MarshalLen ¶
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*Holding) MarshalTo ¶
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*Holding) Unmarshal ¶
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*Holding) UnmarshalBinary ¶
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type Justification ¶
func (*Justification) MarshalBinary ¶
func (o *Justification) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*Justification) MarshalLen ¶
func (o *Justification) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*Justification) MarshalTo ¶
func (o *Justification) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*Justification) Unmarshal ¶
func (o *Justification) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*Justification) UnmarshalBinary ¶
func (o *Justification) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type Metrics ¶
type Metrics struct { AlphaSinceInception float64 AvgDrawDown float64 BestYear *AnnualReturn BetaSinceInception float64 DownsideDeviationSinceInception float64 ExcessKurtosisSinceInception float64 FinalBalance float64 SharpeRatioSinceInception float64 Skewness float64 SortinoRatioSinceInception float64 StdDevSinceInception float64 TaxCostRatio float64 TotalDeposited float64 TotalWithdrawn float64 UlcerIndexAvg float64 UlcerIndexP50 float64 UlcerIndexP90 float64 UlcerIndexP99 float64 WorstYear *AnnualReturn DynamicWithdrawalRateSinceInception float64 PerpetualWithdrawalRateSinceInception float64 SafeWithdrawalRateSinceInception float64 }
func (*Metrics) MarshalBinary ¶
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*Metrics) MarshalLen ¶
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*Metrics) MarshalTo ¶
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*Metrics) MarshalZerologObject ¶
func (*Metrics) Unmarshal ¶
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*Metrics) UnmarshalBinary ¶
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type Model ¶
type Model struct { Portfolio *Portfolio // contains filtered or unexported fields }
Model stores a portfolio and associated price data that is used for computation
func LoadFromDB ¶
func NewPortfolio ¶
NewPortfolio create a portfolio
func (*Model) FillCorporateActions ¶
FillCorporateActions finds any corporate actions and creates transactions for them. The search occurs from the date of the last transaction to `through`
func (*Model) LoadTransactionsFromDB ¶
func (*Model) NotificationsForDate ¶
func (pm *Model) NotificationsForDate(ctx context.Context, forDate time.Time, perf *Performance) []*Notification
func (*Model) RebalanceTo ¶
func (pm *Model) RebalanceTo(ctx context.Context, allocation *data.SecurityAllocation, justifications []*Justification) error
RebalanceTo rebalance the portfolio to the target percentages Assumptions: can only rebalance current holdings
func (*Model) RequestedNotificationsForDate ¶
func (pm *Model) RequestedNotificationsForDate(forDate time.Time) []NotificationFrequency
RequestedNotificationsForDate evaluates a portfolios notifications against the requested date and returns those notifications that are valid for the given date.
func (*Model) SaveWithTransaction ¶
func (*Model) Table ¶ added in v0.5.0
Table formats the portfolio into a human-readable string representation
func (*Model) TargetPortfolio ¶
TargetPortfolio invests the portfolio in the ratios specified by the PieHistory `target`.
type Notification ¶
type NotificationFrequency ¶
type NotificationFrequency int32
const ( NotifyDaily NotificationFrequency = 0x00000010 NotifyWeekly NotificationFrequency = 0x00000100 NotifyMonthly NotificationFrequency = 0x00001000 NotifyAnnually NotificationFrequency = 0x00010000 )
func (NotificationFrequency) String ¶
func (nf NotificationFrequency) String() string
type Performance ¶
type Performance struct { PortfolioID []byte PeriodStart time.Time PeriodEnd time.Time ComputedOn time.Time CurrentAssets []*ReportableHolding Measurements []*PerformanceMeasurement DrawDowns []*DrawDown PortfolioReturns *Returns BenchmarkReturns *Returns PortfolioMetrics *Metrics BenchmarkMetrics *Metrics }
func LoadPerformanceFromDB ¶
func NewPerformance ¶
func NewPerformance(p *Portfolio) *Performance
func (*Performance) ActiveReturn ¶
func (perf *Performance) ActiveReturn(periods uint) float64
ActiveReturn calculates the difference in return vs a benchmark this is considered the amount of return that the "active" management yielded. The value of this metric is highly dependent on appropriate selection of benchmark. For example, comparing a small-cap value fund to the S&P500 benchmark doesn't say much because the underlying return of the assets held does not match the S&P500 well.
func (*Performance) AllDrawDowns ¶
func (perf *Performance) AllDrawDowns(periods uint, kind string) []*DrawDown
AllDrawDowns computes all portfolio draw downs. A draw down is defined as the period in which a portfolio falls from its previous peak. Draw downs include the time period of the loss, percent of loss, and when the portfolio recovered
func (*Performance) Alpha ¶
func (perf *Performance) Alpha(periods uint) float64
alpha is a measure of excess return of a portfolio α = Rp – [Rf + (Rm – Rf) β]
func (*Performance) AverageDrawDown ¶
func (perf *Performance) AverageDrawDown(periods uint, kind string) float64
AverageDrawDown computes the average portfolio draw down. A draw down is defined as the period in which a portfolio falls from its previous peak. Draw downs include the time period of the loss, percent of loss, and when the portfolio recovered
func (*Performance) AvgUlcerIndex ¶
func (perf *Performance) AvgUlcerIndex(periods uint) float64
AvgUlcerIndex compute average ulcer index over the last N periods
func (*Performance) Beta ¶
func (perf *Performance) Beta(periods uint) float64
Beta is a measure of the volatility—or systematic risk—of a security or portfolio compared to the market as a whole. Beta is used in the capital asset pricing model (CAPM), which describes the relationship between systematic risk and expected return for assets (usually stocks). CAPM is widely used as a method for pricing risky securities and for generating estimates of the expected returns of assets, considering both the risk of those assets and the cost of capital.
func (*Performance) CalculateThrough ¶
CalculateThrough computes performance metrics for the given portfolio until `through`
func (*Performance) CalmarRatio ¶
func (perf *Performance) CalmarRatio(periods uint, kind string) float64
CalmarRatio is a gauge of the risk adjusted performance of a portfolio. It is a function of the fund's average compounded annual rate of return versus its maximum drawdown. The higher the Calmar ratio, the better the portfolio performed on a risk-adjusted basis during the given time frame, which is typically set at 36 months.
func (*Performance) DownsideDeviation ¶
func (perf *Performance) DownsideDeviation(periods uint, kind string) float64
DownsideDeviation compute the standard deviation of negative excess returns on a monthly basis, result is annualized
func (*Performance) ExcessKurtosis ¶
func (perf *Performance) ExcessKurtosis(periods uint) float64
ExcessKurtosis calculates the amount of kurtosis relative to the normal distribution. Kurtosis is a statistical measure that is used to describe the size of the tails on a distribution. Excess kurtosis helps determine how much risk is involved in a specific investment. It signals that the probability of obtaining an extreme outcome or value from the event in question is higher than would be found in a probabilistically normal distribution of outcomes.
func (*Performance) InformationRatio ¶
func (perf *Performance) InformationRatio(periods uint) float64
InformationRatio is a measurement of portfolio returns beyond the returns of the benchmark, compared to the volatility of those returns.
func (*Performance) KRatio ¶
func (perf *Performance) KRatio(periods uint) float64
KRatio The K-ratio is a valuation metric that examines the consistency of an equity's return over time. k-ratio = (Slope logVAMI regression line) / n(Standard Error of the Slope)
func (*Performance) KellerRatio ¶
func (perf *Performance) KellerRatio(periods uint, kind string) float64
KellerRatio adjusts return for drawdown such as to reflect the severity of the observed maximum drawdown. In case maximum drawdown is small, the return adjustment is only limited. But with large maximum drawdown, the impact of the return adjustment is amplified.
K = R * ( 1 - D / ( 1 - D ) ), if R >= 0% and D <= 50%, and K = 0% otherwise
func (*Performance) LoadMeasurementsFromDB ¶
func (perf *Performance) LoadMeasurementsFromDB(ctx context.Context, userID string) error
loadMeasurementsFromDB populates the measurements array with values from the database
func (*Performance) LogSummary ¶
func (perf *Performance) LogSummary()
LogSummary will log a summary of the performance simulation
func (*Performance) MWRR ¶
func (perf *Performance) MWRR(periods uint, kind string) float64
MWRR computes the money-weighted rate of return for the specified number of periods if periods = 2, then return (p1 - deposits + withdraws) / p0 if 1 < periods < 252, then return xirr(cashflows) un-annualized else return xirr(cashflows) which is annualized return
func (*Performance) MWRRYtd ¶
func (perf *Performance) MWRRYtd(kind string) float64
MWRRYtd calculates the money weighted YTD return
func (*Performance) MarshalBinary ¶
func (o *Performance) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.CurrentAssets will be replaced with a new value. All nil entries in o.Measurements will be replaced with a new value. All nil entries in o.DrawDowns will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*Performance) MarshalLen ¶
func (o *Performance) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*Performance) MarshalTo ¶
func (o *Performance) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.CurrentAssets will be replaced with a new value. All nil entries in o.Measurements will be replaced with a new value. All nil entries in o.DrawDowns will be replaced with a new value.
func (*Performance) MaxDrawDown ¶
func (perf *Performance) MaxDrawDown(periods uint, kind string) *DrawDown
MaxDrawDown returns the largest drawdown over the given number of periods
func (*Performance) NetProfit ¶
func (perf *Performance) NetProfit() float64
NetProfit total profit earned on portfolio
func (*Performance) NetProfitPercent ¶
func (perf *Performance) NetProfitPercent() float64
NetProfitPercent profit earned on portfolio expressed as a percent
func (*Performance) SaveWithTransaction ¶
func (perf *Performance) SaveWithTransaction(ctx context.Context, trx pgx.Tx, userID string) error
func (*Performance) SharpeRatio ¶
func (perf *Performance) SharpeRatio(periods uint, kind string) float64
SharpeRatio The ratio is the average return earned in excess of the risk-free rate per unit of volatility or total risk. Volatility is a measure of the price fluctuations of an asset or portfolio.
Sharpe = (Rp - Rf) / (annualized std. dev)
Monthly values are chosen here to remain consistent with Morningstar and other online data providers.
func (*Performance) Skew ¶
func (perf *Performance) Skew(periods uint, kind string) float64
Skew computes the skew of the portfolio measurements relative to the normal distribution
func (*Performance) SortinoRatio ¶
func (perf *Performance) SortinoRatio(periods uint, kind string) float64
SortinoRatio a variation of the Sharpe ratio that differentiates harmful volatility from total overall volatility by using the asset's standard deviation of negative portfolio returns—downside deviation—instead of the total standard deviation of portfolio returns. The Sortino ratio takes an asset or portfolio's return and subtracts the risk-free rate, and then divides that amount by the asset's downside deviation.
Calculation is based on this paper by Red Rock Capital http://www.redrockcapital.com/Sortino__A__Sharper__Ratio_Red_Rock_Capital.pdf
func (*Performance) StdDev ¶
func (perf *Performance) StdDev(periods uint, kind string) float64
StdDev calculates the annualized standard deviation based off of the monthly price changes. Monthly values are chosen here to remain consistent with Morningstar and other online data providers.
func (*Performance) TWRR ¶
func (perf *Performance) TWRR(periods uint, kind string) float64
TWRR computes the time-weighted rate of return for the specified number of periods
func (*Performance) TWRRYtd ¶
func (perf *Performance) TWRRYtd(kind string) float64
TWRRYtd calculates the time-weighted YTD return
func (*Performance) Top10DrawDowns ¶
func (perf *Performance) Top10DrawDowns(periods uint, kind string) []*DrawDown
Top10DrawDowns computes the top 10 portfolio draw downs. A draw down is defined as the period in which a portfolio falls from its previous peak. Draw downs include the time period of the loss, percent of loss, and when the portfolio recovered
func (*Performance) TrackingError ¶
func (perf *Performance) TrackingError(periods uint) float64
TrackingError is the divergence between the price behavior of a portfolio and the price behavior of a benchmark.
func (*Performance) TreynorRatio ¶
func (perf *Performance) TreynorRatio(periods uint) float64
TreynorRatio also known as the reward-to-volatility ratio, is a performance metric for determining how much excess return was generated for each unit of risk taken on by a portfolio. treynor = Excess Return / Beta
func (*Performance) UlcerIndex ¶
func (perf *Performance) UlcerIndex() float64
UlcerIndex The Ulcer Index (UI) is a technical indicator that measures downside risk in terms of both the depth and duration of price declines. The index increases in value as the price moves farther away from a recent high and falls as the price rises to new highs. The indicator is usually calculated over a 14-day period, with the Ulcer Index showing the percentage drawdown a trader can expect from the high over that period.
The greater the value of the Ulcer Index, the longer it takes for a stock to get back to the former high. Simply stated, it is designed as one measure of volatility only on the downside.
Percentage Drawdown = [(Close - 14-period High Close)/14-period High Close] x 100 Squared Average = (14-period Sum of Percentage Drawdown Squared)/14 Ulcer Index = Square Root of Squared Average
period is number of days to lookback
func (*Performance) UlcerIndexPercentile ¶
func (perf *Performance) UlcerIndexPercentile(periods uint, percentile float64) float64
UlcerIndexPercentile compute average ulcer index over the last N periods
func (*Performance) Unmarshal ¶
func (o *Performance) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*Performance) UnmarshalBinary ¶
func (o *Performance) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
func (*Performance) ValueAtYearStart ¶
func (perf *Performance) ValueAtYearStart(dt time.Time) float64
type PerformanceMeasurement ¶
type PerformanceMeasurement struct { Time time.Time Value float64 BenchmarkValue float64 RiskFreeValue float64 StrategyGrowthOf10K float64 BenchmarkGrowthOf10K float64 RiskFreeGrowthOf10K float64 Holdings []*ReportableHolding Justification []*Justification TaxLots *TaxLotInfo TotalDeposited float64 TotalWithdrawn float64 // Time-weighted rate of return TWRROneDay float32 TWRRWeekToDate float32 TWRROneWeek float32 TWRRMonthToDate float32 TWRROneMonth float32 TWRRThreeMonth float32 TWRRYearToDate float32 TWRROneYear float32 TWRRThreeYear float32 TWRRFiveYear float32 TWRRTenYear float32 // Money-weighted rate of return MWRROneDay float32 MWRRWeekToDate float32 MWRROneWeek float32 MWRRMonthToDate float32 MWRROneMonth float32 MWRRThreeMonth float32 MWRRYearToDate float32 MWRROneYear float32 MWRRThreeYear float32 MWRRFiveYear float32 MWRRTenYear float32 // GainLoss bucketed by tax treatment AfterTaxReturn float64 BeforeTaxReturn float64 TaxCostRatio float64 LongTermCapitalGain float64 ShortTermCapitalGain float64 UnrealizedLongTermCapitalGain float64 UnrealizedShortTermCapitalGain float64 QualifiedDividend float64 NonQualifiedDividendAndInterestIncome float64 // active return ActiveReturnOneYear float32 ActiveReturnThreeYear float32 ActiveReturnFiveYear float32 ActiveReturnTenYear float32 // alpha AlphaOneYear float32 AlphaThreeYear float32 AlphaFiveYear float32 AlphaTenYear float32 // beta BetaOneYear float32 BetaThreeYear float32 BetaFiveYear float32 BetaTenYear float32 // ratios CalmarRatio float32 DownsideDeviation float32 InformationRatio float32 KRatio float32 KellerRatio float32 SharpeRatio float32 SortinoRatio float32 StdDev float32 TreynorRatio float32 UlcerIndex float32 }
func LoadMeasurementFromDB ¶
func LoadMeasurementFromDB(ctx context.Context, portfolioID []byte, userID string, forDate time.Time) (*PerformanceMeasurement, error)
LoadMeasurementFromDB reads a single measurement for the `portfolio` on the specified `date`
func (*PerformanceMeasurement) MarshalBinary ¶
func (o *PerformanceMeasurement) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.Holdings will be replaced with a new value. All nil entries in o.Justification will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*PerformanceMeasurement) MarshalLen ¶
func (o *PerformanceMeasurement) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*PerformanceMeasurement) MarshalTo ¶
func (o *PerformanceMeasurement) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.Holdings will be replaced with a new value. All nil entries in o.Justification will be replaced with a new value.
func (*PerformanceMeasurement) Unmarshal ¶
func (o *PerformanceMeasurement) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*PerformanceMeasurement) UnmarshalBinary ¶
func (o *PerformanceMeasurement) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type PerformanceMeasurementItem ¶
func (*PerformanceMeasurementItem) MarshalBinary ¶
func (o *PerformanceMeasurementItem) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*PerformanceMeasurementItem) MarshalLen ¶
func (o *PerformanceMeasurementItem) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*PerformanceMeasurementItem) MarshalTo ¶
func (o *PerformanceMeasurementItem) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*PerformanceMeasurementItem) Unmarshal ¶
func (o *PerformanceMeasurementItem) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*PerformanceMeasurementItem) UnmarshalBinary ¶
func (o *PerformanceMeasurementItem) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type PerformanceMeasurementItemList ¶
type PerformanceMeasurementItemList struct { Items []*PerformanceMeasurementItem FieldNames []string }
func (*PerformanceMeasurementItemList) MarshalBinary ¶
func (o *PerformanceMeasurementItemList) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.Items will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*PerformanceMeasurementItemList) MarshalLen ¶
func (o *PerformanceMeasurementItemList) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*PerformanceMeasurementItemList) MarshalTo ¶
func (o *PerformanceMeasurementItemList) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.Items will be replaced with a new value.
func (*PerformanceMeasurementItemList) Unmarshal ¶
func (o *PerformanceMeasurementItemList) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*PerformanceMeasurementItemList) UnmarshalBinary ¶
func (o *PerformanceMeasurementItemList) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type Portfolio ¶
type Portfolio struct { ID []byte UserID string AccountNumber string Brokerage string AccountType string Name string IsOpen bool LastViewed time.Time StartDate time.Time EndDate time.Time Benchmark string StrategyShortcode string StrategyArguments string Schedule string Notifications int32 Transactions []*Transaction CurrentHoldings []*Holding TaxLots *TaxLotInfo PortfolioType string LinkedPortfolios [][]byte PredictedAssets *PortfolioHoldingItem }
func (*Portfolio) MarshalBinary ¶
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.Transactions will be replaced with a new value. All nil entries in o.CurrentHoldings will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*Portfolio) MarshalLen ¶
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*Portfolio) MarshalTo ¶
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.Transactions will be replaced with a new value. All nil entries in o.CurrentHoldings will be replaced with a new value.
func (*Portfolio) Unmarshal ¶
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*Portfolio) UnmarshalBinary ¶
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type PortfolioHoldingItem ¶
type PortfolioHoldingItem struct { Time time.Time Holdings []*ReportableHolding Justification []*Justification PercentReturn float64 Value float64 Predicted bool }
func BuildPredictedHoldings ¶
func BuildPredictedHoldings(tradeDate time.Time, target map[data.Security]float64, justificationMap map[string]float64) *PortfolioHoldingItem
BuildPredictedHoldings creates a PortfolioHoldingItem from a date, target map, and justification map
func (*PortfolioHoldingItem) MarshalBinary ¶
func (o *PortfolioHoldingItem) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.Holdings will be replaced with a new value. All nil entries in o.Justification will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*PortfolioHoldingItem) MarshalLen ¶
func (o *PortfolioHoldingItem) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*PortfolioHoldingItem) MarshalTo ¶
func (o *PortfolioHoldingItem) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.Holdings will be replaced with a new value. All nil entries in o.Justification will be replaced with a new value.
func (*PortfolioHoldingItem) Unmarshal ¶
func (o *PortfolioHoldingItem) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*PortfolioHoldingItem) UnmarshalBinary ¶
func (o *PortfolioHoldingItem) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type PortfolioHoldingItemList ¶
type PortfolioHoldingItemList struct {
Items []*PortfolioHoldingItem
}
func (*PortfolioHoldingItemList) MarshalBinary ¶
func (o *PortfolioHoldingItemList) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.Items will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*PortfolioHoldingItemList) MarshalLen ¶
func (o *PortfolioHoldingItemList) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*PortfolioHoldingItemList) MarshalTo ¶
func (o *PortfolioHoldingItemList) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.Items will be replaced with a new value.
func (*PortfolioHoldingItemList) Unmarshal ¶
func (o *PortfolioHoldingItemList) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*PortfolioHoldingItemList) UnmarshalBinary ¶
func (o *PortfolioHoldingItemList) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type PortfolioTransactionList ¶
type PortfolioTransactionList struct {
Items []*Transaction
}
func (*PortfolioTransactionList) MarshalBinary ¶
func (o *PortfolioTransactionList) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.Items will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*PortfolioTransactionList) MarshalLen ¶
func (o *PortfolioTransactionList) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*PortfolioTransactionList) MarshalTo ¶
func (o *PortfolioTransactionList) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.Items will be replaced with a new value.
func (*PortfolioTransactionList) Unmarshal ¶
func (o *PortfolioTransactionList) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*PortfolioTransactionList) UnmarshalBinary ¶
func (o *PortfolioTransactionList) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type ReportableHolding ¶
type ReportableHolding struct { CompositeFIGI string Ticker string PercentPortfolio float32 Value float64 }
func (*ReportableHolding) MarshalBinary ¶
func (o *ReportableHolding) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*ReportableHolding) MarshalLen ¶
func (o *ReportableHolding) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*ReportableHolding) MarshalTo ¶
func (o *ReportableHolding) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*ReportableHolding) Unmarshal ¶
func (o *ReportableHolding) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*ReportableHolding) UnmarshalBinary ¶
func (o *ReportableHolding) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type Returns ¶
type Returns struct { MWRRSinceInception float64 MWRRYTD float64 MWRROneYear float64 MWRRThreeYear float64 MWRRFiveYear float64 MWRRTenYear float64 TWRRSinceInception float64 TWRRYTD float64 TWRROneYear float64 TWRRThreeYear float64 TWRRFiveYear float64 TWRRTenYear float64 }
func (*Returns) MarshalBinary ¶
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*Returns) MarshalLen ¶
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*Returns) MarshalTo ¶
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*Returns) Unmarshal ¶
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*Returns) UnmarshalBinary ¶
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type TaxLot ¶ added in v0.6.0
func (*TaxLot) MarshalBinary ¶ added in v0.6.0
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. The error return option is portfolio.ColferMax.
func (*TaxLot) MarshalLen ¶ added in v0.6.0
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*TaxLot) MarshalTo ¶ added in v0.6.0
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic.
func (*TaxLot) MarshalZerologObject ¶ added in v0.6.0
func (*TaxLot) Unmarshal ¶ added in v0.6.0
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*TaxLot) UnmarshalBinary ¶ added in v0.6.0
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
type TaxLotInfo ¶ added in v0.6.0
func (*TaxLotInfo) AdjustForSplit ¶ added in v0.6.0
func (t *TaxLotInfo) AdjustForSplit(security *data.Security, splitFactor float64)
LinkWithFIFOMethod identifies tax lots using the first-in, first-out method where the oldest shares acquired are sold first
func (*TaxLotInfo) CheckIfDividendIsQualified ¶ added in v0.6.0
func (t *TaxLotInfo) CheckIfDividendIsQualified(trx *Transaction) bool
CheckIfDividendIsQualified verifies if the specified dividend should be treated as a qualified dividend or non-qualified Qualified dividends are defined in IRS publication 550 (https://www.irs.gov/forms-pubs/about-publication-550) The maximum rate on qualified dividends applies only if all of the following requirements are met.
- The dividends must have been paid by a U.S. corporation or a qualified foreign corporation. (See table 1-3 in pub 550)
- The dividends are not of the type listed later under Dividends that are not qualified dividends. (see pub 550)
- Stock has been held for more than 60 days during the 121-day period that begins 60 days before the ex-dividend date. The ex-dividend date is the first date following the declaration of a dividend on which the buyer of a stock is not entitled to receive the next dividend payment. When counting the number of days you held the stock, include the day you disposed of the stock, but not the day you acquired it.
For penny vault's purposes all dividends are assumed to be qualifying *if* the holding requirement is met. If only a portion of the dividend meets the holding requirement then penny vault assumes 100% of the dividend is qualified. This assumption may cause penny vault to understate the true tax percentage.
NOTE: if a dividend is not qualified at the time of the ex-dividend date Penny Vault does not re-evaluate if it would be come qualified at a future date. This may cause Penny Vault to over-state the amount of taxes paid on dividends
func (*TaxLotInfo) Copy ¶ added in v0.6.0
func (t *TaxLotInfo) Copy() *TaxLotInfo
func (*TaxLotInfo) LinkTransactionsWithTaxLots ¶ added in v0.6.0
func (t *TaxLotInfo) LinkTransactionsWithTaxLots(sell *Transaction) []*Transaction
LinkTransactionsWithTaxLots identifies which tax lots should be linked with the sell transaction and calculate a gain/loss for the transaction based on the identified tax lots
func (*TaxLotInfo) LinkWithFIFOMethod ¶ added in v0.6.0
func (t *TaxLotInfo) LinkWithFIFOMethod(sell *Transaction) []*Transaction
LinkWithFIFOMethod identifies tax lots using the first-in, first-out method where the oldest shares acquired are sold first
func (*TaxLotInfo) MarshalBinary ¶ added in v0.6.0
func (o *TaxLotInfo) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.Items will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*TaxLotInfo) MarshalLen ¶ added in v0.6.0
func (o *TaxLotInfo) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*TaxLotInfo) MarshalTo ¶ added in v0.6.0
func (o *TaxLotInfo) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.Items will be replaced with a new value.
func (*TaxLotInfo) Unmarshal ¶ added in v0.6.0
func (o *TaxLotInfo) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*TaxLotInfo) UnmarshalBinary ¶ added in v0.6.0
func (o *TaxLotInfo) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.
func (*TaxLotInfo) Update ¶ added in v0.6.0
func (t *TaxLotInfo) Update(date time.Time, buys []*Transaction, sells []*Transaction) []*Transaction
Update the TaxLotInfo structure wuth the specified buy and sell transactions using the specified trax lot identification method
type Transaction ¶
type Transaction struct { ID []byte Cleared bool Commission float64 CompositeFIGI string Date time.Time GainLoss float64 Justification []*Justification Kind string Memo string Predicted bool Related [][]byte Source string SourceID string Tags []string TaxDisposition string Ticker string TotalValue float64 }
func (*Transaction) MarshalBinary ¶
func (o *Transaction) MarshalBinary() (data []byte, err error)
MarshalBinary encodes o as Colfer conform encoding.BinaryMarshaler. All nil entries in o.Justification will be replaced with a new value. The error return option is portfolio.ColferMax.
func (*Transaction) MarshalLen ¶
func (o *Transaction) MarshalLen() (int, error)
MarshalLen returns the Colfer serial byte size. The error return option is portfolio.ColferMax.
func (*Transaction) MarshalTo ¶
func (o *Transaction) MarshalTo(buf []byte) int
MarshalTo encodes o as Colfer into buf and returns the number of bytes written. If the buffer is too small, MarshalTo will panic. All nil entries in o.Justification will be replaced with a new value.
func (*Transaction) MarshalZerologObject ¶ added in v0.6.0
func (o *Transaction) MarshalZerologObject(e *zerolog.Event)
func (*Transaction) Security ¶ added in v0.6.0
func (trx *Transaction) Security() *data.Security
Security returns the security associated with the transaction
func (*Transaction) SplitFactor ¶ added in v0.6.0
func (trx *Transaction) SplitFactor() float64
SplitFactor returns the split factor of the split transaction. If the transaction is not a Split transaction then returns 1.0
func (*Transaction) Unmarshal ¶
func (o *Transaction) Unmarshal(data []byte) (int, error)
Unmarshal decodes data as Colfer and returns the number of bytes read. The error return options are io.EOF, portfolio.ColferError and portfolio.ColferMax.
func (*Transaction) UnmarshalBinary ¶
func (o *Transaction) UnmarshalBinary(data []byte) error
UnmarshalBinary decodes data as Colfer conform encoding.BinaryUnmarshaler. The error return options are io.EOF, portfolio.ColferError, portfolio.ColferTail and portfolio.ColferMax.