Lean
$LEAN_TAG$
PositionGroupBuyingPowerModelExtensions.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
.
Orders
;
17
using
System.Collections.Generic;
18
19
namespace
QuantConnect.Securities.Positions
20
{
21
/// <summary>
22
/// Provides methods aimed at reducing the noise introduced from having result/parameter types for each method.
23
/// These methods aim to accept raw arguments and return the desired value type directly.
24
/// </summary>
25
public
static
class
PositionGroupBuyingPowerModelExtensions
26
{
27
/// <summary>
28
/// Gets the margin currently allocated to the specified position group
29
/// </summary>
30
public
static
decimal
GetMaintenanceMargin
(
31
this
IPositionGroupBuyingPowerModel
model,
32
SecurityPortfolioManager
portfolio,
33
IPositionGroup
positionGroup
34
)
35
{
36
return
model.
GetMaintenanceMargin
(
37
new
PositionGroupMaintenanceMarginParameters
(portfolio, positionGroup)
38
);
39
}
40
41
/// <summary>
42
/// The margin that must be held in order to change positions by the changes defined by the provided position group
43
/// </summary>
44
public
static
decimal
GetInitialMarginRequirement
(
45
this
IPositionGroupBuyingPowerModel
model,
46
SecurityPortfolioManager
portfolio,
47
IPositionGroup
positionGroup
48
)
49
{
50
return
model.
GetInitialMarginRequirement
(
51
new
PositionGroupInitialMarginParameters
(portfolio, positionGroup)
52
).
Value
;
53
}
54
55
/// <summary>
56
/// Gets the total margin required to execute the specified order in units of the account currency including fees
57
/// </summary>
58
public
static
decimal
GetInitialMarginRequiredForOrder
(
59
this
IPositionGroupBuyingPowerModel
model,
60
SecurityPortfolioManager
portfolio,
61
IPositionGroup
positionGroup,
62
Order
order
63
)
64
{
65
return
model.
GetInitialMarginRequiredForOrder
(
66
new
PositionGroupInitialMarginForOrderParameters
(portfolio, positionGroup, order)
67
).
Value
;
68
}
69
70
/// <summary>
71
/// Computes the amount of buying power reserved by the provided position group
72
/// </summary>
73
public
static
decimal
GetReservedBuyingPowerForPositionGroup
(
74
this
IPositionGroupBuyingPowerModel
model,
75
SecurityPortfolioManager
portfolio,
76
IPositionGroup
positionGroup
77
)
78
{
79
return
model.
GetReservedBuyingPowerForPositionGroup
(
80
new
ReservedBuyingPowerForPositionGroupParameters
(portfolio, positionGroup)
81
).
AbsoluteUsedBuyingPower
;
82
}
83
84
/// <summary>
85
/// Check if there is sufficient buying power for the position group to execute this order.
86
/// </summary>
87
public
static
HasSufficientBuyingPowerForOrderResult
HasSufficientBuyingPowerForOrder
(
88
this
IPositionGroupBuyingPowerModel
model,
89
SecurityPortfolioManager
portfolio,
90
IPositionGroup
positionGroup,
91
List<Order> orders
92
)
93
{
94
return
model.
HasSufficientBuyingPowerForOrder
(
new
HasSufficientPositionGroupBuyingPowerForOrderParameters
(
95
portfolio, positionGroup, orders
96
));
97
}
98
99
/// <summary>
100
/// Gets the buying power available for a position group trade
101
/// </summary>
102
public
static
PositionGroupBuyingPower
GetPositionGroupBuyingPower
(
103
this
IPositionGroupBuyingPowerModel
model,
104
SecurityPortfolioManager
portfolio,
105
IPositionGroup
positionGroup,
106
OrderDirection
direction
107
)
108
{
109
return
model.
GetPositionGroupBuyingPower
(
new
PositionGroupBuyingPowerParameters
(
110
portfolio, positionGroup, direction
111
));
112
}
113
}
114
}
Common
Securities
Positions
PositionGroupBuyingPowerModelExtensions.cs
Generated by
1.8.17