renderer

package
v0.0.0-...-d29c26b Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllAreZero

func AllAreZero(items ...Zeroable) bool

AllAreZero returns true if all the provided items are zero. It iterates through a variadic slice of items that implement the Zeroable interface.

func ConditionalBlock

func ConditionalBlock(w io.Writer, block func(io.Writer) bool)

ConditionalBlock let you fully write a block and decide at the end to print it or not. If the block function returns true, the content is printed to w, otherwise it is discarded.

func DeclarationMarkdown

func DeclarationMarkdown(s *portfolio.Snapshot) string

DeclarationMarkdown renders the full declaration of stocks ticker.

func HistoryMarkdown

func HistoryMarkdown(snapshots []*portfolio.Snapshot, security, currency string) string

func Now

func Now() time.Time

Now is the current time used in reports. it has to be a global variable so that tests can override it.

func RenderConsolidatedHolding

func RenderConsolidatedHolding(ch *ConsolidatedHolding) string

RenderConsolidatedHolding renders the ConsolidatedHolding struct to a markdown string.

func RenderConsolidatedReview

func RenderConsolidatedReview(cr *ConsolidatedReview, opts ReviewRenderOptions) string

RenderConsolidatedReview renders the ConsolidatedReview struct to a markdown string.

func RenderHolding

func RenderHolding(h *Holding) string

ToMarkdown renders the Holding struct to a markdown string using a text/template.

func RenderMultiPeriodSummary

func RenderMultiPeriodSummary(w io.Writer, on portfolio.Date, ledger *portfolio.Ledger) bool

func RenderReview

func RenderReview(r *Review, opts ReviewRenderOptions) string

RenderReview renders the Review struct to a markdown string.

func Transaction

func Transaction(tx portfolio.Transaction) string

Transaction renders a transaction to a string.

func Transactions

func Transactions(txs []portfolio.Transaction) string

Transactions renders a slice of transactions to a simple list string.

Types

type Accounts

type Accounts struct {
	Cash         []CashAccount         `json:"cash"`
	Counterparty []CounterpartyAccount `json:"counterparty"`
}

Accounts holds the cash and counterparty account details for a review.

type AssetReview

type AssetReview struct {
	Ticker         string            `json:"ticker"`
	StartValue     portfolio.Money   `json:"startValue"`
	EndValue       portfolio.Money   `json:"endValue"`
	TradingFlow    portfolio.Money   `json:"tradingFlow"`
	MarketGain     portfolio.Money   `json:"marketGain"`
	RealizedGain   portfolio.Money   `json:"realizedGain"`
	UnrealizedGain portfolio.Money   `json:"unrealizedGain"`
	Dividends      portfolio.Money   `json:"dividends"`
	TWR            portfolio.Percent `json:"twr"`
}

AssetReview holds all the period metrics for a single asset.

func (AssetReview) IsZero

func (ar AssetReview) IsZero() bool

IsZero checks if all financial values in the AssetReview are zero.

type CashAccount

type CashAccount struct {
	Currency    string            `json:"currency"`
	Value       portfolio.Money   `json:"value"`
	ForexReturn portfolio.Percent `json:"forexReturn"`
}

CashAccount represents a single cash account's state in a review.

type ConsolidatedHolding

type ConsolidatedHolding struct {
	Date                            portfolio.Date  `json:"date"`
	ConsolidatedPortfolioValue      portfolio.Money `json:"consolidatedPortfolioValue"`
	ConsolidatedSecuritiesValue     portfolio.Money `json:"consolidatedSecuritiesValue"`
	ConsolidatedCashValue           portfolio.Money `json:"consolidatedCashValue"`
	ConsolidatedCounterpartiesValue portfolio.Money `json:"consolidatedCounterpartiesValue"`
	Holdings                        []*Holding      `json:"holdings"`
	ReportingCurrency               string          `json:"reportingCurrency"`
}

ConsolidatedHolding represents a consolidated view of multiple holdings.

func NewConsolidatedHolding

func NewConsolidatedHolding(snapshots []*portfolio.Snapshot) *ConsolidatedHolding

NewConsolidatedHolding creates a new ConsolidatedHolding from a list of snapshots. It assumes the reporting currency of the first snapshot for consolidation.

type ConsolidatedReview

