portfolio

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CsvDateFormatDefault string = "2006-01-02"
)

Variables

View Source
var ColNames []string
View Source
var ONE_DAY_DUR = mustParseDuration("24h")

Functions

func CheckTxSanity

func CheckTxSanity(tx *Tx) error

func PrintRenderTable

func PrintRenderTable(tableModel *RenderTable, writer io.Writer)

func SplitTxsBySecurity

func SplitTxsBySecurity(txs []*Tx) map[string][]*Tx

func SuperficialLossPercent

func SuperficialLossPercent(idx int, txs []*Tx, shareBalanceAfterSell uint32) float64

Calculation of partial superficial losses where Superficial loss = (min(#sold, totalAquired, endBalance) / #sold) x (Total Loss) This function returns the left hand side of this formula, on the condition that the loss is actually superficial.

Reference: https://www.adjustedcostbase.ca/blog/applying-the-superficial-loss-rule-for-a-partial-disposition-of-shares/

Types

type ColParser

type ColParser func(string, *Tx) error

type Currency

type Currency string
const (
	DEFAULT_CURRENCY Currency = ""
	CAD              Currency = "CAD"
	USD              Currency = "USD"
)

type LegacyOptions

type LegacyOptions struct {
	NoSuperficialLosses        bool
	NoPartialSuperficialLosses bool
}

func NewLegacyOptions

func NewLegacyOptions() LegacyOptions

type PortfolioSecurityStatus

type PortfolioSecurityStatus struct {
	Security     string
	ShareBalance uint32
	TotalAcb     float64
}

func NewEmptyPortfolioSecurityStatus

func NewEmptyPortfolioSecurityStatus(security string) *PortfolioSecurityStatus

func (*PortfolioSecurityStatus) PerShareAcb

func (s *PortfolioSecurityStatus) PerShareAcb() float64

type RenderTable

type RenderTable struct {
	Header []string
	Rows   [][]string
	Footer []string
	Notes  []string
	Errors []error
}

func RenderTxTableModel

func RenderTxTableModel(deltas []*TxDelta, renderFullDollarValues bool) *RenderTable

type Tx

type Tx struct {
	Security                          string
	Date                              time.Time
	Action                            TxAction
	Shares                            uint32
	AmountPerShare                    float64
	Commission                        float64
	TxCurrency                        Currency
	TxCurrToLocalExchangeRate         float64
	CommissionCurrency                Currency
	CommissionCurrToLocalExchangeRate float64
	Memo                              string
	// The absolute order in which the Tx was read from file or entered.
	// Used as a tiebreak in sorting.
	ReadIndex uint32
}

func DefaultTx

func DefaultTx() *Tx

func ParseTxCsv

func ParseTxCsv(reader io.Reader, initialGlobalReadIndex uint32,
	csvDesc string, rateLoader *fx.RateLoader) ([]*Tx, error)

func SortTxs

func SortTxs(txs []*Tx, legacySortBuysBeforeSells bool) []*Tx

type TxAction

type TxAction int
const (
	NO_ACTION TxAction = iota
	BUY
	SELL
	ROC // Return of capital
)

func (TxAction) String

func (a TxAction) String() string

type TxDelta

type TxDelta struct {
	Tx              *Tx
	PreStatus       *PortfolioSecurityStatus
	PostStatus      *PortfolioSecurityStatus
	CapitalGain     float64
	SuperficialLoss float64
}

func AddTx

func AddTx(idx int, txs []*Tx, preTxStatus *PortfolioSecurityStatus, legacyOptions LegacyOptions) (*TxDelta, error)

func TxsToDeltaList

func TxsToDeltaList(txs []*Tx, initialStatus *PortfolioSecurityStatus, legacyOptions LegacyOptions) ([]*TxDelta, error)

func (*TxDelta) AcbDelta

func (d *TxDelta) AcbDelta() float64

func (*TxDelta) SuperficialLossPercent

func (d *TxDelta) SuperficialLossPercent() float64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL