Tweeted twitter.com/StackQuant/status/961291134332014593
5 deleted 1753 characters in body
source | link

which results to the same maturities due to data from different dates as explained above. I have somehow to loop over the fdates but I have no idea how this could work in that context.Help would be appreciated. I included the code and the data below.

import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

Index_OIS = ql.OvernightIndex("Tonar", 0, ql.JPYCurrency(), ql.Japan(), ql.Actual365Fixed())

data = pd.read_csv('C:/Data_JPY_Playing.csv').fillna('')
pd_date = pd.DatetimeIndex(data['fdate'].values)
data['fdate']data_selected = pd_date
index_datadata[['fdate', ='ptype' data,'maturity','fixing','values']].set_indexto_records('fdate'index=False)  

Rate_Helper_Full_Disc = [] 

for indexfdate, rowptype, maturity, fixing, values in index.iterrows()data_selected:
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc)

    elif row['ptype'] == 'OIS':
        helper_disc = ql.OISRateHelper(0, 
                                       Convert(row['maturity']),
                                       ql.QuoteHandle(ql.SimpleQuote(row['values']/100)), 
                                       Index_OIS)

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()

The data looks like the folloiwng:

fdate ptype   maturity    fixing  values
2017-02-09    OIS 1W              0.0713
2017-02-09    OIS 2W              0.0688
2017-02-09    OIS 3W              0.0663
2017-02-09    OIS 1M      0.0656
2017-02-09    OIS 2M      0.0613
2017-02-09    OIS 3M      0.06
2017-02-09    OIS 4M      0.0563
2017-02-09    OIS 5M      0.055
2017-02-09    OIS 6M      0.0538
2017-02-09    OIS 2Y      0.0538
2017-02-09    OIS 3Y      0.0769
2017-02-09    OIS 4Y      0.1119
2017-02-09    OIS 15Y     0.6888
2017-02-09    OIS 20Y     0.965
2017-02-09    OIS 25Y     1.1081
2017-02-09    OIS 30Y     1.1831
2017-02-09    Deposit 1D  0   0.081
2017-02-10    Deposit 1D  0   0.074
2017-02-10    OIS 1W      0.0725
2017-02-10    OIS 2W      0.07
2017-02-10    OIS 3W      0.0688
2017-02-10    OIS 1M      0.0681
2017-02-10    OIS 2M      0.0625
2017-02-10    OIS 3M      0.0606
2017-02-10    OIS 4M      0.0563
2017-02-10    OIS 5M      0.0563
2017-02-10    OIS 6M      0.055
2017-02-10    OIS 2Y      0.0581
2017-02-10    OIS 3Y      0.0825
2017-02-10    OIS 4Y      0.1238
2017-02-10    OIS 15Y     0.7269
2017-02-10    OIS 20Y     1.0044
2017-02-10    OIS 25Y     1.1475
2017-02-10    OIS 30Y     1.2225

which results to the same maturities due to data from different dates as explained above. I have somehow to loop over the fdates but I have no idea how this could work in that context.Help would be appreciated. I included the code and the data below.

import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

Index_OIS = ql.OvernightIndex("Tonar", 0, ql.JPYCurrency(), ql.Japan(), ql.Actual365Fixed())

data = pd.read_csv('C:/Data_JPY_Playing.csv').fillna('')
pd_date = pd.DatetimeIndex(data['fdate'].values)
data['fdate'] = pd_date
index_data = data.set_index('fdate')

Rate_Helper_Full_Disc = [] 

for index, row in index.iterrows():
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc)

    elif row['ptype'] == 'OIS':
        helper_disc = ql.OISRateHelper(0, 
                                       Convert(row['maturity']),
                                       ql.QuoteHandle(ql.SimpleQuote(row['values']/100)), 
                                       Index_OIS)

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()

The data looks like the folloiwng:

fdate ptype   maturity    fixing  values
2017-02-09    OIS 1W              0.0713
2017-02-09    OIS 2W              0.0688
2017-02-09    OIS 3W              0.0663
2017-02-09    OIS 1M      0.0656
2017-02-09    OIS 2M      0.0613
2017-02-09    OIS 3M      0.06
2017-02-09    OIS 4M      0.0563
2017-02-09    OIS 5M      0.055
2017-02-09    OIS 6M      0.0538
2017-02-09    OIS 2Y      0.0538
2017-02-09    OIS 3Y      0.0769
2017-02-09    OIS 4Y      0.1119
2017-02-09    OIS 15Y     0.6888
2017-02-09    OIS 20Y     0.965
2017-02-09    OIS 25Y     1.1081
2017-02-09    OIS 30Y     1.1831
2017-02-09    Deposit 1D  0   0.081
2017-02-10    Deposit 1D  0   0.074
2017-02-10    OIS 1W      0.0725
2017-02-10    OIS 2W      0.07
2017-02-10    OIS 3W      0.0688
2017-02-10    OIS 1M      0.0681
2017-02-10    OIS 2M      0.0625
2017-02-10    OIS 3M      0.0606
2017-02-10    OIS 4M      0.0563
2017-02-10    OIS 5M      0.0563
2017-02-10    OIS 6M      0.055
2017-02-10    OIS 2Y      0.0581
2017-02-10    OIS 3Y      0.0825
2017-02-10    OIS 4Y      0.1238
2017-02-10    OIS 15Y     0.7269
2017-02-10    OIS 20Y     1.0044
2017-02-10    OIS 25Y     1.1475
2017-02-10    OIS 30Y     1.2225

