<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AD Finance</title>
    <description>The latest articles on DEV Community by AD Finance (@financewithad).</description>
    <link>https://dev.to/financewithad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1137056%2F7b5c929d-de0f-4d6e-93f7-f665531270b5.jpg</url>
      <title>DEV Community: AD Finance</title>
      <link>https://dev.to/financewithad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/financewithad"/>
    <language>en</language>
    <item>
      <title>Calculating Option Theta in Python</title>
      <dc:creator>AD Finance</dc:creator>
      <pubDate>Fri, 11 Aug 2023 03:21:28 +0000</pubDate>
      <link>https://dev.to/financewithad/calculating-option-theta-in-python-5e5h</link>
      <guid>https://dev.to/financewithad/calculating-option-theta-in-python-5e5h</guid>
      <description>&lt;p&gt;Theta is one of the "Greeks" used to measure an option's sensitivity to time decay. Specifically, theta indicates how much an option's price declines as the expiration date approaches. Traders use theta to gauge the impact of time decay on an option's value.&lt;/p&gt;

&lt;p&gt;Calculating theta in Python is straightforward using the &lt;code&gt;pyoptions&lt;/code&gt; library. Here's a step-by-step guide:&lt;/p&gt;

&lt;h2&gt;
  
  
  Import Modules
&lt;/h2&gt;

&lt;p&gt;Begin by importing the necessary modules:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python&lt;br&gt;
import pyoptions&lt;br&gt;
import pandas as pd&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Pyoptions contains the pricing models while pandas is used for data analysis.&lt;/p&gt;
&lt;h2&gt;
  
  
  Extract Option Data
&lt;/h2&gt;

&lt;p&gt;Next, extract the relevant option data needed for theta calculation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;option&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'S'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'K'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'T'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;365&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'r'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.01&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'sigma'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'call'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a dictionary with keys for stock price, strike, time to expiration, interest rate, volatility, and option type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calculate Theta
&lt;/h2&gt;

&lt;p&gt;Now calculate theta by passing the option data dictionary into &lt;code&gt;pyoptions.bsm.theta()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;theta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pyoptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bsm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;theta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;option&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-1.212&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The theta is returned in dollar value terms. As expected for a call option, it shows a negative theta of -$1.212 indicating time decay.&lt;/p&gt;

&lt;p&gt;That's it! With just a few lines of Python, we can easily calculate the theta for any option to quantify time decay. Pyoptions provides a simple way to harness options analytics in Python. Theta is very useful on the option &lt;a href="https://theoptionsuniversity.com/poor-mans-covered-call-strategy-explained/"&gt;pmcc strategy&lt;/a&gt; , &lt;a href="https://theoptionsuniversity.com/wheel-strategy-beginners-guide/"&gt;wheel strategy&lt;/a&gt; or any other option selling strategies. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
