mirror of
https://github.com/Magnus167/msyrs.git
synced 2025-11-20 02:36:09 +00:00
add Python wrapper for downloading JPMaQS indicators as DataFrame
This commit is contained in:
@@ -368,3 +368,41 @@ fn save_indicators_list_as_csvs(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Function to download the JPMaQS tickers as a DataFrame. Solely exists to allow for a simpler
|
||||
/// Python wrapper for downloading JPMaQS data.
|
||||
pub fn download_jpmaqs_indicators_as_df(
|
||||
client_id: String,
|
||||
client_secret: String,
|
||||
tickers: Vec<String>,
|
||||
metrics: Option<Vec<String>>,
|
||||
start_date: Option<String>,
|
||||
end_date: Option<String>,
|
||||
) -> Result<polars::prelude::DataFrame, Box<dyn Error>> {
|
||||
let metrics = metrics.unwrap_or_else(|| {
|
||||
DEFAULT_JPMAQS_METRICS
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect()
|
||||
});
|
||||
|
||||
// if metrics== "ALL", then use the default metrics
|
||||
let metrics = if metrics.len() == 1 && metrics[0] == "ALL" {
|
||||
DEFAULT_JPMAQS_METRICS
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect()
|
||||
} else {
|
||||
metrics
|
||||
};
|
||||
|
||||
let mut jpamqs_download = JPMaQSDownload::new(client_id, client_secret);
|
||||
let download_args = JPMaQSDownloadGetIndicatorArgs {
|
||||
tickers: tickers,
|
||||
metrics: metrics,
|
||||
start_date: start_date.unwrap_or("1990-01-01".to_string()),
|
||||
end_date: end_date.unwrap_or("TODAY+2D".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
jpamqs_download.get_indicators_qdf(download_args)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user