Check out directory structure
Check out the contents of /option_models/init.py
from . import bsm
from . import normal
from . import sabr
In [ ]:
In [31]:
# when directory is imported, __init__.py is executed
# from __init__.py all sub modules are imported as well
import option_models as opt
In [32]:
# you may call
opt.bsm.price, opt.bsm.Model
Out[32]:
In [35]:
from option_models import bsm
# You can even do
#from option_models import bsm as bs
In [36]:
bsm.price, bsm.Model
Out[36]:
In [37]:
# The objects imported different ways are all same (as class type)
bsm.Model == opt.bsm.Model
Out[37]:
In [38]:
# you can create instances
bsm_model1 = bsm.Model(vol=0.2, texp=1)
bsm_model2 = opt.bsm.Model(vol=0.2, texp=1)
In [28]:
# But class instances are diffferent !!
bsm_model1 == bsm_model2
Out[28]:
In [39]:
from option_models.bsm import Model
Model == bsm.Model
# However this is confusing. which Model?
Out[39]:
In [40]:
# Always better to be explicit
from option_models.bsm import Model as BsmModel
from option_models.normal import Model as NormalModel
BsmModel == bsm.Model, NormalModel == opt.normal.Model
Out[40]:
In [ ]:
In [ ]:
In [ ]: