aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/TAGS2572
-rw-r--r--python/analytics/__init__.py3
-rw-r--r--python/analytics/option.py5
-rw-r--r--python/analytics/portfolio.py4
-rw-r--r--python/exploration/portfolio_example.py36
-rw-r--r--python/exploration/portfolio_var.py2
-rw-r--r--python/exploration/swaption_calendar_spread.py93
-rw-r--r--python/exploration/tranches.py7
-rw-r--r--python/graphics.py28
-rw-r--r--python/notebooks/Option Trades.ipynb846
-rw-r--r--python/tests/test_scenarios.py6
11 files changed, 2388 insertions, 1214 deletions
diff --git a/python/TAGS b/python/TAGS
index 19eea624..75a85491 100644
--- a/python/TAGS
+++ b/python/TAGS
@@ -9,8 +9,39 @@ class Daemon:Daemon5,93
def restart(self):restart112,2386
def run(self):run117,2464
+globeop_reports.py,854
+def get_monthly_pnl(group_by = ['identifier']):get_monthly_pnl15,288
+def get_portfolio(report_date = None):get_portfolio24,871
+def curr_port_PNL(date = datetime.date.today(), asset_class='Subprime'):curr_port_PNL36,1488
+def trade_performance():trade_performance44,1934
+def get_net_navs():get_net_navs82,3689
+def alloc(alloc = 'pnl'):alloc95,4348
+def pnl_alloc_plot(df):pnl_alloc_plot123,5588
+def cap_alloc_plot_pie(df):cap_alloc_plot_pie144,6143
+def avg_turnover():avg_turnover157,6581
+def num_bond_by_strat():num_bond_by_strat168,7187
+def num_bond_trades():num_bond_trades175,7518
+def shift_cash(date, amount, df, strat):shift_cash183,7915
+def cap_alloc_plot_bar(df):cap_alloc_plot_bar189,8157
+def calc_trade_performance_stats():calc_trade_performance_stats207,8726
+def get_rmbs_pos_df(date = None):get_rmbs_pos_df230,9649
+
GHquad.h,0
+bbg_index_quotes.py,835
+securities = {}securities5,103
+sql_str = (f"INSERT INTO bbg_index_quotes VALUES({','.join(['%s'] * 8)}) "sql_str17,558
+start_date = datetime.date.today() - datetime.timedelta(days=7) ## one weeek of overlapstart_date19,670
+conn = dbconn('serenitasdb')conn20,758
+ d = retrieve_data(session, securities.keys(), fields=["TICKER", "VERSION"])d22,829
+ ticker_mapping = {v['TICKER']: securities[k] + (v['VERSION'],)ticker_mapping23,909
+ securities = [f"{e['TICKER']} {pcs} Curncy" for e in d.values()]securities26,1062
+ d2 = retrieve_data(session, securities, fields=["PX_LAST"],d227,1135
+ start_date=start_date)start_date28,1203
+ ticker = k.split()[0]ticker31,1322
+ index = "EU"index34,1466
+ index = "XO"index36,1536
+
test_igoption.py,409
index = Index.from_name("ig", 27, "5yr",index3,54
trade_date = datetime.date(2016, 11, 18))trade_date4,95
@@ -19,79 +50,64 @@ strike = 80strike7,224
payer = Swaption(index, exercise_date, strike, strike_is_price = False)payer8,236
receiver = Swaption(index, exercise_date, strike, "receiver", strike_is_price = False)receiver13,377
-markit_red.py,386
-def request_payload(payload):request_payload7,113
-def download_report(report):download_report17,498
-def update_redcodes(conn, fname):update_redcodes33,1023
-def update_redindices(fname):update_redindices53,2025
- report_list = ['REDEntity', 'REDObligation', 'REDEntityDelta', 'REDObligationDelta',report_list74,3139
- fname = download_report("REDIndexCodes")fname77,3350
+markit_red.py,277
+def request_payload(payload):request_payload8,143
+def download_report(report):download_report22,626
+def update_redcodes(conn, fname):update_redcodes37,1132
+def update_redindices(fname):update_redindices59,2265
+ fname = download_report("REDIndexCodes")fname80,3379
-option_trades_et.py,1281
-serenitasdb = dbengine('serenitasdb')serenitasdb16,379
-def get_dfs(index="IG"):get_dfs18,418
-def calendar_spread():calendar_spread24,632
-def put_spread(index = "IG"):put_spread35,1013
-def swaption_analysis():swaption_analysis44,1364
-def beta_calc():beta_calc49,1546
-def build_swaption(index, series, expiry, strike, ref, trade_date, t_range= None, spread_range = None):build_swaption62,1961
- def aux(row, index, swap):aux77,2699
-def calc_delta_pnl(index, series, ref, trade_date, notional, t_range, spread_range):calc_delta_pnl96,3419
-def find_mapped_pv(bought, sold, date):find_mapped_pv121,4358
-def result_fill(df, date):result_fill155,5782
-def plot_color_map(df, val_date):plot_color_map167,6182
-def build_vol_surface_functions(date = datetime.date(2017, 2, 23), index = 'IG', series = '27'):build_vol_surface_functions187,7018
-def vol_from_surface(row, f, g):vol_from_surface212,8513
-def calc_and_plot(bought, sold, traded_price, week, lowerbound, upperbound, deltaPNL=None):calc_and_plot218,8692
-def full_analysis():full_analysis233,9176
-def manual_index_update(index, date): #index as Index Objectmanual_index_update270,10265
-def shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap'):shiftedColorMap284,10767
+parse_gs_exchange.py,577
+class ParseError(Exception):ParseError10,176
+def parse_email(email, fwd_index):parse_email13,215
+def clean_df(all_df):clean_df85,3114
+ fwd_index = []fwd_index104,3913
+ swaption_quotes = {}swaption_quotes105,3932
+ index_df = pd.DataFrame(fwd_index)index_df113,4211
+ index_df = index_df.drop_duplicates(['quotedate', 'index', 'series', 'expiry'])index_df114,4250
+ swaption_quotes = clean_df(swaption_quotes)swaption_quotes116,4370
+ swaption_quotes = swaption_quotes.set_index(['quotedate', 'index', 'series', 'expiry'])swaption_quotes117,4418
-externalmarksbackfill.py,273
-def runAllFill():runAllFill15,301
-def runSingleFill(f):runSingleFill21,458
-def get_CUSIPs():get_CUSIPs50,1582
-def get_BVAL():get_BVAL56,1779
-def pop_BVAL_to_database(df):pop_BVAL_to_database73,2534
-def get_globs():get_globs86,3010
-settings = {settings98,3550
+yieldcurve.py,1499
+def load_curves(currency="USD", date=None):load_curves25,929
+def get_curve(effective_date, currency="USD"):get_curve44,1694
+def getMarkitIRData(effective_date=datetime.date.today(),getMarkitIRData66,2554
+def get_futures_data(date=datetime.date.today()):get_futures_data82,3306
+def rate_helpers(currency="USD", MarkitData=None, evaluation_date=None):rate_helpers89,3615
+def get_dates(date, currency="USD"):get_dates133,5679
+def roll_yc(yc, forward_date):roll_yc149,6473
+def YC(helpers=None, currency="USD", MarkitData=None, evaluation_date=None):YC155,6783
+def jpYC(effective_date, currency="USD", MarkitData=None):jpYC165,7261
+def ql_to_jp(ql_yc):ql_to_jp184,8049
+def build_curves(currency="USD"):build_curves194,8502
+ helpers = rate_helpers("USD")helpers235,10603
+ ts = YC(helpers)ts236,10637
+ cal = calendar_from_name('USA')cal237,10658
+ p1 = Period('1M')p1238,10694
+ p2 = Period('2M')p2239,10716
+ p3 = Period('3M')p3240,10738
+ p6 = Period('6M')p6241,10760
+ p12 = Period('12M')p12242,10782
+ sched = Schedule.from_rule(ts.reference_date, ts.reference_date + Period('5Y'), Period('3M'), cal)sched243,10806
+ days = [pydate_from_qldate(d) for d in sched]days244,10909
+ f3 = [ts.forward_rate(d, d + p3, Actual360(), 0).rate for d in sched]f3245,10959
+ f6 = [ts.forward_rate(d, d + p6, Actual360(), 0).rate for d in sched]f6246,11033
+ f2 = [ts.forward_rate(d, d + p2, Actual360(), 0).rate for d in sched]f2247,11107
-parse_gs_exchange.py,553
-def get_msgs(email_address='ghorel@lmcg.com', count=None):get_msgs11,197
-def parse_email(email, fwd_index):parse_email26,902
-def clean_df(all_df):clean_df96,3720
-def insert_data(swaption_quotes, index_df):insert_data115,4528
- fwd_index = []fwd_index135,5374
- swaption_quotes = {}swaption_quotes136,5393
- swaption_quotes = clean_df(swaption_quotes)swaption_quotes141,5590
- index_df = pd.DataFrame(fwd_index)index_df142,5638
- index_df = index_df.drop_duplicates(['quotedate', 'index', 'series', 'expiry'])index_df143,5677
-
-yieldcurve.py,1416
-def get_curves(currency="USD", date=None):get_curves24,915
-_USD_curves = get_curves("USD")_USD_curves42,1603
-_EUR_curves = get_curves("EUR")_EUR_curves43,1635
-def getMarkitIRData(effective_date = datetime.date.today(),getMarkitIRData45,1668
-def get_futures_data(date = datetime.date.today()):get_futures_data60,2375
-def rate_helpers(currency="USD", MarkitData=None):rate_helpers67,2686
-def get_dates(date, currency="USD"):get_dates109,4709
-def roll_yc(yc, forward_date):roll_yc125,5507
-def YC(helpers = None, currency="USD", MarkitData=None):YC131,5798
-def jpYC(effective_date, currency="USD", MarkitData=None):jpYC138,6114
-def ql_to_jp(ql_yc):ql_to_jp157,6902
-def build_curves(currency="USD"):build_curves167,7355
- ts = YC()ts207,9435
- cal = calendar_from_name('USA')cal208,9449
- p1 = Period('1Mo')p1209,9485
- p2 = Period('2Mo')p2210,9508
- p3 = Period('3Mo')p3211,9531
- p6 = Period('6Mo')p6212,9554
- p12 = Period('12Mo')p12213,9577
- sched = Schedule(ts.reference_date, ts.reference_date+Period('5Yr'), Period('3Mo'), cal)sched214,9602
- days = [pydate_from_qldate(d) for d in sched]days215,9695
- f3 = [ts.forward_rate(d, d+p3, Actual360(), 0).rate for d in sched]f3216,9745
- f6 = [ts.forward_rate(d, d+p6, Actual360(), 0).rate for d in sched]f6217,9817
- f2 = [ts.forward_rate(d, d+p2, Actual360(), 0).rate for d in sched]f2218,9889
+bbg_cds_quotes.py,935
+logger = logging.getLogger('bbg_quotes')logger9,209
+fh = logging.FileHandler(filename=os.path.join(os.environ['LOG_DIR'], 'bbg_quotes.log'))fh10,250
+formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')formatter11,339
+workdate = datetime.date.today()workdate16,505
+serenitasdb = dbconn('serenitasdb')serenitasdb17,538
+index_list = get_index_list(serenitasdb, workdate)index_list18,574
+basket_ids = get_basketids(serenitasdb, index_list, workdate)basket_ids19,625
+bbg_tickers = set(get_bbg_tickers(serenitasdb, basket_ids, workdate))bbg_tickers20,687
+securities = [f'{ticker} Curncy' for ticker in bbg_tickers]securities22,788
+fields = ['UPFRONT_RUNNING_SPREAD', 'UPFRONT_BID', 'UPFRONT_ASK', 'CDS_RECOVERY_RT']fields23,848
+r = {}r25,934
+sql_str = f"INSERT INTO cds_quotes VALUES({','.join(['%s'] * 8)})"sql_str31,1184
+def build_tuple(k, v, workdate, source):build_tuple33,1252
db.py,499
class InfDateAdapter:InfDateAdapter11,278
@@ -99,26 +115,34 @@ class InfDateAdapter:InfDateAdapter11,278
def getquoted(self):getquoted14,364
def nan_to_null(f, _NULL=AsIs('NULL'),nan_to_null22,653
def dbconn(dbname):dbconn32,945
-def dbengine(dbname):dbengine43,1282
-def with_connection(dbname):with_connection53,1719
- def decorator(f):decorator54,1748
- def with_connection_(*args, **kwargs):with_connection_56,1800
-def query_db(conn, sqlstr, params=None, one=True):query_db68,2154
+def dbengine(dbname):dbengine43,1308
+def with_connection(dbname):with_connection55,1803
+ def decorator(f):decorator56,1832
+ def with_connection_(*args, **kwargs):with_connection_58,1884
+def query_db(conn, sqlstr, params=None, one=True):query_db70,2238
+
+backpopulate.py,449
+p = Path('/home/serenitas/CorpCDOs/Tranche_data/CDS')p4,58
+quotefiles = (f for f in p.iterdir() if f.is_file())quotefiles5,112
+tenors = ['6m', '1y', '2y', '3y', '4y', '5y', '7y', '10y']tenors6,165
+conn = dbconn('serenitasdb')conn7,224
+sql_str = "INSERT INTO cds_quotes VALUES({})".format(",".join(["%s"] * 8))sql_str8,253
+tickers = ['CT659914', 'CT391460', 'CT391464', 'CT391468', 'CT391472',tickers10,329
+def convert(s):convert13,448
-backpopulate.py,342
-col =["CY316528", "CY316534", "CY316540", "CY316546", "CY316552", "CY316558", "CY316564", "CY316570"]col4,49
-df = df[df.index.isin(pd.date_range(df.index[0], pd.Timestamp('2016-03-31'), freq=bus_day))]df6,152
-sql_str = "INSERT INTO cds_quotes VALUES({})".format(",".join(["%s"] * 8))sql_str8,246
-conn = dbconn('serenitasdb')conn9,321
+mark_backtest.py,152
+def calc_mark_diff(asset_class = 'Subprime'):calc_mark_diff4,45
+ def closest(x):closest30,1357
+ def remove_max_min(x):remove_max_min51,2174
tests/test_scenarios.py,514
-class TestSenarios(unittest.TestCase):TestSenarios10,287
- option_delta = Index.from_tradeid(874)option_delta11,326
- option1 = BlackSwaption.from_tradeid(7, option_delta)option112,369
- option2 = BlackSwaption.from_tradeid(8, option_delta)option213,427
- portf = Portfolio([option1, option2, option_delta])portf14,485
- date_range = pd.bdate_range(option_delta.trade_date, pd.Timestamp('2017-05-17') - BDay(), freq = '5B')date_range15,541
- def test_portfolio(self):test_portfolio17,649
+class TestSenarios(unittest.TestCase):TestSenarios10,293
+ option_delta = Index.from_tradeid(874)option_delta11,332
+ option1 = BlackSwaption.from_tradeid(7, option_delta)option112,375
+ option2 = BlackSwaption.from_tradeid(8, option_delta)option213,433
+ portf = Portfolio([option1, option2, option_delta])portf14,491
+ date_range = pd.bdate_range(option_delta.trade_date, pd.Timestamp('2017-05-17') - BDay(), freq = '5B')date_range15,547
+ def test_portfolio(self):test_portfolio17,655
tests/test_swaption.py,1230
class TestPutCallParity(unittest.TestCase):TestPutCallParity9,150
@@ -129,24 +153,24 @@ class TestPutCallParity(unittest.TestCase):TestPutCallParity9,150
def test_parity(self):test_parity16,397
def test_parity_black(self):test_parity_black26,927
def test_calibration(self):test_calibration36,1473
- def test_hy(self):test_hy44,1747
-class TestBreakeven(unittest.TestCase):TestBreakeven54,2140
- exercise_date = datetime.date(2017, 3, 15)exercise_date56,2181
- hyindex = Index.from_name("hy", 27, "5yr",hyindex57,2228
- trade_date=datetime.date(2016, 11, 16))trade_date58,2275
- hystrike = 102.5hystrike60,2372
- igindex = Index.from_name("ig", 27, "5yr",igindex62,2394
- trade_date=datetime.date(2016, 11, 18))trade_date63,2441
- igstrike = 80igstrike65,2537
- def test_hypayer(self):test_hypayer67,2556
- def test_hyreceiver(self):test_hyreceiver73,2786
- def test_igpayer(self):test_igpayer80,3070
- def test_igreceiver(self):test_igreceiver86,3288
+ def test_hy(self):test_hy44,1748
+class TestBreakeven(unittest.TestCase):TestBreakeven54,2141
+ exercise_date = datetime.date(2017, 3, 15)exercise_date56,2182
+ hyindex = Index.from_name("hy", 27, "5yr",hyindex57,2229
+ trade_date=datetime.date(2016, 11, 16))trade_date58,2276
+ hystrike = 102.5hystrike60,2373
+ igindex = Index.from_name("ig", 27, "5yr",igindex62,2395
+ trade_date=datetime.date(2016, 11, 18))trade_date63,2442
+ igstrike = 80igstrike65,2538
+ def test_hypayer(self):test_hypayer67,2557
+ def test_hyreceiver(self):test_hyreceiver73,2790
+ def test_igpayer(self):test_igpayer80,3078
+ def test_igreceiver(self):test_igreceiver86,3303
tests/test_yieldcurve.py,207
-class TestYieldCurve(unittest.TestCase):TestYieldCurve10,232
- def assertListAlmostEqual(self, list1, list2, places = 7):assertListAlmostEqual12,274
- def test_bloomberg(self):test_bloomberg17,475
+class TestYieldCurve(unittest.TestCase):TestYieldCurve10,233
+ def assertListAlmostEqual(self, list1, list2, places = 7):assertListAlmostEqual12,275
+ def test_bloomberg(self):test_bloomberg17,476
tests/test_cds.py,345
class TestUpfront(unittest.TestCase):TestUpfront12,246
@@ -156,13 +180,25 @@ class TestUpfront(unittest.TestCase):TestUpfront12,246
def test_cdsone(self):test_cdsone21,537
def test_annuity(self):test_annuity43,1672
-tests/test_dates.py,392
-class TestStartDate(unittest.TestCase):TestStartDate9,117
- def test_previous_twentieth(self):test_previous_twentieth11,158
- def test_previous_twentieth_timestamp(self):test_previous_twentieth_timestamp21,706
-class TestEndDate(unittest.TestCase):TestEndDate31,1260
- def test_enddate(self):test_enddate32,1298
- def test_enddate_pre2015(self):test_enddate_pre201542,1811
+tests/test_swap_index.py,107
+class UsdLiborSwap(unittest.TestCase):UsdLiborSwap8,176
+ def test_creation(self):test_creation9,215
+
+tests/test_dates.py,668
+class TestStartDate(unittest.TestCase):TestStartDate10,166
+ def test_previous_twentieth(self):test_previous_twentieth12,207
+ def test_previous_twentieth_timestamp(self):test_previous_twentieth_timestamp22,755
+class TestEndDate(unittest.TestCase):TestEndDate32,1309
+ def test_enddate(self):test_enddate33,1347
+ def test_enddate_pre2015(self):test_enddate_pre201543,1860
+class TestEndDateC(unittest.TestCase):TestEndDateC57,2624
+ roll_date_c = lambda d, t: TDate_to_pydate(end_dates(pydate_to_TDate(d), t))roll_date_c58,2663
+ def test_enddate(self):test_enddate60,2745
+ def test_enddate_pre2015(self):test_enddate_pre201570,3266
+
+tests/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
tests/test_index.py,1159
class TestPickle(unittest.TestCase):TestPickle12,219
@@ -185,6 +221,48 @@ class TestForwardIndex(unittest.TestCase):TestForwardIndex58,2130
def test_forward_pv(self):test_forward_pv66,2426
def test_forward_pv(self):test_forward_pv72,2726
+tests/test_upfront_cds.py,2424
+def snac_pv(spread, term_date, fixed_coupon=0.01, recovery=0.4, ts=YC()):snac_pv23,1037
+def jpmorgan_curves(trade_date, value_date, start_date, end_date, spread, recovery=0.4):jpmorgan_curves45,2479
+ settings = Settings()settings54,2880
+ yield_helpers = rate_helpers()yield_helpers56,2955
+ ts = YC(helpers = yield_helpers)ts57,2990
+ tenor = Period(5, Years)tenor58,3027
+ trade_date = datetime.date(2009, 5, 21)trade_date59,3056
+ stepin_date = trade_date + datetime.timedelta(days=1)stepin_date60,3100
+ value_date = datetime.date(2009, 5, 26)value_date61,3158
+ term_date = datetime.date(2019, 6, 20)term_date62,3202
+ start_date = datetime.date(2009, 3, 20)start_date63,3245
+ spread = 0.001spread64,3289
+ sc_data = sc.inspect()['data']sc_data66,3408
+ hazard_rate = math.log(1 + sc_data[0][1])hazard_rate67,3443
+ contingent_leg = ContingentLeg(start_date, term_date, 10000000)contingent_leg68,3489
+ fee_leg = FeeLeg(start_date, term_date, True, 10000000, 0.01)fee_leg69,3557
+ flat_curve = FlatHazardRate(0, WeekendsOnly(), hazard_rate, Actual365Fixed())flat_curve71,3624
+ cds_schedule = Schedule(Date.from_datetime(trade_date), Date.from_datetime(term_date),cds_schedule72,3706
+ cds_trade = CreditDefaultSwap.from_upfront(BUYER, 10000000, 0., 0.01, cds_schedule, Following, Actual360(),cds_trade75,3919
+ protection_start = Date.from_datetime(trade_date) + 1,protection_start76,4031
+ last_period_day_counter = Actual360(True))last_period_day_counter77,4133
+ isda_pricer = IsdaCdsEngine(flat_curve, 0.4, ts, accrual_bias=AccrualBias.HalfDayBias,isda_pricer78,4223
+ forwards_in_coupon_period = ForwardsInCouponPeriod.Piecewise)forwards_in_coupon_period79,4314
+ cds_trade2 = CreditDefaultSwap(BUYER, 10000000, spread, cds_schedule, Following, Actual360(),cds_trade283,4472
+ protection_start = Date.from_datetime(trade_date) + 1,protection_start84,4570
+ last_period_day_counter = Actual360(True))last_period_day_counter85,4660
+ h = 0.00168276528775h87,4786
+ flat_curve2 = FlatHazardRate(0, WeekendsOnly(), h, Actual365Fixed())flat_curve288,4811
+ isda_pricer2 = IsdaCdsEngine(flat_curve2, 0.4, ts)isda_pricer289,4884
+
+tests/test_sabr_quantlib.py,720
+strikes = np.array([50, 55, 57.5, 60, 62.5, 65, 67.5, 70, 75, 80, 85])strikes7,257
+pvs = np.array([53.65, 37.75, 31.55, 26.45, 22.25, 18.85, 16.15, 13.95, 10.55,pvs8,328
+option_date = Settings().instance().evaluation_date + Period(3, Months)option_date10,461
+forward = SimpleQuote(58.71e-4)forward11,533
+strikes = np.array([50, 55, 57.5, 60, 62.5, 65, 67.5, 70, 75, 80, 85, 90, 95, 100]) * 1e-4strikes12,565
+vol = np.array([28.5, 31.6, 33.7, 36.1, 38.7, 41.5, 44.1,vol13,656
+vol_quotes = [SimpleQuote(q) for q in vol]vol_quotes15,780
+section = SabrInterpolatedSmileSection(option_date, forward, strikes, False,section17,824
+ is_beta_fixed=True)is_beta_fixed19,988
+
database_consistency.py,248
engine = create_engine('postgresql://et_user@debian/ET')engine6,99
data12 = pd.merge(data1, data2, left_index=True, right_index=True)data1221,1249
@@ -211,15 +289,17 @@ class TestPickle(unittest.TestCase):TestPickle9,201
def test_legs(self):test_legs25,794
pyisda/pyisda/credit_index.pxd,92
-cdef class CurveList:CurveList8,230
-cdef class CreditIndex(CurveList):CreditIndex14,401
+cdef class CurveList:CurveList8,210
+cdef class CreditIndex(CurveList):CreditIndex16,449
pyisda/pyisda/logging.pxd,0
-pyisda/pyisda/date.pxd,191
+pyisda/pyisda/date.pxd,364
cdef long dcc(str day_count) except -1dcc7,206
-cpdef TDate pydate_to_TDate(c_datetime.date d)pydate_to_TDate47,1597
-cpdef c_datetime.date TDate_to_pydate(TDate d)TDate_to_pydate49,1645
+cpdef TDate pydate_to_TDate(c_datetime.date d)pydate_to_TDate50,1790
+cpdef c_datetime.date TDate_to_pydate(TDate d)TDate_to_pydate52,1838
+cdef void _roll_date(TDate d, double* tenors, int n_dates, TDate* output) nogil_roll_date54,1886
+cdef TDate _previous_twentieth(TDate d) nogil_previous_twentieth55,1966
pyisda/pyisda/__init__.py,0
@@ -232,15 +312,20 @@ def set_logging_file(str file_name, TBoolean append = True):set_logging_file15
def log_message(str msg):log_message22,554
def flush():flush27,679
-pyisda/pyisda/date.pyx,246
-cpdef TDate pydate_to_TDate(c_datetime.date d):pydate_to_TDate7,137
-cpdef c_datetime.date TDate_to_pydate(TDate d):TDate_to_pydate10,250
-cdef long dcc(str day_count) except -1:dcc15,434
-def dcc_tostring(long day_count):dcc_tostring25,738
+pyisda/pyisda/date.pyx,593
+cpdef TDate pydate_to_TDate(c_datetime.date d):pydate_to_TDate13,250
+cpdef c_datetime.date TDate_to_pydate(TDate d):TDate_to_pydate16,363
+cdef long dcc(str day_count) except -1:dcc23,600
+def dcc_tostring(long day_count):dcc_tostring33,904
+cdef TDate _previous_twentieth(TDate d) nogil:_previous_twentieth41,1112
+def previous_twentieth(d):previous_twentieth64,1671
+cdef TMonthDayYear next_twentieth(TDate d) nogil:next_twentieth68,1794
+cdef void _roll_date(TDate d, double* tenors, int n_dates, TDate* output) nogil:_roll_date86,2235
+def roll_date(d, tenor):roll_date122,3355
pyisda/pyisda/cdsone.pyx,198
-def upfront_charge(date, value_date, benchmark_start_date, stepin_date,upfront_charge6,120
-def spread_from_upfront(date, value_date, benchmark_start_date, stepin_date,spread_from_upfront68,2806
+def upfront_charge(date, value_date, benchmark_start_date, stepin_date,upfront_charge6,116
+def spread_from_upfront(date, value_date, benchmark_start_date, stepin_date,spread_from_upfront69,2787
pyisda/pyisda/legs.pyx,837
cdef class ContingentLeg:ContingentLeg7,218
@@ -259,80 +344,93 @@ cdef class FeeLeg:FeeLeg75,2818
def accrued(self, today):accrued189,7477
def __dealloc__(self):__dealloc__204,7783
-pyisda/pyisda/curve.pyx,2494
- FOLLOW = <long>'F'FOLLOW30,1013
- PREVIOUS = <long>'P'PREVIOUS31,1036
- NONE = <long>'N'NONE32,1061
- MODIFIED = <long>'M'MODIFIED33,1082
-cdef class Curve(object):Curve38,1225
- def __getstate__(self):__getstate__40,1252
- def __setstate__(self, bytes state):__setstate__48,1565
- def from_bytes(cls, object state):from_bytes56,1818
- def __hash__(self):__hash__71,2339
- def inspect(self):inspect81,2701
- def to_series(self, bint forward=True):to_series97,3264
- def __iter__(self):__iter__122,4284
- def __len__(self):__len__129,4518
- def __deepcopy__(self, memo):__deepcopy__132,4587
- def forward_hazard_rates(self):forward_hazard_rates139,4799
- def base_date(self):base_date170,6045
- def __forward_zero_price(self, d2, d1=None):__forward_zero_price173,6133
-cdef fArray_to_list(TRatePt* fArray, int fNumItems):fArray_to_list195,6864
-cdef class YieldCurve(Curve):YieldCurve202,7071
- def __init__(self, date, str types,__init__231,8033
- def __getstate__(self):__getstate__287,10210
- def __setstate__(self, bytes state):__setstate__301,10800
- def from_bytes(cls, object state):from_bytes315,11291
- def __hash__(self):__hash__338,12075
- def from_discount_factors(cls, base_date, list dates, double[:] dfs, str day_count_conv):from_discount_factors355,12731
- discount_factor = Curve.__forward_zero_pricediscount_factor372,13591
- def dates(self):dates375,13655
- def expected_forward_curve(self, forward_date):expected_forward_curve381,13795
-cdef void tweak_curve(TCurve* sc, TCurve* sc_tweaked, double epsilon,tweak_curve405,14857
-cdef class SpreadCurve(Curve):SpreadCurve428,15597
- def __init__(self, today, YieldCurve yc, start_date, step_in_date,__init__449,16235
- survival_probability = Curve.__forward_zero_pricesurvival_probability512,19213
- def __getstate__(self):__getstate__514,19268
- def __setstate__(self, bytes state):__setstate__528,19833
- def from_bytes(cls, bytes state):from_bytes541,20276
- def __hash__(self):__hash__562,21009
- def from_flat_hazard(cls, base_date, double rate, Basis basis=CONTINUOUS,from_flat_hazard579,21640
- def tweak_curve(self, double epsilon, bint multiplicative=True,tweak_curve605,22610
- def par_spread(self, today, step_in_date, start_date, end_dates,par_spread647,24064
- def ticker(self):ticker694,26106
-def fill_curve(SpreadCurve sc, TDate[:] end_dates):fill_curve701,26274
+pyisda/pyisda/curve.pyx,2697
+ FOLLOW = <long>'F'FOLLOW32,1096
+ PREVIOUS = <long>'P'PREVIOUS33,1119
+ NONE = <long>'N'NONE34,1144
+ MODIFIED = <long>'M'MODIFIED35,1165
+cdef class Curve(object):Curve44,1373
+ def __getstate__(self):__getstate__46,1400
+ def __setstate__(self, bytes state):__setstate__54,1713
+ def from_bytes(cls, object state):from_bytes62,1966
+ def __hash__(self):__hash__77,2487
+ def inspect(self):inspect87,2849
+ def to_series(self, bint forward=True):to_series103,3412
+ def __iter__(self):__iter__131,4549
+ def __len__(self):__len__138,4783
+ def __deepcopy__(self, dict memo):__deepcopy__141,4852
+ def forward_hazard_rates(self):forward_hazard_rates149,5097
+ def base_date(self):base_date180,6343
+ def __forward_zero_price(self, d2, d1=None):__forward_zero_price183,6431
+cdef fArray_to_list(TRatePt* fArray, int fNumItems):fArray_to_list205,7162
+cdef class YieldCurve(Curve):YieldCurve212,7369
+ def __init__(self, date, str types,__init__241,8331
+ def __getstate__(self):__getstate__297,10508
+ def __setstate__(self, bytes state):__setstate__308,10967
+ def __deepcopy__(self, dict memo):__deepcopy__321,11441
+ def from_bytes(cls, object state):from_bytes329,11721
+ def __hash__(self):__hash__352,12505
+ def from_discount_factors(cls, base_date, list dates, double[:] dfs, str day_count_conv):from_discount_factors369,13161
+ discount_factor = Curve.__forward_zero_pricediscount_factor386,14021
+ def dates(self):dates389,14085
+ def expected_forward_curve(self, forward_date):expected_forward_curve395,14225
+cdef void tweak_curve(TCurve* sc, TCurve* sc_tweaked, double epsilon,tweak_curve419,15287
+cdef class SpreadCurve(Curve):SpreadCurve442,16027
+ def __init__(self, today, YieldCurve yc, start_date, step_in_date,__init__464,16700
+ survival_probability = Curve.__forward_zero_pricesurvival_probability570,21409
+ def __getstate__(self):__getstate__572,21464
+ def __setstate__(self, bytes state):__setstate__585,22071
+ def __deepcopy__(self, dict memo):__deepcopy__602,22797
+ def from_bytes(cls, bytes state):from_bytes613,23296
+ def __hash__(self):__hash__639,24277
+ def from_flat_hazard(cls, base_date, double rate, Basis basis=CONTINUOUS,from_flat_hazard655,24970
+ def tweak_curve(self, double epsilon, bint multiplicative=True,tweak_curve681,25940
+ def par_spread(self, today, step_in_date, start_date, end_dates,par_spread726,27588
+ def ticker(self):ticker773,29630
+ def recovery_rates(self):recovery_rates777,29703
+cdef TCurve* _fill_curve(TCurve* sc, TDate* end_dates, int n_dates):_fill_curve786,30061
pyisda/pyisda/curve.pxd,527
- CONTINUOUS = 5000CONTINUOUS179,7643
- DISCOUNT_RATE = 512DISCOUNT_RATE180,7665
- SIMPLE_BASIS = 0SIMPLE_BASIS181,7689
- ANNUAL_BASIS = 1ANNUAL_BASIS182,7710
- DISCOUNT_FACTOR = -2DISCOUNT_FACTOR183,7731
-cdef class Curve:Curve194,7987
-cdef class YieldCurve(Curve):YieldCurve197,8043
-cdef class SpreadCurve(Curve):SpreadCurve200,8103
-cdef fArray_to_list(TRatePt* fArray, int fNumItems)fArray_to_list203,8158
-cdef void tweak_curve(TCurve* sc, TCurve* sc_tweaked, double epsilon,tweak_curve205,8211
+ CONTINUOUS = 5000CONTINUOUS193,8215
+ DISCOUNT_RATE = 512DISCOUNT_RATE194,8237
+ SIMPLE_BASIS = 0SIMPLE_BASIS195,8261
+ ANNUAL_BASIS = 1ANNUAL_BASIS196,8282
+ DISCOUNT_FACTOR = -2DISCOUNT_FACTOR197,8303
+cdef class Curve:Curve208,8559
+cdef class YieldCurve(Curve):YieldCurve211,8615
+cdef class SpreadCurve(Curve):SpreadCurve214,8675
+cdef fArray_to_list(TRatePt* fArray, int fNumItems)fArray_to_list218,8773
+cdef void tweak_curve(TCurve* sc, TCurve* sc_tweaked, double epsilon,tweak_curve220,8826
-pyisda/pyisda/credit_index.pyx,1227
-cdef class CurveList:CurveList19,682
- def __init__(self, list curves, double[:] weights=None):__init__22,763
- def __getitem__(self, str ticker):__getitem__46,1603
- def items(self):items61,2086
- def curves(self):curves74,2463
- def curves(self, list l):curves91,2942
-cdef class CreditIndex(CurveList):CreditIndex110,3466
- def __init__(self, start_date, maturities, list curves, double[:] weights=None):__init__111,3501
- def __dealloc__(self):__dealloc__143,5276
- def pv_vec(self, step_in_date, value_date, YieldCurve yc, double recovery_rate):pv_vec153,5656
- def accrued(self):accrued202,7872
- def pv(self, step_in_date, value_date, maturity, YieldCurve yc not None,pv208,8039
- def theta(self, step_in_date, value_date, maturity, YieldCurve yc not None,theta235,9287
- def duration(self, step_in_date, value_date, maturity, YieldCurve yc not None):duration266,10738
- def maturities(self):maturities301,11839
- def tweak_portfolio(self, double epsilon, maturity, inplace=True):tweak_portfolio310,12038
-cdef pair[TContingentLeg,TFeeLeg] get_legs(TDate maturity,get_legs351,13281
-cdef double pv(unordered_map[string,shared_ptr[TCurve]]& curves,pv385,14798
+pyisda/pyisda/credit_index.pyx,1813
+cdef TFeeLeg* copyFeeLeg(TFeeLeg* leg) nogil:copyFeeLeg31,1229
+cdef TContingentLeg* copyContingentLeg(TContingentLeg* leg) nogil:copyContingentLeg43,1753
+cdef class CurveList:CurveList49,1999
+ def __init__(self, list curves not None, double[:] weights=None, trade_date=None):__init__52,2058
+ def __getitem__(self, str ticker):__getitem__99,3713
+ def items(self):items115,4252
+ def weights(self):weights129,4710
+ def tickers(self):tickers138,5032
+ def trade_date(self):trade_date147,5321
+ def trade_date(self, d):trade_date151,5418
+ def curves(self):curves155,5506
+ def curves(self, list l not None):curves173,6050
+ def __reduce__(self):__reduce__201,7075
+cdef class CreditIndex(CurveList):CreditIndex206,7256
+ def __init__(self, start_date, maturities, list curves, double[:] weights=None,__init__207,7291
+ def __dealloc__(self):__dealloc__225,8182
+ def __reduce__(self):__reduce__262,9846
+ def __hash__(self):__hash__267,10051
+ def pv_vec(self, step_in_date, value_date, YieldCurve yc, double recovery_rate):pv_vec298,11366
+ def accrued(self):accrued349,13600
+ def pv(self, step_in_date, value_date, maturity, YieldCurve yc not None,pv354,13736
+ def theta(self, step_in_date, value_date, maturity, YieldCurve yc not None,theta385,14997
+ def duration(self, step_in_date, value_date, maturity, YieldCurve yc not None):duration433,16989
+ def maturities(self):maturities482,18677
+ def tweak_portfolio(self, double epsilon, maturity, bint inplace=True):tweak_portfolio491,18877
+ def survival_matrix(self, TDate[:] schedule):survival_matrix501,19313
+cdef pair[TContingentLeg_ptr,TFeeLeg_ptr] get_legs(TDate maturity,get_legs557,20951
+cdef double pv(vector[shared_ptr[TCurve]]& curves,pv580,21929
pyisda/pyisda/version.pyx,28
def version():version4,71
@@ -464,36 +562,36 @@ def affected_indices(company_id):affected_indices6,92
def create_newindices(recordslist, lastdate, nissuers):create_newindices18,525
def update_indexmembers(newids, company_id):update_indexmembers40,1428
-bbg_helpers.py,2232
+bbg_helpers.py,2233
logger = logging.getLogger(__name__)logger8,115
BBG_IP = ['192.168.9.61', '192.168.9.65', '192.168.0.10', '192.168.0.12']BBG_IP10,153
def init_bbg_session(ip_list, port=8194):init_bbg_session13,244
def append_overrides(request, d):append_overrides36,993
def event_loop(session, request):event_loop46,1326
def get_pythonvalue(e):get_pythonvalue59,1809
-def field_array_todf(field):field_array_todf67,2079
-def process_historical_msg(msg):process_historical_msg74,2342
-def process_reference_msg(msg):process_reference_msg80,2594
-def process_intraday_tick_msg(msg):process_intraday_tick_msg97,3296
-def retrieve_data(session, securities, fields=[], overrides={},retrieve_data101,3427
- testdate = pd.datetime(2013, 1, 1)testdate184,6653
- hist_securities = ['CADUSD Curncy', "EURUSD Curncy"]hist_securities185,6692
- hist_fields = ['PX_LAST']hist_fields186,6749
- securities = ['004421BW2 Mtge', '75157EAE2 Mtge', 'XS0295516776 Mtge']securities187,6779
- fields = ['CUR_CPN', 'START_ACC_DT']fields188,6854
- hist_data = retrieve_data(session, securities, hist_fields, start_date=testdate,hist_data190,6941
- frequency="MONTHLY")frequency191,7030
- overrides={'SETTLE_DT': testdate}overrides192,7085
- ref_data = retrieve_data(session, securities, fields, overrides=overrides)ref_data193,7127
- struct_data = retrieve_data(session, securities, ["HIST_CASH_FLOW"])struct_data194,7210
- spx_ndx_monthly = retrieve_data(session, ["SPX Index","NDX Index"],spx_ndx_monthly195,7287
- fields=["PX_LAST"],fields196,7363
- start_date=datetime.date(2012, 1, 1),start_date197,7423
- options={'periodicityAdjustment': 'ACTUAL'},options198,7501
- frequency="MONTHLY")frequency199,7586
- trace_data = retrieve_data(session, "BNCMT 2007-1 A5@TRAC Mtge",trace_data200,7647
- start_date=datetime.datetime(2016, 5, 18, 9),start_date201,7720
- end_date=datetime.datetime(2017, 5, 18, 9))end_date202,7801
+def field_array_todf(field):field_array_todf71,2173
+def process_historical_msg(msg):process_historical_msg78,2436
+def process_reference_msg(msg):process_reference_msg84,2688
+def process_intraday_tick_msg(msg):process_intraday_tick_msg101,3390
+def retrieve_data(session, securities, fields=[], overrides={},retrieve_data105,3521
+ testdate = pd.datetime(2013, 1, 1)testdate188,6766
+ hist_securities = ['CADUSD Curncy', "EURUSD Curncy"]hist_securities189,6805
+ hist_fields = ['PX_LAST']hist_fields190,6862
+ securities = ['004421BW2 Mtge', '75157EAE2 Mtge', 'XS0295516776 Mtge']securities191,6892
+ fields = ['CUR_CPN', 'START_ACC_DT']fields192,6967
+ hist_data = retrieve_data(session, securities, hist_fields, start_date=testdate,hist_data194,7054
+ frequency="MONTHLY")frequency195,7143
+ overrides={'SETTLE_DT': testdate}overrides196,7198
+ ref_data = retrieve_data(session, securities, fields, overrides=overrides)ref_data197,7240
+ struct_data = retrieve_data(session, securities, ["HIST_CASH_FLOW"])struct_data198,7323
+ spx_ndx_monthly = retrieve_data(session, ["SPX Index","NDX Index"],spx_ndx_monthly199,7400
+ fields=["PX_LAST"],fields200,7476
+ start_date=datetime.date(2012, 1, 1),start_date201,7536
+ options={'periodicityAdjustment': 'ACTUAL'},options202,7614
+ frequency="MONTHLY")frequency203,7699
+ trace_data = retrieve_data(session, "BNCMT 2007-1 A5@TRAC Mtge",trace_data204,7760
+ start_date=datetime.datetime(2016, 5, 18, 9),start_date205,7833
+ end_date=datetime.datetime(2017, 5, 18, 9))end_date206,7914
send_email.py,473
SCOPES = 'https://www.googleapis.com/auth/gmail.modify'SCOPES15,270
@@ -510,12 +608,22 @@ def main():main62,2055
GHquad.c,56
void GHquad(int n, double* Z, double* w) {GHquad7,167
-download_emails.py,285
-def ListMessagesWithLabels(service, user_id, label_ids=[]):ListMessagesWithLabels17,326
-def labels_dict(service, user_id):labels_dict48,1698
-def get_msg(service, user_id, msg_id):get_msg65,2278
-def msg_content(msg):msg_content72,2566
-def update_emails():update_emails87,3158
+download_emails.py,534
+def ListMessagesWithLabels(service, user_id, label_ids=[]):ListMessagesWithLabels21,445
+def ListHistory(service, user_id, label_id=None, start_history_id=10000):ListHistory52,1817
+def labels_dict(service, user_id):labels_dict89,3376
+class GmailMessage(EmailMessage):GmailMessage106,3956
+ _service = get_gmail_service()_service107,3990
+ def msgdict(self):msgdict109,4026
+ def send(self):send112,4125
+ def from_id(cls, msg_id, user_id='me'):from_id122,4474
+def save_emails(update=True):save_emails135,5032
+
+debug_forward_price.py,219
+hy28 = Index.from_name("hy", 28, "5yr")hy283,58
+hy28_forward = ForwardIndex(hy28, datetime.date(2017, 8, 16))hy28_forward4,98
+r = []r6,178
+ hy28_forward = ForwardIndex(hy28, excercise_date)hy28_forward10,398
marks_to_HY.py,5400
def monthlySpreadDiff(index="IG", tenor="5yr"):monthlySpreadDiff16,435
@@ -594,16 +702,14 @@ difference4 = difference4.set_index('source', append = True)difference4181,839
meanmarkchange= difference4.groupby(level = ['monthend_date', 'source'])['spread'].mean().unstack(level = -1)meanmarkchange182,8458
StdDevmarkchange = difference4.groupby(level = ['monthend_date', 'source'])['spread'].std().unstack(level = -1)StdDevmarkchange183,8568
-cds_curve.py,775
-def get_singlenames_quotes(indexname, date):get_singlenames_quotes22,673
-def build_curve(r, today_date, yc, start_date, step_in_date, value_date, end_dates):build_curve28,891
-def build_curves_dist(quotes, args, workers=4):build_curves_dist43,1577
-def build_curves(quotes, args):build_curves50,1860
-def get_singlenames_curves(index_type, series, trade_date):get_singlenames_curves53,1961
-def all_curves_pv(curves, today_date, jp_yc, start_date, step_in_date, value_date, maturities):all_curves_pv70,2756
-serenitas_engine = dbengine('serenitasdb')serenitas_engine90,3783
-def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr'],calibrate_portfolio92,3827
- df = calibrate_portfolio("HY", 25, ['3yr', '5yr', '7yr', '10yr'])df163,7153
+cds_curve.py,502
+def all_curves_pv(curves, today_date, jp_yc, start_date, step_in_date, value_date, maturities):all_curves_pv11,221
+def calibrate_portfolio(index_type, series, tenors=['3yr', '5yr', '7yr', '10yr'],calibrate_portfolio32,1249
+ parser = argparse.ArgumentParser()parser50,1962
+ args = parser.parse_args()args54,2204
+ conn = dbconn('serenitasdb')conn56,2279
+ start_date = Nonestart_date66,2631
+ df = calibrate_portfolio(index, series, ['3yr', '5yr', '7yr', '10yr'],df68,2658
cds_rebook.py,333
def get_outstanding_positions(engine):get_outstanding_positions7,148
@@ -612,49 +718,56 @@ def rebook(engine, secid, lastdate, already_rebooked):rebook31,1141
def rebook_everything(engine):rebook_everything49,1961
engine = create_engine("postgresql://dawn_user@debian/dawndb")engine59,2338
-dawn_utils.py,111
-def create_trigger_function(conn):create_trigger_function5,80
-def create_triggers():create_triggers34,1110
+dawn_utils.py,363
+def create_trigger_function(db):create_trigger_function6,100
+def create_triggers(db):create_triggers42,1466
+def load_counterparties(engine):load_counterparties51,1815
+def load_trades(engine, schema=None):load_trades70,3153
+def load_trades_futures(engine, schema=None):load_trades_futures100,4798
+def load_wires(engine, schema=None):load_wires135,6686
-parse_emails.py,2740
- level=logging.WARNING,level14,332
- format='%(asctime)s %(message)s')format15,375
-def list_imm_dates(date):list_imm_dates17,430
-def makedf(r, indextype, quote_source):makedf25,610
-def parse_quotedate(fh, date_received):parse_quotedate54,1727
-def parse_refline(line):parse_refline71,2387
-def parse_baml(fh, indextype, series, quotedate, *args):parse_baml83,2842
-def parse_baml_block(fh, indextype):parse_baml_block108,3667
-def parse_ms_block(fh, indextype):parse_ms_block124,4132
-def parse_nomura_block(fh, indextype):parse_nomura_block149,4950
-def parse_sg_block(fh, indextype, expiration_dates):parse_sg_block172,5763
-def parse_gs_block(fh, indextype):parse_gs_block200,6856
-def parse_ms(fh, indextype, *args):parse_ms229,7675
-def parse_nomura(fh, indextype, *args):parse_nomura239,8004
- def aux(line, fh, indextype, option_stack):aux241,8066
-def parse_sg(fh, indextype, expiration_dates):parse_sg257,8675
-def parse_gs(fh, indextype, series, quotedate, ref):parse_gs267,8984
-subject_baml = re.compile("(?:Fwd:){0,2}(?:BAML )?(\w{2})([0-9]{1,2})\s")subject_baml289,9942
-subject_ms = re.compile("[^$]*\$\$ MS CDX OPTIONS: (IG|HY)(\d{2})[^-]*- REF[^\d]*([\d.]+)")subject_ms290,10016
-subject_nomura = re.compile("(?:Fwd:)?CDX (IG|HY)(\d{2}).*- REF:[^\d]*([\d.]+)")subject_nomura291,10108
-subject_gs = re.compile("GS (IG|HY)(\d{2}) 5y.*- Ref [^\d]*([\d.]+)")subject_gs292,10189
-subject_sg = re.compile("SG OPTIONS - CDX (IG|HY) S(\d{2}).* REF[^\d]*([\d.]+)")subject_sg293,10259
-def parse_email(email):parse_email295,10341
-def write_todb(swaption_stack, index_data):write_todb332,12239
-def get_email_list(date):get_email_list354,13126
-def pickle_drop_date(date):pickle_drop_date368,13537
- data_dir = os.path.join(os.getenv("DATA_DIR"), "swaptions")data_dir377,13841
- emails = [f for f in os.scandir(data_dir) if f.is_file()]emails378,13905
- swaption_stack = {}swaption_stack379,13967
- index_data = pd.DataFrame()index_data380,13991
- already_uploaded = pickle.load(fh)already_uploaded383,14074
- already_uploaded = {}already_uploaded385,14151
- index_data = index_data.append(fwd_index)index_data399,14683
- swaption_stack = pd.concat(swaption_stack, names=['quotedate', 'index', 'series'])swaption_stack408,15052
- swaption_stack = swaption_stack.reset_index()swaption_stack409,15139
- swaption_stack = swaption_stack.drop_duplicates(['quotedate', 'index', 'series', 'expiry', 'strike'])swaption_stack410,15189
- index_data = index_data.reset_index()index_data411,15295
- index_data = index_data.drop_duplicates(['quotedate', 'index', 'series', 'expiry'])index_data412,15337
+parse_emails.py,3053
+ level=logging.WARNING,level16,379
+ format='%(asctime)s %(message)s')format17,422
+def list_imm_dates(date):list_imm_dates19,477
+def makedf(r, indextype, quote_source):makedf27,657
+def parse_quotedate(fh, date_received):parse_quotedate55,1740
+def parse_refline(line):parse_refline72,2400
+def parse_baml(fh, indextype, series, quotedate, *args):parse_baml84,2855
+def parse_baml_block(fh, indextype):parse_baml_block110,3723
+def parse_ms_block(fh, indextype):parse_ms_block126,4188
+def parse_nomura_block(fh, indextype):parse_nomura_block158,5298
+def parse_sg_block(fh, indextype, expiration_dates):parse_sg_block181,6111
+def parse_gs_block(fh, indextype):parse_gs_block209,7204
+def parse_ms(fh, indextype, *args):parse_ms238,8023
+def parse_nomura(fh, indextype, *args):parse_nomura250,8416
+ def aux(line, fh, indextype, option_stack):aux252,8478
+def parse_sg(fh, indextype, expiration_dates):parse_sg268,9087
+def parse_gs(fh, indextype, series, quotedate, ref):parse_gs278,9396
+subject_baml = re.compile("(?:Fwd:){0,2}(?:BAML )?(\w{2})([0-9]{1,2})\s")subject_baml301,10391
+subject_ms = re.compile("[^$]*\$\$ MS CDX OPTIONS: (IG|HY)(\d{2})[^-]*- REF[^\d]*([\d.]+)")subject_ms302,10465
+subject_nomura = re.compile("(?:Fwd:)?CDX (IG|HY)(\d{2}).*- REF:[^\d]*([\d.]+)")subject_nomura303,10557
+subject_gs = re.compile("GS (IG|HY)(\d{2}) 5y.*- Ref [^\d]*([\d.]+)")subject_gs304,10638
+subject_sg = re.compile("SG OPTIONS - CDX (IG|HY) S(\d{2}).* REF[^\d]*([\d.]+)")subject_sg305,10708
+def parse_email(email, date_received):parse_email307,10790
+def write_todb(swaption_stack, index_data):write_todb345,12712
+ def gen_sql_str(query, table_name, columns):gen_sql_str346,12756
+def get_email_list(date):get_email_list370,13887
+def pickle_drop_date(date):pickle_drop_date384,14298
+ data_dir = os.path.join(os.getenv("DATA_DIR"), "swaptions")data_dir393,14600
+ emails = [f for f in os.scandir(data_dir) if f.is_file()]emails394,14664
+ swaption_stack = {}swaption_stack395,14726
+ index_data = pd.DataFrame()index_data396,14750
+ already_uploaded = pickle.load(fh)already_uploaded399,14833
+ already_uploaded = {}already_uploaded401,14910
+ date_received = datetime.datetime.strptime(date_received, "%Y-%m-%d %H-%M-%S")date_received404,15011
+ index_data = index_data.append(fwd_index)index_data417,15594
+ swaption_stack = pd.concat(swaption_stack, names=['quotedate', 'index', 'series'])swaption_stack426,15963
+ swaption_stack = swaption_stack.reset_index()swaption_stack427,16050
+ swaption_stack = swaption_stack.drop_duplicates(['quotedate', 'index', 'series', 'expiry', 'strike'])swaption_stack428,16100
+ swaption_stack = swaption_stack.set_index(['quotedate', 'index', 'series', 'expiry'])swaption_stack429,16206
+ index_data = index_data.reset_index()index_data430,16296
+ index_data = index_data.drop_duplicates(['quotedate', 'index', 'series', 'expiry'])index_data431,16338
populate_risk_numbers.py,404
basedir = "/home/share/CorpCDOs"basedir5,65
@@ -665,20 +778,17 @@ def convert(s):convert33,1066
def populate_risk(basedir, db):populate_risk36,1124
basedir = "/home/share/CorpCDOs"basedir62,2593
-saga.py,39
-def saga_option(x, y):saga_option1,0
-
-pnl_explain.py,951
-def get_daycount(identifier, engine = dbengine("dawndb")):get_daycount7,112
-def pnl_explain(identifier, start_date = None, end_date = None,pnl_explain21,580
-def pnl_explain_list(id_list, start_date = None, end_date = None, engine = dbengine("dawndb")):pnl_explain_list101,5037
-def compute_tranche_factors(df, attach, detach):compute_tranche_factors105,5273
-def cds_explain(index, series, tenor, attach = np.nan, detach = np.nan,cds_explain114,5789
-def cds_explain_strat(strat, start_date, end_date, engine = dbengine("dawndb")):cds_explain_strat187,9770
- engine = dbengine("dawndb")engine216,11313
- subprime_list = get_list_range(engine, '2015-09-30', '2015-10-31', 'Subprime')subprime_list224,11647
- df_subprime = pnl_explain_list(subprime_list[['identifier', 'strategy']].to_records(index=False),df_subprime225,11730
- df_subprime = pd.concat(df_subprime, names=['identifier', 'strategy', 'date'])df_subprime227,11903
+pnl_explain.py,949
+def get_daycount(identifier, engine=dbengine("dawndb")):get_daycount7,112
+def pnl_explain(identifier, start_date = None, end_date = None,pnl_explain21,578
+def pnl_explain_list(id_list, start_date = None, end_date = None, engine = dbengine("dawndb")):pnl_explain_list101,5033
+def compute_tranche_factors(df, attach, detach):compute_tranche_factors105,5269
+def cds_explain(index, series, tenor, attach = np.nan, detach = np.nan,cds_explain114,5785
+def cds_explain_strat(strat, start_date, end_date, engine = dbengine("dawndb")):cds_explain_strat187,9766
+ engine = dbengine("dawndb")engine216,11309
+ subprime_list = get_list_range(engine, '2015-09-30', '2015-10-31', 'Subprime')subprime_list224,11643
+ df_subprime = pnl_explain_list(subprime_list[['identifier', 'strategy']].to_records(index=False),df_subprime225,11726
+ df_subprime = pd.concat(df_subprime, names=['identifier', 'strategy', 'date'])df_subprime227,11899
script_calibrate_tranches.py,605
n_int = 500n_int4,69
@@ -718,33 +828,48 @@ def get_mailinglist(name):get_mailinglist14,315
msg_alternative = MIMEMultipart('alternative')msg_alternative54,2237
name = " " + namename56,2309
-client.py,76
-def run():run10,119
- logger = logging.getLogger('intex')logger33,952
+client.py,236
+def run():run9,149
+ logger = logging.getLogger('intex')logger31,903
+ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')formatter32,943
+ sh = logging.StreamHandler(sys.stdout)sh35,1119
-position.py,769
-def get_list(engine, workdate=None, asset_class=None, include_unsettled=True):get_list11,239
-def get_list_range(engine, begin, end, asset_class=None):get_list_range25,1065
-def backpopulate_marks(begin_str='2015-01-15', end_str='2015-07-15'):backpopulate_marks38,1832
-def update_securities(engine, session, workdate):update_securities58,3135
-def init_fx(session, engine, startdate):init_fx76,4068
-def update_fx(engine, session, currencies):update_fx85,4551
-def populate_cashflow_history(engine, session, workdate=None):populate_cashflow_history103,5247
- engine = create_engine('postgresql://dawn_user@debian/dawndb')engine147,7627
- workdate = pd.Timestamp(sys.argv[1])workdate149,7718
- workdate = pd.datetime.today()workdate151,7773
+position.py,1541
+def get_list(engine, workdate=None, asset_class=None, include_unsettled=True):get_list14,290
+def get_list_range(engine, begin, end, asset_class=None):get_list_range28,1116
+def backpopulate_marks(begin_str='2015-01-15', end_str='2015-07-15'):backpopulate_marks41,1883
+def update_securities(engine, session, workdate):update_securities61,3186
+def init_fx(session, engine, startdate):init_fx80,4136
+def update_fx(conn, session, currencies):update_fx89,4619
+def init_swap_rates(conn, session, tenors=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30],init_swap_rates107,5279
+def init_swaption_vol(session,init_swaption_vol123,6031
+def split_tenor_expiry(ticker, vol_type='N'):split_tenor_expiry136,6550
+def insert_swaption_vol(data, conn, source, vol_type="N"):insert_swaption_vol146,6865
+def update_swaption_vol(conn, session,update_swaption_vol166,7830
+def update_swap_rates(conn, session,update_swap_rates205,9479
+def populate_cashflow_history(engine, session, workdate=None):populate_cashflow_history218,10109
+ serenitas_conn = psycopg2.connect(database="serenitasdb",serenitas_conn263,12506
+ user="serenitas_user",user264,12568
+ host="debian")host265,12629
+ dawn_engine = create_engine('postgresql://dawn_user@debian/dawndb')dawn_engine266,12682
+ dawn_conn = dawn_engine.raw_connection()dawn_conn267,12754
+ workdate = pd.Timestamp(sys.argv[1])workdate269,12825
+ workdate = pd.datetime.today()workdate271,12880
-load_globeop_report.py,645
-def get_globs(fname, years=['2013', '2014', '2015', '2016']):get_globs8,119
-def valuation_reports():valuation_reports20,654
-def pnl_reports():pnl_reports43,1565
-def ts(s):ts61,2258
-def monthly_pnl_bycusip(df, strats):monthly_pnl_bycusip64,2297
- df_val = pd.read_hdf('globeop.hdf', 'valuation_report')df_val73,2679
- df_pnl = pd.read_hdf('globeop.hdf', 'pnl')df_pnl74,2739
- subprime_strats = ['MTG_GOOD', 'MTG_RW', 'MTG_IO','MTG_THRU', 'MTG_B4PR']subprime_strats76,2874
- clo_strats = ['CLO_BBB', 'CLO_AAA', 'CLO_BB20']clo_strats77,2952
- df_monthly = monthly_pnl_bycusip(df_pnl, subprime_strats)df_monthly82,3101
+load_globeop_report.py,851
+def get_globs(fname, years=['2013', '2014', '2015', '2016', '2017']):get_globs9,148
+def read_valuation_report(f):read_valuation_report21,703
+def valuation_reports():valuation_reports42,1493
+def read_pnl_report(f):read_pnl_report50,1910
+def pnl_reports():pnl_reports58,2257
+def read_cds_report(f, old_report=False):read_cds_report69,2695
+def cds_reports():cds_reports103,4463
+def monthly_pnl_bycusip(df, strats):monthly_pnl_bycusip113,4851
+ df_val = pd.read_hdf('globeop.hdf', 'valuation_report')df_val121,5213
+ df_pnl = pd.read_hdf('globeop.hdf', 'pnl')df_pnl122,5273
+ subprime_strats = ['MTG_GOOD', 'MTG_RW', 'MTG_IO','MTG_THRU', 'MTG_B4PR']subprime_strats124,5410
+ clo_strats = ['CLO_BBB', 'CLO_AAA', 'CLO_BB20']clo_strats125,5488
+ df_monthly = monthly_pnl_bycusip(df_pnl, subprime_strats)df_monthly130,5637
markit/cds.py,238
logger = logging.getLogger(__name__)logger10,161
@@ -759,12 +884,12 @@ logger = logging.getLogger(__name__)logger9,129
def download_facility(workdate, payload):download_facility11,169
def insert_facility(conn, workdate):insert_facility18,531
def download_marks(conn, workdate, payload):download_marks39,1422
-def update_facility(conn, workdate, payload):update_facility59,2410
+def update_facility(conn, workdate, payload):update_facility59,2414
markit/rates.py,90
-def downloadMarkitIRData(download_date=datetime.date.today(),downloadMarkitIRData12,219
+def downloadMarkitIRData(download_date=datetime.date.today(),downloadMarkitIRData14,255
-markit/__main__.py,1328
+markit/__main__.py,1330
parser = argparse.ArgumentParser()parser20,529
group = parser.add_mutually_exclusive_group(required=True)group21,564
help="download markit loan data")help23,680
@@ -782,26 +907,35 @@ historical = Truehistorical33,1196
logger = logging.getLogger('markit')logger48,1606
fh = logging.FileHandler(filename=log_file)fh49,1643
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')formatter50,1687
- payload={'LEGALENTITY': 'lmcg',payload56,1868
- payload = {'user': 'GuillaumeHorel',payload72,2412
- serenitasdb = dbconn('serenitasdb')serenitasdb83,2852
- engine = create_engine('postgresql://serenitas_user@debian/serenitasdb')engine87,2983
+ payload = {'LEGALENTITY': 'lmcg',payload56,1868
+ payload = {'user': 'GuillaumeHorel',payload72,2418
+ serenitasdb = dbconn('serenitasdb')serenitasdb83,2858
+ engine = create_engine('postgresql://serenitas_user@debian/serenitasdb')engine87,2989
+
+markit/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
markit/utils.py,38
def default_date():default_date4,61
-markit/import_quotes.py,734
-logger = logging.getLogger(__name__)logger11,169
-def convert(x):convert13,207
- ['EU' + str(s) for s in range(19, 28)]index_list23,526
-DOC_CLAUSE_MAPPING14 = {'Full Restructuring': 'MM14',DOC_CLAUSE_MAPPING1425,579
-DOC_CLAUSE_MAPPING = {'Full Restructuring': 'MM',DOC_CLAUSE_MAPPING29,752
-def get_markit_bbg_mapping(database, basketid_list, workdate):get_markit_bbg_mapping33,913
-def get_basketids(database, index_list, workdate):get_basketids58,2251
-def get_current_tickers(database, workdate):get_current_tickers67,2534
-def insert_cds(database, workdate):insert_cds71,2715
-def insert_index(engine, workdate=None):insert_index105,4513
-def insert_tranche(engine, workdate=None):insert_tranche144,6770
+markit/import_quotes.py,807
+logger = logging.getLogger(__name__)logger12,197
+def convert(x):convert14,235
+def get_index_list(database, workdate):get_index_list20,333
+DOC_CLAUSE_MAPPING14 = {'Full Restructuring': 'MM14',DOC_CLAUSE_MAPPING1429,679
+DOC_CLAUSE_MAPPING = {'Full Restructuring': 'MM',DOC_CLAUSE_MAPPING33,852
+def get_markit_bbg_mapping(database, basketid_list, workdate):get_markit_bbg_mapping37,1013
+def get_bbg_tickers(database, basketid_list, workdate):get_bbg_tickers62,2363
+def get_basketids(database, index_list, workdate):get_basketids70,2698
+def get_current_tickers(database, workdate):get_current_tickers77,2953
+def insert_cds(database, workdate):insert_cds82,3186
+def insert_index(engine, workdate=None):insert_index113,4858
+def insert_tranche(engine, workdate=None):insert_tranche150,7026
+
+exchange.py,164
+def get_account(email_address):get_account5,108
+def get_msgs(account=None, email_address='ghorel@lmcg.com', count=None, path=['GS', 'Swaptions'],get_msgs13,496
calibrate_tranches.py,1441
n_int = 500n_int10,147
@@ -844,42 +978,96 @@ sentinel={}sentinel93,3479
table_rows = table.findAll('tr')table_rows105,3844
fields = row.findAll('td')fields107,3928
-calibrate_swaption.py,464
-serenitas_engine = dbengine('serenitasdb')serenitas_engine9,206
-def get_data(index, series, date = datetime.date.min):get_data11,250
-def get_data_latest():get_data_latest26,967
-def calib(option, ref, strike, pay_bid, pay_offer, rec_bid, rec_offer):calib43,1751
-def calibrate(index_type=None, series=None, date=None, nproc=4, latest=False):calibrate64,2459
- parser = argparse.ArgumentParser()parser86,3527
- args = parser.parse_args()args92,3964
+collateral_calc.py,524
+DAILY_DIR = Path(os.environ["DAILY_DIR"])DAILY_DIR10,236
+def download_files(d=None):download_files12,279
+def download_emails():download_emails37,1266
+def sg_collateral(d):sg_collateral47,1656
+def ms_collateral(d):ms_collateral70,2853
+def send_email(account, df_ms, df_sg):send_email83,3330
+ d = (pd.Timestamp.today() - BDay()).normalize()d102,4000
+ df_ms = ms_collateral(d - BDay())df_ms104,4074
+ df_sg = sg_collateral(d)df_sg105,4112
+ account = get_account('ghorel@lmcg.com')account106,4141
-backfill_index.py,589
-engine = create_engine('postgresql://serenitas_user@debian/serenitasdb')engine2,54
-metadata = MetaData(bind = engine)metadata5,148
-index_quotes = Table('index_quotes', metadata, autoload=True)index_quotes6,183
-series=[9]series8,283
-tenor = ['3yr', '5yr', '7yr']tenor10,333
-index_type ='HY'index_type11,363
- index = "{0}{1}".format(index_type.lower(), s)index15,418
- stmt = index_quotes.delete().where((index_quotes.c.index==index_type) &stmt16,473
- df = pd.read_excel('/home/share/CorpCDOs/index historical.xlsx', "{0} {1}".format(index, t))df20,724
+calibrate_swaption.py,503
+serenitas_engine = dbengine('serenitasdb')serenitas_engine11,259
+def get_data(index, series, date=datetime.date.min):get_data13,303
+def get_data_latest():get_data_latest24,936
+def calib(option, ref, strike, pay_bid, pay_offer, rec_bid, rec_offer):calib37,1653
+def MaybePool(nproc):MaybePool59,2366
+def calibrate(index_type=None, series=None, date=None, nproc=4, latest=False):calibrate62,2434
+ parser = argparse.ArgumentParser()parser86,3596
+ args = parser.parse_args()args92,4027
+
+backfill_index.py,335
+serenitasdb = dbconn('serenitasdb')serenitasdb3,76
+series=[18]series7,171
+tenor = ['5yr', '7yr', '10yr']tenor9,222
+index_type ='IG'index_type10,253
+ index = "{0}{1}".format(index_type.lower(), s)index14,308
+ df = pd.read_excel('/home/share/CorpCDOs/index historical.xlsx', "{0} {1}".format(index, t))df15,363
flask-run.py,57
mod = importlib.import_module(sys.argv[1])mod8,164
+rmbs/CRT_data.py,99
+def get_CRT_notional():get_CRT_notional10,159
+def calc_CRT_notional():calc_CRT_notional36,1221
+
+rmbs/marketing.py,118
+def ver_one():ver_one6,87
+def plot_strat():plot_strat29,1253
+def wavg(group, avg_name, weight_name):wavg54,2014
+
+load_refentity.py,529
+parser = etree.XMLParser(remove_blank_text=True)parser6,100
+def todict(xml, uselist=set()):todict9,183
+def dispatch_parsing(col, uselist):dispatch_parsing27,768
+def insert_refentity(fname):insert_refentity36,1012
+def parse_prospectus(xml):parse_prospectus62,2292
+def insert_refobligation(fname):insert_refobligation65,2379
+def get_date(f):get_date105,4687
+ base_dir = Path('/home/serenitas/CorpCDOs/Tranche_data/RED_reports/Deltas')base_dir113,4921
+ f = base_dir / download_report(report)[0]f115,5061
+
+markit_tranche_quotes.py,726
+params = {"username": "serenitasreports",params8,88
+r = requests.get("https://quotes.markit.com/reports/runReport",r14,299
+ params=params)params15,363
+f = io.StringIO(r.text)f17,396
+index_mapping = {'ITRAXX-Europe': 'EU',index_mapping21,478
+def get_latest_quote_id(db):get_latest_quote_id31,982
+def convert_float(s):convert_float37,1157
+serenitasdb = dbconn('serenitasdb')serenitasdb40,1215
+runningdict1 = {0: 500, 3:100, 7:100, 15: 25}runningdict142,1252
+runningdict2 = {0: 500, 3:500, 7:500, 10:100, 15:100, 30:100}runningdict243,1298
+markit_id = get_latest_quote_id(serenitasdb)markit_id44,1360
+headers = [h.lower() for h in next(f).split(",")]headers46,1406
+count = 0count47,1456
+
xmltotab.py,213
ns = '{urn:schemas-microsoft-com:office:spreadsheet}'ns4,35
doc = etree.parse('/home/share/guillaume/grid1_1cz1rlvt.xml')doc6,90
tree = doc.getroot()tree7,152
csvwriter = csv.writer(fh)csvwriter10,210
-task_runner.py,77
-def run():run12,210
- logger = logging.getLogger('intex')logger36,1066
+task_runner.py,75
+def run():run9,172
+ logger = logging.getLogger('intex')logger32,934
+
+tasks.py,356
+def build_portfolios(workdate, dealname, reinvflag):build_portfolios8,124
+def build_scenarios(workdate, dealname, reinvflag):build_scenarios15,472
+class Rpc(object):Rpc22,818
+ def __init__(self, fun, args):__init__23,837
+ def __str__(self):__str__27,921
+ def __call__(self):__call__30,1025
+ def from_json(cls, s):from_json34,1107
-tasks.py,148
-def build_portfolio(workdate, dealname, reinvflag):build_portfolio5,82
-def build_scenarios(workdate, dealname, reinvflag):build_scenarios13,531
+graphics.py,227
+def shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap'):shiftedColorMap5,78
+def plot_time_color_map(df, spread_shock, attr="pnl", path=".", color_map=cm.RdYlGn, index='IG'):plot_time_color_map57,1854
adj_index_price.py,639
index='HY'index4,86
@@ -892,7 +1080,7 @@ index_quotes= Table('index_quotes', metadata, autoload=True)index_quotes11,312
r = factors.ix[i].indexfactor/factors.ix[i+1].indexfactorr28,1248
stmt = index_quotes.update().where((index_quotes.c.date==bindparam('b_date')) &stmt34,1562
-intex/intex_scenarios.py,1335
+intex/intex_scenarios.py,1343
logger = logging.getLogger(__name__)logger16,196
pattern1 = re.compile("REINVEST\[\w+::REINV_TBA(\d)\]\[DEAL,(\d+)\]=.*$")pattern118,234
pattern2 = re.compile("(STANDARD_VAR\[)\w+(::#REINV_END,\d+\]=)(\d.*$)")pattern220,325
@@ -904,14 +1092,14 @@ pattern9 = re.compile("(?P<a>SEVERITY\[\w+,\d+\]=)mkt\(70\)")pattern926,671
global_reinvfloatpercentage = 84global_reinvfloatpercentage29,785
global_reinvfixedpercentage = 16global_reinvfixedpercentage30,818
def get_reinv_assets(conn, dealname, workdate):get_reinv_assets32,852
-def get_recovery(conn, dealname, workdate, defaultrecovery = 50):get_recovery42,1183
-def get_reinvenddate(conn, dealname):get_reinvenddate58,1844
-def generate_scenarios(workdate, dealname, conn):generate_scenarios69,2217
- workdate = sys.argv[1]workdate229,10433
- workdate = str(datetime.date.today())workdate231,10474
- dealnames = sys.argv[2:]dealnames233,10546
- dealnames = [d.split(".")[0] for d indealnames235,10589
- ET = dbconn('etdb')ET239,10834
+def get_recovery(conn, dealname, workdate, defaultrecovery=50):get_recovery42,1205
+def get_reinvenddate(conn, dealname, workdate):get_reinvenddate58,1868
+def generate_scenarios(workdate, dealname, conn):generate_scenarios69,2258
+ workdate = sys.argv[1]workdate231,10580
+ workdate = str(datetime.date.today())workdate233,10621
+ dealnames = sys.argv[2:]dealnames235,10693
+ dealnames = [d.split(".")[0] for d indealnames237,10736
+ ET = dbconn('etdb')ET241,10981
intex/__init__.py,0
@@ -921,113 +1109,233 @@ def convertToNone(s):convertToNone14,240
def insert_new_cusip(conn, line):insert_new_cusip17,310
def upload_cusip_data(conn, filename):upload_cusip_data38,1327
def upload_deal_data(conn, filename):upload_deal_data100,4288
- workdate = sys.argv[1]workdate182,8597
- workdate = str(datetime.date.today())workdate184,8638
- files = [os.path.join(os.environ['DATA_DIR'], "Indicative_" + workdate, f) for f infiles185,8684
- cusip_files = [f for f in files if "TrInfo" in f]cusip_files187,8861
- deal_files = [f for f in files if "TrInfo" not in f]deal_files188,8915
+ workdate = sys.argv[1]workdate183,8568
+ workdate = str(datetime.date.today())workdate185,8609
+ files = [os.path.join(os.environ['DATA_DIR'], "Indicative_" + workdate, f) for f infiles186,8655
+ cusip_files = [f for f in files if "TrInfo" in f]cusip_files188,8832
+ deal_files = [f for f in files if "TrInfo" not in f]deal_files189,8886
intex/__main__.py,150
logger = logging.getLogger('intex')logger6,110
workdate = sys.argv[1]workdate10,212
workdate = str(datetime.date.today())workdate12,245
-intex/load_intex_collateral.py,359
-logger = logging.getLogger(__name__)logger11,212
-fields = ['Asset Name', 'Issuer', 'Contributed Balance', 'Asset Maturity Date',fields13,250
-def convertToNone(s):convertToNone21,759
-def windows1252_encoder(fh):windows1252_encoder24,814
-def upload_data(conn, dealnames, workdate):upload_data28,922
-def intex_data(conn, workdate):intex_data136,6670
+intex/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
+
+intex/load_intex_collateral.py,249
+logger = logging.getLogger(__name__)logger12,237
+fields = ['Asset Name', 'Issuer', 'Contributed Balance', 'Asset Maturity Date',fields14,275
+def upload_data(conn, workdate):upload_data22,809
+def intex_data(conn, workdate):intex_data142,7121
intex/common.py,53
def sanitize_float(intex_float):sanitize_float3,11
analytics/__init__.py,0
-analytics/option.py,2486
-def calib(S0, fp, exercise_date, exercise_date_settle,calib30,756
-def memoize(f):memoize38,1087
- def cached_f(*args, **kwargs):cached_f40,1117
-def ATMstrike(index, exercise_date):ATMstrike51,1400
-class BlackSwaption(ForwardIndex):BlackSwaption70,1923
- __slots__ = ['_forward_yc', '_T', '_G', '_strike', 'option_type',__slots__72,1983
- def __init__(self, index, exercise_date, strike, option_type="payer",__init__75,2122
- def from_tradeid(cls, trade_id, index=None):from_tradeid88,2588
- def exercise_date(self):exercise_date105,3395
- def exercise_date(self, d):exercise_date109,3484
- def strike(self):strike116,3732
- def strike(self, K):strike123,3898
- def atm_strike(self):atm_strike134,4335
- def moneyness(self):moneyness142,4575
- def direction(self):direction146,4660
- def direction(self, d):direction153,4809
- def intrinsic_value(self):intrinsic_value162,5065
- def __hash__(self):__hash__167,5283
- def pv(self):pv172,5471
- def pv(self, val):pv186,6018
- def handle(x):handle196,6395
- def reset_pv(self):reset_pv208,6689
- def pnl(self):pnl212,6764
- def delta(self):delta222,7100
- def T(self):T237,7582
- def gamma(self):gamma244,7754
- def theta(self):theta257,8091
- def vega(self):vega265,8262
- def DV01(self):DV01274,8463
- def breakeven(self):breakeven284,8722
- def __repr__(self):__repr__299,9320
- def __str__(self):__str__327,10943
-class Swaption(BlackSwaption):Swaption330,11028
- __slots__ = ["_cache", "_Z", "_w"]__slots__331,11059
- def __init__(self, index, exercise_date, strike, option_type="payer",__init__332,11098
- def __hash__(self):__hash__338,11351
- def pv(self):pv343,11437
- def pv(self, val):pv377,13031
- def handle(x):handle381,13129
- def __setpv_black(self, val):__setpv_black397,13522
- pv_black = property(None, __setpv_black)pv_black407,13903
-def compute_vol(option, strike, mid):compute_vol410,13950
-class VolatilitySurface(ForwardIndex):VolatilitySurface419,14135
- def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()):__init__420,14174
- def vol(self, T, moneyness, surface_id):vol444,15500
- def list(self, source=None, option_type=None, model=None):list448,15665
- def __iter__(self):__iter__458,16043
- def plot(self, surface_id):plot461,16106
- def __getitem__(self, surface_id):__getitem__472,16544
+analytics/db.py,47
+_engine = dbengine('serenitasdb')_engine2,32
+
+analytics/option.py,4190
+def calib(S0, fp, exercise_date, exercise_date_settle,calib36,938
+def memoize(f):memoize44,1269
+ def cached_f(*args, **kwargs):cached_f46,1299
+def ATMstrike(index, exercise_date):ATMstrike57,1582
+class BlackSwaption(ForwardIndex):BlackSwaption76,2105
+ __slots__ = ['_forward_yc', '_T', '_G', '_strike', 'option_type',__slots__78,2165
+ def __init__(self, index, exercise_date, strike, option_type="payer",__init__81,2304
+ def __setstate__(self, state):__setstate__94,2793
+ def from_tradeid(cls, trade_id, index=None):from_tradeid100,2963
+ def exercise_date(self):exercise_date117,3770
+ def exercise_date(self, d):exercise_date121,3859
+ def strike(self):strike132,4311
+ def strike(self, K):strike139,4477
+ def atm_strike(self):atm_strike150,4914
+ def moneyness(self):moneyness158,5154
+ def direction(self):direction163,5333
+ def direction(self, d):direction170,5482
+ def intrinsic_value(self):intrinsic_value179,5738
+ def __hash__(self):__hash__184,5956
+ def pv(self):pv189,6144
+ def tail_prob(self):tail_prob203,6690
+ def pv(self, val):pv216,7239
+ def handle(x):handle226,7616
+ def reset_pv(self):reset_pv238,7910
+ def pnl(self):pnl242,7985
+ def delta(self):delta252,8321
+ def T(self):T267,8803
+ def gamma(self):gamma274,8978
+ def theta(self):theta287,9315
+ def vega(self):vega295,9486
+ def DV01(self):DV01304,9687
+ def breakeven(self):breakeven314,9946
+ def __repr__(self):__repr__329,10544
+ def __str__(self):__str__357,12167
+class Swaption(BlackSwaption):Swaption360,12252
+ __slots__ = ["_cache", "_Z", "_w"]__slots__361,12283
+ def __init__(self, index, exercise_date, strike, option_type="payer",__init__362,12322
+ def __hash__(self):__hash__368,12575
+ def pv(self):pv373,12661
+ def pv(self, val):pv407,14255
+ def handle(x):handle411,14353
+ def __setpv_black(self, val):__setpv_black427,14746
+ pv_black = property(None, __setpv_black)pv_black437,15127
+def _get_keys(df, models=["black", "precise"]):_get_keys439,15173
+class QuoteSurface():QuoteSurface450,15641
+ def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()):__init__451,15663
+ def list(self, source=None):list473,16855
+class VolSurface(QuoteSurface):VolSurface483,17272
+ def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()):__init__484,17304
+ def __getitem__(self, surface_id):__getitem__488,17488
+ def vol(self, T, moneyness, surface_id):vol502,18293
+ def plot(self, surface_id):plot506,18448
+def _compute_vol(option, strike, mid):_compute_vol521,18985
+def _calibrate(index, quotes, option_model, option_type):_calibrate530,19233
+class ModelBasedVolSurface(VolSurface):ModelBasedVolSurface548,19951
+ def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()):__init__549,19991
+ def list(self, source=None, option_type=None):list561,20645
+ def __getitem__(self, surface_id):__getitem__570,20992
+ def plot(self, surface_id):plot586,21798
+class BlackSwaptionVolSurface(ModelBasedVolSurface):BlackSwaptionVolSurface599,22337
+class SwaptionVolSurface(ModelBasedVolSurface):SwaptionVolSurface602,22400
+def _forward_annuity(expiry, index):_forward_annuity606,22481
+class ProbSurface(QuoteSurface):ProbSurface616,22934
+ def __init__(self, index_type, series, tenor='5yr', trade_date=datetime.date.today()):__init__618,22968
+ def __getitem__(self, surface_id):__getitem__623,23229
+ def tail_prob(self, T, strike, surface_id):tail_prob658,25280
+ def plot(self, surface_id):plot662,25443
+class MyInterp:MyInterp678,26047
+ def __init__(self, T, f):__init__679,26063
+ def __call__(self, x, y):__call__684,26170
+def calib_sabr(x, option, strikes, pv, beta):calib_sabr693,26486
+class SABRVolSurface(VolSurface):SABRVolSurface704,26814
+ def __init__(self, index_type, series, tenor='5yr',__init__705,26848
+ def list(self, source=None, option_type=None):list714,27226
+ def __getitem__(self, surface_id):__getitem__723,27544
analytics/portfolio.py,1022
-serenitasdb = dbengine('serenitasdb')serenitasdb8,185
-def portf_repr(method):portf_repr10,224
- def f(*args):f11,248
-class Portfolio:Portfolio31,1084
- def __init__(self, trades):__init__32,1101
- def pnl(self):pnl52,1874
- def pnl_list(self):pnl_list56,1955
- def pv(self):pv60,2038
- def pv_list(self):pv_list64,2117
- def reset_pv(self):reset_pv67,2184
- def trade_date(self):trade_date72,2278
- def trade_date(self, d):trade_date76,2360
- def mark(self, source_list=[], option_type=None, model="black", surface_id=None):mark85,2653
- def ref(self):ref113,4119
- def ref(self, val):ref120,4300
- def spread(self):spread134,4798
- def spread(self, val):spread141,4991
- def delta(self):delta155,5504
- def gamma(self):gamma162,5745
- def dv01(self):dv01166,5860
- def theta(self):theta170,5943
- def _todf(self):_todf173,6014
- __repr__ = portf_repr('string')__repr__192,6948
- _repr_html_ = portf_repr('html')_repr_html_194,6985
+serenitasdb = dbengine('serenitasdb')serenitasdb8,174
+def portf_repr(method):portf_repr10,213
+ def f(*args):f11,237
+class Portfolio:Portfolio31,1073
+ def __init__(self, trades):__init__32,1090
+ def pnl(self):pnl47,1791
+ def pnl_list(self):pnl_list51,1872
+ def pv(self):pv55,1955
+ def pv_list(self):pv_list59,2034
+ def reset_pv(self):reset_pv62,2101
+ def trade_date(self):trade_date67,2195
+ def trade_date(self, d):trade_date71,2277
+ def mark(self, source_list=[], option_type=None, model="black", surface_id=None):mark80,2570
+ def ref(self):ref106,3886
+ def ref(self, val):ref113,4067
+ def spread(self):spread127,4565
+ def spread(self, val):spread134,4758
+ def delta(self):delta148,5271
+ def gamma(self):gamma155,5512
+ def dv01(self):dv01159,5627
+ def theta(self):theta163,5710
+ def _todf(self):_todf166,5781
+ __repr__ = portf_repr('string')__repr__185,6696
+ _repr_html_ = portf_repr('html')_repr_html_187,6733
+
+analytics/black.py,268
+def d1(F, K, sigma, T):d16,114
+def d2(F, K, sigma, T):d29,207
+def d12(F, K, sigma, T):d1213,316
+def cnd_erf(d):cnd_erf22,524
+def black(F, K, T, sigma, payer=True):black27,684
+def Nx(F, K, sigma, T):Nx35,968
+def bachelier(F, K, T, sigma):bachelier38,1065
-analytics/black.py,184
-def d1(F, K, sigma, T):d15,85
-def d2(F, K, sigma, T):d28,178
-def d12(F, K, sigma, T):d1212,287
-def cnd_erf(d):cnd_erf21,495
-def black(F, K, T, sigma, payer=True):black26,655
+analytics/sabr.py,899
+def sabr_lognormal(alpha, rho, nu, F, K, T):sabr_lognormal7,178
+def sabr_normal(alpha, rho, nu, F, K, T):sabr_normal19,653
+def sabr(alpha, beta, rho, nu, F, K, T):sabr37,1399
+ underlying = Index.from_name("IG", 28, "5yr")underlying64,2521
+ exercise_date = datetime.date(2017, 9, 20)exercise_date66,2602
+ option = BlackSwaption(underlying, exercise_date, 70)option67,2650
+ strikes = np.array([50, 55, 57.5, 60, 62.5, 65, 67.5, 70, 75, 80, 85])strikes69,2711
+ pvs = np.array([44.1, 25.6, 18.9, 14, 10.5, 8.1, 6.4, 5, 3.3, 2.2, 1.5]) * 1e-4pvs70,2787
+ strikes = np.array([50, 55, 57.5, 60, 62.5, 65, 67.5, 70, 75, 80, 85, 90, 95, 100])strikes72,2874
+ pvs = np.array([53.65, 37.75, 31.55, 26.45, 22.25, 18.85, 16.15, 13.95, 10.55,pvs73,2963
+ def calib(x, option, strikes, pv, beta):calib76,3108
+ prog = least_squares(calib, (0.3, 0.5, 0.3),prog87,3469
+
+analytics/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
+
+analytics/tranche_functions.py,1895
+def wrapped_ndpointer(*args, **kwargs):wrapped_ndpointer11,367
+ def from_param(cls, obj):from_param13,445
+libloss = np.ctypeslib.load_library("lossdistrib", os.path.join(libloss19,640
+def GHquad(n):GHquad112,4022
+def stochasticrecov(R, Rtilde, Z, w, rho, porig, pmod):stochasticrecov116,4102
+def fitprob(Z, w, rho, p0):fitprob122,4398
+def BCloss_recov_dist(defaultprob, issuerweights, recov, rho, Z, w, Ngrid=101, defaultflag=False):BCloss_recov_dist127,4574
+def BCloss_recov_trunc(defaultprob, issuerweights, recov, rho, K, Z, w, Ngrid=101, defaultflag=False):BCloss_recov_trunc137,5131
+def lossdistrib_joint(p, pp, w, S, Ngrid=101, defaultflag=False):lossdistrib_joint149,5772
+def lossdistrib_joint_Z(p, pp, w, S, rho, Ngrid=101, defaultflag=False, nZ=500):lossdistrib_joint_Z189,6954
+def joint_default_averagerecov_distrib(p, S, Ngrid=101):joint_default_averagerecov_distrib246,8597
+def adjust_attachments(K, losstodate, factor):adjust_attachments277,9510
+def trancheloss(L, K1, K2):trancheloss284,9710
+def trancherecov(R, K1, K2):trancherecov287,9796
+def tranche_cl(L, R, cs, K1, K2, scaled=False):tranche_cl290,9891
+def tranche_pl(L, cs, K1, K2, scaled=False):tranche_pl303,10390
+def tranche_pv(L, R, cs, K1, K2):tranche_pv315,10771
+def credit_schedule(tradedate, tenor, coupon, yc, enddate=None):credit_schedule318,10874
+def cds_accrued(tradedate, coupon):cds_accrued336,11677
+def dist_transform(q):dist_transform347,12087
+def dist_transform2(q):dist_transform2362,12501
+def compute_pv(q, strike):compute_pv376,12902
+def average_recov(p, R, Ngrid):average_recov383,13104
+ n_issuers = 100n_issuers411,14110
+ p = np.random.rand(n_issuers)p412,14130
+ R = np.random.rand(n_issuers)R413,14164
+ Rbar = joint_default_averagerecov_distrib(p, 1-R, 1001)Rbar414,14198
+ Rbar_slow = average_recov(p, R, 1001)Rbar_slow415,14258
+
+analytics/index_data.py,926
+def insert_quotes():insert_quotes15,350
+def get_index_quotes(index=None, series=None, tenor=None, from_date=None, years=3):get_index_quotes48,2099
+ def make_str(key, val):make_str56,2443
+ def make_params(args):make_params72,2977
+def index_returns(df=None, index=None, series=None, tenor=None, from_date=None, years=3, per=1):index_returns89,3673
+def get_singlenames_quotes(indexname, date):get_singlenames_quotes129,5434
+def build_curve(r, tenors, currency="USD"):build_curve135,5652
+def build_curves(quotes, args):build_curves149,6222
+def build_curves_dist(quotes, args, workers=4):build_curves_dist152,6323
+def _get_singlenames_curves(index_type, series, trade_date):_get_singlenames_curves160,6629
+def get_singlenames_curves(index_type, series, trade_date):get_singlenames_curves168,7003
+def get_tranche_quotes(index_type, series, tenor, date=datetime.date.today()):get_tranche_quotes175,7329
+
+analytics/tranche_basket.py,1697
+class TrancheBasket(BasketIndex):TrancheBasket18,633
+ def __init__(self, index_type: str, series: int, tenor: str, *,__init__19,667
+ def tranche_factors(self):tranche_factors66,3027
+ def _get_quotes(self, spread=None):_get_quotes69,3127
+ def _snacpv(self, spread, coupon, recov):_snacpv82,3747
+ def default_prob(self):default_prob88,4035
+ def tranche_legs(self, K, rho, complement=False, shortened=0):tranche_legs92,4243
+ def tranche_pvs(self, protection=False, complement=False, shortened=0):tranche_pvs115,5337
+ def index_pv(self, discounted=True, shortened=0):index_pv135,6036
+ def expected_loss(self, discounted=True, shortened=0):expected_loss157,6935
+ def expected_loss_trunc(self, K, rho=None, shortened=0):expected_loss_trunc171,7406
+ def probability_trunc(self, K, rho=None, shortened=0):probability_trunc188,8112
+ def recovery_rates(self):recovery_rates202,8651
+ def tranche_durations(self, complement=False):tranche_durations205,8750
+ def _row_names(self):_row_names214,9120
+ def tranche_thetas(self, complement=False, shortened=4, method='ATM'):tranche_thetas219,9312
+ def tranche_fwd_deltas(self, complement=False, shortened=4, method='ATM'):tranche_fwd_deltas228,9795
+ def tranche_deltas(self, complement=False):tranche_deltas239,10208
+ def build_skew(self, skew_type="bottomup"):build_skew261,11131
+ def aux(rho, obj, K, quote, spread, complement):aux265,11275
+ def map_skew(self, index2, method="ATM", shortened=0):map_skew298,12825
+ def aux(x, index1, el1, index2, el2, K2, shortened):aux299,12884
+ def aux2(x, index1, index2, K2, shortened):aux2308,13292
analytics/scenarios.py,403
def run_swaption_scenarios(swaption, date_range, spread_shock, vol_shock,run_swaption_scenarios11,264
@@ -1036,67 +1344,120 @@ def _aux(portf, curr_vols, params, vs):_aux56,1849
def MaybePool(nproc):MaybePool62,2068
def run_portfolio_scenarios(portf, date_range, spread_shock, vol_shock,run_portfolio_scenarios65,2136
-analytics/index.py,2582
-engine = dbengine('serenitasdb')engine23,665
-def g(index, spread, exercise_date, forward_yc=None, pv=0.):g25,700
-def _key_from_index(index):_key_from_index43,1571
-class Index(object):Index49,1755
- __slots__ = ['fixed_rate', 'notional', '_start_date', '_end_date',__slots__51,1830
- def __init__(self, start_date, end_date, recovery, fixed_rate,__init__58,2321
- def __hash__(self):__hash__95,3711
- def start_date(self):start_date99,3824
- def end_date(self):end_date103,3897
- def start_date(self, d):start_date107,3975
- def end_date(self, d):end_date113,4184
- def spread(self):spread119,4386
- def direction(self):direction125,4535
- def direction(self, d):direction132,4687
- def _update(self):_update140,4931
- def spread(self, s):spread157,5847
- def flat_hazard(self):flat_hazard165,6061
- def pv(self):pv171,6225
- def pv(self, val):pv175,6333
- def accrued(self):accrued181,6567
- def days_accrued(self):days_accrued186,6721
- def clean_pv(self):clean_pv190,6804
- def price(self):price194,6923
- def price(self, val):price198,6990
- def ref(self):ref220,8081
- def ref(self, val):ref227,8225
- def DV01(self):DV01234,8370
- def theta(self):theta242,8565
- def IRDV01(self):IRDV01253,9013
- def rec_risk(self):rec_risk272,9585
- def jump_to_default(self):jump_to_default285,9965
- def risky_annuity(self):risky_annuity290,10125
- def trade_date(self):trade_date294,10220
- def trade_date(self, d):trade_date301,10421
- def reset_pv(self):reset_pv329,11657
- def pnl(self):pnl334,11798
- def notify(self):notify344,12241
- def observe(self, obj):observe348,12325
- def mark(self):mark351,12389
- def from_name(cls, index=None, series=None, tenor=None, trade_date=datetime.date.today(),from_name367,13090
- def from_tradeid(cls, trade_id):from_tradeid417,15492
- def __repr__(self):__repr__438,16351
-class ForwardIndex(object):ForwardIndex483,18901
- __slots__ = ['index', 'forward_date', 'exercise_date_settle', 'df',__slots__484,18929
- def __init__(self, index, forward_date):__init__487,19104
- def from_name(cls, index_type, series, tenor, forward_date,from_name499,19558
- def forward_annuity(self):forward_annuity505,19826
- def forward_pv(self):forward_pv509,19909
- def forward_spread(self):forward_spread513,19982
- def ref(self):ref517,20069
- def ref(self, val):ref521,20135
- def __hash__(self):__hash__524,20189
- def _update(self, *args):_update527,20313
+analytics/cms_spread.py,907
+def CMS_spread(T_alpha, X, beta, gamma):CMS_spread32,1322
+def f(v, X, S_alpha_beta, S_alpha_gamma, mu_beta, mu_gamma, T_alpha, rho):f36,1416
+def h(v, X, S_alpha_beta, mu_beta, sigma_alpha_beta, T_alpha):h47,2017
+def get_fixings(conn, tenor1, tenor2, fixing_date=None):get_fixings52,2239
+def build_spread_index(tenor1, tenor2):build_spread_index74,3113
+def get_swaption_vol_data(source="ICPL", vol_type=VolatilityType.ShiftedLognormal,get_swaption_vol_data81,3413
+def get_swaption_vol_surface(date, vol_type):get_swaption_vol_surface100,4097
+def get_swaption_vol_matrix(date, data, vol_type=VolatilityType.ShiftedLognormal):get_swaption_vol_matrix105,4356
+def quantlib_model(date, spread_index, yc, cap, rho, maturity, mean_rev=0.,quantlib_model124,5226
+def plot_surf(surf, tenors):plot_surf146,6310
+def globeop_model(date, spread_index, yc, strike, rho, maturity,globeop_model152,6489
+
+analytics/index.py,2689
+def g(index, spread, exercise_date, forward_yc=None, pv=None):g24,688
+class Index(object):Index52,1980
+ __slots__ = ['fixed_rate', 'notional', '_start_date', '_end_date',__slots__54,2055
+ def __init__(self, start_date, end_date, recovery, fixed_rate,__init__62,2598
+ def __hash__(self):__hash__97,4009
+ def __getstate__(self):__getstate__100,4108
+ def __setstate__(self, state):__setstate__103,4203
+ def start_date(self):start_date109,4369
+ def end_date(self):end_date113,4442
+ def start_date(self, d):start_date117,4520
+ def end_date(self, d):end_date123,4729
+ def spread(self):spread129,4931
+ def direction(self):direction135,5080
+ def direction(self, d):direction142,5232
+ def _update(self):_update150,5476
+ def spread(self, s):spread167,6392
+ def flat_hazard(self):flat_hazard175,6606
+ def pv(self):pv181,6770
+ def pv(self, val):pv185,6878
+ def accrued(self):accrued191,7112
+ def days_accrued(self):days_accrued196,7266
+ def clean_pv(self):clean_pv200,7349
+ def price(self):price204,7468
+ def price(self, val):price208,7535
+ def ref(self):ref230,8626
+ def ref(self, val):ref237,8770
+ def DV01(self):DV01244,8915
+ def theta(self):theta252,9110
+ def IRDV01(self):IRDV01263,9558
+ def rec_risk(self):rec_risk282,10163
+ def jump_to_default(self):jump_to_default295,10543
+ def risky_annuity(self):risky_annuity300,10703
+ def trade_date(self):trade_date304,10798
+ def trade_date(self, d):trade_date311,10999
+ def reset_pv(self):reset_pv327,11687
+ def pnl(self):pnl332,11828
+ def notify(self):notify342,12271
+ def observe(self, obj):observe346,12355
+ def mark(self):mark349,12416
+ def factor(self):factor364,13074
+ def version(self):version372,13270
+ def from_name(cls, index=None, series=None, tenor=None, trade_date=datetime.date.today(),from_name380,13475
+ def from_tradeid(cls, trade_id):from_tradeid435,16138
+ def __repr__(self):__repr__464,17433
+class ForwardIndex(object):ForwardIndex509,19983
+ __slots__ = ['index', 'forward_date', 'exercise_date_settle', 'df',__slots__510,20011
+ def __init__(self, index, forward_date, observer=True):__init__513,20186
+ def from_name(cls, index_type, series, tenor, forward_date,from_name526,20680
+ def forward_annuity(self):forward_annuity532,20948
+ def forward_pv(self):forward_pv536,21031
+ def forward_spread(self):forward_spread540,21104
+ def ref(self):ref544,21191
+ def ref(self, val):ref548,21257
+ def __hash__(self):__hash__551,21311
+ def _update(self, *args):_update554,21435
+
+analytics/utils.py,471
+tenor_t = CategoricalDtype(['3yr', '5yr', '7yr', '10yr'], ordered=True)tenor_t10,289
+def GHquad(n):GHquad12,362
+def previous_twentieth(d):previous_twentieth17,485
+def next_twentieth(d):next_twentieth26,689
+def third_wednesday(d):third_wednesday35,894
+def next_third_wed(d):next_third_wed41,1099
+def roll_date(d, tenor, nd_array=False):roll_date48,1251
+ def kwargs(t):kwargs51,1380
+def build_table(rows, format_strings, row_format):build_table94,3058
+
+analytics/basket_index.py,1693
+def make_index(t, d, args):make_index16,452
+class BasketIndex(CreditIndex):BasketIndex22,603
+ def __init__(self, index_type: str, series: int, tenors: List[str], *,__init__30,776
+ def __reduce__(self):__reduce__64,2796
+ def __hash__(self):__hash__69,2951
+ def aux(v):aux70,2975
+ def _query_version(self, i):_query_version80,3319
+ def factor(self):factor86,3488
+ def cumloss(self):cumloss90,3563
+ def version(self):version94,3639
+ def _get_quotes(self):_get_quotes97,3701
+ trade_date = property(CreditIndex.trade_date.__get__)trade_date100,3742
+ def trade_date(self, d: pd.Timestamp):trade_date103,3824
+ def pv(self, maturity=None, epsilon=0., coupon=None):pv110,4119
+ def coupon_leg(self, maturity=None):coupon_leg131,5038
+ def protection_leg(self, maturity=None):protection_leg134,5143
+ def spread(self, maturity=None, coupon=None):spread137,5234
+ def duration(self, maturity=None):duration143,5510
+ def theta(self, maturity=None, coupon=None):theta154,5988
+ def coupon(self, maturity=None):coupon183,7332
+ def tweak(self, *args):tweak189,7526
+class MarkitBasketIndex(BasketIndex):MarkitBasketIndex216,8549
+ def __init__(self, index_type: str, series: int, tenors: List[str], *,__init__217,8587
+ def _get_quotes(self):_get_quotes230,9434
+ ig28 = BasketIndex("IG", 28, ["3yr", "5yr", "7yr", "10yr"])ig28234,9543
+ settings = Settings()settings237,9727
+ cds_schedule = Schedule.from_rule(settings.evaluation_date, Date.from_datetime(ig28.maturities[-1]),cds_schedule239,9754
+ sp = ig28.survival_matrix(cds_schedule.to_npdates().view('int') + 134774)sp241,9962
-analytics/utils.py,255
-def GHquad(n):GHquad8,179
-def previous_twentieth(d):previous_twentieth13,302
-def next_twentieth(d):next_twentieth22,506
-def roll_date(d, tenor, nd_array=False):roll_date31,711
-def build_table(rows, format_strings, row_format):build_table71,2362
+.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
templates/template-2014-05-19.html,0
@@ -1132,54 +1493,26 @@ templates/template-2015-04-20.html,0
templates/template-2014-04-16.html,0
-test_pickle.py,246
-USD_rates = pd.read_sql_table("usd_rates", dbengine("serenitasdb"),USD_rates22,792
- index_col='effective_date')index_col23,860
-def build_curves():build_curves24,918
-def get_curves(date=None):get_curves54,2451
+exploration/beta_trade.py,690
+def calc_returns(index_list=['HY', 'IG'], save_feather=False):calc_returns19,389
+def calc_betas(returns=None, spans=[5, 20], index_list=['HY', 'IG']):calc_betas30,917
+def plot_betas(betas=None):plot_betas40,1313
+def calc_realized_vol(returns=None):calc_realized_vol50,1577
+def spreads_ratio(series=list(range(22, 29)), index=['IG', 'HY'], tenor='5yr'):spreads_ratio73,2462
+def loglik(beta, returns):loglik79,2727
+ returns = calc_returns()returns86,2906
+ betas = calc_betas(returns)betas87,2935
+ vol = calc_realized_vol(returns)vol89,2989
+ ratios = spreads_ratio()ratios90,3026
+ prog = minimize_scalar(loglik, bracket=(3, 5), args=(returns,))prog91,3055
-tranche_functions.py,1770
-def wrapped_ndpointer(*args, **kwargs):wrapped_ndpointer11,343
- def from_param(cls, obj):from_param13,421
-libloss = np.ctypeslib.load_library("lossdistrib", "../R/lossdistrib/src/")libloss19,616
-def GHquad(n):GHquad93,3228
-def stochasticrecov(R, Rtilde, Z, w, rho, porig, pmod):stochasticrecov97,3308
-def fitprob(Z, w, rho, p0):fitprob103,3604
-def BCloss_recov_dist(defaultprob, issuerweights, recov, rho, Z, w, Ngrid=101, defaultflag=False):BCloss_recov_dist108,3780
-def lossdistrib_joint(p, pp, w, S, Ngrid=101, defaultflag=False):lossdistrib_joint118,4339
-def lossdistrib_joint_Z(p, pp, w, S, rho, Ngrid=101, defaultflag=False, nZ=500):lossdistrib_joint_Z158,5521
-def joint_default_averagerecov_distrib(p, S, Ngrid=101):joint_default_averagerecov_distrib215,7164
-def adjust_attachments(K, losstodate, factor):adjust_attachments246,8077
-def trancheloss(L, K1, K2):trancheloss253,8277
-def trancherecov(R, K1, K2):trancherecov256,8363
-def tranche_cl(L, R, cs, K1, K2, scaled = False):tranche_cl259,8458
-def tranche_pl(L, cs, K1, K2, scaled=False):tranche_pl272,8957
-def tranche_pv(L, R, cs, K1, K2):tranche_pv284,9338
-def creditSchedule(tradedate, tenor, coupon, yc, enddate = None):creditSchedule287,9441
-def cdsAccrued(tradedate, coupon):cdsAccrued305,10209
-def dist_transform(q):dist_transform317,10643
-def dist_transform2(q):dist_transform2332,11057
-def compute_pv(q, strike):compute_pv346,11458
-def average_recov(p, R, Ngrid):average_recov353,11660
- n_issuers = 100n_issuers381,12666
- p = np.random.rand(n_issuers)p382,12686
- R = np.random.rand(n_issuers)R383,12720
- Rbar = joint_default_averagerecov_distrib(p, 1-R, 1001)Rbar384,12754
- Rbar_slow = average_recov(p, R, 1001)Rbar_slow385,12814
-
-exploration/beta_trade.py,633
-returns = index_returns(index=['IG', 'HY'], tenor='5yr')returns8,175
-returns = (returns.returns9,232
-returns = (returns.returns14,376
-vol_sma = returns.hy.rolling(20).std() * math.sqrt(252)vol_sma22,719
-vol_ewma = returns.hy.ewm(span=20).std() * math.sqrt(252)vol_ewma23,775
-scale = 10scale26,896
-am = arch_model(scale * returns.hy.dropna())am27,907
-res = am.fit()res28,952
-vol_garch = res.conditional_volatility * math.sqrt(252)/scalevol_garch29,967
-vol = pd.concat([vol_sma, vol_ewma, vol_garch], axis=1)vol30,1029
-beta_ewma = (returns.beta_ewma33,1109
-resids = returns.ig-beta_ewma*returns.hyresids39,1285
+exploration/tranches.py,326
+engine = dbengine('serenitasdb')engine17,571
+def rv_calc1():rv_calc119,606
+def dispersion():dispersion71,2854
+def scenarios(tranche, shock_range=None, roll_corr=False):scenarios99,4320
+def run_scen(trade_date = pd.Timestamp.today().normalize()- pd.offsets.BDay()):run_scen148,6960
+def plot_pnl():plot_pnl198,9083
exploration/sell_atm_vol.py,357
option_delta = Index.from_name('ig', 28, '5yr')option_delta6,145
@@ -1188,94 +1521,151 @@ receiver = BlackSwaption(option_delta, datetime.date(2017, 8, 16), 62.5, 'receiv
portfolio = Portfolio([payer, receiver, option_delta])portfolio24,668
r = []r27,804
-exploration/curve_trades.py,2027
-df = get_index_quotes("IG", [23, 24, 25, 26, 27], tenor=['3yr', '5yr', '7yr', '10yr'])df6,107
-spreads = df.groupby(level=['date', 'tenor']).nth(-1)['closespread'].unstack(-1)spreads7,194
-spreads = spreads.sort_index(1)spreads10,350
-spreads_diff = spreads.diff(axis=1)spreads_diff11,382
-spreads_diff = spreads_diff.filter([5, 7, 10])spreads_diff12,418
-df = index_returns(index='IG', series=[24, 25, 26, 27, 28], tenor=['3yr', '5yr', '7yr', '10yr'])df17,551
-returns = df.price_return.unstack(-1).dropna().groupby(level='date').nth(-1)returns19,670
-strategy510 = 1.78 * returns['5yr'] - returns['10yr']strategy51020,747
-strategy710 = 1.33 * returns['7yr'] - returns['10yr']strategy71021,801
-strategy3510 = -2 * returns['3yr']+ 3 * returns['5yr'] - 1 * returns['10yr']strategy351022,855
-monthly_returns510 = strategy510.groupby(pd.TimeGrouper(freq='M')).agg(lambda df:(1+df).prod()-1)monthly_returns51024,933
-monthly_returns710 = strategy710.groupby(pd.TimeGrouper(freq='M')).agg(lambda df:(1+df).prod()-1)monthly_returns71025,1031
-monthly_returns3510 = strategy3510.groupby(pd.TimeGrouper(freq='M')).agg(lambda df:(1+df).prod()-1)monthly_returns351026,1129
-sharpe510 = strategy510.mean()/strategy510.std()*math.sqrt(252)sharpe51028,1230
-sharpe710 = strategy710.mean()/strategy710.std()*math.sqrt(252)sharpe71029,1294
-sharpe3510 = strategy3510.mean()/strategy3510.std()*math.sqrt(252)sharpe351030,1358
-monthly_sharpe510 = monthly_returns510.mean()/monthly_returns510.std()*math.sqrt(12)monthly_sharpe51032,1426
-monthly_sharpe710 = monthly_returns710.mean()/monthly_returns710.std()*math.sqrt(12)monthly_sharpe71033,1511
-monthly_sharpe3510 = monthly_returns3510.mean()/monthly_returns3510.std()*math.sqrt(12)monthly_sharpe351034,1596
-worst_drawdown510 = strategy510.nsmallest(10)worst_drawdown51036,1685
-worst_drawdown710 = strategy710.nsmallest(10)worst_drawdown71037,1731
-worst_drawdown3510 = strategy3510.nsmallest(10)worst_drawdown351038,1777
-def forward_loss():forward_loss40,1826
+exploration/test_cms.py,652
+cap = 0.00758cap7,194
+corr = 0.8corr8,208
+r = []r9,219
+maturity = pd.Timestamp("2020-01-19")maturity10,226
+today = pd.Timestamp.today()today11,264
+ cms_spread_coupon_ln = quantlib_model(d, cms30y2y, yc, cap, corr, maturity)cms_spread_coupon_ln17,500
+ rate1 = cms_spread_coupon_ln.raterate118,580
+ cms_spread_coupon_n = quantlib_model(d, cms30y2y, yc, cap, corr, maturity,cms_spread_coupon_n19,618
+ rate2 = cms_spread_coupon_n.raterate221,759
+ rate3 = globeop_model(d, cms30y2y, yc, cap, corr - 0.075, maturity)rate322,796
+df = pd.DataFrame(r, columns=['date', 'QL_ln', 'QL_n', 'Globeop']).set_index('date')df24,907
+
+exploration/curve_trades.py,1273
+_engine = dbengine('serenitasdb')_engine15,461
+def on_the_run(index):on_the_run17,496
+def curve_spread_diff(index='IG', rolling=6):curve_spread_diff23,689
+def spreads_diff_table(spreads_diff):spreads_diff_table35,1217
+ def current(s):current36,1255
+ def zscore(s):zscore38,1300
+def theta_matrix_by_series(index='IG', rolling=6):theta_matrix_by_series44,1517
+def ratio_within_series(index='IG', rolling=6, param='duration'):ratio_within_series53,1999
+def curve_3_5_10(df):curve_3_5_1064,2548
+def curve_5_10(df):curve_5_1075,2872
+def on_the_run_theta(index='IG', rolling=6):on_the_run_theta80,3033
+def curve_returns(index='IG', rolling=6):curve_returns88,3405
+ def sharpe(df, period="daily"):sharpe107,4344
+def cross_series_curve(index='IG', rolling=6):cross_series_curve119,4843
+def forward_loss(index='IG'):forward_loss137,5704
+def curve_model(tenor_1='5yr', tenor_2='10yr'):curve_model154,6655
+def curve_model_results(df, model):curve_model_results169,7304
+def spread_fin_crisis(index='IG'):spread_fin_crisis182,8088
+def forward_spread(index='IG', series=None, tenors=['3yr', '5yr', '7yr', '10yr']):forward_spread206,8989
+def spot_forward(index='IG', series=None, tenors=['3yr', '5yr', '7yr', '10yr']):spot_forward220,9485
+
+exploration/backtest.py,130
+def calc_mark_diff():calc_mark_diff5,64
+ def closest(s):closest12,385
+ def avg_minus_maxmin(s):avg_minus_maxmin20,592
+
+exploration/option_trades.py,1558
+serenitasdb = dbengine('serenitasdb')serenitasdb14,310
+def realized_vol(index, series, tenor='5yr', date=None, years=None, return_type='spread'):realized_vol16,349
+def lr_var(res):lr_var29,1048
+def atm_vol_calc(df, index_type, moneyness):atm_vol_calc42,1443
+def atm_vol(index, date, series=None, moneyness=0.2):atm_vol75,3123
+def rolling_vol(df, col='atm_vol', term=[3]):rolling_vol91,3914
+ def aux(s, col, term):aux95,4128
+def vol_var(percentile=0.975, index='IG', start_date=datetime.date(2014, 6, 11)):vol_var106,4606
+def get_index_spread(index, series, date, conn):get_index_spread119,5093
+def get_index_ref(index, series, date, expiry, conn):get_index_ref131,5487
+def get_option_pnl(strike, expiry, index, series, start_date, engine):get_option_pnl144,5988
+def sell_vol_strategy(index="IG", months=3):sell_vol_strategy179,7669
+def aggregate_trades(d):aggregate_trades205,8976
+def compute_allocation(df):compute_allocation211,9119
+ df = atm_vol("HY", datetime.date(2017, 3, 20))df246,10413
+ df_hy28 = df.xs(28, level='series')df_hy28250,10603
+ results = smf.ols('log_atm_vol ~ log_forward_spread + T', data=df_hy28).fit()results251,10643
+ beta_hy28 = 1 + results.params.log_forward_spreadbeta_hy28252,10725
+ df = atm_vol("IG", datetime.date(2017, 3, 20))df256,10819
+ df_ig28 = df.xs(28, level='series')df_ig28260,11009
+ results = smf.ols('log_atm_vol ~ log_forward_spread + T', data=df_ig28).fit()results261,11049
+ beta_ig28 = 1 + results.params.log_forward_spreadbeta_ig28262,11131
+
+exploration/curve_trades2.py,945
+def on_the_run(index):on_the_run10,267
+def curve_spread_diff(index='IG', rolling=6):curve_spread_diff16,470
+def spreads_diff_table(spreads_diff):spreads_diff_table31,1140
+ def current(s):current32,1178
+ def zscore(s):zscore34,1223
+def theta_matrix_by_series(index='IG', rolling=6):theta_matrix_by_series40,1440
+def ratio_within_series(index='IG', rolling=6, param='duration'):ratio_within_series49,1922
+def curve_3_5_10(theta_ratio_within_series):curve_3_5_1059,2417
+def curve_5_10(theta_ratio_within_series):curve_5_1071,2983
+def on_the_run_theta(index='IG', rolling=6):on_the_run_theta77,3211
+def curve_returns(index='IG', rolling=6):curve_returns85,3583
+ def sharpe(df, period="daily"):sharpe102,4387
+def cross_series_curve(index='IG'):cross_series_curve114,4886
+def forward_loss(index='IG'):forward_loss131,5655
+def read_IG_curve_pos():read_IG_curve_pos148,6606
+def curve_model():curve_model155,6840
+
+exploration/marketing.py,357
+gridsize = 500gridsize6,131
+def run_scenario(pool_size, rho, successprob, issuerweights, amount):run_scenario8,147
+def plot_scenarios(df, bins = [0,0.1, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 2000]):plot_scenarios17,553
+def stats(df):stats37,1333
+def plot_prob_over(df):plot_prob_over44,1565
+def add_to_plot(df, ax):add_to_plot51,1763
+
+exploration/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
-exploration/option_trades.py,1262
-serenitasdb = dbengine('serenitasdb')serenitasdb14,300
-def realized_vol(index, series, tenor='5yr', date=None, years=None, return_type='spread'):realized_vol16,339
-def lr_var(res):lr_var28,972
-def atm_vol_fun(v, moneyness=0.2, index=None):atm_vol_fun41,1366
-def atm_vol(index, date, series=None, moneyness=0.2):atm_vol57,2034
-def atm_vol_calc(df, index):atm_vol_calc71,2636
-def rolling_vol(df, col='atm_vol', term=[3]):rolling_vol84,3200
- def aux(s, col, term):aux87,3362
-def vol_var(percentile=0.975, index='IG', start_date=datetime.date(2014, 6, 11)):vol_var98,3840
-def get_index_spread(index, series, date, conn):get_index_spread111,4327
-def get_index_ref(index, series, date, expiry, conn):get_index_ref123,4721
-def get_option_pnl(strike, expiry, index, series, start_date, engine):get_option_pnl136,5222
-def sell_vol_strategy(index="IG", months=3):sell_vol_strategy171,6903
-def aggregate_trades(d):aggregate_trades197,8210
-def compute_allocation(df):compute_allocation203,8353
- d1 = sell_vol_strategy(months=1)d1227,9135
- d2 = sell_vol_strategy(months=2)d2228,9172
- d3 = sell_vol_strategy(months=3)d3229,9209
- all_tenors = pd.concat([aggregate_trades(d) for d in [d1, d2, d3]], axis=1)all_tenors230,9246
+exploration/sell_vol.py,575
+df = index_returns(index="IG", tenor=["5yr"])df12,438
+df = df.reset_index(['index', 'tenor'], drop=True)df13,484
+spreads = df.dropna().groupby(['date']).nth(-1)['spread_return']spreads14,535
+monthly_returns = spreads.rolling('30D').apply(lambda s: (1 + s).prod() - 1)monthly_returns15,600
+mu = monthly_returns.median()mu16,677
+ecdf = ECDF(monthly_returns)ecdf17,707
+def implied_vol(q):implied_vol19,737
+engine = dbengine('serenitasdb')engine24,949
+sched = Schedule.from_rule(Date(1, 6, 2014), Date(1, 4, 2018), Period(1, Months), UnitedStates())sched25,982
-exploration/swaption_calendar_spread.py,746
-engine = dbengine('serenitasdb')engine23,645
-def shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap'):shiftedColorMap25,680
-def plot_df(df, spread_shock, vol_shock, attr="pnl"):plot_df76,2455
-def plot_color_map(df, spread_shock, vol_shock, attr="pnl", path="."):plot_color_map91,3050
-def plot_time_color_map(df, spread_shock, attr="pnl", path=".", color_map = cm.RdYlGn):plot_time_color_map116,4187
-def dec_jan_2017_trade():dec_jan_2017_trade141,5249
-def april_may_2017_trade(what='pnl'):april_may_2017_trade158,6123
-def june_july_2017_trade():june_july_2017_trade176,6997
-def hy_trade_scenario():hy_trade_scenario207,8494
-def portfolio():portfolio246,10502
-def probabilities():probabilities268,11718
+exploration/swaption_calendar_spread.py,406
+engine = dbengine('serenitasdb')engine22,606
+def plot_df(df, spread_shock, vol_shock, attr="pnl"):plot_df25,642
+def plot_color_map(df, spread_shock, vol_shock, attr="pnl", path=".", index ='IG'):plot_color_map40,1237
+def plot_trade_scenarios(portf, shock_min=-.15, shock_max=.2, period = -1, vol_time_roll=True):plot_trade_scenarios65,2461
+def exercise_probability():exercise_probability94,4069
-exploration/portfolio_var.py,1139
-dawndb = dbengine('dawndb')dawndb10,260
-serenitasdb = dbengine('serenitasdb')serenitasdb11,288
-shock = []shock15,387
-shock_values = [.95,.05]shock_values16,398
-shock = pd.DataFrame.from_records(shock, columns=['index', 'percent', 'shock'], index=['index', 'percent'])shock26,981
-trade_date = datetime.date.today() - BDay(2)trade_date32,1174
- "maturity, folder FROM cds where trade_date < %s",df34,1341
-df = df.groupby(['security_id','maturity','folder']).agg(sum)df36,1498
-df1 = pd.read_sql_query("SELECT redindexcode as security_id, index, series, indexfactor from index_version where lastdate = 'infinity'", serenitasdb)df139,1599
-df2 = pd.read_sql_query("SELECT * from index_maturity", serenitasdb, parse_dates=['maturity'])df240,1749
- " FROM index_quotes where date = %s",df342,1911
-df = df.merge(df1, on='security_id')df45,2030
-df = df.merge(df2, how='inner', on=['index','maturity', 'series'])df46,2067
-df = df.merge(df3, on=['index','series','tenor'])df47,2134
-df1 = df.groupby(['folder']).agg(sum)[[.95,.05]]df153,2477
-df1 = df1.min(axis = 1)df154,2526
+exploration/compression.py,181
+df = get_index_quotes(["IG", "HY"], 27, "5yr")df2,40
+df = df.groupby(level=['date', 'index']).nth(-1)df3,87
+df = df.groupby(level=['date', 'index', 'version']).nth(-1)df5,168
-exploration/portfolio_example.py,697
-option_delta = Index.from_tradeid(870)option_delta23,808
-option1 = BlackSwaption.from_tradeid(5, option_delta)option124,847
-option2 = BlackSwaption.from_tradeid(6, option_delta)option225,901
-portf = Portfolio([option1, option2, option_delta])portf27,956
-date_range = pd.bdate_range(option_delta.trade_date,date_range28,1008
-vol_shock = np.arange(-0.15, 0.3, 0.01)vol_shock30,1129
-spread_shock = np.arange(-0.2, 0.3, 0.01)spread_shock31,1169
-vs = VolatilitySurface("IG", 27, trade_date=option_delta.trade_date)vs32,1211
-vol_surface = vs[vs.list(model="black")[-1]]vol_surface33,1280
-df = run_portfolio_scenarios(portf, date_range, spread_shock, vol_shock, vol_surface,df34,1325
+exploration/cds_pnl.py,318
+trade_date = datetime.date(2017, 5, 31)trade_date7,126
+def get_portf(trade_date):get_portf9,167
+portf = get_portf(datetime.date(2017, 5, 31))portf29,870
+dr = pd.date_range('2017-06-01', '2017-06-30', freq=bus_day)dr30,916
+pnl = []pnl32,978
+ portf = get_portf(datetime.date(2017, 6, 27))portf38,1175
+
+exploration/portfolio_var.py,463
+dawndb = dbengine('dawndb')dawndb14,330
+serenitasdb = dbengine('serenitasdb')serenitasdb15,358
+def on_the_run(index):on_the_run17,397
+def rel_spread_diff(report_date = datetime.date.today(), index='HY', rolling=10):rel_spread_diff23,600
+def get_pos(report_date):get_pos38,1249
+def cleared_cds_margins(report_date=datetime.date.today()):cleared_cds_margins49,1712
+def index_curve_margins(report_date=datetime.date.today()):index_curve_margins71,2856
+
+exploration/portfolio_example.py,681
+option_delta = Index.from_tradeid(870)option_delta7,210
+option1 = BlackSwaption.from_tradeid(5, option_delta)option18,249
+option2 = BlackSwaption.from_tradeid(6, option_delta)option29,303
+portf = Portfolio([option1, option2, option_delta])portf11,358
+date_range = pd.bdate_range(option_delta.trade_date,date_range12,410
+vol_shock = np.arange(-0.15, 0.3, 0.01)vol_shock14,529
+spread_shock = np.arange(-0.2, 0.3, 0.01)spread_shock15,569
+vs = BlackSwaptionVolSurface("IG", 27, trade_date=option_delta.trade_date)vs16,611
+vol_surface = vs[vs.list()[-1]]vol_surface17,686
+df = run_portfolio_scenarios(portf, date_range, spread_shock, vol_shock, vol_surface,df18,718
murano.py,1029
df = pd.read_table("/home/share/guillaume/murano leads.csv.txt", encoding="utf-16-le", low_memory=False)df6,71
@@ -1296,38 +1686,20 @@ investorsdb = dbengine('investorsdb')investorsdb125,5202
sql_str = "INSERT INTO investors VALUES({})".format(",".join(list_placeholders(df)))sql_str126,5240
conn = investorsdb.raw_connection()conn127,5325
-mark_backtest_underpar.py,2286
-df = pd.read_sql_table('external_marks_mapped', dbengine('dawndb'),df11,205
- parse_dates=['date'])parse_dates12,273
-df = df[df.source.notnull()]df13,318
-df_wide = (pd.pivot_table(df, 'mark', ['identifier', 'date'], 'source').df_wide14,347
-df_trades = {}df_trades18,479
- parse_dates=['trade_date'])parse_dates22,725
- parse_dates=['trade_date'])parse_dates26,1018
-df_sell_wide = pd.merge_asof(df_trades['sell'], df_wide, left_on='trade_date', right_on='date', by='identifier')df_sell_wide30,1186
-df_wide_temp = df_wide.set_index('date').shift(periods = -1, freq= 'M', axis = 1).reset_index()df_wide_temp31,1299
-df_buy_wide = pd.merge_asof(df_trades['buy'], df_wide_tempdf_buy_wide32,1395
-d_sell = {}d_sell35,1542
-d_buy = {}d_buy36,1554
-df_long = {}df_long37,1565
-df_long = pd.concat(d_sell, join='inner')df_long47,2025
-df_long = df_long.append(pd.concat(d_buy, join='inner'))df_long48,2067
-df_long = df_long.reset_index().dropna(subset=['price','mark'])df_long49,2124
-diff_threshold = 5diff_threshold53,2277
-begindate = '2013-01-01'begindate54,2296
-enddate = '2018-01-01'enddate55,2321
-df_long = df_long[df_long.identifier.str.len() == 9]df_long57,2345
-df_long = df_long[(df_long['trade_date'] > begindate) & (df_long['trade_date'] < enddate)]df_long58,2398
-order = ['MANAGER','BROKER','BVAL','IDC','MARKIT','PB','PRICESERVE','PRICINGDIRECT','REUTERS','S&P']order70,2758
-g_sell = sb.FacetGrid(df_long[df_long.dir == 'sell'], hue='source', hue_kws={'s':[50] + [20]*9, 'marker': ["o"]+["s"]*9, 'alpha': [1]+[.4]*9}, legend_out=True, aspect = 2.1, size = 4, hue_order = order)g_sell73,2907
-ax_sell = g_sell.map(plt.scatter, 'mark', 'price').add_legend()ax_sell75,3151
-g_buy = sb.FacetGrid(df_long[df_long.dir == 'buy'], hue='source', hue_kws={'s':[50] + [20]*9, 'marker': ["o"]+["s"]*9, 'alpha': [1]+[.4]*9}, legend_out=True, aspect = 2.1, size = 4, hue_order = order)g_buy77,3216
-ax_buy = g_buy.map(plt.scatter, 'mark', 'price').add_legend()ax_buy79,3457
-params = {}params84,3647
-error = {}error85,3659
-trade_PNL = {}trade_PNL86,3670
-trade_PNL_stat = {}trade_PNL_stat87,3685
-buychart = trade_PNL['buy'].unstack(-1).plot()buychart102,4458
+mark_backtest_underpar.py,794
+def get_mark_df(asset_class = 'Subprime'):get_mark_df12,235
+def calc_mark_diff(df, sources= ['PRICESERVE', 'PRICINGDIRECT','BVAL','MARKIT','BROKER', 'REUTERS', 'S&P', 'IDC']):calc_mark_diff25,1000
+def closest(x):closest51,2224
+def remove_max_min(x):remove_max_min58,2431
+def diff_by_source(df):diff_by_source64,2572
+def diff_by_source_percentage(df):diff_by_source_percentage73,2980
+def count_sources(df):count_sources80,3190
+def alt_navs():alt_navs86,3483
+def annual_performance(nav_100):annual_performance100,4184
+def alt_nav_impact():alt_nav_impact106,4376
+def back_test(begindate = '2013-01-01', enddate = '2018-01-01', sell_price_threshold = 200):back_test112,4551
+def stats(df_long, diff_threshold = 5):stats133,5865
+def pretty_plot(df_long):pretty_plot144,6224
insert_index.py,1288
engine = create_engine('postgresql://serenitas_user@debian/serenitasdb')engine4,74
@@ -1358,45 +1730,7 @@ CFLAGS=-O2 -march=native -fpicCFLAGS1,0
LDLIBS=-lm -llapackLDLIBS2,31
LDFLAGS=-fpic -sharedLDFLAGS3,51
-index_data.py,462
-serenitasdb = dbengine('serenitasdb')serenitasdb6,96
-def insert_quotes():insert_quotes8,135
-def get_index_quotes(index=None, series=None, tenor=None, from_date=None, years=3):get_index_quotes41,1880
- def make_str(key, val):make_str49,2224
- def make_params(args):make_params65,2758
-def index_returns(df=None, index=None, series=None, tenor=None, from_date=None, years=3, per=1):index_returns80,3383
- def add_accrued(df):add_accrued110,4643
-
-test_upfront_cds.py,2424
-def snac_pv(spread, term_date, fixed_coupon=0.01, recovery=0.4, ts=YC()):snac_pv23,1044
-def jpmorgan_curves(trade_date, value_date, start_date, end_date, spread, recovery=0.4):jpmorgan_curves45,2476
- settings = Settings()settings54,2877
- yield_helpers = rate_helpers()yield_helpers56,2952
- ts = YC(helpers = yield_helpers)ts57,2987
- tenor = Period(5, Years)tenor58,3024
- trade_date = datetime.date(2009, 5, 21)trade_date59,3053
- stepin_date = trade_date + datetime.timedelta(days=1)stepin_date60,3097
- value_date = datetime.date(2009, 5, 26)value_date61,3155
- term_date = datetime.date(2019, 6, 20)term_date62,3199
- start_date = datetime.date(2009, 3, 20)start_date63,3242
- spread = 0.001spread64,3286
- sc_data = sc.inspect()['data']sc_data66,3405
- hazard_rate = math.log(1 + sc_data[0][1])hazard_rate67,3440
- contingent_leg = ContingentLeg(start_date, term_date, 10000000)contingent_leg68,3486
- fee_leg = FeeLeg(start_date, term_date, True, 10000000, 0.01)fee_leg69,3554
- flat_curve = FlatHazardRate(0, WeekendsOnly(), hazard_rate, Actual365Fixed())flat_curve71,3621
- cds_schedule = Schedule(Date.from_datetime(trade_date), Date.from_datetime(term_date),cds_schedule72,3703
- cds_trade = CreditDefaultSwap.from_upfront(BUYER, 10000000, 0., 0.01, cds_schedule, Following, Actual360(),cds_trade75,3916
- protection_start = Date.from_datetime(trade_date) + 1,protection_start76,4028
- last_period_day_counter = Actual360(True))last_period_day_counter77,4130
- isda_pricer = IsdaCdsEngine(flat_curve, 0.4, ts, accrual_bias=AccrualBias.HalfDayBias,isda_pricer78,4220
- forwards_in_coupon_period = ForwardsInCouponPeriod.Piecewise)forwards_in_coupon_period79,4311
- cds_trade2 = CreditDefaultSwap(BUYER, 10000000, spread, cds_schedule, Following, Actual360(),cds_trade283,4469
- protection_start = Date.from_datetime(trade_date) + 1,protection_start84,4567
- last_period_day_counter = Actual360(True))last_period_day_counter85,4657
- h = 0.00168276528775h87,4783
- flat_curve2 = FlatHazardRate(0, WeekendsOnly(), h, Actual365Fixed())flat_curve288,4808
- isda_pricer2 = IsdaCdsEngine(flat_curve2, 0.4, ts)isda_pricer289,4881
+notebooks/path.py,0
test_hyoption.py,410
index = Index.from_name("hy", 27, "5yr",index3,54
@@ -1406,28 +1740,21 @@ strike = 102.5strike7,225
payer = Swaption(index, exercise_date, strike, strike_is_price = True)payer8,240
receiver = Swaption(index, exercise_date, strike, "receiver", strike_is_price = True)receiver13,374
-bbg_prices.py,1159
-engine = create_engine('postgresql://et_user@debian/ET')engine10,257
-fields_update = ["LN_ISSUE_STATUS", "AMT_OUTSTANDING", "PX_LAST","LAST_UPDATE_DT",fields_update12,315
- "AND not called", engine, index_col='cusip')cusips20,812
-securities = ["{0} Corp".format(cusip) for cusip in cusips.index]securities22,885
- data = retrieve_data(session, securities, fields_update)data25,994
-df = pd.DataFrame.from_dict(data, orient='index')df27,1056
-to_insert = df[['DEFAULTED', 'DEFAULT_DATE', 'CALLED', 'CALLED_DT', 'LN_ISSUE_STATUS', 'ID_BB_UNIQUE']]to_insert32,1261
-to_insert = to_insert.where(to_insert.notnull(), None)to_insert33,1365
-conn = engine.raw_connection()conn35,1421
-currentdata = pd.read_sql_query("SELECT id_bb_unique, pricingdate from bloomberg_corp",currentdata43,1811
- parse_dates=["pricingdate"],parse_dates45,1939
- index_col=['id_bb_unique', 'pricingdate'])index_col46,2000
-df = df.ix[df.index.difference(currentdata.index)]df50,2232
-to_insert = df[['ID_BB_UNIQUE','LAST_UPDATE_DT','PX_LAST','LN_CURRENT_MARGIN',to_insert54,2365
-
-test_hyoption2.py,308
-index = Index.from_name("hy", 27, "5yr",index3,54
- trade_date = datetime.date(2016, 11, 16))trade_date4,95
-exercise_date = datetime.date(2017, 3, 15)exercise_date6,182
-strike = 102.5strike7,225
-payer = Swaption(index, exercise_date, strike, strike_is_price = True)payer8,240
+bbg_prices.py,1158
+engine = create_engine('postgresql://et_user@debian/ET')engine9,252
+fields_update = ["LN_ISSUE_STATUS", "AMT_OUTSTANDING", "PX_LAST","LAST_UPDATE_DT",fields_update11,310
+ "AND not called", engine, index_col='cusip')cusips19,807
+securities = ["{0} Corp".format(cusip) for cusip in cusips.index]securities21,880
+ data = retrieve_data(session, securities, fields_update)data24,989
+df = pd.DataFrame.from_dict(data, orient='index')df26,1051
+to_insert = df[['DEFAULTED', 'DEFAULT_DATE', 'CALLED', 'CALLED_DT', 'LN_ISSUE_STATUS', 'ID_BB_UNIQUE']]to_insert31,1256
+to_insert = to_insert.where(to_insert.notnull(), None)to_insert32,1360
+conn = engine.raw_connection()conn34,1416
+currentdata = pd.read_sql_query("SELECT id_bb_unique, pricingdate from bloomberg_corp",currentdata42,1806
+ parse_dates=["pricingdate"],parse_dates44,1934
+ index_col=['id_bb_unique', 'pricingdate'])index_col45,1995
+df = df.ix[df.index.difference(currentdata.index)]df49,2227
+to_insert = df[['ID_BB_UNIQUE','LAST_UPDATE_DT','PX_LAST','LN_CURRENT_MARGIN',to_insert53,2360
sftp.py,469
hostname="alias.im"hostname4,27
@@ -1441,33 +1768,37 @@ hostkey = host_keys[hostname]['ssh-rsa']hostkey14,347
sftp = paramiko.SFTPClient.from_transport(t)sftp16,448
dirlist = sftp.listdir('.')dirlist17,493
-mark_swaptions.py,817
+mark_swaptions.py,815
level=logging.INFO,level13,295
format='%(asctime)s %(message)s')format14,335
def get_trades(date, engine):get_trades16,390
def get_swaptionvol(index, series, strike, expiry, date, engine):get_swaptionvol25,830
-def mark_trades(date, engine):mark_trades45,1697
- parser = argparse.ArgumentParser()parser97,3990
- type = lambda s: pd.datetime.strptime(s, "%Y-%m-%d").date()),type99,4076
- dawn_engine = dbengine('dawndb')dawn_engine100,4162
- serenitas_engine = dbengine('serenitasdb')serenitas_engine101,4199
- args = parser.parse_args()args102,4246
- workdate = (pd.Timestamp.today()-BDay()).date()workdate104,4307
- workdate = args.workdateworkdate106,4373
- r = mark_trades(workdate, dawn_engine)r108,4407
+def mark_trades(date, engine):mark_trades47,1739
+ parser = argparse.ArgumentParser()parser95,4033
+ type = lambda s: pd.datetime.strptime(s, "%Y-%m-%d").date()),type97,4119
+ dawn_engine = dbengine('dawndb')dawn_engine98,4205
+ serenitas_engine = dbengine('serenitasdb')serenitas_engine99,4242
+ args = parser.parse_args()args100,4289
+ workdate = (pd.Timestamp.today()-BDay()).date()workdate102,4350
+ workdate = args.workdateworkdate104,4416
+ r = mark_trades(workdate, dawn_engine)r106,4450
risk_insight/__init__.py,31
app = Flask(__name__)app2,24
-risk_insight/views.py,349
-def get_attach_from_name(index_type, series):get_attach_from_name7,138
-def get_db():get_db24,676
-def close_connection(exception):close_connection33,982
-def get_risk_numbers():get_risk_numbers39,1127
-def get_indices_quotes():get_indices_quotes56,1848
-def tranches():tranches84,2981
-def indices():indices91,3287
-def main():main95,3408
+risk_insight/views.py,353
+def get_attach_from_name(index_type, series):get_attach_from_name11,176
+def get_db():get_db28,714
+def close_connection(exception):close_connection37,1020
+def get_risk_numbers():get_risk_numbers43,1165
+def get_indices_quotes():get_indices_quotes63,2174
+def tranches():tranches95,3405
+def indices():indices102,3711
+def main():main106,3832
+
+risk_insight/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
risk_insight/templates/index.html,0
@@ -1475,214 +1806,284 @@ risk_insight/templates/tranches.html,0
risk_insight/templates/indices.html,0
-Dawn/__init__.py,290
-app = Flask(__name__)app6,112
-db = SQLAlchemy(app, metadata = MetaData(schema=app.config['SCHEMA']))db8,165
- fh = logging.FileHandler(filename=app.config['LOGFILE'])fh11,255
- formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')formatter13,346
+Dawn/__init__.py,325
+app = Flask(__name__)app8,152
+csrf = CSRFProtect(app)csrf10,205
+db = SQLAlchemy(app, metadata=MetaData(schema=app.config['SCHEMA']))db11,229
+ fh = logging.FileHandler(filename=app.config['LOGFILE'])fh14,317
+ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')formatter16,408
+
+Dawn/models.py,15182
+class Counterparties(db.Model):Counterparties11,309
+ __tablename__ = 'counterparties'__tablename__12,341
+ code = db.Column(db.String(12), primary_key=True)code13,378
+ name = db.Column(db.String)name14,432
+ city = db.Column(db.String)city15,464
+ state = db.Column(db.String(2))state16,496
+ dtc_number = db.Column(db.Integer)dtc_number17,532
+ sales_contact = db.Column(db.String)sales_contact18,571
+ sales_email = db.Column(EmailType)sales_email19,612
+ sales_phone = db.Column(PhoneNumberType())sales_phone20,651
+ valuation_contact1 = db.Column(db.String)valuation_contact121,698
+ valuation_email1 = db.Column(EmailType)valuation_email122,744
+ valuation_contact2 = db.Column(db.String)valuation_contact223,788
+ valuation_email2 = db.Column(EmailType)valuation_email224,834
+ valuation_contact3 = db.Column(db.String)valuation_contact325,878
+ valuation_email3 = db.Column(EmailType)valuation_email326,924
+ valuation_contact4 = db.Column(db.String)valuation_contact427,968
+ valuation_email4 = db.Column(EmailType)valuation_email428,1014
+ notes = db.Column(db.String)notes29,1058
+ instructions = db.Column(db.String, info={'form_field_class': FileField})instructions30,1091
+class Accounts(db.Model):Accounts32,1170
+ __tablename__ = 'accounts'__tablename__33,1196
+ code = db.Column(db.String(5), primary_key=True)code34,1227
+ name = db.Column(db.String)name35,1280
+ custodian = db.Column(db.String)custodian36,1312
+ cash_account = db.Column(db.String)cash_account37,1349
+ counterparty = db.Column(db.String(12), db.ForeignKey('counterparties.code'))counterparty38,1389
+BOND_STRAT = ENUM('M_STR_MAV', 'M_STR_MEZZ', 'CSO_TRANCH',BOND_STRAT40,1472
+CDS_STRAT = ENUM('HEDGE_CSO', 'HEDGE_CLO', 'HEDGE_MAC', 'HEDGE_MBS',CDS_STRAT45,1760
+SWAPTION_STRAT = ENUM('IGPAYER', 'IGREC', 'HYPAYER', 'HYREC',SWAPTION_STRAT50,2069
+ name='swaption_strat')name51,2131
+FUTURE_STRAT = ENUM('M_STR_MAV', 'M_MTG_IO', 'M_STR_MEZZ', 'M_MTG_RW', 'SER_ITRXCURVE',FUTURE_STRAT53,2177
+ name='future_strat')name54,2265
+CASH_STRAT = ENUM('M_CSH_CASH', 'MBSCDSCSH', 'SER_IGCVECSH', 'SER_ITRXCVCSH', 'CSOCDSCSH',CASH_STRAT56,2307
+ name='cash_strat')name59,2521
+SWAPTION_TYPE = ENUM('PAYER', 'RECEIVER',SWAPTION_TYPE61,2559
+ name='swaption_type')name62,2601
+REPO_TYPE = ENUM('REPO', 'REVERSE REPO', name='repo_type')REPO_TYPE64,2645
+FUTURE_TYPE = ENUM('FUTURE', 'CFD', 'SYNTHETIC-FUTURE', 'LME-FORWARD', name='future_type')FUTURE_TYPE65,2704
+CALL_NOTICE = ENUM('24H', '48H', '3D', '4D', '5D', '6D',CALL_NOTICE67,2796
+ASSET_CLASS = ENUM('CSO', 'Subprime', 'CLO', 'Tranches', 'Futures', 'Cash', 'FX', 'Cleared',ASSET_CLASS70,2936
+ name='asset_class')name71,3029
+ACTION = ENUM('NEW', 'UPDATE', 'CANCEL', name='action')ACTION72,3068
+CCY = ENUM('USD', 'CAD', 'EUR', 'YEN', name='currency')CCY74,3125
+BBG_TYPE = ENUM('Mtge', 'Corp', name='bbg_type')BBG_TYPE76,3182
+SWAP_TYPE = ENUM('CD_INDEX', 'CD_INDEX_TRANCHE', 'CD_BASKET_TRANCHE', 'ABS_CDS', name='swap_type')SWAP_TYPE78,3232
+ISDA = ENUM('ISDA2014', 'ISDA2003Cred', name='isda')ISDA80,3332
+DAY_COUNT = ENUM('ACT/360', 'ACT/ACT', '30/360', 'ACT/365', name='day_count')DAY_COUNT82,3386
+BUS_DAY_CONVENTION = ENUM('Modified Following', 'Following', 'Modified Preceding', 'Preceding',BUS_DAY_CONVENTION84,3465
+PROTECTION = ENUM('Buyer', 'Seller', name='protection')PROTECTION86,3650
+class BondDeal(db.Model):BondDeal88,3707
+ __tablename__ = 'bonds'__tablename__89,3733
+ id = db.Column('id', db.Integer, primary_key=True)id90,3761
+ dealid = db.Column(db.String(28))dealid91,3816
+ lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate92,3854
+ action = db.Column(ACTION)action93,3948
+ folder = db.Column(BOND_STRAT, nullable=False)folder94,3979
+ custodian = db.Column(db.String(12), default='BAC', nullable=False)custodian95,4030
+ cashaccount = db.Column(db.String(10), default='V0NSCLMAMB', nullable=False)cashaccount96,4102
+ cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code97,4183
+ info={'choices': [(None, '')],info98,4260
+ trade_date = db.Column(db.Date, nullable = False)trade_date100,4387
+ settle_date = db.Column(db.Date, nullable = False)settle_date101,4441
+ cusip = db.Column(db.String(9), info={'validators': Length(9, 9),cusip102,4496
+ isin = db.Column(db.String(12), info={'validators': Length(12, 12),isin105,4700
+ identifier = db.Column(db.String(12), info={'filters': [lambda x: x or None,],identifier108,4906
+ description = db.Column(db.String(32), nullable = False, info={'trim': True})description110,5052
+ buysell = db.Column(db.Boolean, nullable = False, info={'choices':[(0, 'sell'), (1, 'buy')],buysell111,5134
+ faceamount = db.Column(db.Float, nullable=False)faceamount114,5412
+ price = db.Column(db.Float, nullable=False)price115,5465
+ accrued = db.Column(db.Float, nullable = False)accrued116,5513
+ asset_class = db.Column(ASSET_CLASS)asset_class117,5565
+ ticket = db.Column(db.String, info={'form_field_class': FileField})ticket118,5606
+ principal_payment = db.Column(db.Float)principal_payment119,5678
+ accrued_payment = db.Column(db.Float)accrued_payment120,5722
+ counterparty = db.relationship(Counterparties)counterparty121,5764
+ __table_args__= (db.CheckConstraint('cusip is not Null or isin is not Null'),)__table_args__122,5815
+class CDSDeal(db.Model):CDSDeal124,5899
+ __tablename__ = 'cds'__tablename__125,5924
+ id = db.Column('id', db.Integer, primary_key=True)id126,5950
+ dealid = db.Column(db.String(28))dealid127,6005
+ lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate128,6043
+ action = db.Column(ACTION)action129,6137
+ folder = db.Column(CDS_STRAT, nullable=False)folder130,6168
+ custodian = db.Column(db.String(12), default='SGFCM', nullable=False)custodian131,6218
+ cashaccount = db.Column(db.String(10), default='SGNSCLMASW', nullable=False)cashaccount132,6292
+ cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code133,6373
+ info={'choices': [(None, '')],info134,6450
+ trade_date = db.Column(db.Date, nullable=False)trade_date136,6577
+ effective_date = db.Column(db.Date, nullable=False)effective_date137,6629
+ maturity = db.Column(db.Date, nullable=False)maturity138,6685
+ currency = db.Column(CCY, nullable=False)currency139,6735
+ payment_rolldate = db.Column(BUS_DAY_CONVENTION, nullable=False)payment_rolldate140,6781
+ notional = db.Column(db.Float, nullable=False)notional141,6850
+ fixed_rate = db.Column(db.Float, nullable=False)fixed_rate142,6901
+ day_count = db.Column(DAY_COUNT, nullable=False)day_count143,6954
+ frequency = db.Column(db.SmallInteger, default=4, nullable=False)frequency144,7007
+ protection = db.Column(PROTECTION, nullable=False)protection145,7077
+ security_id = db.Column(db.String(12), nullable=False)security_id146,7132
+ security_desc = db.Column(db.String(32), nullable=False)security_desc147,7191
+ upfront = db.Column(db.Float, nullable=False)upfront148,7252
+ upfront_settle_date = db.Column(db.Date, nullable=False)upfront_settle_date149,7302
+ initial_margin_percentage = db.Column(db.Float)initial_margin_percentage150,7363
+ swap_type = db.Column(SWAP_TYPE, nullable=False)swap_type151,7415
+ attach = db.Column(db.SmallInteger, info={'min': 0, 'max':100})attach152,7468
+ detach = db.Column(db.SmallInteger, info={'min': 0, 'max':100})detach153,7536
+ clearing_facility = db.Column(db.String(12), default='ICE-CREDIT')clearing_facility154,7604
+ isda_definition = db.Column(ISDA)isda_definition155,7675
+ counterparty = db.relationship(Counterparties)counterparty156,7713
+ "clearing_facility is NULL)"),)__table_args__159,7936
+class RepoDeal(db.Model):RepoDeal161,8010
+ __tablename__ = 'repo'__tablename__162,8036
+ id = db.Column('id', db.Integer, primary_key=True)id163,8063
+ lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate164,8118
+ action = db.Column(ACTION)action165,8212
+ folder = db.Column(CDS_STRAT, nullable=False)folder166,8243
+ custodian = db.Column(db.String(12), default='SGFCM', nullable=False)custodian167,8293
+ cashaccount = db.Column(db.String(10), default='SGNSCLMASW', nullable=False)cashaccount168,8367
+ cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code169,8448
+ info={'choices': [(None, '')],info170,8525
+ trade_date = db.Column(db.Date, nullable=False)trade_date172,8652
+ settle_date = db.Column(db.Date, nullable=False)settle_date173,8704
+ cusip = db.Column(db.String(9), info={'validators': Length(9,9),cusip174,8757
+ isin = db.Column(db.String(12), info={'validators': Length(12, 12),isin177,8960
+ identifier = db.Column(db.String(12), info={'filters': [lambda x: x or None,],identifier180,9166
+ description = db.Column(db.String(32), nullable=False, info={'trim': True})description182,9312
+ transation_indicator = db.Column(REPO_TYPE)transation_indicator183,9392
+ faceamount = db.Column(db.Float, nullable=False)faceamount184,9440
+ price = db.Column(db.Float, nullable=False)price185,9493
+ currency = db.Column(CCY, nullable=False)currency186,9541
+ expiration_date = db.Column(db.Date)expiration_date187,9587
+ weighted_amount = db.Column(db.Float)weighted_amount188,9628
+ haircut = db.Column(db.Float)haircut189,9670
+ repo_rate = db.Column(db.Float, nullable=False)repo_rate190,9704
+ call_notice = db.Column(CALL_NOTICE)call_notice191,9756
+ daycount = db.Column(DAY_COUNT)daycount192,9797
+ ticket = db.Column(db.String, info={'form_field_class': FileField})ticket193,9833
+ "haircut is NULL and weighted_amount is NOT NULL)"),__table__args195,10002
+class SwaptionDeal(db.Model):SwaptionDeal198,10178
+ __tablename__ = 'swaptions'__tablename__199,10208
+ id = db.Column('id', db.Integer, primary_key=True)id200,10240
+ dealid = db.Column(db.String(28))dealid201,10295
+ lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate202,10333
+ action = db.Column(ACTION)action203,10427
+ folder = db.Column(SWAPTION_STRAT, nullable=False)folder204,10458
+ custodian = db.Column(db.String(12), default='NONE', nullable=False)custodian205,10513
+ cashaccount = db.Column(db.String(10), default='SGNSCLMASW', nullable=False)cashaccount206,10586
+ cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code207,10667
+ info={'choices': [(None, '')],info208,10744
+ trade_date = db.Column(db.Date, nullable=False)trade_date210,10871
+ settle_date = db.Column(db.Date, nullable=False)settle_date211,10923
+ buysell = db.Column(db.Boolean, nullable=False, info={'choices':[(0, 'sell'), (1, 'buy')],buysell212,10976
+ notional = db.Column(db.Float, nullable=False)notional215,11250
+ swaption_type = db.Column(SWAPTION_TYPE, nullable=False)swaption_type216,11301
+ strike = db.Column(db.Float, nullable=False)strike217,11362
+ price = db.Column(db.Float, nullable=False)price218,11411
+ expiration_date = db.Column(db.Date, nullable=False)expiration_date219,11459
+ initial_margin_percentage = db.Column(db.Float)initial_margin_percentage220,11516
+ index_ref = db.Column(db.Float)index_ref221,11568
+ security_id = db.Column(db.String(12), nullable=False)security_id222,11604
+ security_desc = db.Column(db.String(32), nullable=False)security_desc223,11663
+ fixed_rate = db.Column(db.Float, nullable=False)fixed_rate224,11724
+ maturity = db.Column(db.Date, nullable=False)maturity225,11777
+ currency = db.Column(CCY, nullable=False)currency226,11827
+ counterparty = db.relationship(Counterparties)counterparty227,11873
+class FutureDeal(db.Model):FutureDeal229,11925
+ __tablename__ = 'futures'__tablename__230,11953
+ id = db.Column('id', db.Integer, primary_key=True)id231,11983
+ dealid = db.Column(db.String(28))dealid232,12038
+ lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate233,12076
+ action = db.Column(ACTION)action234,12170
+ folder = db.Column(FUTURE_STRAT, nullable=False)folder235,12201
+ custodian = db.Column(db.String(12), default='INTBR', nullable=False)custodian236,12254
+ cashaccount = db.Column(db.String(10), default='IANSCLMAFU', nullable=False)cashaccount237,12328
+ cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code238,12409
+ info={'choices': [('IBKRNY', 'Interactive Brokers')],info239,12486
+ trade_date = db.Column(db.Date, nullable=False)trade_date241,12636
+ settle_date = db.Column(db.Date, nullable=False)settle_date242,12688
+ buysell = db.Column(db.Boolean, nullable=False, info={'choices':[(0, 'sell'), (1, 'buy')],buysell243,12741
+ bbg_ticker = db.Column(db.String(32), nullable=False)bbg_ticker246,13015
+ quantity = db.Column(db.Float, nullable=False)quantity247,13073
+ price = db.Column(db.Float, nullable=False)price248,13124
+ commission = db.Column(db.Float)commission249,13172
+ swap_type = db.Column(FUTURE_TYPE, nullable=False)swap_type250,13209
+ security_desc = db.Column(db.String(32), nullable=False)security_desc251,13264
+ maturity = db.Column(db.Date, nullable=False)maturity252,13325
+ currency = db.Column(CCY, nullable=False)currency253,13375
+ exchange = db.Column(db.String(3), default='CME', nullable=False)exchange254,13421
+ counterparty = db.relationship(Counterparties)counterparty255,13491
+class CashFlowDeal(db.Model):CashFlowDeal257,13543
+ __tablename__ = 'wires'__tablename__258,13573
+ id = db.Column('id', db.Integer, primary_key=True)id259,13601
+ dealid = db.Column(db.String(28))dealid260,13656
+ lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate261,13694
+ action = db.Column(ACTION)action262,13788
+ folder = db.Column(CASH_STRAT, nullable=False)folder263,13819
+ code = db.Column(db.String(5), db.ForeignKey('accounts.code'), nullable=False)code264,13870
+ amount = db.Column(db.Float, nullable=False)amount265,13953
+ currency = db.Column(CCY, nullable=False)currency266,14002
+ trade_date = db.Column(db.Date, nullable=False)trade_date267,14048
+ account = db.relationship(Accounts)account268,14100
+BaseModelForm = model_form_factory(FlaskForm)BaseModelForm270,14141
+class ModelForm(BaseModelForm):ModelForm271,14187
+ def get_session(self):get_session273,14236
-Dawn/models.py,11647
-class Counterparties(db.Model):Counterparties11,304
- __tablename__ = 'counterparties'__tablename__12,336
- code = db.Column(db.String(12), primary_key=True)code13,373
- name = db.Column(db.String)name14,427
- city = db.Column(db.String)city15,459
- state = db.Column(db.String(2))state16,491
- dtc_number = db.Column(db.Integer)dtc_number17,527
- sales_contact = db.Column(db.String)sales_contact18,566
- sales_email = db.Column(EmailType)sales_email19,607
- sales_phone = db.Column(PhoneNumberType())sales_phone20,646
- valuation_contact1 = db.Column(db.String)valuation_contact121,693
- valuation_email1 = db.Column(EmailType)valuation_email122,739
- valuation_contact2 = db.Column(db.String)valuation_contact223,783
- valuation_email2 = db.Column(EmailType)valuation_email224,829
- valuation_contact3 = db.Column(db.String)valuation_contact325,873
- valuation_email3 = db.Column(EmailType)valuation_email326,919
- valuation_contact4 = db.Column(db.String)valuation_contact427,963
- valuation_email4 = db.Column(EmailType)valuation_email428,1009
- notes = db.Column(db.String)notes29,1053
- instructions = db.Column(db.String, info={'form_field_class': FileField})instructions30,1086
-BOND_STRAT = ENUM('M_STR_MAV', 'M_STR_MEZZ', 'CSO_TRANCH',BOND_STRAT32,1165
-CDS_STRAT = ENUM('HEDGE_CSO', 'HEDGE_CLO', 'HEDGE_MAC', 'HEDGE_MBS',CDS_STRAT37,1453
-SWAPTION_STRAT = ENUM('IGPAYER', 'IGREC', 'HYPAYER', 'HYREC',SWAPTION_STRAT42,1745
- name='swaption_strat')name43,1807
-SWAPTION_TYPE = ENUM('PAYER', 'RECEIVER',SWAPTION_TYPE45,1853
- name='swaption_type')name46,1895
-REPO_TYPE = ENUM('REPO', 'REVERSE REPO', name='repo_type')REPO_TYPE48,1939
-CALL_NOTICE = ENUM('24H', '48H', '3D', '4D', '5D', '6D',CALL_NOTICE49,1998
-ASSET_CLASS = ENUM('CSO', 'Subprime', 'CLO', 'Tranches', 'Futures', 'Cash', 'FX', 'Cleared',ASSET_CLASS52,2138
- name='asset_class')name53,2231
-ACTION = ENUM('NEW', 'UPDATE', 'CANCEL', name='action')ACTION54,2270
-CCY = ENUM('USD', 'CAD', 'EUR', 'YEN', name='currency')CCY56,2327
-BBG_TYPE = ENUM('Mtge', 'Corp', name='bbg_type')BBG_TYPE58,2384
-SWAP_TYPE = ENUM('CD_INDEX', 'CD_INDEX_TRANCHE', 'CD_BASKET_TRANCHE', 'ABS_CDS', name='swap_type')SWAP_TYPE60,2434
-ISDA = ENUM('ISDA2014', 'ISDA2003Cred', name='isda')ISDA62,2534
-DAY_COUNT = ENUM('ACT/360', 'ACT/ACT', '30/360', 'ACT/365', name='day_count')DAY_COUNT64,2588
-BUS_DAY_CONVENTION = ENUM('Modified Following', 'Following', 'Modified Preceding', 'Preceding',BUS_DAY_CONVENTION66,2667
-PROTECTION = ENUM('Buyer', 'Seller', name='protection')PROTECTION68,2852
-class BondDeal(db.Model):BondDeal70,2909
- __tablename__ = 'bonds'__tablename__71,2935
- id = db.Column('id', db.Integer, primary_key=True)id72,2963
- dealid = db.Column(db.String(28))dealid73,3018
- lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate74,3056
- action = db.Column(ACTION)action75,3150
- folder = db.Column(BOND_STRAT, nullable=False)folder76,3181
- custodian = db.Column(db.String(12), default='BAC', nullable=False)custodian77,3232
- cashaccount = db.Column(db.String(10), default='V0NSCLMAMB', nullable=False)cashaccount78,3304
- cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code79,3385
- info={'choices': [(None, '')],info80,3462
- trade_date = db.Column(db.Date, nullable = False)trade_date82,3591
- settle_date = db.Column(db.Date, nullable = False)settle_date83,3645
- cusip = db.Column(db.String(9), info={'validators': Length(9,9),cusip84,3700
- isin = db.Column(db.String(12), info={'validators': Length(12, 12),isin87,3903
- identifier = db.Column(db.String(12), info={'filters': [lambda x: x or None,],identifier90,4109
- description = db.Column(db.String(32), nullable = False, info={'trim': True})description92,4255
- buysell = db.Column(db.Boolean, nullable = False, info={'choices':[(0, 'sell'), (1, 'buy')],buysell93,4337
- faceamount = db.Column(db.Float, nullable=False)faceamount96,4615
- price = db.Column(db.Float, nullable=False)price97,4668
- accrued = db.Column(db.Float, nullable = False)accrued98,4716
- asset_class = db.Column(ASSET_CLASS)asset_class99,4768
- ticket = db.Column(db.String, info={'form_field_class': FileField})ticket100,4809
- principal_payment = db.Column(db.Float)principal_payment101,4881
- accrued_payment = db.Column(db.Float)accrued_payment102,4925
- counterparty = db.relationship(Counterparties)counterparty103,4967
- __table_args__= (db.CheckConstraint('cusip is not Null or isin is not Null'),)__table_args__104,5018
-class CDSDeal(db.Model):CDSDeal106,5102
- __tablename__ = 'cds'__tablename__107,5127
- id = db.Column('id', db.Integer, primary_key=True)id108,5153
- dealid = db.Column(db.String(28))dealid109,5208
- lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate110,5246
- action = db.Column(ACTION)action111,5340
- folder = db.Column(CDS_STRAT, nullable = False)folder112,5371
- custodian = db.Column(db.String(12), default='SGFCM', nullable=False)custodian113,5423
- cashaccount = db.Column(db.String(10), default='SGNSCLMASW', nullable=False)cashaccount114,5497
- cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code115,5578
- info={'choices': [(None, '')],info116,5655
- trade_date = db.Column(db.Date, nullable = False)trade_date118,5784
- effective_date = db.Column(db.Date, nullable = False)effective_date119,5838
- maturity = db.Column(db.Date, nullable = False)maturity120,5896
- currency = db.Column(CCY, nullable = False)currency121,5948
- payment_rolldate = db.Column(BUS_DAY_CONVENTION, nullable = False)payment_rolldate122,5996
- notional = db.Column(db.Float, nullable = False)notional123,6067
- fixed_rate = db.Column(db.Float, nullable = False)fixed_rate124,6120
- day_count = db.Column(DAY_COUNT, nullable = False)day_count125,6175
- frequency = db.Column(db.SmallInteger, default=4, nullable = False)frequency126,6230
- protection = db.Column(PROTECTION, nullable = False)protection127,6302
- security_id = db.Column(db.String(12), nullable = False)security_id128,6359
- security_desc = db.Column(db.String(32), nullable = False)security_desc129,6420
- upfront = db.Column(db.Float, nullable = False)upfront130,6483
- upfront_settle_date = db.Column(db.Date, nullable = False)upfront_settle_date131,6535
- swap_type = db.Column(SWAP_TYPE, nullable = False)swap_type132,6598
- attach = db.Column(db.SmallInteger, info={'min': 0, 'max':100})attach133,6653
- detach = db.Column(db.SmallInteger, info={'min': 0, 'max':100})detach134,6721
- clearing_facility = db.Column(db.String(12), default='ICE-CREDIT')clearing_facility135,6789
- isda_definition = db.Column(ISDA)isda_definition136,6860
- counterparty = db.relationship(Counterparties)counterparty137,6898
- "(attach is not NULL and detach is not NULL)"),)__table_args__139,7028
-class RepoDeal(db.Model):RepoDeal141,7119
- __tablename__ = 'repo'__tablename__142,7145
- id = db.Column('id', db.Integer, primary_key=True)id143,7172
- lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate144,7227
- action = db.Column(ACTION)action145,7321
- folder = db.Column(CDS_STRAT, nullable = False)folder146,7352
- custodian = db.Column(db.String(12), default='SGFCM', nullable=False)custodian147,7404
- cashaccount = db.Column(db.String(10), default='SGNSCLMASW', nullable=False)cashaccount148,7478
- cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code149,7559
- info={'choices': [(None, '')],info150,7636
- trade_date = db.Column(db.Date, nullable = False)trade_date152,7765
- settle_date = db.Column(db.Date, nullable = False)settle_date153,7819
- cusip = db.Column(db.String(9), info={'validators': Length(9,9),cusip154,7874
- isin = db.Column(db.String(12), info={'validators': Length(12, 12),isin157,8077
- identifier = db.Column(db.String(12), info={'filters': [lambda x: x or None,],identifier160,8283
- description = db.Column(db.String(32), nullable = False, info={'trim': True})description162,8429
- transation_indicator = db.Column(REPO_TYPE)transation_indicator163,8511
- faceamount = db.Column(db.Float, nullable = False)faceamount164,8559
- price = db.Column(db.Float, nullable = False)price165,8614
- currency = db.Column(CCY, nullable = False)currency166,8664
- expiration_date = db.Column(db.Date)expiration_date167,8712
- weighted_amount = db.Column(db.Float)weighted_amount168,8753
- haircut = db.Column(db.Float)haircut169,8795
- repo_rate = db.Column(db.Float, nullable = False)repo_rate170,8829
- call_notice = db.Column(CALL_NOTICE)call_notice171,8883
- daycount = db.Column(DAY_COUNT)daycount172,8924
- ticket = db.Column(db.String, info={'form_field_class': FileField})ticket173,8960
- "haircut is NULL and weighted_amount is NOT NULL)"),__table__args175,9129
-class SwaptionDeal(db.Model):SwaptionDeal178,9305
- __tablename__ = 'swaptions'__tablename__179,9335
- id = db.Column('id', db.Integer, primary_key=True)id180,9367
- dealid = db.Column(db.String(28))dealid181,9422
- lastupdate = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())lastupdate182,9460
- action = db.Column(ACTION)action183,9554
- folder = db.Column(SWAPTION_STRAT, nullable = False)folder184,9585
- custodian = db.Column(db.String(12), default='NONE', nullable=False)custodian185,9642
- cashaccount = db.Column(db.String(10), default='SGNSCLMASW', nullable=False)cashaccount186,9715
- cp_code = db.Column(db.String(12), db.ForeignKey('counterparties.code'),cp_code187,9796
- info={'choices': [(None, '')],info188,9873
- trade_date = db.Column(db.Date, nullable = False)trade_date190,10002
- settle_date = db.Column(db.Date, nullable = False)settle_date191,10056
- buysell = db.Column(db.Boolean, nullable = False, info={'choices':[(0, 'sell'), (1, 'buy')],buysell192,10111
- notional = db.Column(db.Float, nullable = False)notional195,10389
- swaption_type = db.Column(SWAPTION_TYPE, nullable = False)swaption_type196,10442
- strike = db.Column(db.Float, nullable = False)strike197,10505
- price = db.Column(db.Float, nullable = False)price198,10556
- expiration_date = db.Column(db.Date, nullable = False)expiration_date199,10606
- initial_margin_percentage = db.Column(db.Float)initial_margin_percentage200,10665
- index_ref = db.Column(db.Float)index_ref201,10717
- security_id = db.Column(db.String(12), nullable = False)security_id202,10753
- security_desc = db.Column(db.String(32), nullable = False)security_desc203,10814
- fixed_rate = db.Column(db.Float, nullable = False)fixed_rate204,10877
- maturity = db.Column(db.Date, nullable = False)maturity205,10932
- currency = db.Column(CCY, nullable = False)currency206,10984
- counterparty = db.relationship(Counterparties)counterparty207,11032
-BaseModelForm = model_form_factory(Form)BaseModelForm209,11084
-class ModelForm(BaseModelForm):ModelForm210,11125
- def get_session(self):get_session212,11174
+Dawn/views.py,2767
+fed_cal = get_calendar('USFederalHolidayCalendar')fed_cal27,754
+bond_cal = HolidayCalendarFactory('BondCalendar', fed_cal, GoodFriday)bond_cal28,805
+bus_day = CustomBusinessDay(calendar=bond_cal())bus_day29,876
+def cp_choices(kind='bond'):cp_choices31,926
+def account_codes():account_codes43,1403
+def get_queue():get_queue46,1512
+def get_db():get_db56,1813
+def close_connection(exception):close_connection65,2119
+class CounterpartyForm(ModelForm):CounterpartyForm70,2234
+ class Meta:Meta71,2269
+ model = Counterpartiesmodel72,2285
+ include_primary_keys = Trueinclude_primary_keys73,2316
+class BondForm(ModelForm):BondForm75,2353
+ upload_globeop = BooleanField(label="Upload to globeop?")upload_globeop76,2380
+ class Meta:Meta77,2442
+ model = BondDealmodel78,2458
+ include_foreign_keys = Trueinclude_foreign_keys79,2483
+ exclude = ['dealid', 'lastupdate', #we generate it with a trigger at the server levelexclude80,2519
+class CDSForm(ModelForm):CDSForm83,2673
+ upload_globeop = BooleanField(label="Upload to globeop?")upload_globeop84,2699
+ class Meta:Meta85,2761
+ model = CDSDealmodel86,2777
+ include_foreign_keys = Trueinclude_foreign_keys87,2801
+ exclude = ['dealid', 'lastupdate']exclude88,2837
+class SwaptionForm(ModelForm):SwaptionForm90,2881
+ upload_globeop = BooleanField(label="Upload to globeop?")upload_globeop91,2912
+ class Meta:Meta92,2974
+ model = SwaptionDealmodel93,2990
+ include_foreign_keys = Trueinclude_foreign_keys94,3019
+ exclude = ['dealid', 'lastupdate']exclude95,3055
+class FutureForm(ModelForm):FutureForm97,3099
+ upload_globeop = BooleanField(label="Upload to globeop?")upload_globeop98,3128
+ class Meta:Meta99,3190
+ model = FutureDealmodel100,3206
+ include_foreign_keys = Trueinclude_foreign_keys101,3233
+ exclude = ['dealid', 'lastupdate']exclude102,3269
+def get_deal(kind):get_deal104,3313
+def _get_form(kind):_get_form116,3596
+def get_form(trade, kind):get_form128,3880
+def get_wire_form(wire):get_wire_form153,4819
+def get_trade(tradeid, kind):get_trade161,5011
+def save_ticket(trade, old_ticket_name):save_ticket165,5126
+def split_direction(g, direction):split_direction178,5610
+def gen_cashflow_deals(form, session, wire_id=None):gen_cashflow_deals190,6170
+def wire_manage(wire_id):wire_manage221,7514
+def trade_manage(tradeid, kind):trade_manage260,9590
+def list_trades(kind):list_trades296,11024
+def download_ticket(tradeid):download_ticket305,11329
+def list_counterparties(instr):list_counterparties318,11843
+def edit_counterparty(cpcode):edit_counterparty329,12370
+def get_bbg_id():get_bbg_id355,13280
-Dawn/views.py,2099
-fed_cal = get_calendar('USFederalHolidayCalendar')fed_cal19,656
-bond_cal = HolidayCalendarFactory('BondCalendar', fed_cal, GoodFriday)bond_cal20,707
-bus_day = CustomBusinessDay(calendar=bond_cal())bus_day21,778
-def cp_choices():cp_choices23,828
-def get_queue():get_queue27,962
-def get_db():get_db37,1284
-def close_connection(exception):close_connection46,1590
-class CounterpartyForm(ModelForm):CounterpartyForm51,1705
- class Meta:Meta52,1740
- model = Counterpartiesmodel53,1756
- include_primary_keys = Trueinclude_primary_keys54,1787
-class BondForm(ModelForm):BondForm56,1824
- upload_globeop = BooleanField(label="Upload to globeop?")upload_globeop57,1851
- class Meta:Meta58,1913
- model = BondDealmodel59,1929
- include_foreign_keys = Trueinclude_foreign_keys60,1954
- exclude = ['dealid', 'lastupdate', #we generate it with a trigger at the server levelexclude61,1990
-class CDSForm(ModelForm):CDSForm64,2144
- upload_globeop = BooleanField(label="Upload to globeop?")upload_globeop65,2170
- class Meta:Meta66,2232
- model = CDSDealmodel67,2248
- include_foreign_keys = Trueinclude_foreign_keys68,2272
- exclude = ['dealid', 'lastupdate']exclude69,2308
-class SwaptionForm(ModelForm):SwaptionForm71,2352
- upload_globeop = BooleanField(label="Upload to globeop?")upload_globeop72,2383
- class Meta:Meta73,2445
- model = SwaptionDealmodel74,2461
- include_foreign_keys = Trueinclude_foreign_keys75,2490
- exclude = ['dealid', 'lastupdate']exclude76,2526
-def get_deal(kind):get_deal79,2571
-def get_form(trade, kind):get_form89,2801
-def get_trade(tradeid, kind):get_trade121,3922
-def save_ticket(trade, old_ticket_name):save_ticket125,4037
-def trade_manage(tradeid, kind):trade_manage141,4783
-def list_trades(kind):list_trades173,6110
-def download_ticket(tradeid):download_ticket180,6359
-def list_counterparties(instr):list_counterparties193,6877
-def edit_counterparty(cpcode):edit_counterparty204,7416
-def get_bbg_id():get_bbg_id230,8360
+Dawn/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
Dawn/templates/swaption_blotter.html,0
+Dawn/templates/wire_blotter.html,0
+
Dawn/templates/trade_entry.html,0
+Dawn/templates/wire_entry.html,0
+
Dawn/templates/edit_cp.html,0
Dawn/templates/base.html,0
@@ -1691,13 +2092,13 @@ Dawn/templates/cds_blotter.html,0
Dawn/templates/bond_blotter.html,0
+Dawn/templates/future_blotter.html,0
+
Dawn/templates/counterparties.html,0
-Dawn/utils.py,197
-def load_counterparties(engine):load_counterparties7,103
-def load_trades(engine):load_trades26,1441
-def bump_rev(filename):bump_rev57,3057
-def simple_serialize(obj):simple_serialize63,3299
+Dawn/utils.py,89
+def bump_rev(filename):bump_rev6,66
+def simple_serialize(obj):simple_serialize12,308
trade_template.py,234
default = "\underline{\hspace{1cm}}"default3,29
@@ -1711,12 +2112,12 @@ fed_cal = get_calendar('USFederalHolidayCalendar')fed_cal9,259
bond_cal = HolidayCalendarFactory('BondCalendar', fed_cal, GoodFriday)bond_cal10,310
bus_day = CustomBusinessDay(calendar=bond_cal())bus_day11,381
def imm_dates(start_date, end_date):imm_dates13,431
-def previous_twentieth(d):previous_twentieth21,767
-def days_accrued(tradedate):days_accrued30,982
-def isleapyear(date):isleapyear40,1427
-def yearfrac(date1, date2, daycount):yearfrac43,1535
-class TestDaysAccrued(unittest.TestCase):TestDaysAccrued60,2077
- def test(self):test61,2119
+def previous_twentieth(d):previous_twentieth21,771
+def days_accrued(tradedate):days_accrued30,986
+def isleapyear(date):isleapyear40,1431
+def yearfrac(date1, date2, daycount):yearfrac43,1539
+class TestDaysAccrued(unittest.TestCase):TestDaysAccrued60,2081
+ def test(self):test61,2123
bbg_newids.py,1671
engine = create_engine('postgresql://et_user@debian/ET')engine7,220
@@ -1743,50 +2144,29 @@ pd_colnames = ['ID_BB_UNIQUE','LAST_UPDATE_DT','PX_LAST','LN_CURRENT_MARGIN',pd
sql_colnames = [c.name for c in bloomberg_corp.columns]sql_colnames72,3462
to_insert2 = df.filter(pd_colnames)to_insert273,3518
-option_exploration.py,1906
-SQL_CON = 'postgresql://serenitas_user@debian/serenitasdb'SQL_CON16,220
-df = pd.read_sql_table('swaption_quotes', SQL_CON, index_col=['quotedate', 'index', 'series', 'expiry'])df17,279
-index_data = pd.read_sql_table('swaption_ref_quotes', SQL_CON, index_col=['quotedate', 'index', 'series', 'expiry'])index_data18,384
-def atm_vol_fun(k, v, moneyness = 0.2):atm_vol_fun24,551
-df_filtered = df.groupby(df.index).filter(lambda x: len(x)>=2)df_filtered36,924
-grouped = df_filtered.groupby(df_filtered.index)grouped37,987
-ind = pd.MultiIndex.from_tuples(ind, names=['quotedate', 'indextype', 'series', 'expiry'])ind39,1112
-df_vol = pd.DataFrame({'atm_vol': atm_vol, 'otm_vol':otm_vol}, index=ind)df_vol40,1203
-df_vol = df_vol.reset_index(level=-1) #move expiry back to the columndf_vol41,1277
-def rolling_vol(df, col='atm_vol'):rolling_vol47,1433
- def aux(k, s, col):aux50,1588
-df_atm_vol_rolling = rolling_vol(df_vol)df_atm_vol_rolling58,2013
-df_otm_vol_rolling = rolling_vol(df_vol, 'otm_vol')df_otm_vol_rolling59,2054
-df_vol_rolling = df_atm_vol_rolling.join(df_otm_vol_rolling)df_vol_rolling60,2106
-df_compare = df_vol_rolling.unstack(level=1)df_compare65,2180
-df_27 = df_compare.xs(27, level='series')df_2766,2225
-df_27 = df_27.groupby(pd.TimeGrouper('D')).last().dropna()df_2767,2267
-df_compare = df_vol_rolling.unstack(level=1)df_compare73,2363
-df_26 = df_compare.xs(26, level='series')df_2674,2408
-df_26 = df_26.groupby(pd.TimeGrouper('D')).last().dropna()df_2675,2450
-df_compare = df_vol_rolling.unstack(level=1)df_compare81,2545
-df_25 = df_compare.xs(25, level='series')df_2582,2590
-df_25 = df_25.groupby(pd.TimeGrouper('D')).last().dropna()df_2583,2632
-skew = df_26.otm_vol.IG-df_26.atm_vol.IGskew94,2788
-skew = df_27.otm_vol.IG-df_27.atm_vol.IGskew100,2854
-ig26_vol = df_vol_rolling.xs(('IG', 26), level=['indextype','series'])ig26_vol106,2920
-
-process_queue.py,1031
-HEADERS = {'bond_trades':['Deal Type', 'Deal ID', 'Action', 'Client', 'Reserved', 'Reserved',HEADERS27,546
-def decode_dict(d):decode_dict80,4858
-def get_redis_queue():get_redis_queue84,5013
-def get_effective_date(d):get_effective_date96,5353
-def aux(v):aux99,5443
-def get_trades(q, queue_name='bond_trades'):get_trades109,5689
-def build_line(obj, queue_name='bond_trades'):build_line123,6188
-def get_bbg_data(conn, session, identifier, cusip=None, isin = None, settle_date = None, asset_class=None,get_bbg_data218,10495
-def bond_trade_process(conn, session, trade):bond_trade_process273,13383
-def cds_trade_process(serenitasdb, dawndb, session, trade):cds_trade_process293,14303
-def generate_csv(l, queue_name='bond_trades'):generate_csv308,14917
-def get_filename(timestamp, queue_name):get_filename319,15274
-def upload_file(timestamp, queue_name='bond_trades'):upload_file325,15529
-def write_buffer(buf, queue_name='bond_trades'):write_buffer337,16011
-def email_subject(trade):email_subject347,16395
+process_queue.py,1414
+HEADERS = {'bond_trades': [HEADERS25,531
+def get_effective_date(d):get_effective_date101,5942
+def get_trades(q, queue_name='bond_trades'):get_trades104,6032
+def rename_keys(d, mapping):rename_keys122,6684
+def build_line(obj, queue_name='bond_trades'):build_line128,6865
+def get_bbg_data(conn, session, identifier, cusip=None, isin = None, settle_date = None, asset_class=None,get_bbg_data236,12001
+def bond_trade_process(conn, session, trade):bond_trade_process291,14889
+def cds_trade_process(serenitasdb, dawndb, session, trade):cds_trade_process317,15994
+def generate_csv(l, queue_name='bond_trades'):generate_csv332,16604
+def get_filename(timestamp, queue_name):get_filename343,16961
+def upload_file(timestamp, queue_name='bond_trades'):upload_file351,17287
+def write_buffer(buf, queue_name='bond_trades'):write_buffer363,17769
+def email_subject(trade):email_subject373,18159
+def print_trade(trade):print_trade377,18399
+ parser = argparse.ArgumentParser()parser383,18573
+ args = parser.parse_args()args385,18711
+ q = get_redis_queue()q386,18742
+ serenitasdb = dbconn('serenitasdb')serenitasdb387,18768
+ dawndb = dbconn('dawndb')dawndb388,18808
+ list_trades = get_trades(q, queue_name)list_trades390,18936
+ buf = generate_csv(list_trades, queue_name)buf401,19452
+ timestamp = write_buffer(buf, queue_name)timestamp402,19508
task_server/__init__.py,320
app = Flask(__name__)app2,24
@@ -1795,26 +2175,26 @@ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(messag
loggers = [logging.getLogger('intex'), app.logger, logging.getLogger(__name__)]loggers11,294
task_server/insert_tranche_quotes.py,658
-logger = logging.getLogger(__name__)logger8,167
-engine = create_engine('postgresql://serenitas_user@debian/serenitasdb')engine10,207
-metadata = MetaData(bind = engine)metadata11,281
-quotes = Table('tranche_quotes', metadata, autoload = True)quotes12,317
-ins = quotes.insert()ins13,378
-def convert(x):convert15,403
-def convert_int(x):convert_int24,604
-tenordict = {'3': '3yr', '5': '5yr', '7':'7yr', '10':'10yr'}tenordict33,812
-runningdict1 = {0: 500, 3:100, 7:100, 15: 25}runningdict134,874
-runningdict2 = {0: 500, 3:500, 7:500, 10:100, 15:100, 30:100}runningdict235,921
-def insert_quotes(year=2016, quote_dir=None):insert_quotes37,986
+logger = logging.getLogger(__name__)logger8,160
+engine = create_engine('postgresql://serenitas_user@debian/serenitasdb')engine10,198
+metadata = MetaData(bind = engine)metadata11,271
+quotes = Table('tranche_quotes', metadata, autoload = True)quotes12,306
+ins = quotes.insert()ins13,366
+def convert(x):convert15,389
+def convert_int(x):convert_int24,581
+tenordict = {'3': '3yr', '5': '5yr', '7':'7yr', '10':'10yr'}tenordict33,780
+runningdict1 = {0: 500, 3:100, 7:100, 15: 25}runningdict134,841
+runningdict2 = {0: 500, 3:500, 7:500, 10:100, 15:100, 30:100}runningdict235,887
+def insert_quotes(year=2016, quote_dir=None):insert_quotes37,950
task_server/rest.py,238
def get_db():get_db11,283
def get_queue():get_queue20,584
def close_db(error):close_db27,768
def intex():intex34,948
-def globeop():globeop40,1113
-def insert_tranches():insert_tranches46,1358
-def run_tasks():run_tasks51,1466
+def globeop():globeop40,1116
+def insert_tranches():insert_tranches46,1364
+def run_tasks():run_tasks51,1475
task_server/__main__.py,565
level=logging.INFO,level9,224
@@ -1827,6 +2207,10 @@ group = parser.add_mutually_exclusive_group(required=True)group13,354
args = parser.parse_args()args22,896
engine = create_engine('postgresql://dawn_user@debian/dawndb')engine27,996
+task_server/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
+
task_server/config.py,330
ftp_password = 'B6#dEu7V'ftp_password1,0
key_password = 'Serenitas;1'key_password2,27
@@ -1835,17 +2219,20 @@ gmail_login = 'david.weeks@serenitascapital.com'gmail_login4,87
markit_password = 'Welcome3!'markit_password5,137
markit_login = 'guillaume.horel@serenitascapital.com'markit_login6,168
-task_server/globeop.py,455
-logger = logging.getLogger(__name__)logger12,200
-def get_ped(s):get_ped20,349
-def key_fun(s):key_fun30,655
-def run_date(s):run_date40,972
-def get_ftp(folder):get_ftp47,1170
-def get_gpg():get_gpg53,1313
-def download_data(workdate):download_data62,1659
-def upload_bond_marks(engine, workdate):upload_bond_marks111,4030
-def upload_cds_marks(engine, workdate):upload_cds_marks123,4637
-def upload_data(engine, workdate):upload_data135,5251
+task_server/globeop.py,619
+logger = logging.getLogger(__name__)logger15,263
+def get_ped(s):get_ped23,412
+def key_fun(s):key_fun33,725
+def run_date(s):run_date43,1042
+def get_ftp(folder):get_ftp50,1240
+def get_gpg():get_gpg56,1383
+def convert_to_csv(f):convert_to_csv65,1743
+def download_data(workdate):download_data71,1954
+def insert_todb(workdate):insert_todb120,4076
+def upload_bond_marks(engine, workdate):upload_bond_marks140,5075
+def upload_cds_marks(engine, workdate):upload_cds_marks152,5683
+def upload_data(engine, workdate):upload_data164,6298
+def back_fill(start_date=pd.datetime(2017,7,20)):back_fill168,6417
parse_gs.py,2375
data_dir = "/home/share/guillaume/swaptions"data_dir6,52
@@ -1913,6 +2300,13 @@ df2bis = pd.read_sql_query("SELECT date FROM test WHERE date<='2014-10-17'",df2
df3 = pd.read_sql_query("SELECT date FROM test", engine,df311,376
parse_dates=['date'])parse_dates12,433
+experiments/test_async.py,157
+async def pomme():pomme3,16
+async def poire():poire8,106
+async def main():main13,196
+async def ping(msg):ping18,275
+async def pong(msg):pong26,416
+
experiments/test_trace.py,359
df = pd.read_clipboard(header=None)df5,101
trace_data = {}trace_data6,137
@@ -1920,10 +2314,34 @@ trace_data = {}trace_data6,137
start_date=datetime.datetime(2016, 5, 22, 12, 42),start_date11,337
end_date=datetime.datetime(2017, 5, 22, 18, 42))end_date12,430
-experiments/test_asyncpg.py,169
-async def dbconn():dbconn5,47
-async def get_singlenames_quotes_async(indexname, date):get_singlenames_quotes_async10,235
-loop = asyncio.get_event_loop()loop20,627
+experiments/test_dask.py,721
+strip_percent = lambda s: float(s.rstrip('%'))/100 if s else np.nanstrip_percent4,48
+tenors = ['6m'] + [f'{y}y' for y in [1, 2, 3, 4, 5, 7, 10, 15, 20, 30]]tenors5,116
+ for t in tenors}converters8,233
+dtype = {'Rating' + t: 'object' for t in tenors}dtype10,303
+df = dd.read_csv("/home/guillaume/composites/*.csv",df14,483
+ skiprows=2,skiprows15,536
+ converters=converters,converters16,556
+ dtype=dtype,dtype17,587
+ parse_dates=['Date'])parse_dates18,608
+ ["Rating" + t for t in tenors]to_categorize22,802
+df = df.categorize(columns=to_categorize, index=False)df23,841
+df = df.set_index("Date")df24,896
+df = df.repartition(npartitions=100)df25,922
+
+experiments/.ropeproject/config.py,90
+def set_prefs(prefs):set_prefs5,45
+def project_opened(project):project_opened110,4652
+
+experiments/test_basket.py,138
+ig29 = TrancheBasket("IG", 29, "5yr", trade_date=pd.Timestamp.today().normalize() - BDay())ig294,96
+df = ig29.tranche_deltas()df8,220
+
+experiments/test_asyncpg.py,235
+async def dbconn():dbconn10,178
+async def get_singlenames_quotes_async(con, indexname, date):get_singlenames_quotes_async16,388
+async def get_curves(con, currency="USD", date=None):get_curves24,738
+async def main():main29,1022
experiments/exchange_example.py,369
credentials = Credentials(username='LEEMUNDER\\ghorel', password='')credentials3,46
@@ -1954,8 +2372,9 @@ df = df.unstack(level=0).stack(level=0).reset_index(level=1)df12,378
tranche_quotes = df.join(index_quotes)tranche_quotes20,813
index_label='quotedate')index_label27,1292
-common.py,52
-def sanitize_float(intex_float):sanitize_float1,0
+common.py,99
+def sanitize_float(intex_float):sanitize_float6,50
+def get_redis_queue():get_redis_queue18,445
futures.py,1105
ticker = "GE"ticker11,178
@@ -1987,31 +2406,40 @@ def plot_allocation(W, fund_return, fund_vol):plot_allocation60,2146
delta = {'CLO': 0.4,delta82,2810
mu = np.array([0.01, 0.075, 0.065, 0.25])mu85,2890
-download_markit_quotes.py,484
- level=logging.INFO,level17,687
- format='%(asctime)s %(message)s')format18,727
-profile = FirefoxProfile()profile21,871
-driver = Firefox(profile)driver27,1181
-menu = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,menu34,1586
-hiddenmenu = WebDriverWait(driver, 10).until(hiddenmenu38,1806
- link = WebDriverWait(driver, 10).until(EC.element_to_be_clickable(link46,2142
-total_wait = 0total_wait57,2559
+download_markit_quotes.py,478
+ level=logging.INFO,level17,720
+ format='%(asctime)s %(message)s')format18,760
+profile = FirefoxProfile()profile21,904
+driver = Firefox(profile)driver27,1214
+ menu = WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.ID,menu35,1474
+hiddenmenu = WebDriverWait(driver, 10).until(hiddenmenu45,1789
+ link = WebDriverWait(driver, 10).until(EC.element_to_be_clickable(link53,2069
+total_wait = 0total_wait63,2446
+
+mark_backtest_backfill.py,273
+def runAllFill():runAllFill15,307
+def runSingleFill(f):runSingleFill21,464
+def get_CUSIPs():get_CUSIPs51,1733
+def get_BVAL():get_BVAL57,1930
+def pop_BVAL_to_database(df):pop_BVAL_to_database74,2685
+def get_globs():get_globs87,3161
+settings = {settings99,3701
load_cf.py,1172
def sanitize_float(string):sanitize_float20,588
def processzipfiles(tradedate=datetime.date.today()):processzipfiles31,841
-def get_configfile(dealname, tradedate):get_configfile51,1915
-def get_dist(date):get_dist61,2293
-def get_dealdata(dealname, tradedate):get_dealdata67,2564
-def get_cusipdata(cusip, tradedate):get_cusipdata75,3017
-def get_dealschedule(dealdata, freq='1Mo', adj=Unadjusted):get_dealschedule80,3220
-def dealname_from_cusip(conn, cusips):dealname_from_cusip87,3670
-def discounts(tradedate):discounts93,3854
-def getdealcf(dealnames, zipfiles, tradedate = datetime.date.today()):getdealcf104,4411
-def getcusipcf(params, cfdata, tradedate):getcusipcf145,6423
-def compute_delta(dist, dealweight, cusip_pv, tradedate, K1 = 0, K2 = 1):compute_delta178,8290
- tradedate = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d").date()tradedate189,8766
- tradedate = datetime.date.today()tradedate191,8857
- params = processzipfiles(tradedate)params192,8900
- cfdata = getdealcf(params["dealnames"], params["zipfiles"], tradedate)cfdata193,8941
- cusipdata = getcusipcf(params, cfdata, tradedate)cusipdata194,9017
+def get_configfile(dealname, tradedate):get_configfile51,1913
+def get_dist(date):get_dist61,2291
+def get_dealdata(dealname, tradedate):get_dealdata67,2562
+def get_cusipdata(cusip, tradedate):get_cusipdata75,3015
+def get_dealschedule(dealdata, freq='1Mo', adj=Unadjusted):get_dealschedule80,3218
+def dealname_from_cusip(conn, cusips):dealname_from_cusip87,3668
+def discounts(tradedate):discounts93,3852
+def getdealcf(dealnames, zipfiles, tradedate = datetime.date.today()):getdealcf104,4409
+def getcusipcf(params, cfdata, tradedate):getcusipcf145,6421
+def compute_delta(dist, dealweight, cusip_pv, tradedate, K1 = 0, K2 = 1):compute_delta178,8288
+ tradedate = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d").date()tradedate189,8764
+ tradedate = datetime.date.today()tradedate191,8855
+ params = processzipfiles(tradedate)params192,8898
+ cfdata = getdealcf(params["dealnames"], params["zipfiles"], tradedate)cfdata193,8939
+ cusipdata = getcusipcf(params, cfdata, tradedate)cusipdata194,9015
diff --git a/python/analytics/__init__.py b/python/analytics/__init__.py
index da3b5ae7..1dc1e24f 100644
--- a/python/analytics/__init__.py
+++ b/python/analytics/__init__.py
@@ -1,5 +1,6 @@
from .index import Index, ForwardIndex
-from .option import BlackSwaption, Swaption, VolatilitySurface, ATMstrike, ProbSurface, QuoteSurface, VolSurface
+from .option import (BlackSwaption, Swaption, ATMstrike, ProbSurface,
+ QuoteSurface, VolSurface, BlackSwaptionVolSurface)
from .portfolio import Portfolio
from .basket_index import MarkitBasketIndex
from .tranche_basket import TrancheBasket
diff --git a/python/analytics/option.py b/python/analytics/option.py
index 4721dfbc..949ea224 100644
--- a/python/analytics/option.py
+++ b/python/analytics/option.py
@@ -596,7 +596,6 @@ class ModelBasedVolSurface(VolSurface):
ax.set_ylabel("Moneyness")
ax.set_zlabel("Volatility")
-
class BlackSwaptionVolSurface(ModelBasedVolSurface):
pass
@@ -702,10 +701,10 @@ def calib_sabr(x, option, strikes, pv, beta):
r[i] = option.pv - pv[i]
return r
-class SABRVolatilitySurface(VolatilitySurface):
+class SABRVolSurface(VolSurface):
def __init__(self, index_type, series, tenor='5yr',
trade_date=datetime.date.today(), beta=None):
- VolatilitySurface.__init__(self, index_type, series, tenor='5yr',
+ VolSurface.__init__(self, index_type, series, tenor='5yr',
trade_date=datetime.date.today())
if index_type == "HY":
self.beta = 3.19
diff --git a/python/analytics/portfolio.py b/python/analytics/portfolio.py
index 50b43477..bea0f5cd 100644
--- a/python/analytics/portfolio.py
+++ b/python/analytics/portfolio.py
@@ -1,5 +1,5 @@
from .index import Index
-from .option import BlackSwaption, VolatilitySurface
+from .option import BlackSwaption, BlackSwaptionVolSurface
from db import dbengine
from warnings import warn
import pandas as pd
@@ -87,7 +87,7 @@ class Portfolio:
k = (index.trade_date, index_type, series, tenor)
if self.swaptions:
if k not in self._vs:
- vs = VolatilitySurface(index_type, series, tenor, index.trade_date)
+ vs = BlackSwaptionVolSurface(index_type, series, tenor, index.trade_date)
if surface_id is None:
for source in source_list:
if len(vs.list(source, option_type, model)) >=1:
diff --git a/python/exploration/portfolio_example.py b/python/exploration/portfolio_example.py
index ebaa6b3b..6b72a2c1 100644
--- a/python/exploration/portfolio_example.py
+++ b/python/exploration/portfolio_example.py
@@ -1,24 +1,8 @@
from analytics import (Portfolio, BlackSwaption, Index,
- VolatilitySurface, Swaption)
+ BlackSwaptionVolSurface, Swaption)
from analytics.scenarios import run_portfolio_scenarios
import pandas as pd
-from pandas.tseries.offsets import BDay
import numpy as np
-import datetime
-
-# option_delta = Index.from_tradeid(874)
-# option1 = BlackSwaption.from_tradeid(7, option_delta)
-# option2 = BlackSwaption.from_tradeid(8, option_delta)
-
-# portf = Portfolio([option1, option2, option_delta])
-# date_range = pd.bdate_range(option_delta.trade_date,
-# pd.Timestamp('2017-05-01'), freq = 'B')
-# pnl = []
-# for date in date_range:
-# portf.trade_date = date.date()
-# portf.mark(source_list=["BAML", "GS"], model="black")
-# pnl.append(portf.pnl)
-# df = pd.DataFrame({'pnl': pnl}, index=date_range)
option_delta = Index.from_tradeid(870)
option1 = BlackSwaption.from_tradeid(5, option_delta)
@@ -26,22 +10,10 @@ option2 = BlackSwaption.from_tradeid(6, option_delta)
portf = Portfolio([option1, option2, option_delta])
date_range = pd.bdate_range(option_delta.trade_date,
- pd.Timestamp('2017-04-19'), freq = 'W')
+ pd.Timestamp('2017-04-19'), freq='W')
vol_shock = np.arange(-0.15, 0.3, 0.01)
spread_shock = np.arange(-0.2, 0.3, 0.01)
-vs = VolatilitySurface("IG", 27, trade_date=option_delta.trade_date)
-vol_surface = vs[vs.list(model="black")[-1]]
+vs = BlackSwaptionVolSurface("IG", 27, trade_date=option_delta.trade_date)
+vol_surface = vs[vs.list()[-1]]
df = run_portfolio_scenarios(portf, date_range, spread_shock, vol_shock, vol_surface,
['pv', 'delta'])
-
-# pnl = []
-# for date in date_range:
-# portf.trade_date = date.date()
-# try:
-# portf.mark(source_list=["BAML", "GS"], model="black")
-# except ValueError:
-# pnl.append(None)
-# continue
-# else:
-# pnl.append(portf.pnl)
-# df = pd.DataFrame({'pnl': pnl}, index=date_range)
diff --git a/python/exploration/portfolio_var.py b/python/exploration/portfolio_var.py
index 7fba2ba2..65b1f113 100644
--- a/python/exploration/portfolio_var.py
+++ b/python/exploration/portfolio_var.py
@@ -1,5 +1,5 @@
from index_data import get_index_quotes, index_returns, _serenitas_engine
-from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio
+from analytics import Index, Portfolio
from db import dbengine, dbconn
from pandas.tseries.offsets import BDay, BMonthEnd
from copy import deepcopy
diff --git a/python/exploration/swaption_calendar_spread.py b/python/exploration/swaption_calendar_spread.py
index d703bbe7..e21ffd66 100644
--- a/python/exploration/swaption_calendar_spread.py
+++ b/python/exploration/swaption_calendar_spread.py
@@ -1,7 +1,8 @@
import sys
#don't do this at home
sys.path.append("..")
-from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio
+from analytics import (Swaption, BlackSwaption, BlackSwaptionVolSurface,
+ Index, ProbSurface, Portfolio)
from analytics.scenarios import run_swaption_scenarios, run_index_scenarios, run_portfolio_scenarios
from pandas.tseries.offsets import BDay
import datetime
@@ -9,19 +10,15 @@ import numpy as np
import pandas as pd
from scipy.interpolate import SmoothBivariateSpline
-from mpl_toolkits.mplot3d import Axes3D
-import matplotlib.pyplot as plt
-
import os
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
-from graphics import plot_time_color_map
+from graphics import plot_time_color_map, plot_color_map
from db import dbengine
engine = dbengine('serenitasdb')
-
def plot_df(df, spread_shock, vol_shock, attr="pnl"):
val_date = df.index[0].date()
fig = plt.figure()
@@ -37,44 +34,17 @@ def plot_df(df, spread_shock, vol_shock, attr="pnl"):
ax.set_zlabel("PnL")
ax.set_title('{} of Trade on {}'.format(attr.title(), val_date))
-def plot_color_map(df, spread_shock, vol_shock, attr="pnl", path=".", index ='IG'):
-
- val_date = df.index[0].date()
- #rows are spread, columns are volatility surface shift
- fig, ax = plt.subplots()
- #We are plotting an image, so we have to sort from high to low on the Y axis
- ascending = [False,False] if index == 'HY' else [True,False]
- df.sort_values(by=['spread','vol_shock'], ascending = ascending, inplace = True)
- series = df[attr]
-
- midpoint = 1 - series.max() / (series.max() + abs(series.min()))
- shifted_cmap = shiftedColorMap(cm.RdYlGn, midpoint=midpoint, name='shifted')
-
- chart = ax.imshow(series.values.reshape(spread_shock.size, vol_shock.size).T,
- extent=(spread_shock.min(), spread_shock.max(),
- vol_shock.min(), vol_shock.max()),
- aspect='auto', interpolation='bilinear', cmap=shifted_cmap)
-
- ax.set_xlabel('Price') if index == 'HY' else ax.set_xlabel('Spread')
- ax.set_ylabel('Volatility shock')
- ax.set_title('{} of Trade on {}'.format(attr.title(), val_date))
-
- fig.colorbar(chart, shrink=.8)
- #fig.savefig(os.path.join(path, "vol_spread_color_map"+ attr+ "_{}.png".format(val_date)))
-
-def plot_trade_scenarios(portf, shock_min=-.15, shock_max=.2, period = -1, vol_time_roll=True):
-
+def plot_trade_scenarios(portf, shock_min=-.15, shock_max=.2, period=-1, vol_time_roll=True):
portf.reset_pv()
earliest_date = min(portf.swaptions, key=lambda x: x.exercise_date).exercise_date
- #earliest_date = max(portf.swaptions,key=attrgetter('exercise_date')).exercise_date
- date_range = pd.bdate_range(portf.indices[0].trade_date, earliest_date - BDay(), freq = '3B')
+ date_range = pd.bdate_range(portf.indices[0].trade_date,
+ earliest_date - BDay(), freq='3B')
vol_shock = np.arange(-0.15, 0.3, 0.01)
spread_shock = np.arange(shock_min, shock_max, 0.01)
index = portf.indices[0].name.split()[1]
series = portf.indices[0].name.split()[3][1:]
- vs = VolatilitySurface(index, series, trade_date=portf.indices[0].trade_date)
- vol_select = vs.list(option_type='payer', model='black')[-1]
- vol_surface = vs[vol_select]
+ vs = BlackSwaptionVolSurface(index, series, trade_date=portf.indices[0].trade_date)
+ vol_surface = vs[vs.list(option_type='payer')[-1]]
df = run_portfolio_scenarios(portf, date_range, spread_shock, vol_shock, vol_surface,
params=["pnl","delta"])
@@ -86,44 +56,11 @@ def plot_trade_scenarios(portf, shock_min=-.15, shock_max=.2, period = -1, vol_t
plot_time_color_map(df[round(df.vol_shock,2)==0], shock, 'pnl', index=index)
plot_time_color_map(df[round(df.vol_shock,2)==.2], shock, 'pnl', index=index)
- #plot_time_color_map(df[round(df.vol_shock,2)==0], shock, 'delta', color_map = cm.coolwarm_r, index=index)
plot_color_map(df.loc[date_range[period]], shock, vol_shock, 'pnl', index=index)
- #plot_df(df.loc[date_range[period]], shock, vol_shock)
return df
def exercise_probability():
-
- from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio, ProbSurface, QuoteSurface, VolSurface
- from analytics.scenarios import run_swaption_scenarios, run_index_scenarios, run_portfolio_scenarios
- import datetime
- from operator import attrgetter
-
- import exploration.swaption_calendar_spread as spread
-
- import sys
- #don't do this at home
- from pandas.tseries.offsets import BDay
- import datetime
- import numpy as np
- import pandas as pd
- from scipy.interpolate import SmoothBivariateSpline
- from matplotlib import cm
- from mpl_toolkits.mplot3d import Axes3D
- import matplotlib.pyplot as plt
- from operator import attrgetter
-
- import os
- import numpy as np
- import matplotlib
- import matplotlib.pyplot as plt
- from mpl_toolkits.axes_grid1 import AxesGrid
-
- import re
- from db import dbengine
engine = dbengine('serenitasdb')
-
- #import swaption_calendar_spread as spread
-
#Ad hoc
option_delta = Index.from_name('HY', 29, '5yr')
option_delta.price = 107.875
@@ -141,18 +78,12 @@ def exercise_probability():
portf = Portfolio([option1, option2, option_delta])
portf.reset_pv()
- earliest_date = min(portf.swaptions,key=attrgetter('exercise_date')).exercise_date
- date_range = pd.bdate_range(portf.indices[0].trade_date, earliest_date - BDay(), freq = '5B')
+ earliest_date = min(portf.swaptions, key=lambda x: x.exercise_date).exercise_date
+ date_range = pd.bdate_range(portf.indices[0].trade_date, earliest_date - BDay(), freq='5B')
vol_shock = np.arange(-0.15, 0.3, 0.01)
spread_shock = np.arange(-0.15, 0.35, 0.01)
index = portf.indices[0].name.split()[1]
series = portf.indices[0].name.split()[3][1:]
- vs = QuoteSurface(index, series, trade_date=portf.indices[0].trade_date)
-
- vs = VolatilitySurface(index, series, trade_date=portf.indices[0].trade_date)
- vol_select = vs.list(option_type='payer', model='black')[-1]
- vol_surface = vs[vol_select]
-
- prob = vs.prob_surf(vol_select)
- vs.prob_plot(vol_select)
+ vs = ProbSurface(index, series, trade_date=portf.indices[0].trade_date)
+ vs.plot(vs.list()[-1])
diff --git a/python/exploration/tranches.py b/python/exploration/tranches.py
index 094c3e9b..028d41b1 100644
--- a/python/exploration/tranches.py
+++ b/python/exploration/tranches.py
@@ -7,7 +7,7 @@ import analytics.basket_index as idx_bkt
import numpy as np
import pandas as pd
-from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio
+from analytics import Swaption, BlackSwaption, Index, BlackSwaptionVolSurface, Portfolio
from analytics.scenarios import run_swaption_scenarios, run_index_scenarios, run_portfolio_scenarios
import exploration.swaption_calendar_spread as spread
from scipy.interpolate import interp1d
@@ -164,9 +164,8 @@ def run_scen(trade_date = pd.Timestamp.today().normalize()- pd.offsets.BDay()):
spread_shock = np.arange(shock_min, shock_max, 0.05)
index = portf.indices[0].name.split()[1]
series = portf.indices[0].name.split()[3][1:]
- vs = VolatilitySurface(index, series, trade_date=trade_date)
- vol_select = vs.list(option_type='payer', model='black')[-1]
- vol_surface = vs[vol_select]
+ vs = BlackSwaptionVolaSurface(index, series, trade_date=trade_date)
+ vol_surface = vs[vs.list(option_type='payer')[-1]]
df = run_portfolio_scenarios(portf, date_range, spread_shock, vol_shock, vol_surface,
params=["pnl","delta"])
diff --git a/python/graphics.py b/python/graphics.py
index 0f348a04..3a88147a 100644
--- a/python/graphics.py
+++ b/python/graphics.py
@@ -1,6 +1,7 @@
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
+from matplotlib.colors import LinearSegmentedColormap
def shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap'):
'''
@@ -48,7 +49,7 @@ def shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap'):
cdict['blue'].append((si, b, b))
cdict['alpha'].append((si, a, a))
- newcmap = matplotlib.colors.LinearSegmentedColormap(name, cdict)
+ newcmap = LinearSegmentedColormap(name, cdict)
plt.register_cmap(cmap=newcmap)
return newcmap
@@ -82,3 +83,28 @@ def plot_time_color_map(df, spread_shock, attr="pnl", path=".", color_map=cm.RdY
fig.colorbar(chart, shrink=.8)
#fig.savefig(os.path.join(path, "spread_time_color_map_"+ attr+ "_{}.png".format(val_date)))
+
+def plot_color_map(df, spread_shock, vol_shock, attr="pnl", path=".", index='IG'):
+ # TODO: merge with plot_time_color_map
+ val_date = df.index[0].date()
+ #rows are spread, columns are volatility surface shift
+ fig, ax = plt.subplots()
+ #We are plotting an image, so we have to sort from high to low on the Y axis
+ ascending = [False,False] if index == 'HY' else [True,False]
+ df.sort_values(by=['spread','vol_shock'], ascending=ascending, inplace=True)
+ series = df[attr]
+
+ midpoint = 1 - series.max() / (series.max() + abs(series.min()))
+ shifted_cmap = shiftedColorMap(cm.RdYlGn, midpoint=midpoint, name='shifted')
+
+ chart = ax.imshow(series.values.reshape(spread_shock.size, vol_shock.size).T,
+ extent=(spread_shock.min(), spread_shock.max(),
+ vol_shock.min(), vol_shock.max()),
+ aspect='auto', interpolation='bilinear', cmap=shifted_cmap)
+
+ ax.set_xlabel('Price') if index == 'HY' else ax.set_xlabel('Spread')
+ ax.set_ylabel('Volatility shock')
+ ax.set_title('{} of Trade on {}'.format(attr.title(), val_date))
+
+ fig.colorbar(chart, shrink=.8)
+ #fig.savefig(os.path.join(path, "vol_spread_color_map"+ attr+ "_{}.png".format(val_date)))
diff --git a/python/notebooks/Option Trades.ipynb b/python/notebooks/Option Trades.ipynb
index 58b32b5d..9aa46523 100644
--- a/python/notebooks/Option Trades.ipynb
+++ b/python/notebooks/Option Trades.ipynb
@@ -2,15 +2,15 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
- "from analytics import Swaption, BlackSwaption, Index, VolatilitySurface, Portfolio\n",
+ "from analytics import Swaption, BlackSwaption, BlackSwaptionVolSurface, Index, Portfolio\n",
"from analytics.scenarios import run_swaption_scenarios, run_index_scenarios, run_portfolio_scenarios\n",
"import datetime\n",
"\n",
- "import exploration.swaption_calendar_spread as spread\n",
+ "from exploration.swaption_calendar_spread import plot_trade_scenarios\n",
"#import swaption_calendar_spread as spread"
]
},
@@ -25,12 +25,830 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/home/guillaume/projects/code/python/analytics/option.py:577: SettingWithCopyWarning: \n",
+ "A value is trying to be set on a copy of a slice from a DataFrame\n",
+ "\n",
+ "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
+ " inplace=True)\n"
+ ]
+ },
+ {
+ "data": {
+ "application/javascript": [
+ "/* Put everything inside the global mpl namespace */\n",
+ "window.mpl = {};\n",
+ "\n",
+ "\n",
+ "mpl.get_websocket_type = function() {\n",
+ " if (typeof(WebSocket) !== 'undefined') {\n",
+ " return WebSocket;\n",
+ " } else if (typeof(MozWebSocket) !== 'undefined') {\n",
+ " return MozWebSocket;\n",
+ " } else {\n",
+ " alert('Your browser does not have WebSocket support.' +\n",
+ " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
+ " 'Firefox 4 and 5 are also supported but you ' +\n",
+ " 'have to enable WebSockets in about:config.');\n",
+ " };\n",
+ "}\n",
+ "\n",
+ "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
+ " this.id = figure_id;\n",
+ "\n",
+ " this.ws = websocket;\n",
+ "\n",
+ " this.supports_binary = (this.ws.binaryType != undefined);\n",
+ "\n",
+ " if (!this.supports_binary) {\n",
+ " var warnings = document.getElementById(\"mpl-warnings\");\n",
+ " if (warnings) {\n",
+ " warnings.style.display = 'block';\n",
+ " warnings.textContent = (\n",
+ " \"This browser does not support binary websocket messages. \" +\n",
+ " \"Performance may be slow.\");\n",
+ " }\n",
+ " }\n",
+ "\n",
+ " this.imageObj = new Image();\n",
+ "\n",
+ " this.context = undefined;\n",
+ " this.message = undefined;\n",
+ " this.canvas = undefined;\n",
+ " this.rubberband_canvas = undefined;\n",
+ " this.rubberband_context = undefined;\n",
+ " this.format_dropdown = undefined;\n",
+ "\n",
+ " this.image_mode = 'full';\n",
+ "\n",
+ " this.root = $('<div/>');\n",
+ " this._root_extra_style(this.root)\n",
+ " this.root.attr('style', 'display: inline-block');\n",
+ "\n",
+ " $(parent_element).append(this.root);\n",
+ "\n",
+ " this._init_header(this);\n",
+ " this._init_canvas(this);\n",
+ " this._init_toolbar(this);\n",
+ "\n",
+ " var fig = this;\n",
+ "\n",
+ " this.waiting = false;\n",
+ "\n",
+ " this.ws.onopen = function () {\n",
+ " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
+ " fig.send_message(\"send_image_mode\", {});\n",
+ " if (mpl.ratio != 1) {\n",
+ " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
+ " }\n",
+ " fig.send_message(\"refresh\", {});\n",
+ " }\n",
+ "\n",
+ " this.imageObj.onload = function() {\n",
+ " if (fig.image_mode == 'full') {\n",
+ " // Full images could contain transparency (where diff images\n",
+ " // almost always do), so we need to clear the canvas so that\n",
+ " // there is no ghosting.\n",
+ " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
+ " }\n",
+ " fig.context.drawImage(fig.imageObj, 0, 0);\n",
+ " };\n",
+ "\n",
+ " this.imageObj.onunload = function() {\n",
+ " fig.ws.close();\n",
+ " }\n",
+ "\n",
+ " this.ws.onmessage = this._make_on_message_function(this);\n",
+ "\n",
+ " this.ondownload = ondownload;\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._init_header = function() {\n",
+ " var titlebar = $(\n",
+ " '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
+ " 'ui-helper-clearfix\"/>');\n",
+ " var titletext = $(\n",
+ " '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
+ " 'text-align: center; padding: 3px;\"/>');\n",
+ " titlebar.append(titletext)\n",
+ " this.root.append(titlebar);\n",
+ " this.header = titletext[0];\n",
+ "}\n",
+ "\n",
+ "\n",
+ "\n",
+ "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
+ "\n",
+ "}\n",
+ "\n",
+ "\n",
+ "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
+ "\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._init_canvas = function() {\n",
+ " var fig = this;\n",
+ "\n",
+ " var canvas_div = $('<div/>');\n",
+ "\n",
+ " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
+ "\n",
+ " function canvas_keyboard_event(event) {\n",
+ " return fig.key_event(event, event['data']);\n",
+ " }\n",
+ "\n",
+ " canvas_div.keydown('key_press', canvas_keyboard_event);\n",
+ " canvas_div.keyup('key_release', canvas_keyboard_event);\n",
+ " this.canvas_div = canvas_div\n",
+ " this._canvas_extra_style(canvas_div)\n",
+ " this.root.append(canvas_div);\n",
+ "\n",
+ " var canvas = $('<canvas/>');\n",
+ " canvas.addClass('mpl-canvas');\n",
+ " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
+ "\n",
+ " this.canvas = canvas[0];\n",
+ " this.context = canvas[0].getContext(\"2d\");\n",
+ "\n",
+ " var backingStore = this.context.backingStorePixelRatio ||\n",
+ "\tthis.context.webkitBackingStorePixelRatio ||\n",
+ "\tthis.context.mozBackingStorePixelRatio ||\n",
+ "\tthis.context.msBackingStorePixelRatio ||\n",
+ "\tthis.context.oBackingStorePixelRatio ||\n",
+ "\tthis.context.backingStorePixelRatio || 1;\n",
+ "\n",
+ " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
+ "\n",
+ " var rubberband = $('<canvas/>');\n",
+ " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
+ "\n",
+ " var pass_mouse_events = true;\n",
+ "\n",
+ " canvas_div.resizable({\n",
+ " start: function(event, ui) {\n",
+ " pass_mouse_events = false;\n",
+ " },\n",
+ " resize: function(event, ui) {\n",
+ " fig.request_resize(ui.size.width, ui.size.height);\n",
+ " },\n",
+ " stop: function(event, ui) {\n",
+ " pass_mouse_events = true;\n",
+ " fig.request_resize(ui.size.width, ui.size.height);\n",
+ " },\n",
+ " });\n",
+ "\n",
+ " function mouse_event_fn(event) {\n",
+ " if (pass_mouse_events)\n",
+ " return fig.mouse_event(event, event['data']);\n",
+ " }\n",
+ "\n",
+ " rubberband.mousedown('button_press', mouse_event_fn);\n",
+ " rubberband.mouseup('button_release', mouse_event_fn);\n",
+ " // Throttle sequential mouse events to 1 every 20ms.\n",
+ " rubberband.mousemove('motion_notify', mouse_event_fn);\n",
+ "\n",
+ " rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
+ " rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
+ "\n",
+ " canvas_div.on(\"wheel\", function (event) {\n",
+ " event = event.originalEvent;\n",
+ " event['data'] = 'scroll'\n",
+ " if (event.deltaY < 0) {\n",
+ " event.step = 1;\n",
+ " } else {\n",
+ " event.step = -1;\n",
+ " }\n",
+ " mouse_event_fn(event);\n",
+ " });\n",
+ "\n",
+ " canvas_div.append(canvas);\n",
+ " canvas_div.append(rubberband);\n",
+ "\n",
+ " this.rubberband = rubberband;\n",
+ " this.rubberband_canvas = rubberband[0];\n",
+ " this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
+ " this.rubberband_context.strokeStyle = \"#000000\";\n",
+ "\n",
+ " this._resize_canvas = function(width, height) {\n",
+ " // Keep the size of the canvas, canvas container, and rubber band\n",
+ " // canvas in synch.\n",
+ " canvas_div.css('width', width)\n",
+ " canvas_div.css('height', height)\n",
+ "\n",
+ " canvas.attr('width', width * mpl.ratio);\n",
+ " canvas.attr('height', height * mpl.ratio);\n",
+ " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
+ "\n",
+ " rubberband.attr('width', width);\n",
+ " rubberband.attr('height', height);\n",
+ " }\n",
+ "\n",
+ " // Set the figure to an initial 600x600px, this will subsequently be updated\n",
+ " // upon first draw.\n",
+ " this._resize_canvas(600, 600);\n",
+ "\n",
+ " // Disable right mouse context menu.\n",
+ " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
+ " return false;\n",
+ " });\n",
+ "\n",
+ " function set_focus () {\n",
+ " canvas.focus();\n",
+ " canvas_div.focus();\n",
+ " }\n",
+ "\n",
+ " window.setTimeout(set_focus, 100);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._init_toolbar = function() {\n",
+ " var fig = this;\n",
+ "\n",
+ " var nav_element = $('<div/>')\n",
+ " nav_element.attr('style', 'width: 100%');\n",
+ " this.root.append(nav_element);\n",
+ "\n",
+ " // Define a callback function for later on.\n",
+ " function toolbar_event(event) {\n",
+ " return fig.toolbar_button_onclick(event['data']);\n",
+ " }\n",
+ " function toolbar_mouse_event(event) {\n",
+ " return fig.toolbar_button_onmouseover(event['data']);\n",
+ " }\n",
+ "\n",
+ " for(var toolbar_ind in mpl.toolbar_items) {\n",
+ " var name = mpl.toolbar_items[toolbar_ind][0];\n",
+ " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
+ " var image = mpl.toolbar_items[toolbar_ind][2];\n",
+ " var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
+ "\n",
+ " if (!name) {\n",
+ " // put a spacer in here.\n",
+ " continue;\n",
+ " }\n",
+ " var button = $('<button/>');\n",
+ " button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
+ " 'ui-button-icon-only');\n",
+ " button.attr('role', 'button');\n",
+ " button.attr('aria-disabled', 'false');\n",
+ " button.click(method_name, toolbar_event);\n",
+ " button.mouseover(tooltip, toolbar_mouse_event);\n",
+ "\n",
+ " var icon_img = $('<span/>');\n",
+ " icon_img.addClass('ui-button-icon-primary ui-icon');\n",
+ " icon_img.addClass(image);\n",
+ " icon_img.addClass('ui-corner-all');\n",
+ "\n",
+ " var tooltip_span = $('<span/>');\n",
+ " tooltip_span.addClass('ui-button-text');\n",
+ " tooltip_span.html(tooltip);\n",
+ "\n",
+ " button.append(icon_img);\n",
+ " button.append(tooltip_span);\n",
+ "\n",
+ " nav_element.append(button);\n",
+ " }\n",
+ "\n",
+ " var fmt_picker_span = $('<span/>');\n",
+ "\n",
+ " var fmt_picker = $('<select/>');\n",
+ " fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
+ " fmt_picker_span.append(fmt_picker);\n",
+ " nav_element.append(fmt_picker_span);\n",
+ " this.format_dropdown = fmt_picker[0];\n",
+ "\n",
+ " for (var ind in mpl.extensions) {\n",
+ " var fmt = mpl.extensions[ind];\n",
+ " var option = $(\n",
+ " '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
+ " fmt_picker.append(option)\n",
+ " }\n",
+ "\n",
+ " // Add hover states to the ui-buttons\n",
+ " $( \".ui-button\" ).hover(\n",
+ " function() { $(this).addClass(\"ui-state-hover\");},\n",
+ " function() { $(this).removeClass(\"ui-state-hover\");}\n",
+ " );\n",
+ "\n",
+ " var status_bar = $('<span class=\"mpl-message\"/>');\n",
+ " nav_element.append(status_bar);\n",
+ " this.message = status_bar[0];\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
+ " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
+ " // which will in turn request a refresh of the image.\n",
+ " this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.send_message = function(type, properties) {\n",
+ " properties['type'] = type;\n",
+ " properties['figure_id'] = this.id;\n",
+ " this.ws.send(JSON.stringify(properties));\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.send_draw_message = function() {\n",
+ " if (!this.waiting) {\n",
+ " this.waiting = true;\n",
+ " this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
+ " }\n",
+ "}\n",
+ "\n",
+ "\n",
+ "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
+ " var format_dropdown = fig.format_dropdown;\n",
+ " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
+ " fig.ondownload(fig, format);\n",
+ "}\n",
+ "\n",
+ "\n",
+ "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
+ " var size = msg['size'];\n",
+ " if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
+ " fig._resize_canvas(size[0], size[1]);\n",
+ " fig.send_message(\"refresh\", {});\n",
+ " };\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
+ " var x0 = msg['x0'] / mpl.ratio;\n",
+ " var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
+ " var x1 = msg['x1'] / mpl.ratio;\n",
+ " var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
+ " x0 = Math.floor(x0) + 0.5;\n",
+ " y0 = Math.floor(y0) + 0.5;\n",
+ " x1 = Math.floor(x1) + 0.5;\n",
+ " y1 = Math.floor(y1) + 0.5;\n",
+ " var min_x = Math.min(x0, x1);\n",
+ " var min_y = Math.min(y0, y1);\n",
+ " var width = Math.abs(x1 - x0);\n",
+ " var height = Math.abs(y1 - y0);\n",
+ "\n",
+ " fig.rubberband_context.clearRect(\n",
+ " 0, 0, fig.canvas.width, fig.canvas.height);\n",
+ "\n",
+ " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
+ " // Updates the figure title.\n",
+ " fig.header.textContent = msg['label'];\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
+ " var cursor = msg['cursor'];\n",
+ " switch(cursor)\n",
+ " {\n",
+ " case 0:\n",
+ " cursor = 'pointer';\n",
+ " break;\n",
+ " case 1:\n",
+ " cursor = 'default';\n",
+ " break;\n",
+ " case 2:\n",
+ " cursor = 'crosshair';\n",
+ " break;\n",
+ " case 3:\n",
+ " cursor = 'move';\n",
+ " break;\n",
+ " }\n",
+ " fig.rubberband_canvas.style.cursor = cursor;\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
+ " fig.message.textContent = msg['message'];\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
+ " // Request the server to send over a new figure.\n",
+ " fig.send_draw_message();\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
+ " fig.image_mode = msg['mode'];\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.updated_canvas_event = function() {\n",
+ " // Called whenever the canvas gets updated.\n",
+ " this.send_message(\"ack\", {});\n",
+ "}\n",
+ "\n",
+ "// A function to construct a web socket function for onmessage handling.\n",
+ "// Called in the figure constructor.\n",
+ "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
+ " return function socket_on_message(evt) {\n",
+ " if (evt.data instanceof Blob) {\n",
+ " /* FIXME: We get \"Resource interpreted as Image but\n",
+ " * transferred with MIME type text/plain:\" errors on\n",
+ " * Chrome. But how to set the MIME type? It doesn't seem\n",
+ " * to be part of the websocket stream */\n",
+ " evt.data.type = \"image/png\";\n",
+ "\n",
+ " /* Free the memory for the previous frames */\n",
+ " if (fig.imageObj.src) {\n",
+ " (window.URL || window.webkitURL).revokeObjectURL(\n",
+ " fig.imageObj.src);\n",
+ " }\n",
+ "\n",
+ " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
+ " evt.data);\n",
+ " fig.updated_canvas_event();\n",
+ " fig.waiting = false;\n",
+ " return;\n",
+ " }\n",
+ " else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
+ " fig.imageObj.src = evt.data;\n",
+ " fig.updated_canvas_event();\n",
+ " fig.waiting = false;\n",
+ " return;\n",
+ " }\n",
+ "\n",
+ " var msg = JSON.parse(evt.data);\n",
+ " var msg_type = msg['type'];\n",
+ "\n",
+ " // Call the \"handle_{type}\" callback, which takes\n",
+ " // the figure and JSON message as its only arguments.\n",
+ " try {\n",
+ " var callback = fig[\"handle_\" + msg_type];\n",
+ " } catch (e) {\n",
+ " console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
+ " return;\n",
+ " }\n",
+ "\n",
+ " if (callback) {\n",
+ " try {\n",
+ " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
+ " callback(fig, msg);\n",
+ " } catch (e) {\n",
+ " console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
+ " }\n",
+ " }\n",
+ " };\n",
+ "}\n",
+ "\n",
+ "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
+ "mpl.findpos = function(e) {\n",
+ " //this section is from http://www.quirksmode.org/js/events_properties.html\n",
+ " var targ;\n",
+ " if (!e)\n",
+ " e = window.event;\n",
+ " if (e.target)\n",
+ " targ = e.target;\n",
+ " else if (e.srcElement)\n",
+ " targ = e.srcElement;\n",
+ " if (targ.nodeType == 3) // defeat Safari bug\n",
+ " targ = targ.parentNode;\n",
+ "\n",
+ " // jQuery normalizes the pageX and pageY\n",
+ " // pageX,Y are the mouse positions relative to the document\n",
+ " // offset() returns the position of the element relative to the document\n",
+ " var x = e.pageX - $(targ).offset().left;\n",
+ " var y = e.pageY - $(targ).offset().top;\n",
+ "\n",
+ " return {\"x\": x, \"y\": y};\n",
+ "};\n",
+ "\n",
+ "/*\n",
+ " * return a copy of an object with only non-object keys\n",
+ " * we need this to avoid circular references\n",
+ " * http://stackoverflow.com/a/24161582/3208463\n",
+ " */\n",
+ "function simpleKeys (original) {\n",
+ " return Object.keys(original).reduce(function (obj, key) {\n",
+ " if (typeof original[key] !== 'object')\n",
+ " obj[key] = original[key]\n",
+ " return obj;\n",
+ " }, {});\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.mouse_event = function(event, name) {\n",
+ " var canvas_pos = mpl.findpos(event)\n",
+ "\n",
+ " if (name === 'button_press')\n",
+ " {\n",
+ " this.canvas.focus();\n",
+ " this.canvas_div.focus();\n",
+ " }\n",
+ "\n",
+ " var x = canvas_pos.x * mpl.ratio;\n",
+ " var y = canvas_pos.y * mpl.ratio;\n",
+ "\n",
+ " this.send_message(name, {x: x, y: y, button: event.button,\n",
+ " step: event.step,\n",
+ " guiEvent: simpleKeys(event)});\n",
+ "\n",
+ " /* This prevents the web browser from automatically changing to\n",
+ " * the text insertion cursor when the button is pressed. We want\n",
+ " * to control all of the cursor setting manually through the\n",
+ " * 'cursor' event from matplotlib */\n",
+ " event.preventDefault();\n",
+ " return false;\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
+ " // Handle any extra behaviour associated with a key event\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.key_event = function(event, name) {\n",
+ "\n",
+ " // Prevent repeat events\n",
+ " if (name == 'key_press')\n",
+ " {\n",
+ " if (event.which === this._key)\n",
+ " return;\n",
+ " else\n",
+ " this._key = event.which;\n",
+ " }\n",
+ " if (name == 'key_release')\n",
+ " this._key = null;\n",
+ "\n",
+ " var value = '';\n",
+ " if (event.ctrlKey && event.which != 17)\n",
+ " value += \"ctrl+\";\n",
+ " if (event.altKey && event.which != 18)\n",
+ " value += \"alt+\";\n",
+ " if (event.shiftKey && event.which != 16)\n",
+ " value += \"shift+\";\n",
+ "\n",
+ " value += 'k';\n",
+ " value += event.which.toString();\n",
+ "\n",
+ " this._key_event_extra(event, name);\n",
+ "\n",
+ " this.send_message(name, {key: value,\n",
+ " guiEvent: simpleKeys(event)});\n",
+ " return false;\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
+ " if (name == 'download') {\n",
+ " this.handle_save(this, null);\n",
+ " } else {\n",
+ " this.send_message(\"toolbar_button\", {name: name});\n",
+ " }\n",
+ "};\n",
+ "\n",
+ "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
+ " this.message.textContent = tooltip;\n",
+ "};\n",
+ "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
+ "\n",
+ "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
+ "\n",
+ "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
+ " // Create a \"websocket\"-like object which calls the given IPython comm\n",
+ " // object with the appropriate methods. Currently this is a non binary\n",
+ " // socket, so there is still some room for performance tuning.\n",
+ " var ws = {};\n",
+ "\n",
+ " ws.close = function() {\n",
+ " comm.close()\n",
+ " };\n",
+ " ws.send = function(m) {\n",
+ " //console.log('sending', m);\n",
+ " comm.send(m);\n",
+ " };\n",
+ " // Register the callback with on_msg.\n",
+ " comm.on_msg(function(msg) {\n",
+ " //console.log('receiving', msg['content']['data'], msg);\n",
+ " // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
+ " ws.onmessage(msg['content']['data'])\n",
+ " });\n",
+ " return ws;\n",
+ "}\n",
+ "\n",
+ "mpl.mpl_figure_comm = function(comm, msg) {\n",
+ " // This is the function which gets called when the mpl process\n",
+ " // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
+ "\n",
+ " var id = msg.content.data.id;\n",
+ " // Get hold of the div created by the display call when the Comm\n",
+ " // socket was opened in Python.\n",
+ " var element = $(\"#\" + id);\n",
+ " var ws_proxy = comm_websocket_adapter(comm)\n",
+ "\n",
+ " function ondownload(figure, format) {\n",
+ " window.open(figure.imageObj.src);\n",
+ " }\n",
+ "\n",
+ " var fig = new mpl.figure(id, ws_proxy,\n",
+ " ondownload,\n",
+ " element.get(0));\n",
+ "\n",
+ " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
+ " // web socket which is closed, not our websocket->open comm proxy.\n",
+ " ws_proxy.onopen();\n",
+ "\n",
+ " fig.parent_element = element.get(0);\n",
+ " fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
+ " if (!fig.cell_info) {\n",
+ " console.error(\"Failed to find cell for figure\", id, fig);\n",
+ " return;\n",
+ " }\n",
+ "\n",
+ " var output_index = fig.cell_info[2]\n",
+ " var cell = fig.cell_info[0];\n",
+ "\n",
+ "};\n",
+ "\n",
+ "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
+ " var width = fig.canvas.width/mpl.ratio\n",
+ " fig.root.unbind('remove')\n",
+ "\n",
+ " // Update the output cell to use the data from the current canvas.\n",
+ " fig.push_to_output();\n",
+ " var dataURL = fig.canvas.toDataURL();\n",
+ " // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
+ " // the notebook keyboard shortcuts fail.\n",
+ " IPython.keyboard_manager.enable()\n",
+ " $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
+ " fig.close_ws(fig, msg);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.close_ws = function(fig, msg){\n",
+ " fig.send_message('closing', msg);\n",
+ " // fig.ws.close()\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
+ " // Turn the data on the canvas into data in the output cell.\n",
+ " var width = this.canvas.width/mpl.ratio\n",
+ " var dataURL = this.canvas.toDataURL();\n",
+ " this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.updated_canvas_event = function() {\n",
+ " // Tell IPython that the notebook contents must change.\n",
+ " IPython.notebook.set_dirty(true);\n",
+ " this.send_message(\"ack\", {});\n",
+ " var fig = this;\n",
+ " // Wait a second, then push the new image to the DOM so\n",
+ " // that it is saved nicely (might be nice to debounce this).\n",
+ " setTimeout(function () { fig.push_to_output() }, 1000);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._init_toolbar = function() {\n",
+ " var fig = this;\n",
+ "\n",
+ " var nav_element = $('<div/>')\n",
+ " nav_element.attr('style', 'width: 100%');\n",
+ " this.root.append(nav_element);\n",
+ "\n",
+ " // Define a callback function for later on.\n",
+ " function toolbar_event(event) {\n",
+ " return fig.toolbar_button_onclick(event['data']);\n",
+ " }\n",
+ " function toolbar_mouse_event(event) {\n",
+ " return fig.toolbar_button_onmouseover(event['data']);\n",
+ " }\n",
+ "\n",
+ " for(var toolbar_ind in mpl.toolbar_items){\n",
+ " var name = mpl.toolbar_items[toolbar_ind][0];\n",
+ " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
+ " var image = mpl.toolbar_items[toolbar_ind][2];\n",
+ " var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
+ "\n",
+ " if (!name) { continue; };\n",
+ "\n",
+ " var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
+ " button.click(method_name, toolbar_event);\n",
+ " button.mouseover(tooltip, toolbar_mouse_event);\n",
+ " nav_element.append(button);\n",
+ " }\n",
+ "\n",
+ " // Add the status bar.\n",
+ " var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
+ " nav_element.append(status_bar);\n",
+ " this.message = status_bar[0];\n",
+ "\n",
+ " // Add the close button to the window.\n",
+ " var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
+ " var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
+ " button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
+ " button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
+ " buttongrp.append(button);\n",
+ " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
+ " titlebar.prepend(buttongrp);\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._root_extra_style = function(el){\n",
+ " var fig = this\n",
+ " el.on(\"remove\", function(){\n",
+ "\tfig.close_ws(fig, {});\n",
+ " });\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._canvas_extra_style = function(el){\n",
+ " // this is important to make the div 'focusable\n",
+ " el.attr('tabindex', 0)\n",
+ " // reach out to IPython and tell the keyboard manager to turn it's self\n",
+ " // off when our div gets focus\n",
+ "\n",
+ " // location in version 3\n",
+ " if (IPython.notebook.keyboard_manager) {\n",
+ " IPython.notebook.keyboard_manager.register_events(el);\n",
+ " }\n",
+ " else {\n",
+ " // location in version 2\n",
+ " IPython.keyboard_manager.register_events(el);\n",
+ " }\n",
+ "\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
+ " var manager = IPython.notebook.keyboard_manager;\n",
+ " if (!manager)\n",
+ " manager = IPython.keyboard_manager;\n",
+ "\n",
+ " // Check for shift+enter\n",
+ " if (event.shiftKey && event.which == 13) {\n",
+ " this.canvas_div.blur();\n",
+ " event.shiftKey = false;\n",
+ " // Send a \"J\" for go to next cell\n",
+ " event.which = 74;\n",
+ " event.keyCode = 74;\n",
+ " manager.command_mode();\n",
+ " manager.handle_keydown(event);\n",
+ " }\n",
+ "}\n",
+ "\n",
+ "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
+ " fig.ondownload(fig, null);\n",
+ "}\n",
+ "\n",
+ "\n",
+ "mpl.find_output_cell = function(html_output) {\n",
+ " // Return the cell and output element which can be found *uniquely* in the notebook.\n",
+ " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
+ " // IPython event is triggered only after the cells have been serialised, which for\n",
+ " // our purposes (turning an active figure into a static one), is too late.\n",
+ " var cells = IPython.notebook.get_cells();\n",
+ " var ncells = cells.length;\n",
+ " for (var i=0; i<ncells; i++) {\n",
+ " var cell = cells[i];\n",
+ " if (cell.cell_type === 'code'){\n",
+ " for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
+ " var data = cell.output_area.outputs[j];\n",
+ " if (data.data) {\n",
+ " // IPython >= 3 moved mimebundle to data attribute of output\n",
+ " data = data.data;\n",
+ " }\n",
+ " if (data['text/html'] == html_output) {\n",
+ " return [cell, data, j];\n",
+ " }\n",
+ " }\n",
+ " }\n",
+ " }\n",
+ "}\n",
+ "\n",
+ "// Register the function which deals with the matplotlib target/channel.\n",
+ "// The kernel may be null if the page has been refreshed.\n",
+ "if (IPython.notebook.kernel != null) {\n",
+ " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
+ "}\n"
+ ],
+ "text/plain": [
+ "<IPython.core.display.Javascript object>"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ "<div id='89a7f060-3b6d-4fbd-84ea-ed955bd951da'></div>"
+ ],
+ "text/plain": [
+ "<IPython.core.display.HTML object>"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "ename": "NameError",
+ "evalue": "name 'matplotlib' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m<ipython-input-8-de95e8fea496>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0mportf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mPortfolio\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0moption1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moption2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moption3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moption_delta\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[0;31m#Plot Scenarios Inputs: Portfolio, spread shock tightening%, spread shock widening%, snapshot period)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 22\u001b[0;31m \u001b[0mplot_trade_scenarios\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mportf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m-\u001b[0m\u001b[0;36m.15\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m.8\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m-\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvol_time_roll\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
+ "\u001b[0;32m~/projects/code/python/exploration/swaption_calendar_spread.py\u001b[0m in \u001b[0;36mplot_trade_scenarios\u001b[0;34m(portf, shock_min, shock_max, period, vol_time_roll)\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[0mshock\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mhy_plot_range\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mindex\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'HY'\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mportf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindices\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mspread\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mspread_shock\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 57\u001b[0;31m \u001b[0mplot_time_color_map\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvol_shock\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshock\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'pnl'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 58\u001b[0m \u001b[0mplot_time_color_map\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvol_shock\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m.2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshock\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'pnl'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 59\u001b[0m \u001b[0mplot_color_map\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mdate_range\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mperiod\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshock\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvol_shock\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'pnl'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;32m~/projects/code/python/graphics.py\u001b[0m in \u001b[0;36mplot_time_color_map\u001b[0;34m(df, spread_shock, attr, path, color_map, index)\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[0mseries\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mattr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 69\u001b[0m \u001b[0mmidpoint\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mseries\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mseries\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mseries\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 70\u001b[0;31m \u001b[0mshifted_cmap\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mshiftedColorMap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcolor_map\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmidpoint\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmidpoint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'shifted'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 71\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 72\u001b[0m chart = ax.imshow(series.values.reshape(date_range.size, spread_shock.size).T,\n",
+ "\u001b[0;32m~/projects/code/python/graphics.py\u001b[0m in \u001b[0;36mshiftedColorMap\u001b[0;34m(cmap, start, midpoint, stop, name)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[0mcdict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'alpha'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 51\u001b[0;31m \u001b[0mnewcmap\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolors\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mLinearSegmentedColormap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 52\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister_cmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcmap\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnewcmap\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mNameError\u001b[0m: name 'matplotlib' is not defined"
+ ]
+ }
+ ],
"source": [
"#Ad hoc\n",
- "option_delta = Index.from_name('IG', 29, '5yr')\n",
+ "option_delta = Index.from_name('IG', 29, '5yr', trade_date=datetime.date(2018, 1, 3))\n",
"option_delta.spread = 50\n",
"option1 = BlackSwaption(option_delta, datetime.date(2018, 2, 21), 55, option_type=\"payer\")\n",
"option2 = BlackSwaption(option_delta, datetime.date(2018, 2, 21), 67.5, option_type=\"payer\")\n",
@@ -50,7 +868,7 @@
"option_delta.notional = abs(option_delta.notional)\n",
"portf = Portfolio([option1, option2, option3, option_delta])\n",
"#Plot Scenarios Inputs: Portfolio, spread shock tightening%, spread shock widening%, snapshot period)\n",
- "df = spread.plot_trade_scenarios(portf, -.15, .8, -4, vol_time_roll=False)"
+ "plot_trade_scenarios(portf, -.15, .8, -4, vol_time_roll=False)"
]
},
{
@@ -101,7 +919,7 @@
"option1 = BlackSwaption.from_tradeid(3, option_delta)\n",
"option2 = BlackSwaption.from_tradeid(4, option_delta)\n",
"portf = Portfolio([option1, option2, option_delta])\n",
- "spread.plot_trade_scenarios(portf)"
+ "plot_trade_scenarios(portf)"
]
},
{
@@ -115,7 +933,7 @@
"option1 = BlackSwaption.from_tradeid(5, option_delta)\n",
"option2 = BlackSwaption.from_tradeid(6, option_delta)\n",
"portf = Portfolio([option1, option2, option_delta])\n",
- "spread.plot_trade_scenarios(portf)"
+ "plot_trade_scenarios(portf)"
]
},
{
@@ -129,7 +947,7 @@
"option1 = BlackSwaption.from_tradeid(7, option_delta)\n",
"option2 = BlackSwaption.from_tradeid(8, option_delta)\n",
"portf = Portfolio([option1, option2, option_delta])\n",
- "spread.plot_trade_scenarios(portf)"
+ "plot_trade_scenarios(portf)"
]
},
{
@@ -149,7 +967,7 @@
"portf = Portfolio([option1_pf, option2_pf, option_delta_pf])\n",
"portf.trade_date = datetime.date(2017, 5, 17)\n",
"portf.mark()\n",
- "spread.plot_trade_scenarios(portf)"
+ "plot_trade_scenarios(portf)"
]
},
{
@@ -163,7 +981,7 @@
"option1 = BlackSwaption.from_tradeid(10, option_delta)\n",
"option2 = BlackSwaption.from_tradeid(11, option_delta)\n",
"portf = Portfolio([option1, option2, option_delta])\n",
- "spread.plot_trade_scenarios(portf)"
+ "plot_trade_scenarios(portf)"
]
},
{
@@ -197,7 +1015,7 @@
"option_delta.notional = abs(option_delta.notional)\n",
"portf = Portfolio([option1, option2, option3, option4, option_delta])\n",
"#Plot Scenarios Inputs: Portfolio, spread shock tightening%, spread shock widening%, snapshot period)\n",
- "df = spread.plot_trade_scenarios(portf, -.15, .8, -4, vol_time_roll=False)"
+ "plot_trade_scenarios(portf, -.15, .8, -4, vol_time_roll=False)"
]
},
{
@@ -253,7 +1071,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.1"
+ "version": "3.6.4"
}
},
"nbformat": 4,
diff --git a/python/tests/test_scenarios.py b/python/tests/test_scenarios.py
index b7f5f9f0..4e695864 100644
--- a/python/tests/test_scenarios.py
+++ b/python/tests/test_scenarios.py
@@ -3,7 +3,7 @@ import datetime
import numpy as np
import pandas as pd
-from analytics import Index, BlackSwaption, Portfolio, VolatilitySurface
+from analytics import Index, BlackSwaption, Portfolio, BlackSwaptionVolSurface
from pandas.tseries.offsets import BDay
from analytics.scenarios import run_portfolio_scenarios, run_swaption_scenarios, run_index_scenarios
@@ -18,8 +18,8 @@ class TestSenarios(unittest.TestCase):
""" check that run_portfolio_scenarios match the sum of the individual pieces"""
vol_shock = np.arange(-0.15, 0.3, 0.01)
spread_shock = np.arange(-0.2, 0.3, 0.01)
- vs = VolatilitySurface("IG", 28, trade_date=self.option_delta.trade_date)
- vol_surface = vs[vs.list(model="black", source="BAML")[-1]]
+ vs = BlackSwaptionVolSurface("IG", 28, trade_date=self.option_delta.trade_date)
+ vol_surface = vs[vs.list(source="BAML")[-1]]
df = run_portfolio_scenarios(self.portf, self.date_range,
spread_shock, vol_shock, vol_surface)
df = df.set_index(['spread', 'vol_shock'], append=True)