The core equity value metrics used in fundamental stock analysis: price-to-earnings (P/E), price-to-book (P/B), and earnings yield. Pure, dependency-free Go math — the same engine behind the DeepValueRadar value-investing tools.
go get github.com/theluckystrike/value-metricspackage main
import (
"fmt"
valuemetrics "github.com/theluckystrike/value-metrics"
)
func main() {
// $50 share, $2 EPS -> P/E of 25
pe := valuemetrics.PriceToEarnings(50.0, 2.0)
fmt.Println(pe) // 25
fmt.Println(valuemetrics.PEVerdict(pe)) // "pricey"
fmt.Println(valuemetrics.EarningsYieldFromPE(pe)) // 0.04 (4%)
// P/B: price 50 vs 30 book/share
fmt.Println(valuemetrics.PriceToBook(50.0, 30.0)) // ~1.667
}| Function | Description |
|---|---|
PriceToEarnings(pricePerShare, eps float64) float64 |
Trailing P/E (0 if EPS <= 0). |
EarningsPerShare(netIncome, sharesOutstanding float64) float64 |
Net income / shares outstanding. |
PriceToBook(pricePerShare, bookValuePerShare float64) float64 |
P/B ratio (0 if book <= 0). |
BookValuePerShare(commonEquity, sharesOutstanding float64) float64 |
Common equity / shares outstanding. |
EarningsYield(eps, pricePerShare float64) float64 |
EPS / price — the reciprocal of P/E. |
EarningsYieldFromPE(pe float64) float64 |
1 / P/E (0 if P/E <= 0). |
PEVerdict(pe float64) string |
undefined / deep-value / cheap / fair / pricey / expensive by modern S&P 500 P/E bands. |
MIT.
- DeepValueRadar value-investing tools: https://deepvalueradar.com/
- Package docs: https://pkg.go.dev/github.com/theluckystrike/value-metrics