Skip to main content

Allocation

Struct Allocation 

Source
pub struct Allocation {
    pub strategy: StrategyType,
    pub ticker: Option<String>,
    pub portions: Vec<AllocationPortion>,
    pub params: HashMap<String, String>,
}
Expand description

A recursive allocation structure supporting nested strategies.

An allocation can be:

  1. A simple ticker hold (ticker + optional strategy)
  2. A strategy with portions (balancer managing sub-allocations)
  3. A mix of both

Fields§

§strategy: StrategyType

The strategy to use for this allocation.

§ticker: Option<String>

The ticker symbol (for hold/scalper strategies).

§portions: Vec<AllocationPortion>

Child portions (for balancer strategy).

§params: HashMap<String, String>

Strategy-specific parameters.

Implementations§

Source§

impl Allocation

Source

pub fn new() -> Self

Creates a new empty allocation with default balancer strategy.

Source

pub fn balancer(portions: Vec<AllocationPortion>) -> Self

Creates a new balancer allocation with portions.

Source

pub fn hold(ticker: impl Into<String>) -> Self

Creates a simple hold allocation for a ticker.

Source

pub fn scalper(ticker: impl Into<String>) -> Self

Creates a scalper allocation for a ticker.

Source

pub fn from_simple(allocations: &[(String, Decimal)]) -> Self

Creates a simple allocation from ticker-percentage pairs.

This is the “short notation” equivalent where:

allocation
  SBER 30
  LKOH 30
  GAZP 40

Becomes a balancer with hold portions.

Source

pub fn from_map(allocations: HashMap<String, Decimal>) -> Self

Creates an allocation from a HashMap of ticker -> percentage.

Source

pub fn set_param(&mut self, key: impl Into<String>, value: impl Into<String>)

Sets a strategy parameter.

Source

pub fn get_param(&self, key: &str) -> Option<&str>

Gets a strategy parameter.

Source

pub fn add_portion(&mut self, portion: AllocationPortion)

Adds a portion to the allocation.

Source

pub fn is_hold(&self) -> bool

Returns true if this is a simple hold strategy.

Source

pub fn is_balancer(&self) -> bool

Returns true if this is a balancer strategy.

Source

pub fn all_tickers(&self) -> Vec<String>

Returns all tickers involved in this allocation (recursively).

Source

pub fn total_percentage(&self) -> Decimal

Calculates the total percentage of all portions.

Source

pub fn is_valid(&self) -> bool

Validates that portions sum to approximately 100%.

Source

pub fn normalize(&mut self)

Normalizes portions to sum to exactly 100%.

Source

pub fn flatten(&self) -> HashMap<String, Decimal>

Flattens the allocation to a simple ticker -> percentage map.

This recursively expands all nested allocations and calculates the effective percentage for each ticker.

Trait Implementations§

Source§

impl Clone for Allocation

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Allocation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Allocation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Allocation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<DesiredAllocation> for Allocation

Converts a DesiredAllocation to the new Allocation format.

Source§

fn from(desired: DesiredAllocation) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Allocation

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Allocation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Allocation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more