Add string factor support

This commit is contained in:
boris
2026-04-23 23:05:43 -07:00
parent 0b0b9333fa
commit 47988cd7e7
6 changed files with 587 additions and 31 deletions

View File

@@ -8,8 +8,9 @@ use chrono::{Datelike, Duration, NaiveDate, NaiveDateTime, NaiveTime};
use crate::cost::ChinaAShareCostModel;
use crate::data::{
DailyMarketSnapshot, DataSet, DividendRecord, FactorValue, IntradayExecutionQuote, PriceBar,
PriceField, SecuritiesMarginRecord, SplitRecord, YieldCurvePoint,
DailyMarketSnapshot, DataSet, DividendRecord, FactorTextValue, FactorValue,
IntradayExecutionQuote, PriceBar, PriceField, SecuritiesMarginRecord, SplitRecord,
YieldCurvePoint,
};
use crate::engine::BacktestError;
use crate::events::{FillEvent, OrderEvent, OrderSide, OrderStatus, ProcessEvent};
@@ -630,6 +631,16 @@ impl StrategyContext<'_> {
self.data.get_factor(symbol, start, end, field)
}
pub fn get_factor_text(
&self,
symbol: &str,
start: NaiveDate,
end: NaiveDate,
field: &str,
) -> Vec<FactorTextValue> {
self.data.get_factor_text(symbol, start, end, field)
}
pub fn get_yield_curve(
&self,
start: NaiveDate,
@@ -738,6 +749,16 @@ impl StrategyContext<'_> {
.get_industry(symbol, self.execution_date, source, level)
}
pub fn get_industry_name(
&self,
symbol: &str,
source: &str,
level: usize,
) -> Option<FactorTextValue> {
self.data
.get_industry_name(symbol, self.execution_date, source, level)
}
pub fn get_dominant_future(&self, underlying_symbol: &str) -> Option<String> {
self.data
.get_dominant_future(underlying_symbol, self.execution_date)