portfolio

package
v0.0.0-...-30fe3bd Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Dow         string = "^DJI"
	SP500       string = "^GSPC"
	Nasdaq      string = "^IXIC"
	Russell2000 string = "^RUT"
	Foreign     string = "VXUS"
	China       string = "000001.SS"
	USBond      string = "BND"
	Treasury10  string = "^TNX"
	Gold        string = "GC=F"
	Oil         string = "CL=F"
	Bitcoin     string = "BTC-USD"
	Ethereum    string = "ETH-USD"
)

Market index symbols

Variables

View Source
var AssetDB = func() map[string]*Asset {
	return map[string]*Asset{
		"SPY":     {"SPY", AssetClassUSStock, AssetClassUSStockLarge},
		"VOO":     {"VOO", AssetClassUSStock, AssetClassUSStockLarge},
		"VTI":     {"VTI", AssetClassUSStock, AssetClassUSStockLarge},
		"VTV":     {"VTV", AssetClassUSStock, AssetClassUSStockLargeValue},
		"VIG":     {"VTV", AssetClassUSStock, AssetClassUSStockLarge},
		"VUG":     {"VUG", AssetClassUSStock, AssetClassUSStockLargeGrowth},
		"QQQ":     {"QQQ", AssetClassUSStock, AssetClassUSStockLargeTech},
		"VO":      {"VO", AssetClassUSStock, AssetClassUSStockMid},
		"VB":      {"VB", AssetClassUSStock, AssetClassUSStockSmall},
		"VEU":     {"VEU", AssetClassInternationalStock, AssetClassInternationalStock},
		"VXUS":    {"VXUS", AssetClassInternationalStock, AssetClassInternationalStock},
		"VWO":     {"VWO", AssetClassInternationalStock, AssetClassEmergingMarketStock},
		"GXC":     {"GXC", AssetClassChinaStock, AssetClassChinaStock},
		"VNQ":     {"VNQ", AssetClassUSRealEstate, AssetClassUSRealEstate},
		"EPR":     {"EPR", AssetClassUSRealEstate, AssetClassUSRealEstateExperiential},
		"VNQI":    {"VNQI", AssetClassInternationalRealEstate, AssetClassInternationalRealEstate},
		"BND":     {"BND", AssetClassUSBond, AssetClassUSBond},
		"GOVT":    {"GOVT", AssetClassUSTreasury, AssetClassUSTreasury},
		"VGLT":    {"VGLT", AssetClassUSTreasury, AssetClassUSTreasuryLongTerm},
		"SPTI":    {"SPTI", AssetClassUSTreasury, AssetClassUSTreasuryIntermediateTerm},
		"SHY":     {"SHY", AssetClassUSTreasury, AssetClassUSTreasuryShortTerm},
		"TIP":     {"TIP", AssetClassUSTreasury, AssetClassUSTreasuryInflationProtected},
		"DBC":     {"DBC", AssetClassCommodity, AssetClassCommodity},
		"USO":     {"USO", AssetClassCommodity, AssetClassCrudeOil},
		"GLD":     {"GLD", AssetClassCommodity, AssetClassGold},
		"IAU":     {"IAU", AssetClassCommodity, AssetClassGold},
		"SLV":     {"SLV", AssetClassCommodity, AssetClassSilver},
		"BTC-USD": {"BTC-USD", AssetClassCrypto, AssetClassCrypto},
		"ETH-USD": {"ETH-USD", AssetClassCrypto, AssetClassCrypto},
	}
}

AssetDB returns a built-in database for assets of interest

Functions

This section is empty.

Types

type Asset

type Asset struct {
	Symbol   string
	Class    AssetClass
	Subclass AssetClass
}

Asset defines a security held in the portfolio

func NewAsset

func NewAsset(symbol string) *Asset

NewAsset returns a new asset

func (*Asset) Clone

func (asset *Asset) Clone() *Asset

Clone makes a copy of the Asset

type AssetClass

type AssetClass string

