支持原生回测事实存储

This commit is contained in:
boris
2026-08-25 05:32:18 +08:00
parent 24e4ac9284
commit 2a6bbb82a6
2 changed files with 22 additions and 6 deletions
+11 -3
View File
@@ -1,7 +1,7 @@
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use chrono::{Datelike, Duration, NaiveDate, NaiveTime, Timelike}; use chrono::{Datelike, Duration, NaiveDate, NaiveTime, Timelike};
use serde::Serialize; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
use crate::broker::{BrokerExecutionReport, BrokerSimulator, MatchingType}; use crate::broker::{BrokerExecutionReport, BrokerSimulator, MatchingType};
@@ -71,7 +71,7 @@ impl Default for FuturesValidationConfig {
} }
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DailyEquityPoint { pub struct DailyEquityPoint {
#[serde(with = "date_format")] #[serde(with = "date_format")]
pub date: NaiveDate, pub date: NaiveDate,
@@ -4217,7 +4217,7 @@ fn futures_cancel_report(
mod date_format { mod date_format {
use chrono::NaiveDate; use chrono::NaiveDate;
use serde::Serializer; use serde::{Deserialize, Deserializer, Serializer};
const FORMAT: &str = "%Y-%m-%d"; const FORMAT: &str = "%Y-%m-%d";
@@ -4227,6 +4227,14 @@ mod date_format {
{ {
serializer.serialize_str(&date.format(FORMAT).to_string()) serializer.serialize_str(&date.format(FORMAT).to_string())
} }
pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDate, D::Error>
where
D: Deserializer<'de>,
{
let value = String::deserialize(deserializer)?;
NaiveDate::parse_from_str(&value, FORMAT).map_err(serde::de::Error::custom)
}
} }
#[cfg(test)] #[cfg(test)]
+11 -3
View File
@@ -1,6 +1,6 @@
use chrono::NaiveDate; use chrono::NaiveDate;
use indexmap::IndexMap; use indexmap::IndexMap;
use serde::Serialize; use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use crate::data::{DataSet, DataSetError, PriceField}; use crate::data::{DataSet, DataSetError, PriceField};
@@ -1692,7 +1692,7 @@ mod tests {
} }
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HoldingSummary { pub struct HoldingSummary {
#[serde(with = "date_format")] #[serde(with = "date_format")]
pub date: NaiveDate, pub date: NaiveDate,
@@ -1730,7 +1730,7 @@ pub struct CashReceivable {
mod date_format { mod date_format {
use chrono::NaiveDate; use chrono::NaiveDate;
use serde::Serializer; use serde::{Deserialize, Deserializer, Serializer};
const FORMAT: &str = "%Y-%m-%d"; const FORMAT: &str = "%Y-%m-%d";
@@ -1740,6 +1740,14 @@ mod date_format {
{ {
serializer.serialize_str(&date.format(FORMAT).to_string()) serializer.serialize_str(&date.format(FORMAT).to_string())
} }
pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDate, D::Error>
where
D: Deserializer<'de>,
{
let value = String::deserialize(deserializer)?;
NaiveDate::parse_from_str(&value, FORMAT).map_err(serde::de::Error::custom)
}
} }
fn round_half_up_u32(value: f64) -> u32 { fn round_half_up_u32(value: f64) -> u32 {