valuemetrics

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 0 Imported by: 0

README

value-metrics

Go Reference

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.

Install

go get github.com/theluckystrike/value-metrics

Quick example

package 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
}

API

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.

License

MIT.

Documentation

Overview

Package valuemetrics implements the core equity value metrics used in fundamental stock analysis: price-to-earnings (P/E), price-to-book (P/B), and earnings yield. These are the same formulas behind the DeepValueRadar value-investing tools at https://deepvalueradar.com/.

A multiple on its own is not a verdict. These numbers are screen inputs, and the rules that consume them there - how the universe is constructed, the valuation-gap trigger a candidate has to clear, and how conviction is scored afterwards - are written up at https://deepvalueradar.com/methodology/.

Quick example:

pe := valuemetrics.PriceToEarnings(50.0, 2.0)  // share price / EPS
// pe == 25.0
y := valuemetrics.EarningsYield(25.0)          // 1 / P/E
// y ~= 0.04 (4%)
_ = valuemetrics.PriceToBook(50.0, 30.0, 1.0)  // price / book per share

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BookValuePerShare

func BookValuePerShare(commonEquity, sharesOutstanding float64) float64

BookValuePerShare returns common equity divided by shares outstanding. It returns 0.0 if shares outstanding is non-positive.

func EarningsPerShare

func EarningsPerShare(netIncome, sharesOutstanding float64) float64

EarningsPerShare returns net income divided by shares outstanding (basic EPS). It returns 0.0 if shares outstanding is non-positive.

func EarningsYield

func EarningsYield(eps, pricePerShare float64) float64

EarningsYield returns EPS divided by price per share — the reciprocal of the P/E ratio. It returns 0.0 if price is non-positive. Useful for comparing a stock's earnings power directly to bond yields.

func EarningsYieldFromPE

func EarningsYieldFromPE(pe float64) float64

EarningsYieldFromPE returns the earnings yield for a given P/E ratio. It returns 0.0 if the P/E ratio is non-positive.

func PEVerdict

func PEVerdict(pe float64) string

PEVerdict returns a plain-language read on a P/E multiple vs. a broad-market benchmark (defaulted to ~20x for the modern S&P 500 average).

func PriceToBook

func PriceToBook(pricePerShare, bookValuePerShare float64) float64

PriceToBook returns the P/B ratio: market price per share divided by book value per share. It returns 0.0 if book value per share is non-positive.

func PriceToEarnings

func PriceToEarnings(pricePerShare, eps float64) float64

PriceToEarnings returns the trailing P/E ratio: price per share divided by earnings per share (EPS). It returns 0.0 if EPS is non-positive (P/E is undefined or negative earnings => not a meaningful positive multiple).

Types

This section is empty.

Jump to

Keyboard shortcuts

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