Skip to content

Commit

Permalink
Upgrade to 0.7.3 (#402)
Browse files Browse the repository at this point in the history
* Update table joins to conditional join

* Update real-time risk on Bitnami kafka repo url, quantlib calendar for USA and Atoti's mapping to condition

* Update customer 360 use case from Atoti mapping to condition

* Update SA-CCR to switch join mapping to conditions

* Update XVA to switch join mapping to conditions

* Update join mapping to condition for CCF

* Fixed tsfresh and protobuf conflict issue for collateral shortfall forecast notebook. Update mapping to condition

* Update mapping to condition for collateral shortfall monitoring

* Update mapping to condition for intraday liquidity

* Update mappings to condition for airline industry use case

* Update mappings to conditions for baseball notebook

* Update mapping to conditions for ca-solar

* Update mapping to conditions for digital marketing

* remove mapping for drug efficacy

* Update mapping to conditions for food processing notebook

* Update mapping to conditions for F1

* update mapping to condition for election nb

* Update mapping to condition for global covid nb

* Update object detection to download data and model, mapping to conditions.

* Update mappings to conditions for pokemon nb

* Update mapping to conditions for pricing simulation nb

* Update mapping from mapping to conditions for sales-commission nb

* Update mapping to conditions for twitter nb

* Update mapping to condition for conditional-function nb

* Update mapping to conditions for curr-cov-weighted-avg nb

* Update mapping to condition for curr-coversion nb

* Update mappings to conditions for introductory-tutorial nb

* Update mappings to conditions for rollup-hierarchies nb

* Reorg pandas chart

* Update `user.roles` to user_service_client.individual_roles instead

* Formatting and update cell metadata for notebooks

* Upgrade Atoti CE to v0.7.3

* Workaround for atoti/atoti#758

* Format notebook
  • Loading branch information
HuifangYeo committed Feb 24, 2023
1 parent 9876859 commit bb7840b
Show file tree
Hide file tree
Showing 85 changed files with 6,732 additions and 6,546 deletions.
400 changes: 202 additions & 198 deletions notebooks/01-use-cases/finance/front-office/pnl-explained/main.ipynb

Large diffs are not rendered by default.

@@ -0,0 +1,29 @@
version: "2"

services:
zookeeper:
image: docker.io/bitnami/zookeeper:3.8
ports:
- "2181:2181"
volumes:
- "zookeeper_data:/bitnami"
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
kafka:
image: docker.io/bitnami/kafka:3.4
ports:
- "9092:9092"
volumes:
- "kafka_data:/bitnami"
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
depends_on:
- zookeeper

volumes:
zookeeper_data:
driver: local
kafka_data:
driver: local
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 82 additions & 84 deletions notebooks/01-use-cases/finance/front-office/real-time-risk/main.ipynb

Large diffs are not rendered by default.

Expand Up @@ -12,7 +12,7 @@ def reprice_trade(spot_price, trade, calc_date):

# conventions
day_count = ql.Actual365Fixed()
calendar = ql.UnitedStates()
calendar = ql.UnitedStates(ql.UnitedStates.NYSE)
volatility = 0.3
dividend_rate = 0.0163
risk_free_rate = 0.001
Expand Down
Expand Up @@ -2935,7 +2935,7 @@
"id": "0b772b49",
"metadata": {},
"source": [
"We can explicitly define the mapping between the tables."
"We can explicitly define the join between the tables."
]
},
{
Expand All @@ -2945,7 +2945,11 @@
"metadata": {},
"outputs": [],
"source": [
"policy_tbl.join(ncd_tbl, mapping={\"PLAN_TYPE\": \"PLAN\", \"POLICY_TYPE\": \"POLICY_TYPE\"})"
"policy_tbl.join(\n",
" ncd_tbl,\n",
" (policy_tbl[\"PLAN_TYPE\"] == ncd_tbl[\"PLAN\"])\n",
" & (policy_tbl[\"POLICY_TYPE\"] == ncd_tbl[\"POLICY_TYPE\"]),\n",
")"
]
},
{
Expand Down
426 changes: 211 additions & 215 deletions notebooks/01-use-cases/finance/insurance/customer360/03-main-csv.ipynb

Large diffs are not rendered by default.

Expand Up @@ -698,7 +698,6 @@
"recall = []\n",
"\n",
"for estimator in model_list:\n",
"\n",
" estimator.fit(X_train, Y_train.values.ravel())\n",
" result = estimator.predict(X_val)\n",
"\n",
Expand Down
Expand Up @@ -314,7 +314,7 @@
"### 1.3 Join tables\n",
"\n",
"We enrich the data from the _Portfolios Allocation_ table by joining to some reference table. \n",
"atoti assume a join based on the common columns between the two table. Otherwise, we could explicitly perform the join by declaring the column mappings. Refer to [atoti documentation](https://docs.atoti.io/latest/index.html) for more examples on [join](https://docs.atoti.io/latest/getting_started/tutorial/tutorial.html#Join)."
"atoti assume a join based on the common columns between the two table. Otherwise, we could explicitly define the conditions for the join. Refer to [atoti documentation](https://docs.atoti.io/latest/index.html) for more examples on [join](https://docs.atoti.io/latest/getting_started/tutorial/tutorial.html#Join)."
]
},
{
Expand Down Expand Up @@ -2734,7 +2734,6 @@
"source": [
"@session.endpoint(\"getIteration/{portfolio}\", method=\"GET\")\n",
"def get_iteration(request, user, session):\n",
"\n",
" portfolio = request.path_parameters[\"portfolio\"]\n",
"\n",
" helper_util = helper.Helper(session)\n",
Expand Down Expand Up @@ -2771,7 +2770,6 @@
"source": [
"@session.endpoint(\"upload/portfolio\", method=\"POST\")\n",
"def upload_portfolio(request, user, session):\n",
"\n",
" helper_util = helper.Helper(session)\n",
" data = request.body\n",
" portfolio = data[\"portfolio\"]\n",
Expand Down
Expand Up @@ -7,7 +7,6 @@ def __init__(self, session):
self.cube = session.cubes["Portfolio optimization"]

def query_and_optimize(self, selected_port, selected_method, selected_iteration):

l, m = self.cube.levels, self.cube.measures
portfolio_tbl = self.session.tables["Portfolios Allocation"]

Expand Down
@@ -1,19 +1,18 @@
# https://bjerring.github.io/equity/2019/11/04/Portfolio-Optimization-using-CVaR.html
#%% packages
# %% packages

import pulp
import pandas as pd
import numpy as np
from pandas_datareader import data


#%% functions
# %% functions


def PortfolioRiskTarget(
mu, scen, CVaR_target=1, lamb=1, max_weight=1, min_weight=None, cvar_alpha=0.05
):

"""This function finds the optimal enhanced index portfolio according to some benchmark. The portfolio corresponds to the tangency portfolio where risk is evaluated according to the CVaR of the tracking error. The model is formulated using fractional programming.
Parameters
Expand Down Expand Up @@ -87,7 +86,6 @@ def PortfolioRiskTarget(

### Add minimum weight constraint, either zero or atleast minimum weight
if min_weight is not None:

for i in i_idx:
model += x[i] >= min_weight * b_z[i]
model += x[i] <= b_z[i]
Expand All @@ -104,7 +102,6 @@ def PortfolioRiskTarget(

# Get positions
if pulp.LpStatus[model.status] == "Optimal":

# print variables
var_model = dict()
for variable in model.variables():
Expand Down Expand Up @@ -136,7 +133,6 @@ def PortfolioRiskTarget(
def PortfolioLambda(
mu, mu_b, scen, scen_b, max_weight=1, min_weight=None, cvar_alpha=0.05, ft_points=15
):

# asset names
assets = mu.index

Expand Down
Expand Up @@ -13,6 +13,7 @@
import numpy as np
from pypfopt import HRPOpt


# https://github.com/robertmartin8/PyPortfolioOpt/blob/master/cookbook/3-Advanced-Mean-Variance-Optimisation.ipynb
# https://github.com/robertmartin8/PyPortfolioOpt/blob/master/examples.py
# Deviation Risk Parity objective from Kolm et al (2014)
Expand Down
Expand Up @@ -29,7 +29,6 @@ def download_tickers(symbols, duration):


def get_historical_vector(data):

df_close = data["Adj Close"].copy()
# drop those stocks where there are nan values
df_close.dropna(axis="columns", inplace=True)
Expand Down
Expand Up @@ -308,7 +308,7 @@
"### 1.3 Join tables\n",
"\n",
"We enrich the data from the _Portfolios Allocation_ table by joining to some reference table. \n",
"atoti assume a join based on the common columns between the two table. Otherwise, we could explicitly perform the join by declaring the column mappings. Refer to [atoti documentation](https://docs.atoti.io/latest/index.html) for more examples on [join](https://docs.atoti.io/latest/getting_started/tutorial/tutorial.html#Join)."
"atoti assume a join based on the common columns between the two table. Otherwise, we could explicitly define the conditions for the join. Refer to [atoti documentation](https://docs.atoti.io/latest/index.html) for more examples on [join](https://docs.atoti.io/latest/getting_started/tutorial/tutorial.html#Join)."
]
},
{
Expand Down
Expand Up @@ -58,7 +58,6 @@ def exec_optimization(
ticker_lower,
target_return=None,
):

print("=====================================================")
print(f"sector_mapper: {sector_mapper}")
print(f"sector_upper: {sector_upper}")
Expand Down
Expand Up @@ -121,7 +121,6 @@ def load_limits(
target_returns,
# limit_type="Ticker",
):

lb_ticker_max_weight = "Max ticker weight"
lb_ticker_min_weight = "Min ticker weight"
lb_sector_max_weight = "Max sector weight"
Expand Down
Expand Up @@ -8,7 +8,6 @@

class Widgets:
def __init__(self, query):

self.optimizer = opt_utils.Optimizer()
self.query = query
portfolio = query.get_portfolio()
Expand Down Expand Up @@ -133,7 +132,6 @@ def get_final_weights(self, obj):
return weights_lower, weights_upper # , max_optional

def load_basic_results(self, _portfolio, _iteration, _opt_mtd, weights_df):

weights_df["Portfolio"] = _portfolio
weights_df["Iteration"] = _iteration
weights_df["Opt Method"] = _opt_mtd
Expand Down Expand Up @@ -386,7 +384,6 @@ def update_sector_total(self, weight_type, change):
)

def update_ticker_total(self, weight_type, change):

difference = change["new"] - change["old"]

if weight_type == "min":
Expand Down

0 comments on commit bb7840b

Please sign in to comment.