type ConsolidatedReview struct {
	AsOf              string          `json:"asOf"`
	Range             portfolio.Range `json:"range"`
	Reviews           []*Review       `json:"reviews"`
	ReportingCurrency string          `json:"reportingCurrency"`

	ConsolidatedTotalPortfolioValue      portfolio.Money `json:"consolidatedTotalPortfolioValue"`
	ConsolidatedTotalCashValue           portfolio.Money `json:"consolidatedTotalCashValue"`
	ConsolidatedTotalCounterpartiesValue portfolio.Money `json:"consolidatedTotalCounterpartiesValue"`
	ConsolidatedPreviousValue            portfolio.Money `json:"consolidatedPreviousValue"`
	ConsolidatedCapitalFlow              portfolio.Money `json:"consolidatedCapitalFlow"`
	ConsolidatedMarketGains              portfolio.Money `json:"consolidatedMarketGains"`
	ConsolidatedForexGains               portfolio.Money `json:"consolidatedForexGains"`
	ConsolidatedNetChange                portfolio.Money `json:"consolidatedNetChange"`
	ConsolidatedCashChange               portfolio.Money `json:"consolidatedCashChange"`
	ConsolidatedCounterpartiesChange     portfolio.Money `json:"consolidatedCounterpartiesChange"`
	ConsolidatedMarketValueChange        portfolio.Money `json:"consolidatedMarketValueChange"`
	ConsolidatedDividends                portfolio.Money `json:"consolidatedDividends"`
	ConsolidatedTotalGains               portfolio.Money `json:"consolidatedTotalGains"`
	ConsolidatedTotalStartMarketValue    portfolio.Money `json:"consolidatedTotalStartMarketValue"`
	ConsolidatedTotalEndMarketValue      portfolio.Money `json:"consolidatedTotalEndMarketValue"`
	ConsolidatedTotalNetTradingFlow      portfolio.Money `json:"consolidatedTotalNetTradingFlow"`
	ConsolidatedTotalRealizedGains       portfolio.Money `json:"consolidatedTotalRealizedGains"`
	ConsolidatedTotalUnrealizedGains     portfolio.Money `json:"consolidatedTotalUnrealizedGains"`
}

ConsolidatedReview aggregates multiple reviews into a single consolidated report.

func NewConsolidatedReview

func NewConsolidatedReview(portfolioReviews []*portfolio.Review, method portfolio.CostBasisMethod) *ConsolidatedReview

NewConsolidatedReview creates a new ConsolidatedReview from a list of portfolio.Review objects.

type CounterpartyAccount

type CounterpartyAccount struct {
	Name  string          `json:"name"`
	Value portfolio.Money `json:"value"`
}

CounterpartyAccount represents a single counterparty account's state in a review.

type Holding

type Holding struct {

	// Name of the ledger.
	Name string `json:"name,omitempty"`
	// Date of the holding
	Date portfolio.Date `json:"date"`
	// TotalPortfolioValue is the total value of the portfolio in the reporting currency.
	TotalPortfolioValue portfolio.Money `json:"totalPortfolioValue"`
	// TotalSecuritiesValue is the total value of all securities in the reporting currency.
	TotalSecuritiesValue portfolio.Money `json:"totalSecuritiesValue"`
	// TotalCashValue is the total value of all cash balances in the reporting currency.
	TotalCashValue portfolio.Money `json:"totalCashValue"`
	// TotalCounterpartiesValue is the total value of all counterparty accounts in the reporting currency.
	TotalCounterpartiesValue portfolio.Money `json:"totalCounterpartiesValue"`
	// Securities is a list of all securities held.
	Securities []HoldingSecurity `json:"securities"`
	// Cash is a list of all cash balances by currency.
	Cash []HoldingCash `json:"cash"`
	// Counterparties is a list of all counterparties balances.
	Counterparties []HoldingCounterparty `json:"counterparties"`
}

Holding is a struct to represent the holding data in json. Numbers are handled using the exact decimal types (Money, Quantity, etc.) So that they already contain basics renderers (SignedString etc.)

func NewHolding

func NewHolding(s *portfolio.Snapshot) *Holding

NewHolding creates a new Holding struct from a portfolio snapshot. It populates the struct with all the necessary data for rendering a holding report.

type HoldingCash

type HoldingCash struct {
	Currency string          `json:"currency"`
	Balance  portfolio.Money `json:"balance"`
}

