Add RQData factor helper APIs

This commit is contained in:
boris
2026-04-23 22:04:55 -07:00
parent f056aa3468
commit 882053e12b
6 changed files with 704 additions and 5 deletions

View File

@@ -205,6 +205,10 @@ fn two_day_futures_data() -> DataSet {
("custom_alpha".to_string(), 7.0),
("margin_all".to_string(), 1.0),
("yield_curve_1y".to_string(), 0.02),
("total_shares".to_string(), 123.0),
("stock_connect_north_bound".to_string(), 1.0),
("industry_citics_l1".to_string(), 10.0),
("fundamental_net_profit".to_string(), 99.0),
]),
),
factor_row(
@@ -214,6 +218,10 @@ fn two_day_futures_data() -> DataSet {
("custom_alpha".to_string(), 8.0),
("margin_all".to_string(), 1.0),
("yield_curve_1y".to_string(), 0.021),
("total_shares".to_string(), 124.0),
("stock_connect_north_bound".to_string(), 1.0),
("industry_citics_l1".to_string(), 10.0),
("fundamental_net_profit".to_string(), 101.0),
]),
),
],
@@ -556,13 +564,44 @@ impl Strategy for AdvancedDataApiProbeStrategy {
let dominant = ctx.get_dominant_future("IF").unwrap_or_default();
let dominant_prices =
ctx.get_dominant_future_price("IF", ctx.execution_date, ctx.execution_date, "1d");
let shares = ctx.get_shares("000001.SZ", ctx.execution_date, ctx.execution_date, "total");
let turnover = ctx.get_turnover_rate(
"000001.SZ",
ctx.execution_date,
ctx.execution_date,
"turnover",
);
let price_change =
ctx.get_price_change_rate("000001.SZ", ctx.execution_date, ctx.execution_date);
let stock_connect = ctx.get_stock_connect(
"000001.SZ",
ctx.execution_date,
ctx.execution_date,
"north_bound",
);
let industry = ctx
.get_industry("000001.SZ", "citics", 1)
.map(|row| row.value)
.unwrap_or_default();
let fundamentals = ctx.get_fundamentals(
"000001.SZ",
ctx.execution_date,
ctx.execution_date,
"net_profit",
);
self.observed.borrow_mut().push(format!(
"factor={:.0};margin={};yield={:.3};dominant={};prices={}",
"factor={:.0};margin={};yield={:.3};dominant={};prices={};shares={:.0};turnover={:.1};change={:.3};connect={:.0};industry={:.0};profit={:.0}",
factors.first().map(|row| row.value).unwrap_or_default(),
margin_stocks.join(","),
yield_curve.first().map(|row| row.value).unwrap_or_default(),
dominant,
dominant_prices.len()
dominant_prices.len(),
shares.first().map(|row| row.value).unwrap_or_default(),
turnover.first().map(|row| row.value).unwrap_or_default(),
price_change.first().map(|row| row.value).unwrap_or_default(),
stock_connect.first().map(|row| row.value).unwrap_or_default(),
industry,
fundamentals.first().map(|row| row.value).unwrap_or_default()
));
Ok(StrategyDecision::default())
}
@@ -1857,7 +1896,9 @@ fn strategy_context_exposes_advanced_rqdata_helpers() {
assert_eq!(
observed.borrow().as_slice(),
&["factor=7;margin=000001.SZ;yield=0.020;dominant=IF2501;prices=1"]
&[
"factor=7;margin=000001.SZ;yield=0.020;dominant=IF2501;prices=1;shares=123;turnover=1.0;change=0.000;connect=1;industry=10;profit=99"
]
);
assert!(result.analyzer_report().positions.is_empty());
}