nustack
ReferenceNu STD

fin

Nu surface for financial value types - `Percentage` and `BasisPoint`.

Module nustd.fin.

Nu surface for financial value types - Percentage and BasisPoint.

There is no Python stdlib fin module; these are Nu's own value types, built the same way the stdlib surfaces are - a native dataclass (native, exported with a Py prefix) wrapped by a Form (forms) whose constructors and methods are interactions atoms. Import them like the rest of the std library:

from nustd.fin import BasisPoint, Percentage       # Forms: Percentage.of(75.5)
from nustd.fin import PyBasisPoint, PyPercentage    # raw Python values

ScalarQuery

NameSortCallMeaning
BasisPointscalar_queryBasisPoint()A basis-point count as a Form - 1/100th of a percent (500 = 5%).
Percentagescalar_queryPercentage()A percentage as a Form (75.5 = 75.5%).

BasisPoint

A basis-point count as a Form - 1/100th of a percent (500 = 5%).

BasisPoint()

Path nustd.fin.BasisPoint. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Build one with BasisPoint.of(500) (or from_pct / from_dec); convert with to_pct / to_dec; apply to an amount with apply / add_to / sub_from.

Methods

BasisPoint.of(value)

A basis-point count from a raw int: BasisPoint(500).

Builds BasisPoint.

Arguments

NameTypeDefaultMeaning
valueIntArg

Undocumented: example.

BasisPoint.from_pct(pct)

From a percentage: BasisPoint.from_pct(5.0) -> 500 bps.

Builds BasisPoint.

Arguments

NameTypeDefaultMeaning
pctFloatArg

Undocumented: example.

BasisPoint.from_dec(dec)

From a decimal ratio: BasisPoint.from_dec(0.05) -> 500 bps.

Builds BasisPoint.

Arguments

NameTypeDefaultMeaning
decFloatArg

Undocumented: example.

.to_pct()

The percentage (500 bps -> 5.0).

Builds Float.

Undocumented: example.

.to_dec()

The decimal ratio (500 bps -> 0.05).

Builds Float.

Undocumented: example.

.to_int()

The raw basis-point count.

Builds Int.

Undocumented: example.

.apply(amount)

This many basis points of amount.

Builds Float.

Arguments

NameTypeDefaultMeaning
amountFloatArg

Undocumented: example.

.add_to(amount)

amount grown by these basis points.

Builds Float.

Arguments

NameTypeDefaultMeaning
amountFloatArg

Undocumented: example.

.sub_from(amount)

amount reduced by these basis points.

Builds Float.

Arguments

NameTypeDefaultMeaning
amountFloatArg

Undocumented: example.

a + b

Builds BasisPoint.

Arguments

NameTypeDefaultMeaning
otherBasisPointArg

Undocumented: summary, example.

a - b

Builds BasisPoint.

Arguments

NameTypeDefaultMeaning
otherBasisPointArg

Undocumented: summary, example.

a * b

Builds BasisPoint.

Arguments

NameTypeDefaultMeaning
factorFloatArg

Undocumented: summary, example.

a / b

Builds BasisPoint.

Arguments

NameTypeDefaultMeaning
divisorFloatArg

Undocumented: summary, example.

a // b

Builds BasisPoint.

Arguments

NameTypeDefaultMeaning
divisorIntArg

Undocumented: summary, example.

a > b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherBasisPointArg

Undocumented: summary, example.

a < b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherBasisPointArg

Undocumented: summary, example.

a >= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherBasisPointArg

Undocumented: summary, example.

a <= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherBasisPointArg

Undocumented: summary, example.

.eq(other)

Whether two basis-point counts are equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherBasisPointArg

Undocumented: example.

.ne(other)

Whether two basis-point counts differ.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherBasisPointArg

Undocumented: example.

Inherited methods

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

Percentage

A percentage as a Form (75.5 = 75.5%).

Percentage()

Path nustd.fin.Percentage. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Build one with Percentage.of(75.5) (or from_dec / from_bps / from_ratio); convert with to_dec / to_bps; apply to an amount with apply / add_to / sub_from.

Methods

Percentage.of(value)

A percentage from a raw value: Percentage(75.5).

Builds Percentage.

Arguments

NameTypeDefaultMeaning
valueFloatArg

Undocumented: example.

Percentage.from_dec(dec)

From a decimal ratio: Percentage.from_dec(0.755) -> 75.5%.

Builds Percentage.

Arguments

NameTypeDefaultMeaning
decFloatArg

Undocumented: example.

Percentage.from_bps(bps)

From basis points: Percentage.from_bps(7550) -> 75.5%.

Builds Percentage.

Arguments

NameTypeDefaultMeaning
bpsIntArg

Undocumented: example.

Percentage.from_ratio(numerator, denominator)

From a ratio: Percentage.from_ratio(3, 4) -> 75%.

Builds Percentage.

Arguments

NameTypeDefaultMeaning
numeratorFloatArg
denominatorFloatArg

Undocumented: example.

.to_dec()

The decimal ratio (75.5% -> 0.755).

Builds Float.

Undocumented: example.

.to_bps()

The basis points (75.5% -> 7550).

Builds Int.

Undocumented: example.

.to_float()

The raw percentage value.

Builds Float.

Undocumented: example.

.apply(amount)

This percentage of amount.

Builds Float.

Arguments

NameTypeDefaultMeaning
amountFloatArg

Undocumented: example.

.add_to(amount)

amount grown by this percentage.

Builds Float.

Arguments

NameTypeDefaultMeaning
amountFloatArg

Undocumented: example.

.sub_from(amount)

amount reduced by this percentage.

Builds Float.

Arguments

NameTypeDefaultMeaning
amountFloatArg

Undocumented: example.

.is_valid(min_val=0.0, max_val=100.0)

Whether the value falls within [min_val, max_val].

Builds Bool.

Arguments

NameTypeDefaultMeaning
min_valfloat0.0
max_valfloat100.0

Undocumented: example.

.clamp(min_val=0.0, max_val=100.0)

This percentage clamped to [min_val, max_val].

Builds Percentage.

Arguments

NameTypeDefaultMeaning
min_valfloat0.0
max_valfloat100.0

Undocumented: example.

a + b

Builds Percentage.

Arguments

NameTypeDefaultMeaning
otherPercentageArg

Undocumented: summary, example.

a - b

Builds Percentage.

Arguments

NameTypeDefaultMeaning
otherPercentageArg

Undocumented: summary, example.

a * b

Builds Percentage.

Arguments

NameTypeDefaultMeaning
factorFloatArg

Undocumented: summary, example.

a / b

Builds Percentage.

Arguments

NameTypeDefaultMeaning
divisorFloatArg

Undocumented: summary, example.

-a

Builds Percentage.

Undocumented: summary, example.

a > b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherPercentageArg

Undocumented: summary, example.

a < b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherPercentageArg

Undocumented: summary, example.

a >= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherPercentageArg

Undocumented: summary, example.

a <= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherPercentageArg

Undocumented: summary, example.

.eq(other)

Whether two percentages are equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherPercentageArg

Undocumented: example.

.ne(other)

Whether two percentages differ.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherPercentageArg

Undocumented: example.

Inherited methods

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

On this page