mirror of
https://github.com/Magnus167/msyrs.git
synced 2025-08-20 13:00:01 +00:00
Add documentation comments for ticker-related functions
This commit is contained in:
parent
1dd82e0b23
commit
ed9b0c2e0f
@ -3,6 +3,7 @@ use polars::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error;
|
||||
|
||||
/// Split a ticker string into `cid` and `xcat`.
|
||||
pub fn split_ticker(ticker: String) -> Result<(String, String), Box<dyn Error>> {
|
||||
// split by the first underscore character. return the first and second parts.
|
||||
let parts: Vec<&str> = ticker.splitn(2, '_').collect();
|
||||
@ -12,6 +13,7 @@ pub fn split_ticker(ticker: String) -> Result<(String, String), Box<dyn Error>>
|
||||
Ok((parts[0].to_string(), parts[1].to_string()))
|
||||
}
|
||||
|
||||
/// Get the minimum and maximum dates from a date column in a DataFrame.
|
||||
pub fn get_min_max_real_dates(
|
||||
df: &DataFrame,
|
||||
date_col: &str,
|
||||
@ -41,20 +43,24 @@ pub fn get_min_max_real_dates(
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the `cid` from a ticker string.
|
||||
#[allow(dead_code)]
|
||||
pub fn get_cid(ticker: String) -> Result<String, Box<dyn Error>> {
|
||||
split_ticker(ticker).map(|(cid, _)| cid)
|
||||
}
|
||||
|
||||
/// Get the `xcat` from a ticker string.
|
||||
#[allow(dead_code)]
|
||||
pub fn get_xcat(ticker: String) -> Result<String, Box<dyn Error>> {
|
||||
split_ticker(ticker).map(|(_, xcat)| xcat)
|
||||
}
|
||||
|
||||
/// Get the `cid` and `xcat` from a ticker string.
|
||||
pub fn create_ticker(cid: &str, xcat: &str) -> String {
|
||||
format!("{}_{}", cid, xcat)
|
||||
}
|
||||
|
||||
/// Create all possible tickers from a list of `cids` and `xcats`.
|
||||
pub fn create_intersecting_tickers(cids: &[&str], xcats: &[&str]) -> Vec<String> {
|
||||
let mut tickers = Vec::new();
|
||||
for cid in cids {
|
||||
|
Loading…
x
Reference in New Issue
Block a user