Skip to content

Commit

Permalink
Adds Dividend Yield Model
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatarino committed Mar 7, 2024
1 parent d7677a8 commit 9cd1534
Show file tree
Hide file tree
Showing 39 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>The dividend yield refers to the rate of return an investor earns from holding a stock in the form of dividends. Dividends are periodic payments made by a company to its shareholders out of its earnings.</p>

<p>In the context of option pricing models, the dividend yield is a critical factor because it affects the value of the underlying stock. When calculating the theoretical price of an option using these models, the dividend yield is factored into the equation.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<p>To set the dividend yield model for an option indicator, use the <code>dividendYieldModel</code> parameter.</p>

<div class="section-example-container">
<pre class="csharp">// Before creating the indicator, create the set dividend yield model
var dividendYieldModel = new DividendYieldProvider(symbol.Underlying);
_iv = new ImpliedVolatility(symbol, RiskFreeInterestRateModel, dividendYieldModel, OptionPricingModelType.BlackScholes);</pre>
<pre class="python"># Before creating the indicator, create the set dividend yield model
dividendYieldModel = DividendYieldProvider(symbol.Underlying)
self.iv = ImpliedVolatility(symbol, self.RiskFreeInterestRateModel, dividendYieldModel, OptionPricingModelType.BlackScholes)</pre>
</div>

<p>To view all the pre-built dividend yield models, see <a href='/docs/v2/writing-algorithms/reality-modeling/dividend-yield/supported-models'>Supported Models</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>For US Equity Options, the default dividend yield model is the <a href='/docs/v2/writing-algorithms/reality-modeling/dividend-yield/supported-models#04-Dividend-Yield-Provider-Model'>DividendYieldProvider</a>, which provides the yield of the last payment.</pp>
<p>For other option types, the default dividend yield model is the <a href='/docs/v2/writing-algorithms/reality-modeling/dividend-yield/supported-models#02-Constant-Model'>ConstantDividendYieldModel</a> with zero yield.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p>Dividend yield models must extend the <code>IDividendYieldModel</code> interface. Extensions of the <code>IDividendYieldModel</code> interface must implement a <code>GetDividendYield</code> method. The <code>GetDividendYield</code> method returns the dividend yield for a given date.</p>

<div class="section-example-container">
<pre class="csharp">// Before creating the indicator, create the set dividend yield model
var dividendYieldModel = new MyDividendYieldModel();
_iv = new ImpliedVolatility(symbol, RiskFreeInterestRateModel, dividendYieldModel, OptionPricingModelType.BlackScholes);

// Define the custom dividend yield model
public class MyDividendYieldModel : IDividendYieldModel
{
public decimal GetDividendYield(DateTime date)
{
return 0.02m;
}
}</pre>
<pre class="python"># Before creating the indicator, create the set dividend yield model
dividendYieldModel = MyDividendYieldModel()
self.iv = ImpliedVolatility(symbol, self.RiskFreeInterestRateModel, dividendYieldModel, OptionPricingModelType.BlackScholes)

# Define the custom dividend yield model
class MyDividendYieldModel:
def GetDividendYield(self, date: datetime) -&gt; float:
return 0.02</pre>
</div>

<p>For a full example algorithm, see <span class='python'><a href='https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_20d0faedc86be00cb5f7e2e2cc4f9b79.html'>this backtest</a></span><span class='csharp'><a href='https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_157d3106f24568d8aa43d169f2ccf52a.html'>this backtest</a></span>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "metadata",
"values": {
"description": "The dividend yield refers to the rate of return an investor earns from holding a stock in the form of dividends.",
"keywords": "dividend yield, option modeling, option indicators",
"og:description": "The dividend yield refers to the rate of return an investor earns from holding a stock in the form of dividends.",
"og:title": "Key Concepts - Documentation QuantConnect.com",
"og:type": "website",
"og:site_name": "Key Concepts - QuantConnect.com",
"og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/reality-modeling/dividend-yield/key-concepts.png"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>This page describes all of the pre-built dividend yield models in LEAN. If none of these models perform exactly how you want, create a <a href='/docs/v2/writing-algorithms/reality-modeling/dividend-yield/key-concepts#04-Model-Structure'>custom dividend yield model</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<p>The <code>ConstantDividendYieldModel</code> returns a constant yield across time. It's the default dividend yield rate model for securities that don't pay dividends.</p>

<div class="section-example-container">
<pre class="csharp">_dividendYieldModel = new ConstantDividendYieldModel(0.02m);</pre>
<pre class="python">self.dividendYieldModel = ConstantDividendYieldModel(0.02);</pre>
</div>

<p>The following table describes the arguments the model accepts:</p>

<table class="qc-table table">
<thead>
<tr>
<th>Argument</th>
<th>Data Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>dividendYield</code></td>
<td><code class="csharp">decimal</code><code class="python">float</code></td>
<td>The dividend yield</td>
</tr>
</tbody>
</table>

<p>To view the implementation of this model, see the <a target="_blank" rel="nofollow" href="https://github.com/QuantConnect/Lean/blob/master/Common/Data/ConstantDividendYieldModel.cs">LEAN GitHub repository</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<p>The <code>DividendYieldProvider</code> estimated annualized continuous dividend yield at given date from historical dividend payments.</p>

<div class="section-example-container">
<pre class="csharp">var symbol = AddEquity("MSFT").Symbol;
_dividendYieldModel = new DividendYieldProvider(symbol);</pre>
<pre class="python">symbol = self.AddEquity("MSFT").Symbol
self.dividendYieldModel = DividendYieldProvider(symbol);</pre>
</div>

<p>The following table describes the arguments the model accepts:</p>

<table class="qc-table table">
<thead>
<tr>
<th>Argument</th>
<th>Data Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>symbol</code></td>
<td><code>Symbol</code></td>
<td>The symbol of a dividend-paying security</td>
</tr>
</tbody>
</table>

<p>To view the implementation of this model, see the <a target="_blank" rel="nofollow" href="https://github.com/QuantConnect/Lean/blob/master/Common/Data/DividendYieldProvider.cs">LEAN GitHub repository</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "metadata",
"values": {
"description": "This page describes all of the pre-built dividend yield models in LEAN",
"keywords": "constant dividend yield, historical dividend yield,",
"og:description": "This page describes all of the pre-built dividend yield models in LEAN",
"og:title": "Supported Models - Documentation QuantConnect.com",
"og:type": "website",
"og:site_name": "Supported Models - QuantConnect.com",
"og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/reality-modeling/dividend-yield/supported-models.png"
}
}

0 comments on commit 9cd1534

Please sign in to comment.