-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathtest_contvar.py
35 lines (27 loc) · 977 Bytes
/
test_contvar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from probo.marketdata import MarketData
from probo.payoff import VanillaPayoff, call_payoff, put_payoff
from probo.engine import MonteCarloEngine, NaiveMonteCarloPricer, ControlVariatePricer
from probo.facade import OptionFacade
## Set up the market data
spot = 41.0
rate = 0.08
volatility = 0.30
dividend = 0.0
thedata = MarketData(rate, spot, volatility, dividend)
## Set up the option
expiry = 1.0
strike = 40.0
thecall = VanillaPayoff(expiry, strike, call_payoff)
theput = VanillaPayoff(expiry, strike, put_payoff)
## Set up Naive Monte Carlo
nreps = 5000
steps = 1
pricer = ControlVariatePricer
mcengine = MonteCarloEngine(nreps, steps, pricer)
## Calculate the price
option1 = OptionFacade(thecall, mcengine, thedata)
price1 = option1.price()
print("The call price via Naive Monte Carlo is: {0:.3f}".format(price1))
option2 = OptionFacade(theput, mcengine, thedata)
price2 = option2.price()
print("The put price via Naive Monte Carlo is: {0:.3f}".format(price2))