techtonique_apis.techto_reserving
1import tempfile 2import pandas as pd 3from xlwings import func, arg, ret 4from .techtonique_apis import TechtoniqueAPI 5 6api = TechtoniqueAPI() 7 8 9@func 10@arg("df", index=False, doc="Excel range with reserving triangle data.") 11@arg("method", doc='Reserving method (default: "chainladder")') 12@ret(index=False, doc="Reserving results as a table for Excel") 13def techto_reserving( 14 df: pd.DataFrame, 15 method: str = "chainladder", 16) -> pd.DataFrame: 17 """ 18 Reserving: pass a triangle as a DataFrame from Excel, return reserving results. 19 20 Excel/xlwings custom function: Classical reserving on a triangle from Excel using the Techtonique API. 21 22 Parameters 23 ---------- 24 25 df : pd.DataFrame 26 The input triangle data as a DataFrame (from Excel range). 27 28 method : str, default "chainladder" 29 Reserving method to use. 30 31 Returns 32 ------- 33 34 pd.DataFrame 35 Reserving results as a DataFrame for Excel. 36 37 --- 38 xlwings lite docstring (for Excel help): 39 Classical reserving on a triangle from Excel using the Techtonique API. 40 - df: Excel range with reserving triangle data. 41 - method: Reserving method (default: chainladder). 42 Returns: Reserving results as a table for Excel. 43 """ 44 with tempfile.NamedTemporaryFile(suffix=".csv", delete=False) as tmp: 45 df.to_csv(tmp.name, index=False) 46 result = api.reserving( 47 file_path=tmp.name, 48 method=method, 49 ) 50 if method == "chainladder": 51 return pd.DataFrame(result) 52 return pd.DataFrame({"origin": result["Origin"], 53 "IBNR": result["IBNR"], 54 "IBNR 95": result["IBNR 95%"]}) 55 56 57@func 58@arg("df", index=False, doc="Excel range with reserving triangle data.") 59@arg("method", doc='ML reserving method (default: "RidgeCV")') 60@ret(index=False, doc="ML reserving results as a table for Excel") 61def techto_mlreserving( 62 df: pd.DataFrame, 63 method: str = "RidgeCV", 64) -> pd.DataFrame: 65 """ 66 ML Reserving: pass a triangle as a DataFrame from Excel, return ML reserving results. 67 68 Excel/xlwings custom function: ML reserving on a triangle from Excel using the Techtonique API. 69 70 Parameters 71 ---------- 72 73 df : pd.DataFrame 74 The input triangle data as a DataFrame (from Excel range). 75 76 method : str, default "RidgeCV" 77 ML reserving method to use. 78 79 Returns 80 ------- 81 82 pd.DataFrame 83 ML reserving results as a DataFrame for Excel. 84 85 --- 86 xlwings lite docstring (for Excel help): 87 ML reserving on a triangle from Excel using the Techtonique API. 88 - df: Excel range with reserving triangle data. 89 - method: ML reserving method (default: RidgeCV). 90 Returns: ML reserving results as a table for Excel. 91 """ 92 with tempfile.NamedTemporaryFile(suffix=".csv", delete=False) as tmp: 93 df.to_csv(tmp.name, index=False) 94 result = api.mlreserving( 95 file_path=tmp.name, 96 method=method, 97 ) 98 return pd.DataFrame({"origin": result["Origin"], 99 "IBNR": result["IBNR"], 100 "IBNR 95": result["IBNR 95%"]})
10@func 11@arg("df", index=False, doc="Excel range with reserving triangle data.") 12@arg("method", doc='Reserving method (default: "chainladder")') 13@ret(index=False, doc="Reserving results as a table for Excel") 14def techto_reserving( 15 df: pd.DataFrame, 16 method: str = "chainladder", 17) -> pd.DataFrame: 18 """ 19 Reserving: pass a triangle as a DataFrame from Excel, return reserving results. 20 21 Excel/xlwings custom function: Classical reserving on a triangle from Excel using the Techtonique API. 22 23 Parameters 24 ---------- 25 26 df : pd.DataFrame 27 The input triangle data as a DataFrame (from Excel range). 28 29 method : str, default "chainladder" 30 Reserving method to use. 31 32 Returns 33 ------- 34 35 pd.DataFrame 36 Reserving results as a DataFrame for Excel. 37 38 --- 39 xlwings lite docstring (for Excel help): 40 Classical reserving on a triangle from Excel using the Techtonique API. 41 - df: Excel range with reserving triangle data. 42 - method: Reserving method (default: chainladder). 43 Returns: Reserving results as a table for Excel. 44 """ 45 with tempfile.NamedTemporaryFile(suffix=".csv", delete=False) as tmp: 46 df.to_csv(tmp.name, index=False) 47 result = api.reserving( 48 file_path=tmp.name, 49 method=method, 50 ) 51 if method == "chainladder": 52 return pd.DataFrame(result) 53 return pd.DataFrame({"origin": result["Origin"], 54 "IBNR": result["IBNR"], 55 "IBNR 95": result["IBNR 95%"]})
Reserving: pass a triangle as a DataFrame from Excel, return reserving results.
Excel/xlwings custom function: Classical reserving on a triangle from Excel using the Techtonique API.
Parameters
df : pd.DataFrame The input triangle data as a DataFrame (from Excel range).
method : str, default "chainladder" Reserving method to use.
Returns
pd.DataFrame Reserving results as a DataFrame for Excel.
xlwings lite docstring (for Excel help): Classical reserving on a triangle from Excel using the Techtonique API.
- df: Excel range with reserving triangle data.
- method: Reserving method (default: chainladder). Returns: Reserving results as a table for Excel.
58@func 59@arg("df", index=False, doc="Excel range with reserving triangle data.") 60@arg("method", doc='ML reserving method (default: "RidgeCV")') 61@ret(index=False, doc="ML reserving results as a table for Excel") 62def techto_mlreserving( 63 df: pd.DataFrame, 64 method: str = "RidgeCV", 65) -> pd.DataFrame: 66 """ 67 ML Reserving: pass a triangle as a DataFrame from Excel, return ML reserving results. 68 69 Excel/xlwings custom function: ML reserving on a triangle from Excel using the Techtonique API. 70 71 Parameters 72 ---------- 73 74 df : pd.DataFrame 75 The input triangle data as a DataFrame (from Excel range). 76 77 method : str, default "RidgeCV" 78 ML reserving method to use. 79 80 Returns 81 ------- 82 83 pd.DataFrame 84 ML reserving results as a DataFrame for Excel. 85 86 --- 87 xlwings lite docstring (for Excel help): 88 ML reserving on a triangle from Excel using the Techtonique API. 89 - df: Excel range with reserving triangle data. 90 - method: ML reserving method (default: RidgeCV). 91 Returns: ML reserving results as a table for Excel. 92 """ 93 with tempfile.NamedTemporaryFile(suffix=".csv", delete=False) as tmp: 94 df.to_csv(tmp.name, index=False) 95 result = api.mlreserving( 96 file_path=tmp.name, 97 method=method, 98 ) 99 return pd.DataFrame({"origin": result["Origin"], 100 "IBNR": result["IBNR"], 101 "IBNR 95": result["IBNR 95%"]})
ML Reserving: pass a triangle as a DataFrame from Excel, return ML reserving results.
Excel/xlwings custom function: ML reserving on a triangle from Excel using the Techtonique API.
Parameters
df : pd.DataFrame The input triangle data as a DataFrame (from Excel range).
method : str, default "RidgeCV" ML reserving method to use.
Returns
pd.DataFrame ML reserving results as a DataFrame for Excel.
xlwings lite docstring (for Excel help): ML reserving on a triangle from Excel using the Techtonique API.
- df: Excel range with reserving triangle data.
- method: ML reserving method (default: RidgeCV). Returns: ML reserving results as a table for Excel.