GithubHelp home page GithubHelp logo

mibianlib's People

Contributors

smickles avatar vikramcbajaj avatar yassinemaaroufi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mibianlib's Issues

ZeroDivisionError: float division by zero - not able to get calculation on expiry day.

\python\python36\lib\site-packages\mibian\__init__.py in __init__(self, args, volatility, callPrice, putPrice, performance)
    271 			self._d1_ = (log(self.underlyingPrice / self.strikePrice) + \
    272                                         (self.interestRate + (self.volatility**2) / 2) * \
--> 273 					self.daysToExpiration) / self._a_
    274                         self._d2_ = self._d1_ - self._a_
    275                         if performance:

ZeroDivisionError: float division by zero

i have suggession to add '+ 0.0001' to line of division or try catch and add 0.0001 which will give correct ans rather than error:

		self._d1_ = (log(self.underlyingPrice / self.strikePrice) + \
				(self.interestRate - self.dividendYield + \
				(self.volatility**2) / 2) * self.daysToExpiration) / \
				self._a_ + 0.0001

NameError: global name 'norm' is not defined in Python3

Scipy is already installed in the python3 virtualenv-
(py33) root@www:~/nifty/quantandfinancial# apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-nose is already the newest version.
python-numpy is already the newest version.
ipython is already the newest version.
ipython-notebook is already the newest version.
python-matplotlib is already the newest version.
python-pandas is already the newest version.
python-scipy is already the newest version.
python-sympy is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

but I still get
(py33) root@www:~/nifty/quantandfinancial# python3 black_scholes.py
Mibian requires scipy to work properly
Traceback (most recent call last):
File "black_scholes.py", line 36, in
c = mibian.BS([ 6051.55 , 6000, .0007, tte], volatility=volat)
File "/root/py33/lib/python3.3/site-packages/mibian/init.py", line 278, in init
[self.callPrice, self.putPrice] = self._price()
File "/root/py33/lib/python3.3/site-packages/mibian/init.py", line 307, in _price
call = self.underlyingPrice * norm.cdf(self.d1) -
NameError: global name 'norm' is not defined

Clarification on volatility value/calculation

Great library. I have a question about how you would get the volatility value (20) in the below example

c = mibian.BS([1.4565, 1.45, 1, 30], volatility=20)

I'm currently using dataframe close prices like so

logreturn = np.log(df/df.shift(1))
volatility = np.sqrt(252*logreturn.var())

I've seen in your code the line below but just multiplying what I currently use by 100 still isn't very clean

self.volatility = float(volatility) / 100

Can you clarify how you would get 20 for volatility?

Name norm is not defined using python 3.9 version

``[self.callPrice, self.putPrice] = self._price()
277 else:
--> 278 [self.callPrice, self.putPrice] = self._price()
279 [self.callDelta, self.putDelta] = self._delta()
280 [self.callDelta2, self.putDelta2] = self._delta2()

File c:\program files\python39\lib\site-packages\mibian_init_.py:307, in BS._price(self)
305 raise ZeroDivisionError('The strike price cannot be zero')
306 else:
--> 307 call = self.underlyingPrice * norm.cdf(self.d1) -
308 self.strikePrice * e**(-self.interestRate *
309 self.daysToExpiration) * norm.cdf(self.d2)
310 put = self.strikePrice * e**(-self.interestRate *
311 self.daysToExpiration) * norm.cdf(-self.d2) -
312 self.underlyingPrice * norm.cdf(-self.d1)
313 return [call, put]

NameError: name 'norm' is not defined

Performance Problems - Too Slow

I'm trying to calculate implied volatility and the greeks for around 40.000 options.

It takes me almost 20 minutes against another algorithm that do the same job in a fast way (less than 2 minutes).

Maybe it will need a better use of libraries like numpy and pandas in order to get things faster.

IndexError: list index out of range

Use example c = mibian.BS([1.4565, 1.45, 1, 30], volatility=20) output sussessful result, but c = mibian.GK([100, 100, 5, 30], volatility=25) is error. Why?

Traceback (most recent call last):
  File "xxx/opserver/option_calculator/app.py", line 16, in <module>
    c = mibian.GK([100, 100, 5, 30], volatility=25)
  File "xxx\opserver\lib\site-packages\mibian\__init__.py", line 78, in __init__
    self.daysToExpiration = float(args[4]) / 365
IndexError: list index out of range

Enhancment

Hi,

Would you be interested in me adding a function to calculate an options volatility?

Enhancement

Are you interested in supporting decimal types instead of just float types for prices?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.