StrategyEngine

Struct StrategyEngine 

Source
pub struct StrategyEngine {
    pub strategies: Vec<Box<dyn Strategy>>,
}

Fields§

§strategies: Vec<Box<dyn Strategy>>

Implementations§

Source§

impl StrategyEngine

Source

pub fn new() -> Self

初始化策略引擎

Source

pub fn add_strategy(&mut self, strategy: Box<dyn Strategy>)

添加策略

Source

pub fn backtest(&self, prices: Vec<f64>) -> Vec<f64>

回测所有策略

Examples found in repository?
examples/solana_trader.rs (line 18)
17    pub fn determine_strategy(&mut self, prices: Vec<f64>) {
18        let results = self.engine.backtest(prices.clone());
19        let best_strategy_index = results
20            .iter()
21            .enumerate()
22            .max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap())
23            .unwrap()
24            .0;
25
26        self.current_strategy = Some(best_strategy_index);
27        println!("Best Strategy: {}", best_strategy_index + 1);
28    }
Source

pub fn calculate_indicators(&self, prices: Vec<f64>) -> Vec<f64>

计算指标

Trait Implementations§

Source§

impl Default for StrategyEngine

Source§

fn default() -> Self

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

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V