Skip to content

Commit 735c616

Browse files
committed
Model Structure for Pricing Model
1 parent ed2a3ef commit 735c616

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<p>Pricing models should extend the <code>OptionPriceModel</code> class. Extensions of the <code>OptionPriceModel</code> class must implement the <code class="csharp">Evaluate</code><code class="python">evaluate</code> method, which receives <code>OptionPriceModelParameters</code> and returns an <code>OptionPriceModelResult</code> that contains the theoretical price, the implied volatility, and Greeks.</p>
2+
<div class="section-example-container">
3+
<pre class="csharp">public class CustomOptionPriceModelExampleAlgorithm : QCAlgorithm
4+
{
5+
public override void Initialize()
6+
{
7+
// In the Initialize method, set the custom option price model for an added option chain to use the custom model
8+
var option = AddOption("SPY");
9+
option.SetPriceModel(new CustomOptionPriceModel());
10+
}
11+
}
12+
13+
// Define the custom option price model
14+
private class CustomOptionPriceModel : OptionPriceModel
15+
{
16+
public override OptionPriceModelResult Evaluate(OptionPriceModelParameters parameters)
17+
{
18+
var contract = parameters.Contract;
19+
var underlying = contract.UnderlyingLastPrice;
20+
var strike = contract.Strike;
21+
22+
var intrinsicValue = contract.Right == OptionRight.Call
23+
? Math.Max(0, underlying - strike);
24+
: Math.Max(0, strike - underlying);
25+
26+
var theoreticalPrice = intrinsicValue + 1.0m;
27+
return new OptionPriceModelResult(theoreticalPrice, new Greeks(0.5m, 0.1m, 0.2m, -0.05m, 0.1m, 2.0m));
28+
}
29+
}</pre>
30+
<pre class="python">class CustomOptionPriceModelExampleAlgorithm(QCAlgorithm):
31+
def initialize(self) -&gt; None:
32+
# In the Initialize method, set the custom price model for an added option chain to use the custom model
33+
option = self.add_option("SPY")
34+
option.set_price_model(CustomOptionPriceModel())
35+
36+
# Define the custom price model
37+
class CustomOptionPriceModel(OptionPriceModel):
38+
def evaluate(self, parameters: OptionPriceModelParameters) -&gt; OptionPriceModelResult:
39+
contract = parameters.contract
40+
underlying = contract.underlying_last_price
41+
strike = contract.strike
42+
43+
intrinsic = max(0, underlying - strike) if contract.right == OptionRight.CALL else max(0, strike - underlying)
44+
45+
theoretical_price = intrinsic + 1.0
46+
47+
return OptionPriceModelResult(theoretical_price, Greeks(0.5, 0.1, 0.2, -0.05, 0.1, 2.0))</pre>
48+
</div>
49+
<p>The <code>OptionPriceModelParameters</code> object has the following members:</p>
50+
<div data-tree='QuantConnect.Securities.Option.OptionPriceModelParameters'></div>

03 Writing Algorithms/24 Reality Modeling/09 Options Models/01 Pricing/05 Disable Pricing.html renamed to 03 Writing Algorithms/24 Reality Modeling/09 Options Models/01 Pricing/06 Disable Pricing.html

File renamed without changes.

03 Writing Algorithms/24 Reality Modeling/09 Options Models/01 Pricing/06 Supported Models.html renamed to 03 Writing Algorithms/24 Reality Modeling/09 Options Models/01 Pricing/07 Supported Models.html

File renamed without changes.

0 commit comments

Comments
 (0)