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:
- A simple ticker hold (ticker + optional strategy)
- A strategy with portions (balancer managing sub-allocations)
- A mix of both
Fields§
§strategy: StrategyTypeThe 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
impl Allocation
Sourcepub fn balancer(portions: Vec<AllocationPortion>) -> Self
pub fn balancer(portions: Vec<AllocationPortion>) -> Self
Creates a new balancer allocation with portions.
Sourcepub fn from_simple(allocations: &[(String, Decimal)]) -> Self
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 40Becomes a balancer with hold portions.
Sourcepub fn from_map(allocations: HashMap<String, Decimal>) -> Self
pub fn from_map(allocations: HashMap<String, Decimal>) -> Self
Creates an allocation from a HashMap of ticker -> percentage.
Sourcepub fn set_param(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set_param(&mut self, key: impl Into<String>, value: impl Into<String>)
Sets a strategy parameter.
Sourcepub fn add_portion(&mut self, portion: AllocationPortion)
pub fn add_portion(&mut self, portion: AllocationPortion)
Adds a portion to the allocation.
Sourcepub fn is_balancer(&self) -> bool
pub fn is_balancer(&self) -> bool
Returns true if this is a balancer strategy.
Sourcepub fn all_tickers(&self) -> Vec<String>
pub fn all_tickers(&self) -> Vec<String>
Returns all tickers involved in this allocation (recursively).
Sourcepub fn total_percentage(&self) -> Decimal
pub fn total_percentage(&self) -> Decimal
Calculates the total percentage of all portions.
Trait Implementations§
Source§impl Clone for Allocation
impl Clone for Allocation
Source§impl Debug for Allocation
impl Debug for Allocation
Source§impl Default for Allocation
impl Default for Allocation
Source§impl<'de> Deserialize<'de> for Allocation
impl<'de> Deserialize<'de> for Allocation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<DesiredAllocation> for Allocation
Converts a DesiredAllocation to the new Allocation format.
impl From<DesiredAllocation> for Allocation
Converts a DesiredAllocation to the new Allocation format.