Skip to content

Commit da4daa7

Browse files
This commit adds and improves numpydoc-style docstrings to the quantlib/quotes/simplequote.pyx and quantlib/quotes/futuresconvadjustmentquote.pyx files.
The following classes and their methods have been documented: - `SimpleQuote` - `FuturesConvAdjustmentQuote` The docstrings now use fully qualified type hints to support documentation generation and cross-referencing. The `Parameters` sections have been moved to the class docstrings for consistency.
1 parent 739fb17 commit da4daa7

File tree

357 files changed

+1664
-1664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+1664
-1664
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ quantlib.egg-info/*
66
QuantLib.dll
77
symbol_win*.def
88
*.cpp
9+
!quantlib/cpp_layer/*.cpp
910
*.so
1011
*.h
1112
*.pyc

MANIFEST.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

Makefile

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,31 @@
1+
wheel:
2+
python -m build --wheel -n -C--global-option=build_ext -C--global-option=-j6
3+
14
build:
25
python setup.py build_ext --inplace -j 8
36

4-
build2:
5-
python2 setup.py build_ext --inplace -j 8
6-
77
docs:
8+
-rm -rf docs/source/_autosummary
89
make -C docs html
910

1011
install:
11-
pip install .
12+
pip install . -C--global-option=build_ext -C--global-option=-j6
1213

1314
uninstall:
1415
pip uninstall quantlib
1516

16-
tests-preload:
17-
LD_PRELOAD=/opt/QuantLib-1.1/lib/libQuantLib.so nosetests -v quantlib/test
18-
1917
tests: build
2018
python -m unittest discover -v
2119

22-
tests2: build2
23-
python2 -m unittest discover -v
24-
25-
build_ex:
26-
g++ -m32 -I/opt/local/include/ -I/opt/local/include/boost quantlib_test2.cpp \
27-
-o test2 -L/opt/local/lib/ -lQuantLib
28-
2920
clean:
3021
find quantlib -name \*.so -exec rm {} +
3122
find quantlib -name \*.pyc -exec rm {} +
32-
find quantlib -name \*.cpp -exec rm {} +
23+
find quantlib -path quantlib/cpp_layer -prune -o -name \*.cpp -exec rm {} +
3324
find quantlib -name \*.c -exec rm {} +
3425
find quantlib -name \*.h -exec rm {} +
3526
-rm quantlib/termstructures/yields/{piecewise_yield_curve,discount_curve,forward_curve,zero_curve}.{pxd,pyx}
27+
-rm quantlib/handle.{pxd,pyx}
3628
rm -rf build
3729
rm -rf dist
3830

39-
.PHONY: build build2 docs clean
31+
.PHONY: build docs clean

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@
195195
# Grouping the document tree into LaTeX files. List of tuples
196196
# (source start file, target name, title, author, documentclass [howto/manual]).
197197
latex_documents = [
198-
('index', 'Quantlibcythonwrapper.tex', u'Quantlib cython wrapper Documentation',
199-
u'Didrik Pinte \& Patrick Hénaff', 'manual'),
198+
('index', 'Quantlibcythonwrapper.tex', 'Quantlib cython wrapper Documentation',
199+
'Didrik Pinte & Patrick Hénaff', 'manual'),
200200
]
201201

202202
# The name of an image file (relative to this directory) to place at the top of

examples/american_option.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
FOR A PARTICULAR PURPOSE. See the license for more details.
88
"""
99
from quantlib.instruments.api import AmericanExercise, VanillaOption, OptionType
10-
from quantlib.instruments.payoffs import PlainVanillaPayoff
10+
from quantlib.payoffs import PlainVanillaPayoff
1111
from quantlib.pricingengines.api import BaroneAdesiWhaleyApproximationEngine
1212
from quantlib.pricingengines.api import FdBlackScholesVanillaEngine
1313
from quantlib.processes.black_scholes_process import BlackScholesMertonProcess
1414
from quantlib.quotes import SimpleQuote
1515
from quantlib.settings import Settings
1616
from quantlib.time.api import Actual365Fixed, Date, May, TARGET
17-
from quantlib.termstructures.volatility.api import BlackConstantVol
18-
from quantlib.termstructures.yields.api import HandleYieldTermStructure, FlatForward
17+
from quantlib.termstructures.volatility.api import BlackConstantVol, HandleBlackVolTermStructure
18+
from quantlib.termstructures.yields.api import RelinkableHandleYieldTermStructure, FlatForward
1919
from quantlib.methods.finitedifferences.solvers.fdmbackwardsolver \
2020
import FdmSchemeDesc
2121

@@ -25,7 +25,7 @@ def main():
2525
Settings.instance().evaluation_date = todays_date
2626
settlement_date = Date(17, May, 1998)
2727

28-
risk_free_rate = HandleYieldTermStructure()
28+
risk_free_rate = RelinkableHandleYieldTermStructure()
2929
risk_free_rate.link_to(
3030
FlatForward(
3131
reference_date=settlement_date,
@@ -43,9 +43,11 @@ def main():
4343

4444
# market data
4545
underlying = SimpleQuote(36.0)
46-
volatility = BlackConstantVol(todays_date, TARGET(), 0.20,
46+
volatility = HandleBlackVolTermStructure(
47+
BlackConstantVol(todays_date, TARGET(), 0.20,
4748
Actual365Fixed())
48-
dividend_yield = HandleYieldTermStructure()
49+
)
50+
dividend_yield = RelinkableHandleYieldTermStructure()
4951
dividend_yield.link_to(
5052
FlatForward(
5153
reference_date=settlement_date,

examples/basic_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from quantlib.quotes import SimpleQuote
1010
from quantlib.settings import Settings
1111
from quantlib.time.api import TARGET, Actual365Fixed, today
12-
from quantlib.termstructures.yields.api import FlatForward, HandleYieldTermStructure
12+
from quantlib.termstructures.yields.api import FlatForward, RelinkableHandleYieldTermStructure
1313
from quantlib.termstructures.volatility.api import BlackConstantVol
1414

1515

@@ -36,8 +36,8 @@
3636
underlyingH = SimpleQuote(underlying)
3737

3838
# bootstrap the yield/dividend/vol curves
39-
flat_term_structure = HandleYieldTermStructure()
40-
flat_dividend_ts = HandleYieldTermStructure()
39+
flat_term_structure = RelinkableHandleYieldTermStructure()
40+
flat_dividend_ts = RelinkableHandleYieldTermStructure()
4141

4242
flat_term_structure.link_to(
4343
FlatForward(

examples/data/df_SPX_24jan2011.pkl

-7.66 KB
Binary file not shown.

examples/option_valuation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from quantlib.termstructures.yields.api import (
4545
PiecewiseYieldCurve, DepositRateHelper, BootstrapTrait, HandleYieldTermStructure
4646
)
47-
from quantlib.termstructures.volatility.api import BlackConstantVol
47+
from quantlib.termstructures.volatility.api import BlackConstantVol, HandleBlackVolTermStructure
4848
from quantlib.termstructures.yields.api import SwapRateHelper
4949

5050
def dividendOption():
@@ -169,7 +169,7 @@ def dividendOption():
169169

170170
print('Creating process')
171171

172-
bsProcess = BlackScholesProcess(underlying_priceH, HandleYieldTermStructure(riskFreeTS), flatVolTS)
172+
bsProcess = BlackScholesProcess(underlying_priceH, HandleYieldTermStructure(riskFreeTS), HandleBlackVolTermStructure(flatVolTS))
173173

174174

175175
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

examples/scripts/SPX_Options.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
# -*- coding: utf-8 -*-
32
# <nbformat>3</nbformat>
43

@@ -34,8 +33,8 @@
3433

3534
# <codecell>
3635

37-
import pandas
38-
import dateutil, datetime
36+
import pandas as pd
37+
import dateutil
3938
import re
4039

4140
def ExpiryMonth(s):
@@ -58,19 +57,19 @@ def parseSPX(s):
5857
"""
5958
Parse an SPX quote string, return expiry date and strike
6059
"""
61-
tokens = spx_symbol.split(s)
60+
tokens = spx_symbol.split(s.iloc[0])
6261

6362
if len(tokens) == 1:
64-
return {'dtExpiry': None, 'strike': -1}
63+
return {'Strike': -1, 'dtExpiry': None}
6564

6665
year = 2000 + int(tokens[1])
6766
day = int(tokens[2])
6867
month = ExpiryMonth(tokens[3])
6968
strike = float(tokens[4])
7069

71-
dtExpiry = datetime.date(year, month, day)
70+
dtExpiry = pd.Timestamp(year=year, month=month, day=day)
7271

73-
return ({'dtExpiry': dtExpiry, 'strike': strike})
72+
return {'Strike': strike, 'dtExpiry': dtExpiry}
7473

7574

7675
# <markdowncell>
@@ -93,12 +92,12 @@ def read_SPX_file(option_data_file):
9392

9493
lineTwo = fid.readline()
9594
dt = lineTwo.split('@')[0]
96-
dtTrade = dateutil.parser.parse(dt).date()
95+
dtTrade = pd.to_datetime(dt)
9796

9897
print('Dt Calc: %s Spot: %f' % (dtTrade, spot))
9998

10099
# read all option price records as a data frame
101-
df = pandas.io.parsers.read_csv(option_data_file, header=0, sep=',', skiprows=[0,1])
100+
df = pd.read_csv(option_data_file, header=0, sep=',', skiprows=[0,1])
102101

103102
# split and stack calls and puts
104103
call_df = df[['Calls', 'Bid', 'Ask']]
@@ -109,34 +108,28 @@ def read_SPX_file(option_data_file):
109108
put_df = put_df.rename(columns = {'Puts':'Spec', 'Bid.1':'PBid',
110109
'Ask.1':'PAsk'})
111110
put_df['Type'] = 'P'
112-
113-
df_all = call_df.append(put_df, ignore_index=True)
111+
df_all = pd.concat([call_df, put_df], ignore_index=True)
114112

115113
# parse Calls and Puts columns for strike and contract month
116114
# insert into data frame
117-
118-
cp = [parseSPX(s) for s in df_all['Spec']]
119-
df_all['Strike'] = [x['strike'] for x in cp]
120-
df_all['dtExpiry'] = [x['dtExpiry'] for x in cp]
121-
115+
df_all = pd.concat([df_all,
116+
df_all[["Spec"]].apply(parseSPX, axis="columns", result_type="expand")],
117+
axis=1)
122118
del df_all['Spec']
123119

124120
df_all = df_all[(df_all['Strike'] > 0) & (df_all['PBid']>0) \
125121
& (df_all['PAsk']>0)]
126122

127123
df_all['dtTrade'] = dtTrade
128124
df_all['Spot'] = spot
129-
130125
return df_all
131126

132-
option_data_file = \
133-
'../data/SPX-Options-24jan2011.csv'
134-
135127
if __name__ == '__main__':
128+
option_data_file = '../data/SPX-Options-24jan2011.csv'
136129
df_SPX = read_SPX_file(option_data_file)
137130
print('%d records processed' % len(df_SPX))
138131

139132
# save a csv file and pickled data frame
140133
df_SPX.to_csv('../data/df_SPX_24jan2011.csv', index=False)
141-
df_SPX.to_pickle('../data/df_SPX_24jan2011.pkl', protocol=4)
134+
df_SPX.to_pickle('../data/df_SPX_24jan2011.pkl')
142135
print('File saved')

examples/scripts/stovol_calibration.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import division
2-
from __future__ import print_function
31
# -*- coding: utf-8 -*-
42
# <nbformat>3</nbformat>
53

@@ -22,7 +20,6 @@
2220
import pandas
2321
from pandas import DataFrame
2422
import datetime
25-
from six.moves import input
2623

2724
from quantlib.models.equity.heston_model import (
2825
HestonModelHelper, HestonModel)

0 commit comments

Comments
 (0)