Ejemplo n.º 1
0
def main(job_date, cpty):
    base_path = os.getcwd() + "/"
    os.makedirs("Input", mode=0o777, exist_ok=True)
    os.makedirs("Market", mode=0o777, exist_ok=True)
    os.makedirs("Output", mode=0o777, exist_ok=True)

    storage_client = storage.Client.from_service_account_json(
        './vannarho-fb3267082c74.json')

    risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)
    risk_engine.risk_exe = '/home/condor/risk_engine/build/App/ore'

    # download params for counterparty
    bucket_name = 'risk_params'
    prefix = job_date + '/' + cpty + '/'
    # prefix = '09-10-20/cpty_01/'
    dl_dir = './Input/'
    get_input_blobs(bucket_name, prefix, dl_dir, storage_client)

    # download params for market
    bucket_name = 'market_params'
    prefix = job_date + '/'
    dl_dir = './Market/'
    get_input_blobs(bucket_name, prefix, dl_dir, storage_client)

    # run risk analytics
    risk_engine.print_headline(
        "Run risk engine to produce NPV cube and exposures")
    risk_engine.run("Input/ore.xml")
    # risk_engine.get_times("Output/log.txt")

    # upload risk output files
    bucket_name = 'cpty_risk_outputs'
    # destination_blob_name = '09-10-20/cpty_01/'
    destination_blob_name = job_date + '/' + cpty + '/'
    source_dir = './Output/'
    # source_dir = '/risk_run/Output/'
    upload_blob(bucket_name, source_dir, destination_blob_name, storage_client)
Ejemplo n.º 2
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline(
    "Run RiskEngine to illustrate use of fixed vs float cross currency swaps")
risk_engine.run("Input/ore.xml")
Ejemplo n.º 3
0
#!/usr/bin/env python

import sys

from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline("Run RiskEngine to produce NPV cube and exposures")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")

risk_engine.print_headline("Run RiskEngine again to price European Swaptions")
risk_engine.run("Input/ore_swaption.xml")

risk_engine.print_headline(
    "Plot results: Simulated exposures vs analytical swaption prices")

risk_engine.setup_plot("swaptions")
risk_engine.plot("exposure_trade_Swap_20y.csv", 2, 3, 'b', "Swap EPE")
risk_engine.plot("exposure_trade_Swap_20y.csv", 2, 4, 'r', "Swap ENE")
risk_engine.plot("swaption_npv.csv", 3, 4, 'g', "NPV Swaptions", marker='s')
risk_engine.decorate_plot(
    title="Example 1 - Simulated exposures vs analytical swaption prices")
risk_engine.save_plot_to_file()
Ejemplo n.º 4
0
#!/usr/bin/env python

import sys
import os
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

# Portfolio 1 run
risk_engine.print_headline(
    "Run RiskEngine to produce NPV cube and exposures for portfolio 1")
risk_engine.run("Input/ore_portfolio_1.xml")
risk_engine.get_times("Output/portfolio_1/log.txt")

risk_engine.print_headline("Plot results for portfolio 1")

risk_engine.setup_plot("portfolio_1")
risk_engine.plot(os.path.join("portfolio_1", "exposure_trade_swap_01.csv"), 2,
                 3, 'b', "EPE Swap")
risk_engine.plot(os.path.join("portfolio_1", "exposure_trade_collar_01.csv"),
                 2, 4, 'r', "ENE Collar")
risk_engine.plot(os.path.join("portfolio_1", "exposure_nettingset_CPTY_A.csv"),
                 2, 4, 'g', "ENE Netting")
#risk_engine.plot(os.path.join("portfolio_1", "exposure_nettingset_CPTY_A.csv"), 2, 3, 'g', "EPE Netting")
risk_engine.decorate_plot(title="Example 6, Portfolio 1")
risk_engine.save_plot_to_file(os.path.join("Output", "portfolio_1"))

# Portfolio 2 run
risk_engine.print_headline(
    "Run RiskEngine to produce NPV cube and exposures for portfolio 2")
risk_engine.run("Input/ore_portfolio_2.xml")
Ejemplo n.º 5
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline("Run RiskEngine to produce NPV cube and exposures")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")
Ejemplo n.º 6
0
#!/usr/bin/env python

import os
import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

# Case A
risk_engine.print_headline(
    "Run RiskEngine (case A (swap eur), 1st order regression)")
risk_engine.run("Input/ore_A1.xml")
risk_engine.get_times("Output/log_1.txt")
risk_engine.save_output_to_subdir(
    "case_A_eur_swap",
    ["log_1.txt", "dim_evolution_1.txt", "dim_regression_1.txt"])
risk_engine.print_headline(
    "Run RiskEngine (case A (swap eur), 2nd order regression)")
risk_engine.run("Input/ore_A2.xml")
risk_engine.save_output_to_subdir(
    "case_A_eur_swap",
    ["log_2.txt", "dim_evolution_2.txt", "dim_regression_2.txt"])
risk_engine.print_headline(
    "Run RiskEngine (case A (swap eur), zero order regression)")
