示例#1
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"))
示例#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 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()
示例#3
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()
示例#4
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()
示例#5
0
    "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)")
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")
示例#6
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()

示例#7
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.setup_plot("example_swap_cash_physical")
risk_engine.plot("exposure_trade_Swap.csv", 2, 3, 'b', "EPE Swap")
risk_engine.plot("exposure_trade_SwaptionCash.csv", 2, 3, 'r',
                 "EPE Swaption Cash")
risk_engine.plot("exposure_trade_SwaptionPhysical.csv", 2, 3, 'g',
                 "EPE Swaption Physical")
risk_engine.plot("exposure_trade_SwaptionCashPremium.csv", 2, 3, 'c',
                 "EPE Swaption Cash with Premium")
#risk_engine.plot("exposure_trade_SwaptionPhysicalPremium.csv", 2, 3, 'y', "EPE Swaption Physical with Premium")
risk_engine.decorate_plot(title="Example 3")
risk_engine.save_plot_to_file()
示例#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")
示例#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 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()
示例#10
0
# threshhold>0 with collateral and dynamic initial margin
risk_engine.print_headline(
    "Run RiskEngine to postprocess the NPV cube, with collateral (threshold>0) and dynamic initial margin"
)
risk_engine.run("Input/ore_threshold_dim.xml")
risk_engine.save_output_to_subdir(
    "collateral_threshold_dim",
    ["log.txt", "xva.csv", "dim_regression.txt", "dim_evolution.txt"] +
    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")
示例#11
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("example_swaption")
risk_engine.plot("exposure_trade_Swap.csv", 2, 3, 'b', "EPE Forward Swap")
risk_engine.plot("exposure_trade_SwaptionCash.csv", 2, 3, 'r',
                 "EPE Swaption (Cash)")
risk_engine.plot("exposure_trade_SwaptionPhysical.csv", 2, 3, 'g',
                 "EPE Swaption (Physical)")
risk_engine.decorate_plot(title="Example 4", ylabel="Exposure")
risk_engine.save_plot_to_file()
示例#12
0
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 to price European Payer Swaptions")
risk_engine.run("Input/ore_payer_swaption.xml")

risk_engine.print_headline(
    "Run RiskEngine to price European Receiver Swaptions")
risk_engine.run("Input/ore_receiver_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_20.csv", 2, 3, 'b', "EPE")
risk_engine.plot("exposure_trade_Swap_20.csv", 2, 4, 'r', "ENE")
risk_engine.plot_npv("npv_payer.csv", 6, 'g', 'Payer Swaption', marker='s')
risk_engine.plot_npv("npv_receiver.csv",
                     6,
                     'm',
                     "Receiver Swaption",
                     marker='s')
risk_engine.decorate_plot(title="Example 2")
risk_engine.save_plot_to_file()
示例#13
0
    "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")

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,
示例#14
0
for line in npv.readlines():
    if "CALL" in line:
        line_list = line.split(',')
        call = ([[0.0, float(line_list[6])],
                 [float(line_list[3]),
                  float(line_list[6])]])
    if "PUT" in line:
        line_list = line.split(',')
        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")