MCPcopy Create free account
hub / github.com/Open-Quant/openquant / load_rows

Function load_rows

crates/openquant/tests/futures_roll.rs:22–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22fn load_rows() -> Vec<FuturesRollRow> {
23 let open_path = fixture_dir().join("open_df.csv");
24 let close_path = fixture_dir().join("close_df.csv");
25
26 let mut open_rdr = ReaderBuilder::new().has_headers(true).from_path(open_path).unwrap();
27 let mut close_rdr = ReaderBuilder::new().has_headers(true).from_path(close_path).unwrap();
28
29 let opens: Vec<OpenRow> = open_rdr.deserialize().map(|r| r.unwrap()).collect();
30 let closes: Vec<CloseRow> = close_rdr.deserialize().map(|r| r.unwrap()).collect();
31 assert_eq!(opens.len(), closes.len());
32
33 let roll_1 = NaiveDate::from_ymd_opt(2017, 3, 20).unwrap();
34 let roll_2 = NaiveDate::from_ymd_opt(2018, 1, 17).unwrap();
35
36 let mut rows = Vec::with_capacity(opens.len());
37 for (o, c) in opens.into_iter().zip(closes) {
38 assert_eq!(o.date, c.date);
39 let date = NaiveDate::parse_from_str(&o.date, "%Y-%m-%d").unwrap();
40 let current = if date <= roll_1 {
41 "futures_1"
42 } else if date <= roll_2 {
43 "futures_2"
44 } else {
45 "futures_3"
46 };
47 rows.push(FuturesRollRow {
48 date,
49 open: o.spx,
50 close: c.spx,
51 security: current.to_string(),
52 current_security: current.to_string(),
53 });
54 }
55 rows
56}
57
58fn unique_count(v: &[f64]) -> usize {
59 let mut uniq: Vec<f64> = Vec::new();

Callers 1

test_futures_rollFunction · 0.85

Calls 2

lenMethod · 0.80
fixture_dirFunction · 0.70

Tested by

no test coverage detected