risk_engine.run("Input/ore_A0.xml")
risk_engine.save_output_to_subdir(
    "case_A_eur_swap",
    ["log_0.txt", "dim_evolution_0.txt", "dim_regression_0.txt"])

risk_engine.print_headline("Plot results")
Ejemplo n.º 7
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv)>1 else False)

risk_engine.print_headline("Run RiskEngine to produce CDS NPV")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")

Ejemplo n.º 8
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline(
    "Run RiskEngine for Sensitivity, Stress and Parametric VaR Analysis")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")
Ejemplo n.º 9
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv)>1 else False)

risk_engine.print_headline("Run RiskEngine to produce NPV cube and exposures")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")

risk_engine.print_headline("Plot results: Simulated exposures")

risk_engine.setup_plot("cmsspread")
risk_engine.plot("exposure_trade_CMS_Spread_Swap.csv", 2, 3, 'b', "Swap EPE")
risk_engine.plot("exposure_trade_CMS_Spread_Swap.csv", 2, 4, 'r', "Swap ENE")
risk_engine.decorate_plot(title="Example 28 - Simulated exposures for CMS Spread trades")
risk_engine.save_plot_to_file()

Ejemplo n.º 10
0
import os
import sys
sys.path.append('Helpers/')
import TradeGenerator

from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv)>1 else False)

risk_engine.print_headline("Running in currency trades")
risk_engine.run("Input/ois_ore.xml")

risk_engine.print_headline("Running EUR out of currency trades")
risk_engine.run("Input/EUR_xois_ore.xml")

risk_engine.print_headline("Running USD out of currency trades")
risk_engine.run("Input/USD_xois_ore.xml")

Ejemplo n.º 11
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline(
    "Run RiskEngine to produce NPV for equity derivatives")
risk_engine.run("Input/ore.xml")

risk_engine.print_headline(
    "Plot results: Simulated exposures (Equity call option, forward, swap)")

risk_engine.setup_plot("eq_call")
risk_engine.plot("exposure_trade_EqCall_Luft.csv", 2, 3, 'r', "Call EPE")
risk_engine.plot("exposure_trade_EqForwardTrade_Luft.csv", 2, 3, 'b',
                 "Fwd EPE")
risk_engine.decorate_plot(
    title="Example 16 - Simulated exposures for Luft call option and fwd trade"
)
risk_engine.save_plot_to_file()

#risk_engine.setup_plot("eq_swap")
#risk_engine.plot("exposure_trade_EquitySwap_1.csv", 2, 3, 'r', "Equity Swap 1 EPE")
#risk_engine.plot("exposure_trade_EquitySwap_2.csv", 2, 4, 'b', "Equity Swap 2 ENE")
#risk_engine.decorate_plot(title="Example 16 - Simulated exposures for Equity Swaps")
#risk_engine.save_plot_to_file()
Ejemplo n.º 12
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline(
    "Run RiskEngine for Sensitivity Analysis (simulating full volatility surfaces)"
)
risk_engine.run("Input/ore_fullSurface.xml")
risk_engine.get_times("Output/log_fullSurface.txt")

risk_engine.print_headline(
    "Run RiskEngine for Sensitivity Analysis (simulating volatility atm strikes only)"
)
risk_engine.run("Input/ore_atmOnly.xml")
risk_engine.get_times("Output/log_atmOnly.txt")
Ejemplo n.º 13
0
#!/usr/bin/env python

import glob
import os
import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

# whithout collateral
risk_engine.print_headline(
    "Run RiskEngine to produce NPV cube and exposures, without collateral")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")
risk_engine.save_output_to_subdir(
    "collateral_none", ["log.txt", "xva.csv"] +
    glob.glob(os.path.join(os.getcwd(), os.path.join("Output", "exposure*"))))

# Threshhold>0
risk_engine.print_headline(
    "Run RiskEngine to postprocess the NPV cube, with collateral (threshold>0)"
)
risk_engine.run("Input/ore_threshold.xml")
risk_engine.save_output_to_subdir(
    "collateral_threshold", ["log.txt", "xva.csv"] +
    glob.glob(os.path.join(os.getcwd(), os.path.join("Output", "exposure*"))) +
    glob.glob(os.path.join(os.getcwd(), os.path.join("Output", "colva*"))))

# mta=0
risk_engine.print_headline(
    "Run RiskEngine to postprocess the NPV cube, with collateral (threshold=0)"
Ejemplo n.º 14
0
#!/usr/bin/env python

import sys
sys.path.append('../')
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv)>1 else False)

risk_engine.print_headline("Run RiskEngine to produce NPV cube and exposures for CrossCurrencySwaps")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")

risk_engine.print_headline("Plot results: Cross Currency Swap exposures, with and without FX reset")

risk_engine.setup_plot("example_xccy_reset")
risk_engine.plot("exposure_trade_XCCY_Swap_EUR_USD.csv", 2, 3, 'b', "Swap")
risk_engine.plot("exposure_trade_XCCY_Swap_EUR_USD_RESET.csv", 2, 3, 'r', "Resettable Swap")
risk_engine.decorate_plot(title="Example 9", legend_loc="upper left")
risk_engine.save_plot_to_file()
Ejemplo n.º 15
0
#!/usr/bin/env python

