Lean
$LEAN_TAG$
OptionChain.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
System;
17
using
System.Collections.Generic;
18
using
QuantConnect
.
Data
.
UniverseSelection
;
19
using
QuantConnect
.
Securities
;
20
21
namespace
QuantConnect.Data.Market
22
{
23
/// <summary>
24
/// Represents an entire chain of option contracts for a single underlying security.
25
/// This type is <see cref="IEnumerable{OptionContract}"/>
26
/// </summary>
27
public
class
OptionChain
:
BaseChain
<OptionContract, OptionContracts>
28
{
29
/// <summary>
30
/// Initializes a new instance of the <see cref="OptionChain"/> class
31
/// </summary>
32
/// <param name="canonicalOptionSymbol">The symbol for this chain.</param>
33
/// <param name="time">The time of this chain</param>
34
/// <param name="flatten">Whether to flatten the data frame</param>
35
public
OptionChain
(
Symbol
canonicalOptionSymbol, DateTime time,
bool
flatten =
true
)
36
: base(canonicalOptionSymbol, time,
MarketDataType
.
OptionChain
, flatten)
37
{
38
}
39
40
/// <summary>
41
/// Initializes a new option chain for a list of contracts as <see cref="OptionUniverse"/> instances
42
/// </summary>
43
/// <param name="canonicalOptionSymbol">The canonical option symbol</param>
44
/// <param name="time">The time of this chain</param>
45
/// <param name="contracts">The list of contracts data</param>
46
/// <param name="symbolProperties">The option symbol properties</param>
47
/// <param name="flatten">Whether to flatten the data frame</param>
48
public
OptionChain
(
Symbol
canonicalOptionSymbol, DateTime time, IEnumerable<OptionUniverse> contracts,
SymbolProperties
symbolProperties,
49
bool
flatten =
true
)
50
: this(canonicalOptionSymbol, time, flatten)
51
{
52
foreach
(var contractData
in
contracts)
53
{
54
Underlying
??= contractData.Underlying;
55
if
(contractData.Symbol.ID.Date.Date < time.Date)
continue
;
56
Contracts
[contractData.Symbol] =
OptionContract
.
Create
(contractData, symbolProperties);
57
}
58
}
59
60
/// <summary>
61
/// Initializes a new instance of the <see cref="OptionChain"/> class as a clone of the specified instance
62
/// </summary>
63
private
OptionChain
(
OptionChain
other)
64
: base(other)
65
{
66
}
67
68
/// <summary>
69
/// Return a new instance clone of this object, used in fill forward
70
/// </summary>
71
/// <returns>A clone of the current object</returns>
72
public
override
BaseData
Clone
()
73
{
74
return
new
OptionChain
(
this
);
75
}
76
}
77
}
Common
Data
Market
OptionChain.cs
Generated by
1.8.17