Lean
$LEAN_TAG$
IVolatilityModel.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
.
Data
;
17
using
System;
18
using
System.Collections.Generic;
19
using
System.Linq;
20
using
QuantConnect
.
Securities
.
Volatility
;
21
22
namespace
QuantConnect.Securities
23
{
24
/// <summary>
25
/// Represents a model that computes the volatility of a security
26
/// </summary>
27
/// <remarks>Please use<see cref="BaseVolatilityModel"/> as the base class for
28
/// any implementations of<see cref="IVolatilityModel"/></remarks>
29
public
interface
IVolatilityModel
30
{
31
/// <summary>
32
/// Gets the volatility of the security as a percentage
33
/// </summary>
34
decimal
Volatility
{
get
; }
35
36
/// <summary>
37
/// Updates this model using the new price information in
38
/// the specified security instance
39
/// </summary>
40
/// <param name="security">The security to calculate volatility for</param>
41
/// <param name="data">The new data used to update the model</param>
42
void
Update
(
Security
security,
BaseData
data);
43
44
/// <summary>
45
/// Returns history requirements for the volatility model expressed in the form of history request
46
/// </summary>
47
/// <param name="security">The security of the request</param>
48
/// <param name="utcTime">The date/time of the request</param>
49
/// <returns>History request object list, or empty if no requirements</returns>
50
IEnumerable<HistoryRequest>
GetHistoryRequirements
(
Security
security, DateTime utcTime);
51
}
52
53
/// <summary>
54
/// Provides access to a null implementation for <see cref="IVolatilityModel"/>
55
/// </summary>
56
public
static
class
VolatilityModel
57
{
58
/// <summary>
59
/// Gets an instance of <see cref="IVolatilityModel"/> that will always
60
/// return 0 for its volatility and does nothing during Update.
61
/// </summary>
62
public
static
readonly
IVolatilityModel
Null
=
new
NullVolatilityModel();
63
64
private
sealed
class
NullVolatilityModel :
IVolatilityModel
65
{
66
public
decimal Volatility {
get
;
private
set
; }
67
68
public
void
Update(
Security
security,
BaseData
data) { }
69
70
public
IEnumerable<HistoryRequest> GetHistoryRequirements(Security security, DateTime utcTime) {
return
Enumerable.Empty<
HistoryRequest
>(); }
71
}
72
}
73
}
Common
Securities
Volatility
IVolatilityModel.cs
Generated by
1.8.17