diff --git a/quantlib/indexes/_inflation_index.pxd b/quantlib/indexes/_inflation_index.pxd index 1c487e103..1200e69d2 100644 --- a/quantlib/indexes/_inflation_index.pxd +++ b/quantlib/indexes/_inflation_index.pxd @@ -23,7 +23,6 @@ cdef extern from 'ql/indexes/inflationindex.hpp' namespace 'QuantLib' nogil: cdef cppclass CPI: enum InterpolationType: - AsIndex Flat Linear diff --git a/quantlib/indexes/inflation_index.pxd b/quantlib/indexes/inflation_index.pxd index 98becdbb0..b4e1ae079 100644 --- a/quantlib/indexes/inflation_index.pxd +++ b/quantlib/indexes/inflation_index.pxd @@ -2,7 +2,6 @@ from quantlib.index cimport Index cdef extern from "ql/indexes/inflationindex.hpp" namespace "QuantLib::CPI" nogil: cpdef enum InterpolationType "QuantLib::CPI::InterpolationType": - AsIndex Flat Linear diff --git a/quantlib/instruments/bonds/_cpibond.pxd b/quantlib/instruments/bonds/_cpibond.pxd index 16bb89a5a..eb532f261 100644 --- a/quantlib/instruments/bonds/_cpibond.pxd +++ b/quantlib/instruments/bonds/_cpibond.pxd @@ -1,5 +1,4 @@ from quantlib.types cimport Natural, Rate, Real -from libcpp cimport bool from libcpp.vector cimport vector from .._bond cimport Bond @@ -10,19 +9,16 @@ from quantlib.time._daycounter cimport DayCounter from quantlib.time._period cimport Period from quantlib.time._schedule cimport Schedule from quantlib.ext cimport shared_ptr -from quantlib.indexes._inflation_index cimport ZeroInflationIndex - -from .cpibond cimport InterpolationType +from quantlib.indexes._inflation_index cimport ZeroInflationIndex, CPI cdef extern from 'ql/instruments/bonds/cpibond.hpp' namespace 'QuantLib' nogil: cdef cppclass CPIBond(Bond): CPIBond(Natural settlementDays, Real faceAmount, - bool growthOnly, Real baseCPI, const Period& observationLag, shared_ptr[ZeroInflationIndex]& cpiIndex, - InterpolationType observationInterpolation, + CPI.InterpolationType observationInterpolation, const Schedule& schedule, vector[Rate]& coupons, const DayCounter& accrualDayCounter, diff --git a/quantlib/instruments/bonds/cpibond.pxd b/quantlib/instruments/bonds/cpibond.pxd index a99781f11..2b0e7dcac 100644 --- a/quantlib/instruments/bonds/cpibond.pxd +++ b/quantlib/instruments/bonds/cpibond.pxd @@ -1,10 +1,4 @@ from ..bond cimport Bond -cdef extern from 'ql/cashflows/cpicoupon.hpp' namespace 'QuantLib::CPI': - cpdef enum InterpolationType: - AsIndex - Flat - Linear - cdef class CPIBond(Bond): pass diff --git a/quantlib/instruments/bonds/cpibond.pyx b/quantlib/instruments/bonds/cpibond.pyx index 24f97100f..98a954bc0 100644 --- a/quantlib/instruments/bonds/cpibond.pyx +++ b/quantlib/instruments/bonds/cpibond.pyx @@ -1,12 +1,11 @@ from cython.operator cimport dereference as deref from quantlib.types cimport Natural, Rate, Real -from libcpp cimport bool from libcpp.vector cimport vector from . cimport _cpibond from quantlib.ext cimport static_pointer_cast cimport quantlib.indexes._inflation_index as _inf -from quantlib.indexes.inflation_index cimport ZeroInflationIndex +from quantlib.indexes.inflation_index cimport InterpolationType, ZeroInflationIndex from quantlib.time.businessdayconvention cimport BusinessDayConvention, Following, Unadjusted from quantlib.time.calendar cimport Calendar from quantlib.time.schedule cimport Schedule @@ -15,7 +14,7 @@ from quantlib.time.daycounter cimport DayCounter cdef class CPIBond(Bond): """ CPI bond """ - def __init__(self, Natural settlement_days, Real face_amount, bool growth_only, + def __init__(self, Natural settlement_days, Real face_amount, Real baseCPI, Period observation_lag not None, ZeroInflationIndex cpi_index not None, InterpolationType observation_interpolation, @@ -29,7 +28,7 @@ cdef class CPIBond(Bond): self._thisptr.reset( new _cpibond.CPIBond( - settlement_days, face_amount, growth_only, baseCPI, + settlement_days, face_amount, baseCPI, deref(observation_lag._thisptr), static_pointer_cast[_inf.ZeroInflationIndex]( cpi_index._thisptr), diff --git a/quantlib/instruments/swap.pyx b/quantlib/instruments/swap.pyx index 1905984de..2907bf9ac 100644 --- a/quantlib/instruments/swap.pyx +++ b/quantlib/instruments/swap.pyx @@ -101,7 +101,7 @@ cdef class Swap(Instrument): """The discount factor at the NPV date.""" return get_swap(self).npvDateDiscount() - def leg(self, int i): + def leg(self, Size i): """The i-th leg of the swap. Parameters @@ -117,7 +117,7 @@ cdef class Swap(Instrument): raise IndexError(f"leg #{i} doesn't exist") return leg - def __getitem__(self, int i): + def __getitem__(self, Size i): """The i-th leg of the swap.""" cdef Leg leg = Leg.__new__(Leg) cdef _swap.Swap* swap = <_swap.Swap*>self._thisptr.get() diff --git a/quantlib/math/matrix.pyx b/quantlib/math/matrix.pyx index 91ce13d5b..19cc2c1b9 100644 --- a/quantlib/math/matrix.pyx +++ b/quantlib/math/matrix.pyx @@ -30,7 +30,7 @@ cdef class Matrix: dims[1] = self._thisptr.columns() cdef arr = np.PyArray_SimpleNew(2, &dims[0], np.NPY_DOUBLE) cdef double[:,::1] r = arr - cdef size_t i, j + cdef np.npy_intp i, j for i in range(dims[0]): for j in range(dims[1]): r[i,j] = self._thisptr[i][j] diff --git a/quantlib/pricingengines/bond/_bondfunctions.pxd b/quantlib/pricingengines/bond/_bondfunctions.pxd index 80f316783..8c1502deb 100644 --- a/quantlib/pricingengines/bond/_bondfunctions.pxd +++ b/quantlib/pricingengines/bond/_bondfunctions.pxd @@ -69,7 +69,6 @@ cdef extern from 'ql/pricingengines/bond/bondfunctions.hpp' namespace 'QuantLib: cdef Spread zSpread(Bond bond, Bond.Price Price, shared_ptr[YieldTermStructure], - DayCounter dayCounter, Compounding compounding, Frequency frequency, Date settlementDate, diff --git a/quantlib/pricingengines/bond/bondfunctions.pyx b/quantlib/pricingengines/bond/bondfunctions.pyx index dfa4938d6..c7519d7b4 100644 --- a/quantlib/pricingengines/bond/bondfunctions.pyx +++ b/quantlib/pricingengines/bond/bondfunctions.pyx @@ -133,7 +133,6 @@ def basisPointValue(Bond bond not None, def zSpread(Bond bond, Price price, YieldTermStructure yts not None, - DayCounter day_counter not None, Compounding compounding, Frequency frequency, Date settlement_date=Date(), @@ -145,7 +144,6 @@ def zSpread(Bond bond, Price price, deref(bond.as_ptr()), price._this, static_pointer_cast[_yts.YieldTermStructure](yts._thisptr), - deref(day_counter._thisptr), compounding, frequency, settlement_date._thisptr, diff --git a/quantlib/reference/data_structures.py b/quantlib/reference/data_structures.py deleted file mode 100644 index 1596ffefb..000000000 --- a/quantlib/reference/data_structures.py +++ /dev/null @@ -1,33 +0,0 @@ -""" Definition of canonical data structures used in the -high-level functions of pyql. The data structures are all pandas DataFrames, -with defined column names and types. The data frames are empty, and should be -used as follows: - ->>> import quantlib.reference.data_structures as df ->>> x = df.option_quotes.reindex(index=range(10)) -""" - -import numpy as np -from pandas import DataFrame - -import quantlib.reference.names as nm - - -def option_quotes_template(): - - return DataFrame(np.empty((0,), dtype=[(nm.TRADE_DATE, 'object'), - (nm.STRIKE, 'f4'), - (nm.EXPIRY_DATE, 'object'), - (nm.OPTION_TYPE, 'a1'), - (nm.SPOT, 'f4'), - (nm.EXERCISE_STYLE, 'a4'), - (nm.PRICE_BID, 'f4'), - (nm.PRICE_ASK, 'f4')])) - - -def riskfree_dividend_template(): - return DataFrame.from_records(np.empty((1,), - dtype=[(nm.DIVIDEND_YIELD, 'f4'), - (nm.INTEREST_RATE, 'f4'), - (nm.MATURITY_DATE, 'object')]), - index=nm.MATURITY_DATE) diff --git a/quantlib/termstructures/_inflation_term_structure.pxd b/quantlib/termstructures/_inflation_term_structure.pxd index 638ed3390..845fc9bff 100644 --- a/quantlib/termstructures/_inflation_term_structure.pxd +++ b/quantlib/termstructures/_inflation_term_structure.pxd @@ -45,11 +45,8 @@ cdef extern from 'ql/termstructures/inflationtermstructure.hpp' namespace 'Quant const shared_ptr[Seasonality] &seasonality # = boost::shared_ptr() ) except + - Rate zeroRate(Date& d, - Period& inst_obs_lag, - bool force_linear_interpolation, + Rate zeroRate(Date d, bool extrapolate) - Rate zeroRate(Time t, bool extrapolate) @@ -73,12 +70,8 @@ cdef extern from 'ql/termstructures/inflationtermstructure.hpp' namespace 'Quant Frequency frequency, const DayCounter& dayCounter, const shared_ptr[Seasonality]& seasonality) except + - - Rate yoyRate(Date& d, - Period& inst_obs_lag, - bool force_linear_interpolation, - bool extrapolate) except + - + Rate yoyRate(Date d, + bool extrapolate) except + Rate yoyRate(Time t, bool extrapolate) except + diff --git a/quantlib/termstructures/inflation/_inflation_helpers.pxd b/quantlib/termstructures/inflation/_inflation_helpers.pxd index 1559bd8be..452fd49c2 100644 --- a/quantlib/termstructures/inflation/_inflation_helpers.pxd +++ b/quantlib/termstructures/inflation/_inflation_helpers.pxd @@ -25,8 +25,7 @@ cdef extern from 'ql/termstructures/inflation/inflationhelpers.hpp' namespace 'Q BusinessDayConvention payment_convention, const DayCounter& day_counter, const shared_ptr[ZeroInflationIndex]& zii, - CPI.InterpolationType observationInterpolation, - const Handle[_yts.YieldTermStructure]& nominal_term_structure) except + + CPI.InterpolationType observationInterpolation) except + # Year-on-year inflation-swap bootstrap helper cdef cppclass YearOnYearInflationSwapHelper(YoYInflationTraits.helper): diff --git a/quantlib/termstructures/inflation/inflation_helpers.pyx b/quantlib/termstructures/inflation/inflation_helpers.pyx index 71b6c1f8b..c5025e3fe 100644 --- a/quantlib/termstructures/inflation/inflation_helpers.pyx +++ b/quantlib/termstructures/inflation/inflation_helpers.pyx @@ -24,8 +24,7 @@ cdef class ZeroCouponInflationSwapHelper: BusinessDayConvention payment_convention, DayCounter day_counter not None, ZeroInflationIndex zii not None, - InterpolationType observation_interpolation, - HandleYieldTermStructure nominal_term_structure not None): + InterpolationType observation_interpolation): self._thisptr = shared_ptr[ZeroInflationTraits.helper]( new _ih.ZeroCouponInflationSwapHelper( quote.handle(), @@ -34,8 +33,7 @@ cdef class ZeroCouponInflationSwapHelper: calendar._thisptr, payment_convention, deref(day_counter._thisptr), static_pointer_cast[_ii.ZeroInflationIndex](zii._thisptr), - observation_interpolation, - nominal_term_structure.handle()) + observation_interpolation) ) def set_term_structure(self, ZeroInflationTermStructure ts): diff --git a/quantlib/termstructures/inflation_term_structure.pyx b/quantlib/termstructures/inflation_term_structure.pyx index d45af4a33..237eb9e7f 100644 --- a/quantlib/termstructures/inflation_term_structure.pyx +++ b/quantlib/termstructures/inflation_term_structure.pyx @@ -34,8 +34,7 @@ cdef class InflationTermStructure(TermStructure): cdef class ZeroInflationTermStructure(InflationTermStructure): - def zero_rate(self, d, Period inst_obs_lag=Period(-1, Days), - bool force_linear_interpolation=False, bool extrapolate=False): + def zero_rate(self, d, bool extrapolate=False): cdef _if.ZeroInflationTermStructure* term_structure = \ @@ -44,17 +43,13 @@ cdef class ZeroInflationTermStructure(InflationTermStructure): if isinstance(d, Date): return term_structure.zeroRate( (d)._thisptr, - deref(inst_obs_lag._thisptr), - force_linear_interpolation, extrapolate) else: return term_structure.zeroRate(d, extrapolate) cdef class YoYInflationTermStructure(InflationTermStructure): - def yoy_rate(self, d, Period inst_obs_lag=Period(-1, Days), - bool force_linear_interpolation=False, - bool extrapolate=False): + def yoy_rate(self, Date d, bool extrapolate=False): cdef _if.YoYInflationTermStructure* term_structure = \ <_if.YoYInflationTermStructure*>self._thisptr.get() @@ -62,8 +57,6 @@ cdef class YoYInflationTermStructure(InflationTermStructure): if isinstance(d, Date): return term_structure.yoyRate( (d)._thisptr, - deref(inst_obs_lag._thisptr), - force_linear_interpolation, extrapolate) else: return term_structure.yoyRate(d, extrapolate) diff --git a/quantlib/termstructures/yields/_piecewise_zerospreaded_termstructure.pxd b/quantlib/termstructures/yields/_piecewise_zerospreaded_termstructure.pxd index c17538066..34e36fcaa 100644 --- a/quantlib/termstructures/yields/_piecewise_zerospreaded_termstructure.pxd +++ b/quantlib/termstructures/yields/_piecewise_zerospreaded_termstructure.pxd @@ -1,7 +1,6 @@ from libcpp.vector cimport vector from quantlib._handle cimport Handle from quantlib.time._date cimport Date -from quantlib.time._daycounter cimport DayCounter from quantlib.time.frequency cimport Frequency from quantlib.termstructures._yield_term_structure cimport YieldTermStructure @@ -16,7 +15,6 @@ cdef extern from 'ql/termstructures/yield/piecewisezerospreadedtermstructure.hpp const vector[Handle[Quote]]& spreads, const vector[Date]& dates, Compounding comp, # = Continuous, - Frequency freq, # = NoFrequency, - const DayCounter& dc), # = DayCounter(), + Frequency freq) # = NoFrequency, #const Interpolator& factory) # = Interpolator()) ctypedef InterpolatedPiecewiseZeroSpreadedTermStructure[Linear] PiecewiseZeroSpreadedTermStructure diff --git a/quantlib/termstructures/yields/_zero_spreaded_term_structure.pxd b/quantlib/termstructures/yields/_zero_spreaded_term_structure.pxd index 8a48723cd..c8bb1ded0 100644 --- a/quantlib/termstructures/yields/_zero_spreaded_term_structure.pxd +++ b/quantlib/termstructures/yields/_zero_spreaded_term_structure.pxd @@ -1,7 +1,6 @@ from libcpp.vector cimport vector from quantlib._handle cimport Handle from quantlib.time._date cimport Date -from quantlib.time._daycounter cimport DayCounter from quantlib.time.frequency cimport Frequency from quantlib.termstructures._yield_term_structure cimport YieldTermStructure @@ -15,5 +14,4 @@ cdef extern from 'ql/termstructures/yield/zerospreadedtermstructure.hpp' namespa const Handle[YieldTermStructure]&, Handle[Quote]& spread, Compounding comp, # = Continuous, - Frequency freq, # = NoFrequency, - const DayCounter& dc), # = DayCounter(), + Frequency freq) # = NoFrequency, diff --git a/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx b/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx index 092eee59a..9aceb8656 100644 --- a/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx +++ b/quantlib/termstructures/yields/piecewise_zerospreaded_termstructure.pyx @@ -2,7 +2,6 @@ from cython.operator cimport dereference as deref from libcpp.vector cimport vector from quantlib.compounding cimport Compounding from quantlib.handle cimport Handle -from quantlib.time.daycounter cimport DayCounter from quantlib.time.frequency cimport Frequency, NoFrequency from quantlib.time._date cimport Date as QlDate from quantlib.time.date cimport Date @@ -13,8 +12,8 @@ from . cimport _piecewise_zerospreaded_termstructure as _pzt cdef class PiecewiseZeroSpreadedTermStructure(YieldTermStructure): def __init__(self, HandleYieldTermStructure h not None, list spreads, list dates, - Compounding comp=Compounding.Continuous, Frequency freq=NoFrequency, - DayCounter dc not None=DayCounter()): + Compounding comp=Compounding.Continuous, + Frequency freq=NoFrequency): cdef vector[Handle[_qt.Quote]] spreads_vec cdef vector[QlDate] dates_vec cdef Quote s @@ -32,6 +31,5 @@ cdef class PiecewiseZeroSpreadedTermStructure(YieldTermStructure): dates_vec, comp, freq, - deref(dc._thisptr) ) ) diff --git a/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx b/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx index 69219397c..c59b312e6 100644 --- a/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx +++ b/quantlib/termstructures/yields/zero_spreaded_term_structure.pyx @@ -1,15 +1,14 @@ from cython.operator cimport dereference as deref from quantlib.compounding cimport Compounding from quantlib.handle cimport HandleYieldTermStructure -from quantlib.time.daycounter cimport DayCounter from quantlib.time.frequency cimport Frequency, NoFrequency from quantlib.quote cimport Quote from . cimport _zero_spreaded_term_structure as _zsts cdef class ZeroSpreadedTermStructure(YieldTermStructure): def __init__(self, HandleYieldTermStructure h not None, Quote spread, - Compounding comp=Compounding.Continuous, Frequency freq=NoFrequency, - DayCounter dc not None=DayCounter()): + Compounding comp=Compounding.Continuous, + Frequency freq=NoFrequency): self._thisptr.reset( new _zsts.ZeroSpreadedTermStructure( @@ -17,6 +16,5 @@ cdef class ZeroSpreadedTermStructure(YieldTermStructure): spread.handle(), comp, freq, - deref(dc._thisptr) ) ) diff --git a/quantlib/util/options.py b/quantlib/util/options.py index 6b3fe9f8b..05bd496d9 100644 --- a/quantlib/util/options.py +++ b/quantlib/util/options.py @@ -9,7 +9,6 @@ import numpy as np import quantlib.reference.names as nm -import quantlib.reference.data_structures as ds from pandas import DataFrame from quantlib.instruments.vanillaoption import VanillaOption @@ -107,9 +106,11 @@ def options_to_rates(options, t_min=1. / 12., n_min=6): implied_dividend_yields.append(dividend_yield) expiry_dates.append(expiry_date) - rates = ds.riskfree_dividend_template().reindex(index=expiry_dates) - rates[nm.INTEREST_RATE] = implied_interest_rates - rates[nm.DIVIDEND_YIELD] = implied_dividend_yields + return DataFrame({ + nm.INTEREST_RATE: implied_interest_rates, + nm.DIVIDEND_YIELD: implied_dividend_yields, + }, + index=expiry_dates return rates diff --git a/test/test_bondfunctions.py b/test/test_bondfunctions.py index 8a3d58c45..431a2756d 100644 --- a/test/test_bondfunctions.py +++ b/test/test_bondfunctions.py @@ -98,7 +98,7 @@ def test_display(self): d = bf.start_date(self.bond) - zspd = bf.zSpread(self.bond, Price(100.0), self.flat_term_structure, Actual365Fixed(), + zspd = bf.zSpread(self.bond, Price(100.0), self.flat_term_structure, Compounded, Semiannual, self.settlement_date, 1e-6, 100, 0.5) @@ -149,10 +149,10 @@ def test_display(self): self.settlement_date, rate_helpers, ts_day_counter, accuracy=tolerance) - pyc_zspd=bf.zSpread(self.bond, Price(102.0), ts, ActualActual(ActualActual.ISDA), + pyc_zspd=bf.zSpread(self.bond, Price(102.0), ts, Compounded, Semiannual, Date(1, April, 2015), 1e-6, 100, 0.05) - pyc_zspd_disco=bf.zSpread(self.bond, Price(95.0), ts, ActualActual(ActualActual.ISDA), + pyc_zspd_disco=bf.zSpread(self.bond, Price(95.0), ts, Compounded, Semiannual, self.settlement_date, 1e-6, 100, 0.05) diff --git a/test/test_inflation.py b/test/test_inflation.py index 3bdf8c524..ec54d86af 100644 --- a/test/test_inflation.py +++ b/test/test_inflation.py @@ -14,7 +14,7 @@ from quantlib.time.api import ( UnitedKingdom, ModifiedFollowing, ActualActual, Schedule, Actual365Fixed, Unadjusted, Monthly ) from quantlib.time.dategeneration import DateGeneration -from quantlib.instruments.bonds.cpibond import CPIBond, InterpolationType +from quantlib.instruments.bonds.cpibond import CPIBond from quantlib.pricingengines.bond import DiscountingBondEngine from quantlib.settings import Settings from quantlib.handle import RelinkableHandleZeroInflationTermStructure @@ -100,7 +100,7 @@ def setUp(self): self.helpers = [ZeroCouponInflationSwapHelper( SimpleQuote(r / 100), observation_lag, - maturity, self.calendar, ModifiedFollowing, day_counter, self.ii, InterpolationType.AsIndex, self.yts) \ + maturity, self.calendar, ModifiedFollowing, day_counter, self.ii, InterpolationType.Flat) \ for maturity, r in zip(dates, rates)] base_date = self.ii.last_fixing_date @@ -119,7 +119,6 @@ def test_clean_price(self): contractObservationLag = Period(3, Months) observationInterpolation = InterpolationType.Flat settlement_days = 3 - growth_only = True baseCPI = 206.1 @@ -130,7 +129,7 @@ def test_clean_price(self): Unadjusted, DateGeneration.Backward) - cpi_bond = CPIBond(settlement_days, notional, growth_only, + cpi_bond = CPIBond(settlement_days, notional, baseCPI, contractObservationLag, fixed_index, observationInterpolation, fixed_schedule, fixed_rates, fixed_day_count, ModifiedFollowing) @@ -138,9 +137,10 @@ def test_clean_price(self): engine = DiscountingBondEngine(self.yts) cpi_bond.set_pricing_engine(engine) set_coupon_pricer(cpi_bond.cashflows, CPICouponPricer(self.yts)) - storedPrice = 383.054224764 - calculated = cpi_bond.clean_price() - self.assertAlmostEqual(storedPrice, calculated) + stored_price = 396.4704581 + self.assertAlmostEqual(stored_price, cpi_bond.dirty_price, 5) + stored_price = 394.79676679 + self.assertAlmostEqual(stored_price, cpi_bond.clean_price()) if __name__ == '__main__': unittest.main() diff --git a/test/test_mlab.py b/test/test_mlab.py index 80c90e024..621db20c8 100644 --- a/test/test_mlab.py +++ b/test/test_mlab.py @@ -1,6 +1,7 @@ import unittest from datetime import date +import pandas as pd from quantlib.mlab.option_pricing import heston_pricer, blsprice, blsimpv from quantlib.mlab.fixed_income import bndprice, cfamounts from quantlib.mlab.term_structure import zbt_libor_yield @@ -8,7 +9,6 @@ from quantlib.util.rates import make_rate_helper, zero_rate import quantlib.reference.names as nm -import quantlib.reference.data_structures as ds from quantlib.termstructures.yields.api import ( PiecewiseYieldCurve, BootstrapTrait ) @@ -25,17 +25,20 @@ def test_heston_pricer(self): spot = 1290.58 # option definition - options = ds.option_quotes_template().reindex(index=range(2)) - options[nm.OPTION_TYPE] = ['C', 'P'] - options[nm.STRIKE] = [1290, 1290] - options[nm.EXPIRY_DATE] = [date(2015, 1, 1), date(2015, 1, 1)] - options[nm.SPOT] = [spot] * 2 - + data = { + nm.OPTION_TYPE: ["C", "P"], + nm.STRIKE: [1290, 1290], + nm.EXPIRY_DATE: [date(2015, 1, 1), date(2015, 1, 1)], + nm.SPOT: [spot] * 2, + } + options = pd.DataFrame(data) # interest rate and dividend yield - rates = ds.riskfree_dividend_template().reindex( - index=[date(2011, 3, 16), date(2013, 3, 16), date(2015, 3, 16)]) - rates[nm.DIVIDEND_YIELD] = [.021, .023, .024] - rates[nm.INTEREST_RATE] = [.010, .015, .019] + rates = pd.DataFrame(data={ + nm.DIVIDEND_YIELD: [.021, .023, .024], + nm.INTEREST_RATE: [.010, .015, .019], + }, + index=[date(2011, 3, 16), date(2013, 3, 16), date(2015, 3, 16)], + ) # heston model heston_params = dict(v0=0.051965, diff --git a/test/test_reference.py b/test/test_reference.py deleted file mode 100644 index 1602b58b5..000000000 --- a/test/test_reference.py +++ /dev/null @@ -1,31 +0,0 @@ -import numpy as np - -from datetime import date, timedelta - -import unittest -import quantlib.reference.data_structures as df -import quantlib.reference.names as nm - -class ReferenceTestCase(unittest.TestCase): - - def setUp(self): - pass - - def test_option_quotes(self): - x = df.option_quotes_template().reindex(index=range(10)) - x[nm.STRIKE] = range(10) - x[nm.OPTION_TYPE] = ['C']*10 - x[nm.EXPIRY_DATE] = [date(2000,1,1)]*10 - x[nm.SPOT] = [100]*10 - self.assertTrue(True) - - - def test_riskfree_dividend(self): - x = df.riskfree_dividend_template().reindex( - index=[date(2000,1,1)+timedelta(days=k) for k in range(10)]) - x[nm.DIVIDEND_YIELD] = np.linspace(.01, .03, 10) - x[nm.INTEREST_RATE] = np.linspace(.02, .04, 10) - self.assertTrue(True) - -if __name__ == '__main__': - unittest.main()