AssetClass defines the type for asset classes and subclasses

const (
	AssetClassUSStock                      AssetClass = "US Stock"
	AssetClassUSStockLarge                 AssetClass = "US Stock Large"
	AssetClassUSStockLargeValue            AssetClass = "US Stock Large Value"
	AssetClassUSStockLargeGrowth           AssetClass = "US Stock Large Growth"
	AssetClassUSStockLargeTech             AssetClass = "US Stock Large Tech"
	AssetClassUSStockMid                   AssetClass = "US Stock Mid"
	AssetClassUSStockSmall                 AssetClass = "US Stock Small"
	AssetClassInternationalStock           AssetClass = "International Stock"
	AssetClassEmergingMarketStock          AssetClass = "Emerging Market Stock"
	AssetClassChinaStock                   AssetClass = "China Stock"
	AssetClassUSRealEstate                 AssetClass = "US Real Estate"
	AssetClassUSRealEstateExperiential     AssetClass = "US Real Estate Experiential"
	AssetClassInternationalRealEstate      AssetClass = "International Real Estate"
	AssetClassUSBond                       AssetClass = "US Bond"
	AssetClassUSTreasury                   AssetClass = "US Treasury"
	AssetClassUSTreasuryLongTerm           AssetClass = "US Treasury Long Term"
	AssetClassUSTreasuryIntermediateTerm   AssetClass = "US Treasury Intermediate Term"
	AssetClassUSTreasuryShortTerm          AssetClass = "US Treasury Short Term"
	AssetClassUSTreasuryInflationProtected AssetClass = "US Treasury Inflation Protected"
	AssetClassCommodity                    AssetClass = "Commodity"
	AssetClassCrudeOil                     AssetClass = "CrudeOil"
	AssetClassGold                         AssetClass = "Gold"
	AssetClassSilver                       AssetClass = "Silver"
	AssetClassCrypto                       AssetClass = "Crypto"
	AssetClassOther                        AssetClass = "Other"
)

Asset class definitions

type Historic

type Historic struct {
	Open  float64
	Close float64
	Date  time.Time
}

Historic represents a historic quote or portfolio value

type Holding

type Holding struct {
	Asset     *Asset
	Quantity  float64
	CostBasis float64
	Watch     float64
	Quote     *finance.Quote
	Status    *HoldingStatus
}

Holding defines a position in the portfolio

func NewHolding

func NewHolding(symbol string, quantity float64, basis float64, watch float64) *Holding

NewHolding returns a new holding object

func (*Holding) Clone

func (holding *Holding) Clone() *Holding

Clone makes a copy of the Holding, with dynamic quote and status zeroed out

func (*Holding) GetHistoricalQuote

func (holding *Holding) GetHistoricalQuote(date time.Time) (*finance.ChartBar, error)

GetHistoricalQuote returns the quote on a specific day

func (*Holding) Refresh

func (holding *Holding) Refresh() error

Refresh gets the current quote and computes the current status of a particular holding

func (*Holding) RefreshQuote

func (holding *Holding) RefreshQuote() error

RefreshQuote gets the current quote of a particular holding

func (*Holding) RefreshStatus

func (holding *Holding) RefreshStatus()

RefreshStatus computes the current status of a holding from the current quote

type HoldingStatus

type HoldingStatus struct {
	Value             float64
	Unrealized        float64
	UnrealizedPercent float64
}

HoldingStatus defines the real-time status of a particular holding

type Market

type Market struct {
	Dow         *finance.Index
	SP500       *finance.Index
	Nasdaq      *finance.Index
	Russell2000 *finance.Index
	Foreign     *finance.Index
	China       *finance.Index
	USBond      *finance.Index
	Treasury10  *finance.Index
	Gold        *finance.Index
	Oil         *finance.Index
	Bitcoin     *finance.Index
	Ethereum    *finance.Index
}

Market defines the broader market indices we track

func NewMarket

func NewMarket() *Market

NewMarket returns a new market

func (*Market) Refresh

