Count fraction: private API
PortfolioOptimisers.count_or_fraction — Function
count_or_fraction(x::Option{<:UnresolvedValue})
count_or_fraction(x::Integer)
count_or_fraction(x::Real)Return the AbstractCountOrFraction that a field of a part of a set holds, or the value that the field holds in its place.
The constructor of each such field calls this function, so a plain number becomes a CountOf or a FractionOf, and each reader dispatches on the two members alone. A plain number is the shorthand of AbstractCountOrFraction: the type of the number selects the member.
The function is a repair at a constructor, so it returns unchanged each value that needs no repair: nothing, a member of the family, a rule or a function that computes the part, and a TimeDependent schedule. Each of these is an UnresolvedValue or nothing. Each other type is a MethodError.
Algorithm
- Return
nothing, a member of the family, or anotherUnresolvedValueunchanged. - Return
CountOf(x)for anInteger.Boolis anInteger, sotrueis a count of one. - Refuse
x == 1for any other real number. ReturnFractionOf(x)otherwise.
Validation
- A plain real number that is not an
Integerand equals one throws aDomainError. A search grid promotes the count1to1.0, and the whole set is a different part. StateCountOf(1)orFractionOf(1.0). - The constructors of
CountOfandFractionOfcheck the range.
Returns
x::Option{<:UnresolvedValue}: ACountOffor anInteger, aFractionOffor each other real number, andxunchanged otherwise.
Examples
julia> PortfolioOptimisers.count_or_fraction(3)CountOf val ┴ Int64: 3julia> PortfolioOptimisers.count_or_fraction(0.2)FractionOf val ┴ Float64: 0.2Related
PortfolioOptimisers.Real_CountFraction — Type
const Real_CountFraction = Union{Real, AbstractCountOrFraction}Alias for every value that a field of a part of a set accepts: a plain number, which count_or_fraction reads by its type, or a member of AbstractCountOrFraction.
Related