Lean
$LEAN_TAG$
OptionPriceModelPriceGenerator.cs
1
/*
2
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
16
using
QuantConnect
.
Securities
;
17
using
System;
18
using
QuantConnect
.
Data
.
Market
;
19
using
QuantConnect
.
Securities
.
Option
;
20
21
namespace
QuantConnect.ToolBox.RandomDataGenerator
22
{
23
/// <summary>
24
/// Pricing model used to determine the fair price or theoretical value for a call or a put option price
25
/// by default using the Black-Scholes-Merton model
26
/// </summary>
27
public
class
OptionPriceModelPriceGenerator
:
IPriceGenerator
28
{
29
private
readonly
Option
_option;
30
31
/// <summary>
32
/// <see cref="RandomPriceGenerator"/> is always ready to generate new price values as it does not depend on volatility model
33
/// </summary>
34
public
bool
WarmedUp
=> _option.PriceModel is
QLOptionPriceModel
optionPriceModel && optionPriceModel.
VolatilityEstimatorWarmedUp
|| _option.PriceModel is not
QLOptionPriceModel
;
35
36
/// <summary>
37
/// Creates instance of <see cref="OptionPriceModelPriceGenerator"/>
38
/// </summary>
39
///<param name="security"><see cref="Security"/> object for which to generate price data</param>
40
public
OptionPriceModelPriceGenerator
(
Security
security)
41
{
42
if
(security ==
null
)
43
{
44
throw
new
ArgumentNullException(nameof(security),
"security cannot be null"
);
45
}
46
47
if
(!security.
Symbol
.
SecurityType
.IsOption())
48
{
49
throw
new
ArgumentException($
"{nameof(OptionPriceModelPriceGenerator)} model cannot be applied to non-option security."
);
50
}
51
52
_option = security as
Option
;
53
}
54
55
/// <summary>
56
/// For Black-Scholes-Merton model price calculation relies <see cref="IOptionPriceModel"/> of the security
57
/// </summary>
58
/// <param name="maximumPercentDeviation">The maximum percent deviation. This value is in percent space,
59
/// so a value of 1m is equal to 1%.</param>
60
/// <param name="referenceDate">current reference date</param>
61
/// <returns>A new decimal suitable for usage as new security price</returns>
62
public
decimal
NextValue
(decimal maximumPercentDeviation, DateTime referenceDate)
63
{
64
return
_option.PriceModel
65
.Evaluate(
66
_option,
67
null
,
68
OptionContract
.
Create
(
69
referenceDate,
70
_option,
71
new
Tick
(referenceDate, _option.Underlying.Symbol, _option.Underlying.Price, _option.Underlying.Price)
72
))
73
.TheoreticalPrice;
74
}
75
}
76
}
ToolBox
RandomDataGenerator
OptionPriceModelPriceGenerator.cs
Generated by
1.8.17