This article suggests another architectural approach to the one elaborated in part 2 of this series of articles dedicated to option pricing via Python.

In the latter indeed, we detailed how to create a class of option analytics (premium, delta, gamma, etc) and chart them in 3D. This approach is still not so bad, since we already encapsulate the computation logic inside a class “Option”.

However, what about if we want to implement any other exotic option, should we implement its code in a separate class? It makes more sense to group features that are common to any kind of Option in a base class, and have every children implementing their own specificities in overridden premium(), delta() … methods or properties. Common sense would be to make it more object oriented, and have a Vanilla Option and any other more sophisticate exotic option deriving from a more abstract class “Option”. In other words we want a more reusable class hierarchy.

This article provides some keys to better understand object class inheritance in Python for Finance.

Below you will find the adjusted code with BSVanilla and BSAsian inheriting from an Option abstract class.

Here is the code of the main procedure:

Option pricing python inheritance

Asian call option premium