In 2018, I got interest in investing in calls and puts, but I was not sure which was the amount of money I should be offering for them. That is how I came with the Black Scholes equation. I made a script that:
- Connects with a broker API and gets information about calls and puts.
- Gets info of the current stock market situation.
- Webscraps daily reports of volatility.
- Creates a database containing all the info gatherer above and uses the BS formula to calculate the theorethical value of calls.
- Displays thos calls being offered below the BS calculation.
I made several changes to this script trouth the years, making it better, faster and more reliable.
Lets look at the data
I ussually use bullmarketbrokers as my main broker, but due to some problems with their API, I started to use invertironline’s API, which turned to be more reliable. The key point is that the data gathered is the same and makes no difference.
In a normal day we can see a table like this one for the stock market
and like this for puts and calls
So at the end we have almost all the data required to perform the calculations using the BS formula, with exception of the stock’s volatility.
Volatility
The volatility of each stock is not something that you can obtain from the broker. There are some websites that continously publish reports about stocks. So I included functions that downloads the report (.pdf) and extracts the volatility of the last 52 weeks for all the main stocks and appends them to the data we already got.
The scripts
I made use of pandas
,numpy
, math
for data analysis, and request
,BeautifulSoup
for webscrapping.
All the data is gathered and stored locally by simply running Data_opciones.py.
Later, by running Opciones.py the output is like follows for Calls.
Accion P_A Tipo_opcion Target Vencmt. Opcion_cotizacion Vol Teorico %VT
0 ALUA 67.4 Call 31.0 1.639710e+09 33.70 0.3358 38.45 87.65
1 ALUA 67.4 Call 61.0 1.639710e+09 10.00 0.3358 11.05 90.50
4 ALUA 67.4 Call 69.0 1.639710e+09 5.00 0.3358 5.61 89.13
5 ALUA 67.4 Call 71.0 1.639710e+09 4.00 0.3358 4.59 87.15
6 ALUA 67.4 Call 73.0 1.639710e+09 2.45 0.3358 3.70 66.22
.. ... ... ... ... ... ... ... ... ...
275 YPFD 895.5 Call 880.0 1.639710e+09 92.00 0.4222 108.16 85.06
279 YPFD 895.5 Call 960.0 1.639710e+09 65.00 0.4222 67.10 96.87
282 YPFD 895.5 Call 1000.0 1.639710e+09 45.00 0.4222 51.51 87.36
287 YPFD 895.5 Call 1150.0 1.639710e+09 15.50 0.4222 16.66 93.04
290 YPFD 895.5 Call 1200.0 1.639710e+09 10.00 0.4222 10.96 91.24
All these options are currently at prices below BS formula. Nice!!
To Do
I am thinking on expanding this project, as there are some calls and puts strategies that can be done in the stock market that guarantees profit with high probability.