which results to the same maturities due to data from different dates as explained above. I have somehow to loop over the fdates but I have no idea how this could work in that context.Help would be appreciated.

import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

data = pd.read_csv('C:/Data_JPY_Playing.csv').fillna('')

data_selected = data[['fdate', 'ptype' ,'maturity','fixing','values']].to_records(index=False)  

Rate_Helper_Full_Disc = [] 

for fdate, ptype, maturity, fixing, values in data_selected:
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()
4 added 126 characters in body
source | link
import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

Index_OIS = ql.OvernightIndex("Tonar", 0, ql.JPYCurrency(), ql.Japan(), ql.Actual365Fixed())

data = pd.read_csv('C:/Data_JPY_Playing.csv').fillna('')
pd_date = pd.DatetimeIndex(data['fdate'].values)
data['fdate'] = pd_date
index_data = data.set_index('fdate')

Rate_Helper_Full_Disc = [] 

for index, row in dataindex.iterrows():
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc)

    elif row['ptype'] == 'OIS':
        helper_disc = ql.OISRateHelper(0, 
                                       Convert(row['maturity']),
                                       ql.QuoteHandle(ql.SimpleQuote(row['values']/100)), 
                                       Index_OIS)

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()
import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

Index_OIS = ql.OvernightIndex("Tonar", 0, ql.JPYCurrency(), ql.Japan(), ql.Actual365Fixed())

data = pd.read_csv('C:/Data_JPY_Playing.csv').fillna('')

Rate_Helper_Full_Disc = [] 

for index, row in data.iterrows():
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc)

    elif row['ptype'] == 'OIS':
        helper_disc = ql.OISRateHelper(0, 
                                       Convert(row['maturity']),
                                       ql.QuoteHandle(ql.SimpleQuote(row['values']/100)), 
                                       Index_OIS)

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()
import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

Index_OIS = ql.OvernightIndex("Tonar", 0, ql.JPYCurrency(), ql.Japan(), ql.Actual365Fixed())

data = pd.read_csv('C:/Data_JPY_Playing.csv').fillna('')
pd_date = pd.DatetimeIndex(data['fdate'].values)
data['fdate'] = pd_date
index_data = data.set_index('fdate')

Rate_Helper_Full_Disc = [] 

for index, row in index.iterrows():
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc)

    elif row['ptype'] == 'OIS':
        helper_disc = ql.OISRateHelper(0, 
                                       Convert(row['maturity']),
                                       ql.QuoteHandle(ql.SimpleQuote(row['values']/100)), 
                                       Index_OIS)

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()
3 deleted 18 characters in body
source | link
import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

Index_OIS = ql.OvernightIndex("Tonar", 0, ql.JPYCurrency(), ql.Japan(), ql.Actual365Fixed())

data = pd.read_csv('C:/Users/mcm/Desktop/Data_JPY_Playing.csv').fillna('')

Rate_Helper_Full_Disc = [] 

for index, row in data.iterrows():
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc)

    elif row['ptype'] == 'OIS':
        helper_disc = ql.OISRateHelper(0, 
                                       Convert(row['maturity']),
                                       ql.QuoteHandle(ql.SimpleQuote(row['values']/100)), 
                                       Index_OIS)

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()
import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

Index_OIS = ql.OvernightIndex("Tonar", 0, ql.JPYCurrency(), ql.Japan(), ql.Actual365Fixed())

data = pd.read_csv('C:/Users/mcm/Desktop/Data_JPY_Playing.csv').fillna('')

Rate_Helper_Full_Disc = [] 

for index, row in data.iterrows():
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc)

    elif row['ptype'] == 'OIS':
        helper_disc = ql.OISRateHelper(0, 
                                       Convert(row['maturity']),
                                       ql.QuoteHandle(ql.SimpleQuote(row['values']/100)), 
                                       Index_OIS)

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()
import QuantLib as ql
import pandas as pd
import matplotlib.pyplot as plt

def Convert(Period):
    unit =[]
    if Period[-1:] == 'D':
        unit = ql.Days
    elif Period[-1:] == 'M':
        unit = ql.Months
    elif Period[-1:] == 'W':
        unit = ql.Weeks
    elif Period[-1:] == 'Y':
        unit = ql.Years
    period_object = ql.Period(int(Period[:-1]), unit)
    return period_object

date = ql.Date(9, ql.February, 2017)
ql.Settings.instance().evaluationDate = date

Index_OIS = ql.OvernightIndex("Tonar", 0, ql.JPYCurrency(), ql.Japan(), ql.Actual365Fixed())

data = pd.read_csv('C:/Data_JPY_Playing.csv').fillna('')

Rate_Helper_Full_Disc = [] 

for index, row in data.iterrows():
    if row['ptype'] == 'Deposit':
        helper_disc = ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(row['values']/100)),
                                           Convert(row['maturity']), 
                                           int(row['fixing']),
                                           ql.Japan(), 
                                           ql.ModifiedFollowing, 
                                           False, 
                                           ql.Actual365Fixed())

        Rate_Helper_Full_Disc.append(helper_disc)

    elif row['ptype'] == 'OIS':
        helper_disc = ql.OISRateHelper(0, 
                                       Convert(row['maturity']),
                                       ql.QuoteHandle(ql.SimpleQuote(row['values']/100)), 
                                       Index_OIS)

        Rate_Helper_Full_Disc.append(helper_disc) 

disc_curve = ql.PiecewiseCubicZero(date, Rate_Helper_Full_Disc, ql.Actual365Fixed())
disc_curve.enableExtrapolation()
2 Update old code.
source | link
1
source | link