Liking cljdoc? Tell your friends :D

linopt-commons-math3.constraints

Generic constraint builders over a universe (a seq of items - maps, or anything get works on - in the same order as the LP variables they represent).

Every builder returns a FLAT sequence: linopt-commons-math3.solver /linear-optimization reads its constraints argument as one flat run of coeffs relation rhs coeffs relation rhs ... (it groups every 3 elements itself). Builder outputs are safe to concat together directly - flat seqs concatenated stay flat, so composing several constraints needs no extra flattening step.

Nothing here knows what an item represents - callers supply the key/column names and grouping/weighting functions. Domain rules (rating buckets, issuer tiers, benchmark composition, ...) are composed from these.

Generic constraint builders over a `universe` (a seq of items - maps, or
anything `get` works on - in the same order as the LP variables they
represent).

Every builder returns a FLAT sequence: `linopt-commons-math3.solver
/linear-optimization` reads its `constraints` argument as one flat run of
`coeffs relation rhs coeffs relation rhs ...` (it groups every 3 elements
itself). Builder outputs are safe to `concat` together directly - flat
seqs concatenated stay flat, so composing several constraints needs no
extra flattening step.

Nothing here knows what an item represents - callers supply the key/column
names and grouping/weighting functions. Domain rules (rating buckets,
issuer tiers, benchmark composition, ...) are composed from these.
raw docstring

benchmark-relative-average-constraintclj

(benchmark-relative-average-constraint universe-coll
                                       bench-coll
                                       weight-fn
                                       value-fn
                                       ow-uw)
(benchmark-relative-average-constraint universe-coll
                                       bench-coll
                                       weight-fn
                                       value-fn
                                       ow-uw
                                       total-weight)

±ow-uw band around the benchmark's weight-weighted average of value-fn (e.g. duration, beta). bench-coll/weight-fn compute the benchmark average; the LP coefficients are value-fn applied to universe-coll.

The LP variables are weights on some total scale (e.g. 0-100 NAV%, or the invested 100-minus-cash if some weight is held back); total-weight is that scale (default 1.0, i.e. weights already sum to 1), needed because sum(value_i * weight_i) = bench-avg * total-weight at the true benchmark average, not bench-avg itself.

`±ow-uw` band around the benchmark's weight-weighted average of `value-fn`
(e.g. duration, beta). `bench-coll`/`weight-fn` compute the benchmark
average; the LP coefficients are `value-fn` applied to `universe-coll`.

The LP variables are weights on some total scale (e.g. 0-100 NAV%, or the
invested 100-minus-cash if some weight is held back); `total-weight` is
that scale (default `1.0`, i.e. weights already sum to 1), needed because
`sum(value_i * weight_i) = bench-avg * total-weight` at the true benchmark
average, not `bench-avg` itself.
sourceraw docstring

benchmark-relative-group-constraintclj

(benchmark-relative-group-constraint universe-coll
                                     bench-coll
                                     weight-fn
                                     group-key-fn
                                     ow-uw)

Per-group ±ow-uw band around each group's benchmark weight. The LP coefficient vectors run over universe-coll (the investable/LP variables); the benchmark weight for each group is computed over bench-coll (the reference universe, via weight-fn/group-key-fn). Only groups that have at least one investable item are constrained - a group with benchmark weight but no investable item can't be held, so a positive lower bound for it would be infeasible.

Per-group `±ow-uw` band around each group's benchmark weight. The LP
coefficient vectors run over `universe-coll` (the investable/LP variables);
the benchmark weight for each group is computed over `bench-coll` (the
reference universe, via `weight-fn`/`group-key-fn`). Only groups that have
at least one investable item are constrained - a group with benchmark
weight but no investable item can't be held, so a positive lower bound for
it would be infeasible.
sourceraw docstring

benchmark-weights-byclj

(benchmark-weights-by bench-coll weight-fn group-key-fn)

Sum weight-fn over bench-coll (the reference/true-index universe), grouped by group-key-fn. Feeds benchmark-relative-group-constraint.

Sum `weight-fn` over `bench-coll` (the reference/true-index universe),
grouped by `group-key-fn`. Feeds `benchmark-relative-group-constraint`.
sourceraw docstring

group-constraintclj

(group-constraint universe group-key target-value [mn mx])

Band constraint [min max] on the summed weight of items where (get item group-key) equals target-value.

Band constraint `[min max]` on the summed weight of items where
`(get item group-key)` equals `target-value`.
sourceraw docstring

grouped-cap-constraintclj

(grouped-cap-constraint universe group-key-fn cap-fn)

Per-group upper bound, e.g. an issuer/ticker concentration limit where the cap itself depends on the group (rating, sector, ...).

group-key-fn maps an item to its group. cap-fn receives [group items] (all items in that group) and returns that group's max weight, or nil to skip the constraint entirely for that group.

Per-group upper bound, e.g. an issuer/ticker concentration limit where the
cap itself depends on the group (rating, sector, ...).

`group-key-fn` maps an item to its group. `cap-fn` receives `[group items]`
(all items in that group) and returns that group's max weight, or nil to
skip the constraint entirely for that group.
sourceraw docstring

position-boundsclj

(position-bounds n mn mx)

Per-item [min max] bound on each of the n variables. mn/mx can be nil to skip that side - e.g. pass nil for mn when the solver already gets :non-negative? true, so a redundant >= 0 row (and its n-long coefficient array) is never allocated instead of being built and later dropped by the solver.

Per-item `[min max]` bound on each of the `n` variables. `mn`/`mx` can be
`nil` to skip that side - e.g. pass `nil` for `mn` when the solver already
gets `:non-negative? true`, so a redundant `>= 0` row (and its `n`-long
coefficient array) is never allocated instead of being built and later
dropped by the solver.
sourceraw docstring

predicate-constraintclj

(predicate-constraint universe pred rel target)

Single one-sided constraint on the summed weight of items matching pred (an arbitrary item predicate): sum(weight_i : pred(item_i)) rel target. Generalizes rating-bucket / flag-style caps that group-constraint can't express because membership isn't a single equality check. For a band on both sides, concat two calls (one :<=, one :>=).

Single one-sided constraint on the summed weight of items matching `pred`
(an arbitrary item predicate): `sum(weight_i : pred(item_i)) rel target`.
Generalizes rating-bucket / flag-style caps that `group-constraint` can't
express because membership isn't a single equality check. For a band on
both sides, concat two calls (one `:<=`, one `:>=`).
sourceraw docstring

sum-constraintclj

(sum-constraint n target)

Sum of all n variables equals target.

Sum of all `n` variables equals `target`.
sourceraw docstring

value-band-constraintclj

(value-band-constraint universe value-key [mn mx])

Band constraint [min max] on the sum of (get item value-key) across universe (e.g. a weight-weighted duration/beta, where each item's LP coefficient IS its per-unit value).

Band constraint `[min max]` on the sum of `(get item value-key)` across
`universe` (e.g. a weight-weighted duration/beta, where each item's LP
coefficient IS its per-unit value).
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close