Count fraction
PortfolioOptimisers.AbstractCountOrFraction — Type
abstract type AbstractCountOrFraction <: AbstractAlgorithmAbstract supertype for the two forms of the size of a part of a set: a CountOf of its members and a FractionOf of the set.
A field that takes a part of a set holds one of the two members, such as the assets that a subset draws, the rows of a window or the neighbours of a period. The type of the member selects the reading, and the type of the number inside it does not. Julia promotes the elements of a vector literal to one type, so a search grid can turn the plain count 3 into 3.0. A CountOf(3) keeps its type in the same grid.
A member checks its value and does no rounding. The size of the set is known only to the reader, and each reader rounds a fraction of its own set by the rule of its source. So one fraction can give a different count at two sites. A reader that uses floor keeps no more than the fraction, and a reader that uses ceil keeps no less.
A field of this kind also takes a plain number, through count_or_fraction. An Integer is a count and any other real number is a fraction. The plain form is a shorthand, and the wrapper is the form to prefer. A plain 1.0 is refused, because a grid can promote the count 1 to it.
Interfaces
The family is closed. Each reader dispatches on CountOf and on FractionOf, and holds one method for each. A new member needs a method at every reader, so the library adds no member.
Related
PortfolioOptimisers.CountOf — Type
struct CountOf{T} <: AbstractCountOrFractionThe size of a part of a set, stated as a number of its members.
The reader takes val members. It clamps val to the size of the set where the set can be smaller, and the docstring of each field states whether it clamps or refuses.
Fields
val: The number of members of the set.
Constructors
CountOf(; val::Integer) -> CountOfKeywords correspond to the struct's fields. No count suits every set, so val has no default.
Validation
val >= 1. ADomainErroris thrown otherwise.
Examples
julia> CountOf(3)CountOf val ┴ Int64: 3Related
PortfolioOptimisers.FractionOf — Type
struct FractionOf{T} <: AbstractCountOrFractionThe size of a part of a set, stated as a fraction of the size of the set.
The reader multiplies val by the size of its set, and rounds the product to a count by the rule of its source. The docstring of each field states the rounding.
Fields
val: The fraction of the set, in(0, 1].
Constructors
FractionOf(; val::Real) -> FractionOfKeywords correspond to the struct's fields. No fraction suits every set, so val has no default.
Validation
0 < val <= 1. ADomainErroris thrown otherwise.val = 1is the whole set.
Examples
julia> FractionOf(0.2)FractionOf val ┴ Float64: 0.2Related