use serde::{Deserialize, Serialize};
use crate::{
error::ChapatyResult,
gym::trading::{action::Actions, observation::Observation},
impl_add_sub_mul_div_primitive, impl_from_primitive,
};
pub mod trading;
pub trait Env {
fn reset(&mut self) -> ChapatyResult<(Observation<'_>, Reward, StepOutcome)>;
fn step(&mut self, actions: Actions) -> ChapatyResult<(Observation<'_>, Reward, StepOutcome)>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Reward(pub i64);
impl_from_primitive!(Reward, i64);
impl_add_sub_mul_div_primitive!(Reward, i64);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EnvStatus {
Ready,
Running,
EpisodeDone,
Done,
}
impl EnvStatus {
pub fn is_ready(&self) -> bool {
matches!(self, Self::Ready)
}
pub fn is_running(&self) -> bool {
matches!(self, Self::Running)
}
pub fn is_episode_done(&self) -> bool {
matches!(self, Self::EpisodeDone)
}
pub fn is_done(&self) -> bool {
matches!(self, Self::Done)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StepOutcome {
InProgress,
Terminated,
Truncated,
Done,
}
impl StepOutcome {
pub fn is_done(&self) -> bool {
matches!(self, Self::Done)
}
pub fn is_terminated(&self) -> bool {
matches!(self, Self::Terminated)
}
pub fn is_truncated(&self) -> bool {
matches!(self, Self::Truncated)
}
pub fn is_terminal(&self) -> bool {
self.is_terminated() || self.is_truncated()
}
}