pub struct RebalancingEngine { /* private fields */ }Expand description
Rebalancing engine
Implementations§
Source§impl RebalancingEngine
impl RebalancingEngine
pub fn new() -> Self
pub fn initialize(&mut self) -> Result<(), FinancialError>
Sourcepub fn register_strategy(&mut self, strategy: RebalancingStrategy)
pub fn register_strategy(&mut self, strategy: RebalancingStrategy)
Register a rebalancing strategy, keyed by strategy.strategy_id.
Sourcepub fn get_strategy(&self, strategy_id: &str) -> Option<&RebalancingStrategy>
pub fn get_strategy(&self, strategy_id: &str) -> Option<&RebalancingStrategy>
Look up a registered strategy by id.
Sourcepub fn calculate_drift(portfolio: &Portfolio) -> HashMap<String, f64>
pub fn calculate_drift(portfolio: &Portfolio) -> HashMap<String, f64>
Compute the current portfolio weights (market_value / total) keyed by
asset_id. These are the “drifted” weights that rebalance compares
against a strategy’s target_weights. Returns an empty map when the
portfolio has no positive market value.
Sourcepub fn rebalance(
&self,
portfolio: &mut Portfolio,
strategy: &RebalancingStrategy,
) -> Result<Vec<RebalanceTrade>, FinancialError>
pub fn rebalance( &self, portfolio: &mut Portfolio, strategy: &RebalancingStrategy, ) -> Result<Vec<RebalanceTrade>, FinancialError>
Compute drift against strategy.target_weights and, for any asset whose
drift exceeds strategy.parameters.deviation_threshold, generate a
RebalanceTrade that would move the asset back to its target weight.
Trades are sized in units: quantity = |target_value − current_value| / current_price, where target_value = target_weight · total_value. The
portfolio is not mutated by this method — it only proposes trades;
applying them (and their costs) is the execution layer’s job.
Auto Trait Implementations§
impl Freeze for RebalancingEngine
impl RefUnwindSafe for RebalancingEngine
impl Send for RebalancingEngine
impl Sync for RebalancingEngine
impl Unpin for RebalancingEngine
impl UnsafeUnpin for RebalancingEngine
impl UnwindSafe for RebalancingEngine
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more