Ejemplo n.º 1
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.º 2
0
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"))

# Portfolio 3 run
Ejemplo n.º 3
0
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)")
risk_engine.plot("swaption_npv.csv", 3, 4, 'g', "NPV Swaptions", marker='s')

risk_engine.decorate_plot(
    title="Example 12 - Simulated exposures with and without horizon shift")
risk_engine.save_plot_to_file()

risk_engine.print_headline(
    "Plot results: Zero rate distribution with and without shift")

risk_engine.setup_plot("rates")
risk_engine.plot_zeroratedist("scenariodump.csv",
                              0,
                              23,
                              5,
                              'r',
                              label="No horizon shift",
                              title="")
risk_engine.plot_zeroratedist(
    "scenariodump2.csv",
Ejemplo n.º 4
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.º 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")

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.º 6
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.º 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 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.º 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 to produce NPV")
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("CPI Swap")
risk_engine.plot("exposure_trade_CPI_Swap_1.csv", 2, 3, 'b', "EPE CPI Swap")
risk_engine.decorate_plot(title="Example 17", ylabel="Exposure")
risk_engine.save_plot_to_file()

risk_engine.setup_plot("YoY Swap")
risk_engine.plot("exposure_trade_YearOnYear_Swap.csv", 2, 3, 'b',
                 "EPE YoY Swap")
risk_engine.decorate_plot(title="Example 17", ylabel="Exposure")
risk_engine.save_plot_to_file()

risk_engine.run("Input/ore_capfloor.xml")
risk_engine.get_times("Output/log_capfloor.txt")
Ejemplo n.º 9
0
    glob.glob(os.path.join(os.getcwd(), os.path.join("Output", "exposure*"))) +
    glob.glob(os.path.join(os.getcwd(), os.path.join("Output", "colva*"))))

risk_engine.print_headline("Plot results")

risk_engine.setup_plot("nocollateral_epe")
risk_engine.plot(os.path.join("collateral_none", "exposure_trade_Swap_1.csv"),
                 2, 3, 'b', "EPE Swap 1")
risk_engine.plot(os.path.join("collateral_none", "exposure_trade_Swap_2.csv"),
                 2, 3, 'r', "EPE Swap 2")
risk_engine.plot(os.path.join("collateral_none", "exposure_trade_Swap_3.csv"),
                 2, 3, 'g', "EPE Swap 3")
risk_engine.plot(
    os.path.join("collateral_none", "exposure_nettingset_CPTY_A.csv"), 2, 3,
    'm', "EPE NettingSet")
risk_engine.decorate_plot(title="Example 10")
risk_engine.save_plot_to_file()

risk_engine.setup_plot("nocollateral_ene")
risk_engine.plot(os.path.join("collateral_none", "exposure_trade_Swap_1.csv"),
                 2, 4, 'b', "ENE Swap 1")
risk_engine.plot(os.path.join("collateral_none", "exposure_trade_Swap_2.csv"),
                 2, 4, 'r', "ENE Swap 2")
risk_engine.plot(os.path.join("collateral_none", "exposure_trade_Swap_3.csv"),
                 2, 4, 'g', "ENE Swap 3")
risk_engine.plot(
    os.path.join("collateral_none", "exposure_nettingset_CPTY_A.csv"), 2, 4,
    'm', "ENE NettingSet")
risk_engine.decorate_plot(title="Example 10")
risk_engine.save_plot_to_file()
Ejemplo n.º 10
0
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")

risk_engine.setup_plot("dim_evolution_A_swap_eur")
risk_engine.plot(os.path.join("case_A_eur_swap", "dim_evolution_1.txt"), 0, 3,
                 'y', "Zero Order Regression")
risk_engine.plot(os.path.join("case_A_eur_swap", "dim_evolution_1.txt"), 0, 4,
                 'c', "First Order Regression")
risk_engine.plot(os.path.join("case_A_eur_swap", "dim_evolution_2.txt"), 0, 4,
                 'm', "Second Order Regression")
#risk_engine.plot(os.path.join("case_A_eur_swap", "dim_evolution_2.txt"), 0, 6, 'r', "Simple DIM")
risk_engine.decorate_plot(title="Example 13 (A) - DIM Evolution Swap EUR",
                          xlabel="Timestep",
                          ylabel="DIM")
risk_engine.save_plot_to_file()

# TODO: Extend the DIM related postprocessor output so that we can avoid scaling and squaring while plotting
risk_engine.setup_plot("dim_regression_A_swap_eur")
risk_engine.plotScaled(os.path.join("case_A_eur_swap", "dim_regression_1.txt"),
                       1,
                       6,
                       'c',
                       'Simulation Data',
                       marker='+',
                       linestyle='',
                       exponent=2.0,
                       yScale=1e10,
                       xScale=1,
Ejemplo n.º 11
0
        put = ([[0.0, float(line_list[6])],
                [float(line_list[3]), float(line_list[6])]])

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

risk_engine.setup_plot("forward")
risk_engine.plot("exposure_trade_FXFWD_EURUSD_10Y.csv", 2, 3, 'b', "EPE")
risk_engine.plot("exposure_trade_FXFWD_EURUSD_10Y.csv", 2, 4, 'r', "ENE")
risk_engine.plot_line([0, call[1][0]], [call[0][1], call[1][1]],
                      color='g',
                      label="Call Price")
risk_engine.plot_line([0, put[1][0]], [put[0][1], put[1][1]],
                      color='m',
                      label="Put Price")
risk_engine.decorate_plot(title="Example 7 - FX Forward")
risk_engine.save_plot_to_file()

risk_engine.setup_plot("option")
risk_engine.plot("exposure_trade_FX_CALL_OPTION_EURUSD_10Y.csv", 2, 3, 'b',
                 "EPE")
risk_engine.plot("exposure_trade_FX_PUT_OPTION_EURUSD_10Y.csv", 2, 3, 'r',
                 "ENE")
risk_engine.plot_line([0, call[1][0]], [call[0][1], call[1][1]],
                      color='g',
                      label="Call Price")
risk_engine.plot_line([0, put[1][0]], [put[0][1], put[1][1]],
                      color='m',
                      label="Put Price")
risk_engine.decorate_plot(title="Example 7 - FX Option")
risk_engine.save_plot_to_file()