import sys
sys.path.append('../')
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline(
    "Run RiskEngine to produce NPV cube and exposures, without collateral")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")

risk_engine.print_headline("Plot results")

risk_engine.setup_plot("plot_callable_swap")
risk_engine.plot("exposure_trade_Swap.csv", 2, 3, 'b', "EPE Swap")
risk_engine.plot("exposure_trade_Swaption.csv", 2, 4, 'r', "ENE Swaption")
risk_engine.plot("exposure_nettingset_CPTY_A.csv", 2, 3, 'g',
                 "EPE Netting Set")
risk_engine.plot("exposure_trade_ShortSwap.csv", 2, 3, 'm', "EPE Short Swap")
risk_engine.decorate_plot(title="Example 5")
risk_engine.save_plot_to_file()
Ejemplo n.º 16
0
#!/usr/bin/env python

import sys
import os
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv)>1 else False)

# Portfolio 1 run
 
risk_engine.print_headline("Plot results for portfolio 1")
 
risk_engine.setup_plot("portfolio_1")
risk_engine.plot(os.path.join("portfolio_1", "exposure_trade_swap_01.csv"), 2, 3, 'b', "EPE Swap")
risk_engine.plot(os.path.join("portfolio_1", "exposure_trade_collar_01.csv"), 2, 4, 'r', "ENE Collar")
risk_engine.plot(os.path.join("portfolio_1", "exposure_nettingset_CPTY_A.csv"), 2, 4, 'g', "ENE Netting")
#risk_engine.plot(os.path.join("portfolio_1", "exposure_nettingset_CPTY_A.csv"), 2, 3, 'g', "EPE Netting")
risk_engine.decorate_plot(title="Example 6, Portfolio 1")
risk_engine.save_plot_to_file(os.path.join("Output", "portfolio_1"))

# Portfolio 2 run

risk_engine.print_headline("Plot results for portfolio 2")

risk_engine.setup_plot("portfolio_2")
risk_engine.plot(os.path.join("portfolio_2", "exposure_trade_floor_01.csv"), 2, 3, 'b', "EPE Floor")
risk_engine.plot(os.path.join("portfolio_2", "exposure_trade_cap_01.csv"), 2, 4, 'r', "ENE Cap")
risk_engine.plot(os.path.join("portfolio_2", "exposure_nettingset_CPTY_B.csv"), 2, 3, 'g', "EPE Net Cap and Floor")
risk_engine.plot(os.path.join("portfolio_2", "exposure_trade_collar_02.csv"), 2, 4, 'g', "ENE Collar", offset=1, marker='o', linestyle='')
risk_engine.decorate_plot(title="Example 6, Portfolio 2")
risk_engine.save_plot_to_file(os.path.join("Output", "portfolio_2"))
Ejemplo n.º 17
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline("Run RiskEngine to produce T0 Bond")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")
Ejemplo n.º 18
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline("Run RiskEngine with flat vols")
risk_engine.run("Input/ore_flat.xml")

risk_engine.print_headline("Run RiskEngine with smiles")
risk_engine.run("Input/ore_smile.xml")
Ejemplo n.º 19
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline(
    "Run RiskEngine to produce NPV cube and exposures without horizon shift")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")

risk_engine.print_headline(
    "Run RiskEngine to produce NPV cube and exposures with horizon shift")
risk_engine.run("Input/ore2.xml")

risk_engine.print_headline("Run RiskEngine again to price European Swaptions")
risk_engine.run("Input/ore_swaption.xml")

risk_engine.print_headline(
    "Plot results: Simulated exposures vs analytical swaption prices")

risk_engine.setup_plot("swaptions")
risk_engine.plot("exposure_trade_Swap_50y.csv", 2, 3, 'b',
                 "Swap EPE (no horizon shift)")
risk_engine.plot("exposure_trade_Swap_50y.csv", 2, 4, 'r',
                 "Swap ENE (no horizon shift)")
risk_engine.plot("exposure_trade_Swap_50y_2.csv", 2, 3, 'g',
                 "Swap EPE (shifted horizon)")
risk_engine.plot("exposure_trade_Swap_50y_2.csv", 2, 4, 'y',
                 "Swap ENE (shifted horizon)")
Ejemplo n.º 20
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline(
    "Run RiskEngine to illustrate use of discount ratio curve")

risk_engine.print_headline("Run with USD base currency")
risk_engine.run("Input/ore_usd_base.xml")

risk_engine.print_headline(
    "Run with EUR base currency using GBP-IN-EUR discount modified ratio curve"
)
risk_engine.run("Input/ore_eur_base.xml")
Ejemplo n.º 21
0
#!/usr/bin/env python

import sys
from risk_helper import RiskEngine

risk_engine = RiskEngine(sys.argv[1] if len(sys.argv) > 1 else False)

risk_engine.print_headline("Run RiskEngine to build USD-Prime curve.")
risk_engine.run("Input/ore.xml")
risk_engine.get_times("Output/log.txt")