aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics/__init__.py
blob: 83fab3ebf4be2f31caa03f894e01a877a37a7d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys

sys.path.append("..")
from utils.db import serenitas_engine, dawn_engine, dbconn, DataError, serenitas_pool

from .index import CreditIndex, ForwardIndex
from .option import (
    BlackSwaption,
    Swaption,
    ATMstrike,
    ProbSurface,
    QuoteSurface,
    VolSurface,
    BlackSwaptionVolSurface,
)
from .portfolio import Portfolio
from .basket_index import MarkitBasketIndex
from .tranche_basket import DualCorrTranche, TrancheBasket
from .ir_swaption import IRSwaption

import pandas as pd
import datetime


def on_the_run(index, value_date=datetime.date.today()):
    r = serenitas_engine.execute(
        "SELECT max(series) FROM index_maturity WHERE index=%s " "and issue_date <= %s",
        (index, value_date),
    )
    series, = r.fetchone()
    return series


def init_ontr(value_date=datetime.date.today()):
    global _ontr, _beta
    _ontr = CreditIndex("HY", on_the_run("HY", value_date), "5yr", value_date)
    _ontr.mark()
    df_beta = pd.read_sql_query(
        "select distinct on (asset_class) "
        "asset_class, beta from beta "
        "where date <= %s order by asset_class, date desc",
        dawn_engine,
        ["asset_class"],
        params=(value_date,),
    )
    _beta = df_beta["beta"].to_dict()