HoldingCash represents a single cash balance.

type HoldingCounterparty

type HoldingCounterparty struct {
	Name    string          `json:"name"`
	Balance portfolio.Money `json:"balance"`
}

HoldingCounterparty represents a single counterparty balance.

type HoldingSecurity

type HoldingSecurity struct {
	Ticker      string             `json:"ticker"`
	Quantity    portfolio.Quantity `json:"quantity"`
	Price       portfolio.Money    `json:"price"`
	MarketValue portfolio.Money    `json:"marketValue"`
	ID          portfolio.ID       `json:"id"`
	LastUpdate  portfolio.Date     `json:"lastUpdate"`
	Description string             `json:"description,omitempty"`
}

HoldingSecurity represents a single security holding.

type RenderableTransaction

type RenderableTransaction struct {
	When   string
	Detail string
}

RenderableTransaction holds the data for a single transaction line in a report.

type Review

type Review struct {
	Name                     string          `json:"name,omitempty"`
	AsOf                     string          `json:"asOf"`
	Range                    portfolio.Range `json:"range"`
	TotalPortfolioValue      portfolio.Money `json:"totalPortfolioValue"`
	TotalCashValue           portfolio.Money `json:"totalCashValue"`
	TotalCounterpartiesValue portfolio.Money `json:"totalCounterpartiesValue"`
	PreviousValue            portfolio.Money `json:"previousValue"`
	CapitalFlow              portfolio.Money `json:"capitalFlow"`
	MarketGains              portfolio.Money `json:"marketGains"`
	ForexGains               portfolio.Money `json:"forexGains"`
	NetChange                portfolio.Money `json:"netChange"`
	CashChange               portfolio.Money `json:"cashChange"`
	CounterpartiesChange     portfolio.Money `json:"counterpartiesChange"`
	MarketValueChange        portfolio.Money `json:"marketValueChange"`
	Dividends                portfolio.Money `json:"dividends"`
	TotalGains               portfolio.Money `json:"totalGains"`
	// Totals for the asset report
	TotalStartMarketValue portfolio.Money   `json:"totalStartMarketValue"`
	TotalEndMarketValue   portfolio.Money   `json:"totalEndMarketValue"`
	TotalNetTradingFlow   portfolio.Money   `json:"totalNetTradingFlow"`
	TotalRealizedGains    portfolio.Money   `json:"totalRealizedGains"`
	TotalUnrealizedGains  portfolio.Money   `json:"totalUnrealizedGains"`
	TotalTWR              portfolio.Percent `json:"totalTwr"`

	Accounts     Accounts      `json:"accounts"`
	Assets       []AssetReview `json:"assets"`
	Transactions []RenderableTransaction
}

Review is a struct to represent the review data for rendering.

func NewReview

func NewReview(pr *portfolio.Review, method portfolio.CostBasisMethod) *Review

NewReview creates a new renderer.Review from a portfolio.Review.

type ReviewRenderOptions

type ReviewRenderOptions struct {
	SimplifiedView   bool // Use the simplified asset view instead of the consolidated one.
	SkipTransactions bool // Do not render the transactions section.
}

ReviewRenderOptions holds configuration for rendering a review report.

type SectionPrinter

type SectionPrinter struct {
	// contains filtered or unexported fields
}

SectionPrinter is a helper to conditionally print a header and a footer for a section only if content is actually written to it.

func Header(f func(io.Writer)) *SectionPrinter

Header creates a new SectionPrinter and sets the function that will be called to print the section header. Deprecated: use ConditionalBlock instead.

func (*SectionPrinter) Footer

func (p *SectionPrinter) Footer(f func(io.Writer)) *SectionPrinter

Footer sets the function that will be called to print the section footer.

func (*SectionPrinter) PrintFooter

func (p *SectionPrinter) PrintFooter(w io.Writer)

PrintFooter prints the section footer, but only if the header was ever printed. It should be called after the loop that prints the rows.

func (*SectionPrinter) PrintHeader

func (p *SectionPrinter) PrintHeader(w io.Writer)

PrintHeader prints the section header, but only on the first call. Subsequent calls do nothing. It should be called just before printing the first row.

type Zeroable

type Zeroable interface {
	IsZero() bool
}

Zeroable defines an interface for types that can be checked for a zero value.

Jump to

Keyboard shortcuts

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