Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
from quantlib.compounding import Continuous
from quantlib.pricingengines.bond import DiscountingBondEngine
from quantlib.time.date import Date, August, Period, Jul, Annual, Years
from quantlib.time.daycounters.simple import Actual365Fixed
from quantlib.time.daycounters.actual_actual import ActualActual, ISMA
from quantlib.time.schedule import Schedule, Backward
from quantlib.settings import Settings
from quantlib.termstructures.yields.api import (
FlatForward, YieldTermStructure
)
todays_date = Date(25, August, 2011)
settings = Settings.instance()
settings.evaluation_date = todays_date
calendar = TARGET()
effective_date = Date(10, Jul, 2006)
termination_date = calendar.advance(
effective_date, 10, Years, convention=Unadjusted
)
settlement_days = 3
face_amount = 100.0
coupon_rate = 0.05
redemption = 100.0
fixed_bond_schedule = Schedule.from_rule(
effective_date,
def main():
# global data
todays_date = Date(15, May, 1998)
Settings.instance().evaluation_date = todays_date
settlement_date = Date(17, May, 1998)
risk_free_rate = FlatForward(
reference_date=settlement_date,
forward=0.06,
daycounter=Actual365Fixed()
)
# option parameters
exercise = AmericanExercise(
earliest_exercise_date=settlement_date,
latest_exercise_date=Date(17, May, 1999)
)
payoff = PlainVanillaPayoff(Put, 40.0)
# market data
from quantlib.termstructures.credit.api import (
SpreadCdsHelper, PiecewiseDefaultCurve, ProbabilityTrait, Interpolator )
from quantlib.termstructures.yields.api import FlatForward
if __name__ == '__main__':
#*********************
#*** MARKET DATA ***
#*********************
calendar = TARGET()
todays_date = Date(15, May, 2007)
# must be a business day
todays_date = calendar.adjust(todays_date)
Settings.instance().evaluation_date = todays_date
# dummy curve
ts_curve = FlatForward(
reference_date=todays_date, forward=0.01, daycounter=Actual365Fixed()
)
# In Lehmans Brothers "guide to exotic credit derivatives"
# p. 32 there's a simple case, zero flat curve with a flat CDS
# curve with constant market spreads of 150 bp and RR = 50%
# corresponds to a flat 3% hazard rate. The implied 1-year
# survival probability is 97.04% and the 2-years is 94.18%
# market
recovery_rate = 0.5
quoted_spreads = [0.0150, 0.0150, 0.0150, 0.0150 ]
tenors = [Period(i, Months) for i in [3, 6, 12, 24]]
""" Simple example pricing a European option
using a Black&Scholes Merton process."""
from quantlib.instruments.api import (EuropeanExercise, PlainVanillaPayoff, Put,
VanillaOption)
from quantlib.pricingengines.api import AnalyticEuropeanEngine
from quantlib.processes.black_scholes_process import BlackScholesMertonProcess
from quantlib.quotes import SimpleQuote
from quantlib.settings import Settings
from quantlib.time.api import TARGET, Actual365Fixed, today
from quantlib.termstructures.yields.api import FlatForward
from quantlib.termstructures.volatility.api import BlackConstantVol
settings = Settings.instance()
calendar = TARGET()
offset = 366
todays_date = today() - offset
settlement_date = todays_date + 2
settings.evaluation_date = todays_date
# options parameters
option_type = Put
underlying = 36
strike = 40
dividend_yield = 0.00
risk_free_rate = 0.06
volatility = 0.20
from quantlib.settings import Settings
from quantlib.quotes import SimpleQuote
from quantlib.termstructures.yields.api import DepositRateHelper, FraRateHelper
from quantlib.termstructures.yields.api import FuturesRateHelper, SwapRateHelper
from quantlib.termstructures.yields.api import YieldTermStructure
from quantlib.termstructures.yields.api import (
PiecewiseYieldCurve, BootstrapTrait, Interpolator )
from quantlib.time.api import Actual360, Date, November, TARGET, Weeks, Annual
from quantlib.time.api import Months, Years, Period, ModifiedFollowing
from quantlib.time.api import Unadjusted, Thirty360, Semiannual, Schedule
from quantlib.time.api import ActualActual, ISDA
from quantlib.time.schedule import Forward
# global data
calendar = TARGET()
todaysDate = Date(6,November,2001);
Settings.instance().evaluation_date = todaysDate
settlementDate = Date(8,November,2001);
# market quotes
deposits = { (1,Weeks): 0.0382,
(1,Months): 0.0372,
(3,Months): 0.0363,
(6,Months): 0.0353,
(9,Months): 0.0348,
(1,Years): 0.0345 }
FRAs = { (3,6): 0.037125,
(6,9): 0.037125,
(9,12): 0.037125 }
futures = { Date(19,12,2001): 96.2875,
Date(20,3,2002): 96.7875,
from quantlib.processes.bates_process import BatesProcess
from quantlib.models.equity.bates_model import BatesModel
from quantlib.processes.heston_process import HestonProcess
from quantlib.models.equity.heston_model import HestonModel
from quantlib.quotes import SimpleQuote
from quantlib.settings import Settings
from quantlib.time.api import today, NullCalendar, ActualActual
from quantlib.util.rates import flat_rate
import pylab as pl
from quantlib.sim.simulate import simulate_model
# The Heston Process
# ------------------
settings = Settings.instance()
settlement_date = today()
settings.evaluation_date = settlement_date
daycounter = ActualActual()
calendar = NullCalendar()
interest_rate = .1
dividend_yield = .04
risk_free_ts = flat_rate(interest_rate, daycounter)
dividend_ts = flat_rate(dividend_yield, daycounter)
s0 = SimpleQuote(100.0)
# Heston model
# The Heston Process
# ------------------
#
def flat_rate(forward, daycounter):
return FlatForward(
quote = SimpleQuote(forward),
settlement_days = 0,
calendar = NullCalendar(),
daycounter = daycounter
)
settings = Settings.instance()
settlement_date = today()
settings.evaluation_date = settlement_date
daycounter = ActualActual()
calendar = NullCalendar()
interest_rate = .1
dividend_yield = .04
risk_free_ts = flat_rate(interest_rate, daycounter)
dividend_ts = flat_rate(dividend_yield, daycounter)
s0 = SimpleQuote(100.0)
# Heston model