Skip to content

Commit

Permalink
Merge pull request #164 from ultima-ib/total_deltasens_to_total_sens
Browse files Browse the repository at this point in the history
Returning pyarrow as a required dep
  • Loading branch information
AnatolyBuga committed Jul 27, 2023
2 parents be42f19 + 74971dc commit b106984
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.4.1"
version = "0.4.2"
authors = ["Anatoly Bugakov"]
description = "Ultibi is a BI tool for no code data analysis"
documentation = "https://ultimabi.uk/ultibi-frtb-book/"
Expand Down
6 changes: 3 additions & 3 deletions frtb_engine/src/measures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use crate::rrao::rrao_measures;

use crate::totals::sa_total_measures;

use crate::prelude::total_delta_sens;
use crate::prelude::total_sensis_sum;
use ultibi::CPM;

/// Exporting Measures
Expand All @@ -64,8 +64,8 @@ pub(crate) fn frtb_measure_vec() -> Vec<Measure> {
calc_params: vec![],
}),
Measure::Base(BaseMeasure {
name: "Total DeltaSens".to_string(),
calculator: std::sync::Arc::new(|_: &CPM| Ok(total_delta_sens())),
name: "Total Sens".to_string(),
calculator: std::sync::Arc::new(|_: &CPM| Ok(total_sensis_sum())),
aggregation: None,
precomputefilter: None,
calc_params: vec![],
Expand Down
2 changes: 1 addition & 1 deletion frtb_engine/src/sbm/commodity/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ultibi::{
use ndarray::Array2;

pub fn total_commodity_delta_sens(_: &CPM) -> PolarsResult<Expr> {
Ok(rc_rcat_sens("Delta", "Commodity", total_delta_sens()))
Ok(rc_rcat_sens("Delta", "Commodity", total_sensis_sum()))
}

/// Total Commodity Delta
Expand Down
4 changes: 2 additions & 2 deletions frtb_engine/src/sbm/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use std::sync::{Arc, Mutex};

use crate::prelude::{RhoOverwrite, RhoType};

/// Sum of all delta sensis, from spot to 30Y tenor
/// Sum of all sensis, across all tenors, from spot to 30Y tenor
/// In practice should be used only with filter on RiskClass
/// as combining FX and IR sensis is meaningless
pub fn total_delta_sens() -> Expr {
pub fn total_sensis_sum() -> Expr {
// When adding Exprs NULLs have to be filled Otherwise returns NULL
col("SensitivitySpot").fill_null(0.)
+ col("Sensitivity_025Y").fill_null(0.)
Expand Down
4 changes: 2 additions & 2 deletions frtb_engine/src/sbm/common_curv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn curv_delta(rc: &'static str, risk: Expr) -> Expr {
}

pub(crate) fn total_sens_curv_weighted() -> Expr {
total_delta_sens() * col("CurvatureRiskWeight")
total_sensis_sum() * col("CurvatureRiskWeight")
}

/// CSR
Expand Down Expand Up @@ -102,7 +102,7 @@ pub(crate) fn rc_cvr_5(rc: &'static str, dir: Cvr) -> Expr {
}

pub(crate) fn curv_delta_total(rc: &'static str) -> Expr {
curv_delta(rc, total_delta_sens())
curv_delta(rc, total_sensis_sum())
}

pub(crate) fn curv_delta_spot(rc: &'static str) -> Expr {
Expand Down
2 changes: 1 addition & 1 deletion frtb_engine/src/sbm/csr_sec_ctp/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ultibi::{polars::prelude::max_horizontal, BaseMeasure, CPM};
use crate::prelude::*;

pub fn total_csr_sec_ctp_delta_sens(_: &CPM) -> PolarsResult<Expr> {
Ok(rc_rcat_sens("Delta", "CSR_Sec_CTP", total_delta_sens()))
Ok(rc_rcat_sens("Delta", "CSR_Sec_CTP", total_sensis_sum()))
}
/// Helper functions

Expand Down
2 changes: 1 addition & 1 deletion frtb_engine/src/sbm/csr_sec_nonctp/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ultibi::{
use ndarray::Array2;

pub fn total_csr_sec_nonctp_delta_sens(_: &CPM) -> PolarsResult<Expr> {
Ok(rc_rcat_sens("Delta", "CSR_Sec_nonCTP", total_delta_sens()))
Ok(rc_rcat_sens("Delta", "CSR_Sec_nonCTP", total_sensis_sum()))
}
/// Helper functions

Expand Down
2 changes: 1 addition & 1 deletion frtb_engine/src/sbm/girr/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::risk_weights::REDUCED_IR_WEIGHT;
use ndarray::{parallel::prelude::ParallelIterator, Array1, Array2};

pub fn total_ir_delta_sens(_: &CPM) -> PolarsResult<Expr> {
Ok(rc_rcat_sens("Delta", "GIRR", total_delta_sens()))
Ok(rc_rcat_sens("Delta", "GIRR", total_sensis_sum()))
}
/// Helper functions
fn girr_delta_sens_weighted_spot() -> Expr {
Expand Down
4 changes: 2 additions & 2 deletions pyultima/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ else
VENV_BIN=$(VENV)/bin
endif

venv: ## Set up virtual environment
python3 -m venv $(VENV)
venv: ## Set up virtual environment - local use
$(PY311) -m venv $(VENV)
$(VENV_BIN)/python -m pip install --upgrade pip
$(VENV_BIN)/pip install -r requirements.txt
$(VENV_BIN)/pip install -r requirements-lint.txt
Expand Down
3 changes: 2 additions & 1 deletion pyultima/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ authors = [
]
license = { file = "LICENSE" }
dependencies = [
"polars >= 0.18.7",
"polars >= 0.18.7",
"pyarrow >= 7.0.0"
]
keywords = ["dataframe", "visualization", "aggregation", "calculation",
"chart", "data", "dataviz", "pivot-table", "frtb", "risk"]
Expand Down
1 change: 0 additions & 1 deletion pyultima/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

# Dependencies
polars
pyarrow

# Tooling
maturin
Expand Down
4 changes: 3 additions & 1 deletion pyultima/ultibi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import polars # reexport
import pyarrow

from .internals import (
AggRequest,
Expand All @@ -26,6 +25,9 @@
aggregation_ops,
)

# import pyarrow - not needed


__all__ = [
"AggRequest",
"ComputeRequest",
Expand Down
11 changes: 6 additions & 5 deletions pyultima/ultibi/internals/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,30 @@ def __init__(self, ds: DataSetWrapper) -> None:
Class constructor - not to br called directly.
call .from_frame() or .from_config()
"""

self.inner = ds

self.fields: list[str] = self.inner.fields()
"""All column which you can group by. Currently those are string
and bool columns
"""
self.fields: list[str] = self.inner.fields()

self.measures: "dict[str, str | None]" = self.inner.measures()
"""{measureName: "aggtype restriction(if any, otherwise
None)"}. If none, then you can use any of the availiable agg operations.
Check :func:`~ultima.internals.aggregation_ops` for supported aggregation
operations
"""
self.measures: "dict[str, str | None]" = self.inner.measures()

self.calc_params: "list[tuple[str, str|None, str|None]]" = (
self.inner.calc_params()
)
"""parameters which you can pass to the Request for the given DataSet
Returns:
list[dict[str, str|None]]: List of {"name": parameter name to be
passed to the request, "hint": type hint of the param}
"""
self.calc_params: "list[tuple[str, str|None, str|None]]" = (
self.inner.calc_params()
)

@classmethod
def from_config_path(cls: Type[DS], path: str) -> DS:
Expand Down

0 comments on commit b106984

Please sign in to comment.