Add suspended and ST data helpers
This commit is contained in:
@@ -947,6 +947,18 @@ impl DataSet {
|
||||
self.calendar.next_trading_date(date, n)
|
||||
}
|
||||
|
||||
pub fn is_suspended_flags(&self, date: NaiveDate, symbol: &str, count: usize) -> Vec<bool> {
|
||||
self.historical_daily_flags(date, symbol, count, |candidate, market| {
|
||||
candidate.is_some_and(|row| row.is_paused) || market.is_some_and(|row| row.paused)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_st_stock_flags(&self, date: NaiveDate, symbol: &str, count: usize) -> Vec<bool> {
|
||||
self.historical_daily_flags(date, symbol, count, |candidate, _| {
|
||||
candidate.is_some_and(|row| row.is_st)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn price(&self, date: NaiveDate, symbol: &str, field: PriceField) -> Option<f64> {
|
||||
let snapshot = self.market(date, symbol)?;
|
||||
Some(snapshot.price(field))
|
||||
@@ -1047,6 +1059,36 @@ impl DataSet {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn historical_daily_flags<F>(
|
||||
&self,
|
||||
date: NaiveDate,
|
||||
symbol: &str,
|
||||
count: usize,
|
||||
evaluator: F,
|
||||
) -> Vec<bool>
|
||||
where
|
||||
F: Fn(Option<&CandidateEligibility>, Option<&DailyMarketSnapshot>) -> bool,
|
||||
{
|
||||
if count == 0 {
|
||||
return Vec::new();
|
||||
}
|
||||
let days = self
|
||||
.calendar
|
||||
.iter()
|
||||
.filter(|day| *day <= date)
|
||||
.collect::<Vec<_>>();
|
||||
let start = days.len().saturating_sub(count);
|
||||
days[start..]
|
||||
.iter()
|
||||
.map(|day| {
|
||||
evaluator(
|
||||
self.candidate_index.get(&(*day, symbol.to_string())),
|
||||
self.market_index.get(&(*day, symbol.to_string())),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn market_decision_close(&self, date: NaiveDate, symbol: &str) -> Option<f64> {
|
||||
self.market_series_by_symbol
|
||||
.get(symbol)
|
||||
|
||||
Reference in New Issue
Block a user