func (market *Market) Refresh() error

Refresh fetches the latest quotes for the market indices

type Performance

type Performance struct {
	Portfolio       *Portfolio
	BenchmarkSymbol string
	InitialBalance  float64
	StartDate       time.Time
	EndDate         time.Time
	Result          *PerformanceResult
	Benchmark       *PerformanceResult
	Ready           bool
}

Performance analyzes the historic performance of a portfolio and compares it against a benchmark

func NewPerformance

func NewPerformance(portfolio *Portfolio, benchmark string, initialBalance float64) *Performance

NewPerformance creates a new analysis of the historic performance of a portfolio

func (*Performance) Compute

func (performance *Performance) Compute() error

Compute generates the performance data for the portfolio

type PerformanceResult

type PerformanceResult struct {
	Portfolio    *Portfolio
	Historic     []Historic
	FinalBalance float64
	CAGR         float64
	Stdev        float64
	BestYear     float64
	WorstYear    float64
	MaxDrawdown  float64
	SharpeRatio  float64
	Return       *Return
}

PerformanceResult contains the historic performance of a portfolio

func NewPerformanceResult

func NewPerformanceResult() *PerformanceResult

NewPerformanceResult creates a new historic performance result of a portfolio

type Portfolio

type Portfolio struct {
	Name             string
	CostBasis        float64
	Symbols          []string
	Holdings         map[string]*Holding
	TargetAllocation map[string]float64
	Status           *Status
	Performance      *Performance
}

Portfolio defines a portfolio of asset holdings

func NewPortfolio

func NewPortfolio() *Portfolio

NewPortfolio returns an empty portfolio of asset holdings

func (*Portfolio) Clone

func (portfolio *Portfolio) Clone() *Portfolio

Clone makes a copy of the Portfolio

func (*Portfolio) Load

func (portfolio *Portfolio) Load(config portfolioConfig) error

Load loads a portfolio from the config

func (*Portfolio) Refresh

func (portfolio *Portfolio) Refresh() error

Refresh computes the current status of the entire portfolio and its holdings

func (*Portfolio) RefreshStatus

func (portfolio *Portfolio) RefreshStatus()

RefreshStatus computes the current status of the entire portfolio

type Profile

type Profile struct {
	Name             string
	Cash             float64
	CostBasis        float64
	Market           *Market
	Portfolios       []*Portfolio
	TargetAllocation map[string]float64
	MergedPortfolio  *Portfolio
	Status           *ProfileStatus
}

Profile contains multiple portfolios

func NewProfile

func NewProfile(name string) *Profile

NewProfile returns an empty profile

func (*Profile) Load

func (profile *Profile) Load(name string) error

Load loads a profile from the given file

func (*Profile) Refresh

func (profile *Profile) Refresh() error

Refresh computes the current status of the entire profile and its portfolios

func (*Profile) RefreshStatus

func (profile *Profile) RefreshStatus()

RefreshStatus computes the current status of the entire profile

type ProfileStatus

type ProfileStatus struct {
	Value                      float64
	RegularMarketChange        float64
	RegularMarketChangePercent float64
	Unrealized                 float64
	UnrealizedPercent          float64
	Allocation                 map[string]float64
}

ProfileStatus defines the real-time status of the entire portfolio

type Return

type Return struct {
	OneMonth   float64
	ThreeMonth float64
	SixMonth   float64
	YTD        float64
	OneYear    float64
	ThreeYear  float64
	FiveYear   float64
	TenYear    float64
	Max        float64
}

Return represents the trailing returns of a portfolio

func NewReturn

func NewReturn() *Return

NewReturn creates a new trailing return result of a portfolio

type Status

type Status struct {
	Value                      float64
	RegularMarketChange        float64
	RegularMarketChangePercent float64
	Unrealized                 float64
	UnrealizedPercent          float64
	Allocation                 map[string]float64
}

Status defines the real-time status of the entire portfolio

Jump to

Keyboard shortcuts

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