mirror of
https://github.com/Magnus167/msyrs.git
synced 2025-11-19 20:26:09 +00:00
moving stuff around
This commit is contained in:
43
src/_py/download.rs
Normal file
43
src/_py/download.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use pyo3::prelude::*;
|
||||
use pyo3_polars::PyDataFrame;
|
||||
|
||||
/// Python wrapper for [`crate::utils::qdf`] module.
|
||||
#[allow(deprecated)]
|
||||
#[pymodule]
|
||||
pub fn download(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(download_jpmaqs_indicators_as_df, m)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Python wrapper for downloading JPMAQS indicators as a DataFrame.
|
||||
/// See [`crate::download::jpmaqsdownload::download_jpmaqs_indicators_as_df`] for full documentation.
|
||||
/// Arguments:
|
||||
/// - `client_id`: The client ID.
|
||||
/// - `client_secret`: The client secret.
|
||||
/// - `tickers`: The tickers.
|
||||
/// - `start_date`: The start date.
|
||||
/// - `end_date`: The end date.
|
||||
///
|
||||
/// Returns:
|
||||
/// - A standardized Quantamental DataFrame.
|
||||
#[pyfunction]
|
||||
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>,
|
||||
) -> PyResult<PyDataFrame> {
|
||||
Ok(PyDataFrame(
|
||||
crate::download::jpmaqsdownload::download_jpmaqs_indicators_as_df(
|
||||
client_id,
|
||||
client_secret,
|
||||
tickers,
|
||||
metrics,
|
||||
start_date,
|
||||
end_date,
|
||||
)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
21
src/_py/mod.rs
Normal file
21
src/_py/mod.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
/// Python wrapper for [`crate::utils::qdf`].
|
||||
pub mod qdf;
|
||||
|
||||
/// Python wrapper for [`crate::download`].
|
||||
pub mod download;
|
||||
|
||||
/// Python wrapper for [`crate::panel`].
|
||||
pub mod panel;
|
||||
|
||||
use pyo3::{prelude::*, wrap_pymodule};
|
||||
|
||||
/// PyO3 bindings for the `msyrs` Python wrapper.
|
||||
#[allow(deprecated)]
|
||||
#[pymodule]
|
||||
pub fn msyrs(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_wrapped(wrap_pymodule!(qdf::qdf))?;
|
||||
m.add_wrapped(wrap_pymodule!(download::download))?;
|
||||
m.add_wrapped(wrap_pymodule!(panel::panel))?;
|
||||
Ok(())
|
||||
}
|
||||
46
src/_py/panel.rs
Normal file
46
src/_py/panel.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use pyo3::prelude::*;
|
||||
use pyo3_polars::PyDataFrame;
|
||||
|
||||
/// Python wrapper for [`crate::panel`] module.
|
||||
#[allow(deprecated)]
|
||||
#[pymodule]
|
||||
pub fn panel(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(historic_vol, m)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Python wrapper for calculating historic volatility.
|
||||
/// See [`crate::panel::historic_vol`] for full documentation.
|
||||
#[pyfunction]
|
||||
pub fn historic_vol(
|
||||
df: PyDataFrame,
|
||||
xcat: String,
|
||||
cids: Option<Vec<String>>,
|
||||
lback_periods: Option<usize>,
|
||||
lback_method: Option<String>,
|
||||
half_life: Option<f64>,
|
||||
start: Option<String>,
|
||||
end: Option<String>,
|
||||
est_freq: Option<String>,
|
||||
remove_zeros: Option<bool>,
|
||||
postfix: Option<String>,
|
||||
nan_tolerance: Option<f64>,
|
||||
) -> PyResult<PyDataFrame> {
|
||||
Ok(PyDataFrame(
|
||||
crate::panel::historic_vol::historic_vol(
|
||||
df.into(),
|
||||
xcat,
|
||||
cids,
|
||||
lback_periods,
|
||||
lback_method,
|
||||
half_life,
|
||||
start,
|
||||
end,
|
||||
est_freq,
|
||||
remove_zeros,
|
||||
postfix,
|
||||
nan_tolerance,
|
||||
)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
88
src/_py/qdf.rs
Normal file
88
src/_py/qdf.rs
Normal file
@@ -0,0 +1,88 @@
|
||||
use pyo3::prelude::*;
|
||||
use pyo3_polars::PyDataFrame;
|
||||
|
||||
/// Python wrapper for [`crate::utils::qdf`] module.
|
||||
#[allow(deprecated)]
|
||||
#[pymodule]
|
||||
pub fn qdf(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(load_qdf, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(load_qdf_from_download_bank, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(reduce_dataframe, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(update_dataframe, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(pivot_dataframe_by_ticker, m)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Python wrapper for loading a Quantamental DataFrame from a CSV file.
|
||||
/// See [`crate::utils::qdf::load_quantamental_dataframe`] for full documentation.
|
||||
#[pyfunction]
|
||||
pub fn load_qdf(file_path: String) -> PyResult<PyDataFrame> {
|
||||
Ok(PyDataFrame(
|
||||
crate::utils::qdf::load_quantamental_dataframe(file_path).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Python wrapper for loading a Quantamental DataFrame from a download bank.
|
||||
/// See [`crate::utils::qdf::load::load_qdf_from_download_bank`] for full documentation.
|
||||
#[pyfunction]
|
||||
pub fn load_qdf_from_download_bank(
|
||||
folder_path: String,
|
||||
cids: Option<Vec<String>>,
|
||||
xcats: Option<Vec<String>>,
|
||||
tickers: Option<Vec<String>>,
|
||||
) -> PyResult<PyDataFrame> {
|
||||
Ok(PyDataFrame(
|
||||
crate::utils::qdf::load::load_qdf_from_download_bank(folder_path, cids, xcats, tickers)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Python wrapper for reduce_dataframe
|
||||
/// See [`crate::utils::qdf::reduce_df::reduce_dataframe`] for full documentation.
|
||||
#[pyfunction]
|
||||
pub fn reduce_dataframe(
|
||||
df: PyDataFrame,
|
||||
cids: Option<Vec<String>>,
|
||||
xcats: Option<Vec<String>>,
|
||||
metrics: Option<Vec<String>>,
|
||||
start: Option<String>,
|
||||
end: Option<String>,
|
||||
intersect: Option<bool>,
|
||||
) -> PyResult<PyDataFrame> {
|
||||
Ok(PyDataFrame(
|
||||
crate::utils::qdf::reduce_df::reduce_dataframe(
|
||||
df.into(),
|
||||
cids,
|
||||
xcats,
|
||||
metrics,
|
||||
start,
|
||||
end,
|
||||
intersect.unwrap_or(false),
|
||||
)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Python wrapper for update_dataframe
|
||||
/// See [`crate::utils::qdf::update_df::update_dataframe`] for full documentation.
|
||||
#[pyfunction]
|
||||
pub fn update_dataframe(
|
||||
df: PyDataFrame,
|
||||
df_add: PyDataFrame,
|
||||
xcat_replace: Option<bool>,
|
||||
) -> PyResult<PyDataFrame> {
|
||||
let xcat_replace = xcat_replace.unwrap_or(false);
|
||||
Ok(PyDataFrame(
|
||||
crate::utils::qdf::update_df::update_dataframe(&df.into(), &df_add.into(), xcat_replace)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Python wrapper for pivoting a dataframe by ticker.
|
||||
/// See [`crate::utils::qdf::pivots::pivot_dataframe_by_ticker`] for full documentation.
|
||||
#[pyfunction]
|
||||
pub fn pivot_dataframe_by_ticker(df: PyDataFrame, metric: Option<String>) -> PyResult<PyDataFrame> {
|
||||
Ok(PyDataFrame(
|
||||
crate::utils::qdf::pivots::pivot_dataframe_by_ticker(df.into(), metric).unwrap(),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user