1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
4pub enum ProcessType {
5 #[default]
6 GeometricBrownianMotion,
7 OrnsteinUhlenbeck,
8 CoxIngersollRoss,
9 Heston,
10 MertonJumpDiffusion,
11 Hawkes,
12 Custom(String),
13}
14
15impl ProcessType {
16 pub fn as_key(&self) -> String {
17 match self {
18 Self::GeometricBrownianMotion => "GBM".to_string(),
19 Self::OrnsteinUhlenbeck => "OU".to_string(),
20 Self::CoxIngersollRoss => "CIR".to_string(),
21 Self::Heston => "Heston".to_string(),
22 Self::MertonJumpDiffusion => "MertonJD".to_string(),
23 Self::Hawkes => "Hawkes".to_string(),
24 Self::Custom(s) => sanitize_string(s),
25 }
26 }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
30pub enum OrderBookType {
31 #[default]
32 ConstantLiquidity,
33 LinearImpact,
34 ExponentialImpact,
35 Custom(String),
36}
37
38impl OrderBookType {
39 pub fn as_key(&self) -> String {
40 match self {
41 Self::ConstantLiquidity => "ConstLiq".to_string(),
42 Self::LinearImpact => "LinImp".to_string(),
43 Self::ExponentialImpact => "ExpImp".to_string(),
44 Self::Custom(s) => sanitize_string(s),
45 }
46 }
47}
48
49#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
50pub struct ModelIdentifier {
51 pub process: ProcessType,
52 pub order_book: OrderBookType,
53 pub version: String,
54 pub tags: Vec<String>,
55}
56
57impl ModelIdentifier {
58 pub fn new(process: ProcessType, order_book: OrderBookType, version: &str) -> Self {
59 Self {
60 process,
61 order_book,
62 version: version.to_string(),
63 tags: Vec::new(),
64 }
65 }
66
67 pub fn with_tag(mut self, tag: &str) -> Self {
68 self.tags.push(tag.to_string());
69 self
70 }
71
72 pub fn to_filename(&self) -> String {
73 let p_str = self.process.as_key();
74 let ob_str = self.order_book.as_key();
75 let v_str = sanitize_string(&self.version);
76
77 let mut name = format!("{}_{}_{}", p_str, ob_str, v_str);
78
79 if !self.tags.is_empty() {
80 let tags_str = self
81 .tags
82 .iter()
83 .map(|t| sanitize_string(t))
84 .collect::<Vec<_>>()
85 .join("-");
86 name.push('_');
87 name.push_str(&tags_str);
88 }
89
90 name.push_str(".bin");
91 name
92 }
93}
94
95fn sanitize_string(s: &str) -> String {
96 s.chars()
97 .map(|c| {
98 if c.is_alphanumeric() || c == '-' || c == '.' {
99 c
100 } else {
101 '_'
102 }
103 })
104 .collect()
105}