yassinemaaroufi / mibianlib Goto Github PK
View Code? Open in Web Editor NEWPython Options Pricing Library
Home Page: http://code.mibian.net
Python Options Pricing Library
Home Page: http://code.mibian.net
In this c = mibian.BS([1.4565, 1.45, 1, 30], volatility=20)
volatility means implied Volatility ? Or Something else?
\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
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
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?
I suggest adding topics such as options
, black-scholes
, option-pricing
in the About section at https://github.com/yassinemaaroufi/MibianLib
``[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
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.
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
The link to http://code.mibian.net/ leads to a car dealership.
All are facing issues with Mibian - one calculation alone takes 5 to 15 secs. In previous version this issue was not there, could not find any solution for this..
Same issue posted by sombody else also in https://stackoverflow.com/questions/73348961/mibian-taking-very-long-time-to-calculate
Any solutions?
Hi,
Would you be interested in me adding a function to calculate an options volatility?
Are you interested in supporting decimal
types instead of just float
types for prices?
import mibian
File "C:\Users\costa\Anaconda3\lib\site-packages\mibian__init__.py", line 11
print 'Mibian requires scipy to work properly'
^
SyntaxError: Missing parentheses in call to 'print'
I am wondering if you would be interested in supporting american options, and discrete dividends?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.