Skip to main content

TradingEnv

Struct TradingEnv 

Source
pub struct TradingEnv { /* private fields */ }
Expand description

A steppable, leak-free trading environment over a frozen dataset. The caller drives it: reset returns the first observation, then each step applies the supplied decision and advances one bar.

Implementations§

Source§

impl TradingEnv

Source

pub fn new( data: Dataset, window: Window, costs: CostModel, seed: u64, ) -> TradingEnv

Build an environment that steps window over data with seeded execution noise and the given cost model.

Source

pub fn reset(&mut self) -> MarketObservation

Reset to the start of the window and return the first point-in-time observation. Re-seeds the book, so it is safe to call repeatedly.

Source

pub fn step(&mut self, decision: Decision) -> StepResult

Apply decision at the current bar and advance one step. The returned reward is the bar’s portfolio return; done is set once the window is exhausted (further calls re-apply the final bar harmlessly).

Source

pub fn clone_state(&self) -> EnvState

Snapshot the mutable sim state (time cursor + book) in O(1) — no replay. The returned EnvState is a value: clone it, stash it, restore it later with restore_state to fork the env from this exact point (e.g. tree search / what-if rollouts over the same frozen data). The immutable config (data, window, costs, seed) is not snapshotted — it never changes — so a snapshot is cheap and a restore is exact.

Source

pub fn restore_state(&mut self, state: EnvState)

Restore a snapshot taken by clone_state: the env resumes producing the exact byte-identical trajectory it would have from the snapshot point, including seeded execution noise (the RNG cursor is part of the snapshot).

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.