# Options Pricing with Python - Exotics and the Vanna Volga method

#### Quasar Chunawala

Hi friends,

I delivered a talk to my team today on Options Pricing with Python. It was tremendous fun - with lots of intuitive examples, code-snippets and visuals.

I would love to share the powerpoint deck and the PDF document containing the code snippets.

Cheers!
Quasar.

#### Attachments

• Options pricing using Python.pptx
2.1 MB · Views: 584
• Options pricing with Python - Examples.pdf
1.4 MB · Views: 927

#### Daniel Duffy

##### C++ author, trainer
Neat.

In binomial, the code can be optimised to choose C/P out of the loop

for (n = ...)
{
if (C)
{
...
}
else(P)
{

}
}

if else in loops slows things down. Init once and just use without asking is it a C or a P.
Loop unswitching - Wikipedia

#### Quasar Chunawala

Neat.

In binomial, the code can be optimised to choose C/P out of the loop

for (n = ...)
{
if (C)
{
...
}
else(P)
{

}
}

if else in loops slows things down. Init once and just use without asking is it a C or a P.
Loop unswitching - Wikipedia

That's a cool optimization! It never crossed my mind.

#### Daniel Duffy

##### C++ author, trainer
another common issue is
C++:
for (i = 0; i < N, ++i)
{

if (0 == i)
{
a[I] = 42;
}

a[I] = ....

}

#### Daniel Duffy

##### C++ author, trainer
Just out of curiosity: what's the run-time performance of Python for Binomial? Say NT = 10^4.

#### BlackMamba

This was great, Quasar!

#### BlackMamba

@Quasar Chunawala I remember reading somewhere else on the forum that you had passed the Level II exam of the CFA Program. Did you ever go on to sit and complete Level III? Just recently passed Level II, signing up for Level III in June 2018 in the coming weeks.

#### pingu

Hi friends,

I delivered a talk to my team today on Options Pricing with Python. It was tremendous fun - with lots of intuitive examples, code-snippets and visuals.

I would love to share the powerpoint deck and the PDF document containing the code snippets.

Cheers!
Quasar.
Your python code doesn't look really Pythonic. It looks more like you are coding in C++ or Java instead of Python.

For example, your initialization of the C ndarray could be done better this way:
C++:
if optionType == 'C':
C[N] = np.where(S[N] > strike, S[N]-strike, 0)
else:
C[N] = np.where(strike > S[N], strike-S[N], 0)

or if you want to take it to the next level:
C++:
C[N] = np.where(S[N] > strike, S[N]-strike, 0) if optionType == 'C' else np.where(strike > S[N], strike-S[N], 0)

In Scientific Python, you tried to avoid loops as much as possible. That's the power of the language.

#### ggut

Hi, I tried using the code as you wrote it and keep getting a math domain error.

sigma = sigma2 + (-sigma2 + math.sqrt(sigma2*2 + d1d2 *(2sigma2*P+Q)))/(d1d2) -> causes the issue as the "P" component is negative under the square root. I am probably missing something. Any help would be appreciated. Thanks.

#### Rihab Saidi

Hi, I tried using the code as you wrote it and keep getting a math domain error.

sigma = sigma2 + (-sigma2 + math.sqrt(sigma2*2 + d1d2 *(2sigma2*P+Q)))/(d1d2) -> causes the issue as the "P" component is negative under the square root. I am probably missing something. Any help would be appreciated. Thanks.
you have to divide the volatility by 100
and replace math.sqrt with numpy.sqrt (import numpy)

Replies
2
Views
958
Replies
0
Views
1K
Replies
9
Views
4K
Replies
2
Views
1K
Replies
27
Views
5K