This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e9aba0
commit 851e007
Showing
2,093 changed files
with
10,521 additions
and
8,571 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
<p align="center"> | ||
<img src="https://data.atoti.io/notebooks/banners/logo.png" alt="atoti logo"> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/atoti/atoti/discussions"><img src="https://img.shields.io/github/discussions/atoti/atoti" alt="GitHub Discussion"></a> | ||
<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fatoti%2Fnotebooks&count_bg=%23FF7375&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false" alt="Hits"></a> | ||
<a href="https://stackoverflow.com/questions/tagged/atoti"><img src="https://img.shields.io/badge/StackOverflow-atoti-f58024.svg" alt="stackoverflow"></a> | ||
</p> | ||
|
||
|
||
## Financial use cases | ||
|
||
<ol><li> | ||
<details open> | ||
<summary><b>Front Office</b></summary><blockquote> | ||
<br/> | ||
|
||
<table> | ||
|
||
<img src="https://data.atoti.io/notebooks/banners/Atoti_plus_RVB_Icon.png" width="15px"/><b> indicates requires Atoti+</b> | ||
|
||
<tr> | ||
<td><b>Notebooks</b></td> | ||
<td><b>Related media</b></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/front-office/cumulative-pnl/main.ipynb"> cumulative-pnl </a></td> | ||
<td><a href="https://www.atoti.io/articles/dynamic-performance-analytics-handling-of-non-linear-aggregation/?utm_source=github">📰 Dynamic Performance Analytics: Handling of non-linear aggregation</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/front-office/pnl-explained/main.ipynb"> pnl-explained </a></td> | ||
<td><a href="https://www.atoti.io/articles/pnl-explained-with-atoti/?utm_source=github">📰 PnL Explained with atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="2"><a href="notebooks/01-use-cases/finance/front-office/real-time-risk/main.ipynb"> real-time-risk </a></td> | ||
<td><a href="https://www.atoti.io/guides/implementing-real-time-sources-with-atoti/?utm_source=github">📰 Implementing real-time sources with atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td valign="center"><a href="https://www.atoti.io/guides/implementing-real-time-sources-with-atoti/?utm_source=github">📰 Real-time risk analytics with atoti</a></td> | ||
</tr> | ||
</table> | ||
<br/> | ||
</blockquote></details> | ||
|
||
</li><li> | ||
<details open> | ||
<summary><b>Risk Management</b></summary><blockquote> | ||
<br/> | ||
|
||
<ul><li> | ||
<details open> | ||
<summary><b>Credit Risk</b></summary><blockquote> | ||
<br/> | ||
|
||
<table> | ||
|
||
<img src="https://data.atoti.io/notebooks/banners/Atoti_plus_RVB_Icon.png" width="15px"/><b> indicates requires Atoti+</b> | ||
|
||
<tr> | ||
<td><b>Notebooks</b></td> | ||
<td><b>Related media</b></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="2"><a href="notebooks/01-use-cases/finance/risk-management/credit-risk/ifrs9/main.ipynb"> ifrs9 </a></td> | ||
<td><a href="https://www.atoti.io/articles/ifrs-9-data-viz-ecl-pd-analytics-and-the-vintage-matrix/?utm_source=github">📰 IFRS 9 Data Viz: ECL, PD Analytics and the Vintage Matrix</a></td> | ||
</tr> | ||
<tr> | ||
<td valign="center"><a href="https://www.atoti.io/articles/tutorial-how-to-build-an-ifrs-9-solution-with-python-and-atoti/?utm_source=github">📰 Tutorial: How to build an IFRS 9 solution with Python and atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/risk-management/credit-risk/sa-ccr/main.ipynb"> sa-ccr </a></td> | ||
<td><a href="https://www.atoti.io/articles/sa-ccr-with-python-and-atoti/?utm_source=github">📰 SA-CCR with python and atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/risk-management/credit-risk/xva/main.ipynb"> xva </a></td> | ||
<td><a href="https://www.atoti.io/articles/interactive-xva-analytics-with-python-and-atoti/?utm_source=github">📰 Interactive xVA analytics with Python and atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="/notebooks/01-use-cases/finance/treasury/collateral-shortfall-forecast/notebooks/main.ipynb"> collateral-shortfall-forecast </a></td> | ||
<td><a href="https://www.atoti.io/articles/collateral-modelling-and-simulation-using-atoti-and-machine-learning/?utm_source=github">📰 Collateral Modelling and Simulation Using atoti and Machine Learning</a></td> | ||
</tr> | ||
</table> | ||
<br/> | ||
</blockquote></details> | ||
</li><li> | ||
<details open> | ||
<summary><b>Market Risk</b></summary><blockquote> | ||
<br/> | ||
|
||
<table> | ||
|
||
<img src="https://data.atoti.io/notebooks/banners/Atoti_plus_RVB_Icon.png" width="15px"/><b> indicates requires Atoti+</b> | ||
|
||
<tr> | ||
<td><b>Notebooks</b></td> | ||
<td><b>Related media</b></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/risk-management/market-risk/sbm/main.ipynb"> sbm </a></td> | ||
<td><a href="https://www.atoti.io/articles/faster-algorithm-for-frtb-sbm-risk-aggregation/?utm_source=github">📰 Faster Algorithm for FRTB SBM Risk Aggregation</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/risk-management/market-risk/stressed-var-calibration/main.ipynb"> stressed-var-calibration </a></td> | ||
<td><a href="https://www.atoti.io/articles/market-risk-analytics-in-python-interactive-rolling-var/?utm_source=github">📰 Market risk analytics in python: Interactive rolling VaR</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/front-offices/main.ipynb"> pnl-explained </a></td> | ||
<td><a href="https://www.atoti.io/articles/pnl-explained-with-atoti/?utm_source=github">📰 PnL Explained with atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/risk-management/market-risk/value-at-risk/main.ipynb"> value-at-risk </a></td> | ||
<td> </td> | ||
</tr> | ||
</table> | ||
<br/> | ||
</blockquote></details> | ||
</li><li> | ||
<details open> | ||
<summary><b>Operational Risk</b></summary><blockquote> | ||
<br/> | ||
|
||
<table> | ||
|
||
<img src="https://data.atoti.io/notebooks/banners/Atoti_plus_RVB_Icon.png" width="15px"/><b> indicates requires Atoti+</b> | ||
|
||
<tr> | ||
<td><b>Notebooks</b></td> | ||
<td><b>Related media</b></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="2"><a href="notebooks/01-use-cases/finance/risk-management/operational-risk/credit-card-fraud-detection/main.ipynb"> credit-card-fraud-detection </a></td> | ||
<td><a href="https://www.atoti.io/articles/credit-card-fraud-detection-part1/?utm_source=github">📰 Part 1: Investigating fraudulent transactions real-time with atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td valign="center"><a href="https://www.atoti.io/articles/credit-card-fraud-detection-part2//?utm_source=github">📰 Part 2: Fraud detection with Faker and PyCaret</a></td> | ||
</tr> | ||
</table> | ||
<br/> | ||
</blockquote></details> | ||
</li> | ||
</ul> | ||
<br/> | ||
</blockquote></details> | ||
|
||
</li><li> | ||
<details open> | ||
<summary><b>Treasury</b></summary><blockquote> | ||
<br/> | ||
|
||
<table> | ||
|
||
<img src="https://data.atoti.io/notebooks/banners/Atoti_plus_RVB_Icon.png" width="15px"/><b> indicates requires Atoti+</b> | ||
|
||
<tr> | ||
<td><b>Notebooks</b></td> | ||
<td><b>Related media</b></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/treasury/collateral-shortfall-forecast/main.ipynb"> collateral-shortfall-forecast </a></td> | ||
<td><a href="https://www.atoti.io/articles/collateral-modelling-and-simulation-using-atoti-and-machine-learning/?utm_source=github">📰 Collateral Modelling and Simulation Using atoti and Machine Learning</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/treasury/collateral-shortfall-monitoring/main.ipynb"> collateral-shortfall-monitoring </a></td> | ||
<td><a href="https://www.atoti.io/articles/rapid-collateral-modelling-and-simulation-with-atoti/?utm_source=github">📰 Rapid collateral modelling and simulation with atoti</a></td> | ||
</tr> | ||
</table> | ||
<br/> | ||
</blockquote></details> | ||
|
||
</li><li> | ||
<details open> | ||
<summary><b>Insurance</b></summary><blockquote> | ||
<br/> | ||
|
||
<table> | ||
|
||
<img src="https://data.atoti.io/notebooks/banners/Atoti_plus_RVB_Icon.png" width="15px"/><b> indicates requires Atoti+</b> | ||
|
||
<tr> | ||
<td><b>Notebooks</b></td> | ||
<td><b>Related media</b></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/insurance/customer 360/03-main-csv.ipynb"> customer 360 </a></td> | ||
<td><a href="https://www.atoti.io/articles/customer-360-how-it-can-be-achieved-with-atoti/?utm_source=github">📰 Customer 360: How it can be achieved with atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/insurance/price-elasticity/main.ipynb"> price-elasticity </a></td> | ||
<td><a href="https://www.atoti.io/articles/unravel-price-elasticity-of-demand-with-atoti/?utm_source=github">📰 Unravel price elasticity of demand with atoti</a></td> | ||
</tr> | ||
</table> | ||
<br/> | ||
</blockquote></details> | ||
|
||
</li></ol> | ||
|
||
|
||
<br/> | ||
<p align="center"> | ||
Reach out to <a href="https://www.activeviam.com/contact-us/"><img src="https://data.atoti.io/notebooks/banners/ActiveViam-RVB-150dpi.png" alt="atoti logo" width="150px" /></a> for more information. | ||
</p> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<p align="center"> | ||
<img src="https://data.atoti.io/notebooks/banners/logo.png" alt="atoti logo"> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/atoti/atoti/discussions"><img src="https://img.shields.io/github/discussions/atoti/atoti" alt="GitHub Discussion"></a> | ||
<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fatoti%2Fnotebooks&count_bg=%23FF7375&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false" alt="Hits"></a> | ||
<a href="https://stackoverflow.com/questions/tagged/atoti"><img src="https://img.shields.io/badge/StackOverflow-atoti-f58024.svg" alt="stackoverflow"></a> | ||
</p> | ||
|
||
|
||
## Financial use cases for Front Office | ||
|
||
|
||
<table> | ||
|
||
<img src="https://data.atoti.io/notebooks/banners/Atoti_plus_RVB_Icon.png" width="15px"/><b> indicates requires Atoti+</b> | ||
|
||
<tr> | ||
<td><b>Notebooks</b></td> | ||
<td><b>Related media</b></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/front-office/cumulative-pnl/main.ipynb"> cumulative-pnl </a></td> | ||
<td><a href="https://www.atoti.io/articles/dynamic-performance-analytics-handling-of-non-linear-aggregation/?utm_source=github">📰 Dynamic Performance Analytics: Handling of non-linear aggregation</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="1"><a href="notebooks/01-use-cases/finance/front-office/pnl-explained/main.ipynb"> pnl-explained </a></td> | ||
<td><a href="https://www.atoti.io/articles/pnl-explained-with-atoti/?utm_source=github">📰 PnL Explained with atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td rowspan="2"><a href="notebooks/01-use-cases/finance/front-office/real-time-risk/main.ipynb"> real-time-risk </a></td> | ||
<td><a href="https://www.atoti.io/guides/implementing-real-time-sources-with-atoti/?utm_source=github">📰 Implementing real-time sources with atoti</a></td> | ||
</tr> | ||
<tr> | ||
<td valign="center"><a href="https://www.atoti.io/guides/implementing-real-time-sources-with-atoti/?utm_source=github">📰 Real-time risk analytics with atoti</a></td> | ||
</tr> | ||
</table> | ||
|
||
|
||
<br/> | ||
<p align="center"> | ||
Reach out to <a href="https://www.activeviam.com/contact-us/"><img src="https://data.atoti.io/notebooks/banners/ActiveViam-RVB-150dpi.png" alt="atoti logo" width="150px" /></a> for more information. | ||
</p> |
Binary file added
BIN
+68 KB
notebooks/01-use-cases/finance/front-office/cumulative-pnl/content/content.mv.db
Binary file not shown.
File renamed without changes
File renamed without changes.
Binary file added
BIN
+92 KB
notebooks/01-use-cases/finance/front-office/pnl-explained/content/content.mv.db
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
130 changes: 65 additions & 65 deletions
130
...real-time-risk/pricing_engine_emulator.py → ...real-time-risk/pricing_engine_emulator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
import numpy as np | ||
import QuantLib as ql | ||
import pandas as pd | ||
|
||
|
||
def reprice_trade(spot_price, trade, calc_date): | ||
# This function takes option trade object and spot prices and computes valuation and risk metrics. | ||
# Volatility and interest rates are set to some constants for simplicity. | ||
|
||
calculation_date = ql.Date(calc_date.day, calc_date.month, calc_date.year) | ||
ql.Settings.instance().evaluationDate = calculation_date | ||
|
||
# conventions | ||
day_count = ql.Actual365Fixed() | ||
calendar = ql.UnitedStates() | ||
volatility = 0.3 | ||
dividend_rate = 0.0163 | ||
risk_free_rate = 0.001 | ||
|
||
maturity = trade["Maturity"] | ||
|
||
maturity_date = ql.Date(maturity.day, maturity.month, maturity.year) | ||
option_type = ql.Option.Call if trade.OptionType == "Call" else ql.Option.Put | ||
strike_price = trade.Strike | ||
|
||
# construct the European Option | ||
payoff = ql.PlainVanillaPayoff(option_type, strike_price) | ||
exercise = ql.EuropeanExercise(maturity_date) | ||
european_option = ql.VanillaOption(payoff, exercise) | ||
|
||
# The Black-Scholes-Merto process is constructed here. | ||
spot_handle = ql.QuoteHandle(ql.SimpleQuote(spot_price)) | ||
flat_ts = ql.YieldTermStructureHandle( | ||
ql.FlatForward(calculation_date, risk_free_rate, day_count) | ||
) | ||
dividend_yield = ql.YieldTermStructureHandle( | ||
ql.FlatForward(calculation_date, dividend_rate, day_count) | ||
) | ||
flat_vol_ts = ql.BlackVolTermStructureHandle( | ||
ql.BlackConstantVol(calculation_date, calendar, volatility, day_count) | ||
) | ||
bsm_process = ql.BlackScholesMertonProcess( | ||
spot_handle, dividend_yield, flat_ts, flat_vol_ts | ||
) | ||
|
||
european_option.setPricingEngine(ql.AnalyticEuropeanEngine(bsm_process)) | ||
|
||
return { | ||
"AsOfDate": calc_date.strftime("%Y-%m-%d"), | ||
"TradeId": trade["TradeId"], | ||
"RiskFactor": trade["Ticker"], | ||
"MarketValue": european_option.NPV(), | ||
"Delta": european_option.delta() * spot_price * trade["Quantity"], | ||
} | ||
|
||
|
||
def reprice_portfolio(market_data, positions, calc_date): | ||
# This function reprices trades and greeks if market data is available, | ||
# and returns new risk numbers as a dataframe | ||
risk = [] | ||
for i, trade in positions.iterrows(): | ||
spot_price_update = market_data[trade["Ticker"]] | ||
if not np.isnan(spot_price_update): | ||
risk = risk + [reprice_trade(spot_price_update, trade, calc_date)] | ||
return pd.DataFrame(data=risk) | ||
import numpy as np | ||
import QuantLib as ql | ||
import pandas as pd | ||
|
||
|
||
def reprice_trade(spot_price, trade, calc_date): | ||
# This function takes option trade object and spot prices and computes valuation and risk metrics. | ||
# Volatility and interest rates are set to some constants for simplicity. | ||
|
||
calculation_date = ql.Date(calc_date.day, calc_date.month, calc_date.year) | ||
ql.Settings.instance().evaluationDate = calculation_date | ||
|
||
# conventions | ||
day_count = ql.Actual365Fixed() | ||
calendar = ql.UnitedStates() | ||
volatility = 0.3 | ||
dividend_rate = 0.0163 | ||
risk_free_rate = 0.001 | ||
|
||
maturity = trade["Maturity"] | ||
|
||
maturity_date = ql.Date(maturity.day, maturity.month, maturity.year) | ||
option_type = ql.Option.Call if trade.OptionType == "Call" else ql.Option.Put | ||
strike_price = trade.Strike | ||
|
||
# construct the European Option | ||
payoff = ql.PlainVanillaPayoff(option_type, strike_price) | ||
exercise = ql.EuropeanExercise(maturity_date) | ||
european_option = ql.VanillaOption(payoff, exercise) | ||
|
||
# The Black-Scholes-Merto process is constructed here. | ||
spot_handle = ql.QuoteHandle(ql.SimpleQuote(spot_price)) | ||
flat_ts = ql.YieldTermStructureHandle( | ||
ql.FlatForward(calculation_date, risk_free_rate, day_count) | ||
) | ||
dividend_yield = ql.YieldTermStructureHandle( | ||
ql.FlatForward(calculation_date, dividend_rate, day_count) | ||
) | ||
flat_vol_ts = ql.BlackVolTermStructureHandle( | ||
ql.BlackConstantVol(calculation_date, calendar, volatility, day_count) | ||
) | ||
bsm_process = ql.BlackScholesMertonProcess( | ||
spot_handle, dividend_yield, flat_ts, flat_vol_ts | ||
) | ||
|
||
european_option.setPricingEngine(ql.AnalyticEuropeanEngine(bsm_process)) | ||
|
||
return { | ||
"AsOfDate": calc_date.strftime("%Y-%m-%d"), | ||
"TradeId": trade["TradeId"], | ||
"RiskFactor": trade["Ticker"], | ||
"MarketValue": european_option.NPV(), | ||
"Delta": european_option.delta() * spot_price * trade["Quantity"], | ||
} | ||
|
||
|
||
def reprice_portfolio(market_data, positions, calc_date): | ||
# This function reprices trades and greeks if market data is available, | ||
# and returns new risk numbers as a dataframe | ||
risk = [] | ||
for i, trade in positions.iterrows(): | ||
spot_price_update = market_data[trade["Ticker"]] | ||
if not np.isnan(spot_price_update): | ||
risk = risk + [reprice_trade(spot_price_update, trade, calc_date)] | ||
return pd.DataFrame(data=risk) |
Oops, something went wrong.