aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/yieldcurve.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/python/yieldcurve.py b/python/yieldcurve.py
index 997a363b..c865c9bb 100644
--- a/python/yieldcurve.py
+++ b/python/yieldcurve.py
@@ -11,7 +11,7 @@ from quantlib.time.api import (WeekendsOnly, Date, Period, Days, Schedule, Annua
from quantlib.currency.api import USDCurrency, EURCurrency
from quantlib.indexes.ibor_index import IborIndex
from quantlib.termstructures.yields.api import (
- PiecewiseYieldCurve, DepositRateHelper, SwapRateHelper)
+ PiecewiseYieldCurve, DepositRateHelper, SwapRateHelper, BootstrapTrait, Interpolator)
from quantlib.time.date import pydate_from_qldate
import numpy as np
@@ -19,6 +19,8 @@ import pandas as pd
import matplotlib.pyplot as plt
from quantlib.quotes import SimpleQuote
from db import dbconn
+from pyisda.curve import YieldCurve
+import array
def getMarkitIRData(effective_date = datetime.date.today(),
currency = "USD"):
@@ -98,12 +100,20 @@ def rate_helpers(currency="USD", MarkitData=None):
return deps + swaps
def YC(currency="USD", helpers = None, MarkitData=None):
- settings = Settings()
if helpers is None:
helpers = rate_helpers(currency, MarkitData)
- curve = PiecewiseYieldCurve("discount", "loglinear", settings.evaluation_date,
- helpers, Actual365Fixed())
- return curve
+ calendar = WeekendsOnly()
+ return PiecewiseYieldCurve(BootstrapTrait.Discount, Interpolator.LogLinear,
+ 0, calendar, helpers, Actual365Fixed())
+def ql_to_jp(ql_yc):
+ """ convert a QuantLib yield curve to a JP's one"""
+ if ql_yc._trait == BootstrapTrait.Discount:
+ dfs = array.array('d', ql_yc.data[1:])
+ dates = [pydate_from_qldate(d) for d in ql_yc.dates[1:]]
+ trade_date = pydate_from_qldate(ql_yc.dates[0])
+ return YieldCurve.from_discount_factors(trade_date, dates, dfs, 'ACT/365F')
+ else:
+ raise RuntimeErrror('QuantLib curve needs to use Discount trait')
if __name__=="__main__":
#evaluation_date = Date(29, 4, 2014)