Lean
$LEAN_TAG$
AlgorithmSettings.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
QuantConnect
.
Interfaces
;
18
using
QuantConnect
.
Securities
;
19
using
QuantConnect
.
Orders
.
Fills
;
20
using
QuantConnect
.
Configuration
;
21
22
namespace
QuantConnect
23
{
24
/// <summary>
25
/// This class includes user settings for the algorithm which can be changed in the <see cref="IAlgorithm.Initialize"/> method
26
/// </summary>
27
public
class
AlgorithmSettings
:
IAlgorithmSettings
28
{
29
private
static
TimeSpan _defaultDatabasesRefreshPeriod =
30
TimeSpan.TryParse(
Config
.
Get
(
"databases-refresh-period"
,
"1.00:00:00"
), out var refreshPeriod) ? refreshPeriod :
Time
.
OneDay
;
31
32
/// <summary>
33
/// Gets whether or not WarmUpIndicator is allowed to warm up indicators
34
/// </summary>
35
public
bool
AutomaticIndicatorWarmUp
{
get
;
set
; }
36
37
/// <summary>
38
/// True if should rebalance portfolio on security changes. True by default
39
/// </summary>
40
public
bool
?
RebalancePortfolioOnSecurityChanges
{
get
;
set
; }
41
42
/// <summary>
43
/// True if should rebalance portfolio on new insights or expiration of insights. True by default
44
/// </summary>
45
public
bool
?
RebalancePortfolioOnInsightChanges
{
get
;
set
; }
46
47
/// <summary>
48
/// The absolute maximum valid total portfolio value target percentage
49
/// </summary>
50
/// <remarks>This setting is currently being used to filter out undesired target percent values,
51
/// caused by the IPortfolioConstructionModel implementation being used.
52
/// For example rounding errors, math operations</remarks>
53
public
decimal
MaxAbsolutePortfolioTargetPercentage
{
get
;
set
; }
54
55
/// <summary>
56
/// The absolute minimum valid total portfolio value target percentage
57
/// </summary>
58
/// <remarks>This setting is currently being used to filter out undesired target percent values,
59
/// caused by the IPortfolioConstructionModel implementation being used.
60
/// For example rounding errors, math operations</remarks>
61
public
decimal
MinAbsolutePortfolioTargetPercentage
{
get
;
set
; }
62
63
/// <summary>
64
/// Configurable minimum order margin portfolio percentage to ignore bad orders, orders with unrealistic small sizes
65
/// </summary>
66
/// <remarks>Default value is 0.1% of the portfolio value. This setting is useful to avoid small trading noise when using SetHoldings</remarks>
67
public
decimal
MinimumOrderMarginPortfolioPercentage
{
get
;
set
; }
68
69
/// <summary>
70
/// Gets/sets the maximum number of concurrent market data subscriptions available
71
/// </summary>
72
/// <remarks>
73
/// All securities added with <see cref="IAlgorithm.AddSecurity"/> are counted as one,
74
/// with the exception of options and futures where every single contract in a chain counts as one.
75
/// </remarks>
76
[Obsolete(
"This property is deprecated. Please observe data subscription limits set by your brokerage to avoid runtime errors."
)]
77
public
int
DataSubscriptionLimit
{
get
;
set
; } =
int
.MaxValue;
78
79
/// <summary>
80
/// Gets/sets the SetHoldings buffers value.
81
/// The buffer is used for orders not to be rejected due to volatility when using SetHoldings and CalculateOrderQuantity
82
/// </summary>
83
public
decimal?
FreePortfolioValue
{
get
;
set
; }
84
85
/// <summary>
86
/// Gets/sets the SetHoldings buffers value percentage.
87
/// This percentage will be used to set the <see cref="FreePortfolioValue"/>
88
/// based on the <see cref="SecurityPortfolioManager.TotalPortfolioValue"/>
89
/// </summary>
90
public
decimal
FreePortfolioValuePercentage
{
get
;
set
; }
91
92
/// <summary>
93
/// Gets/sets if Liquidate() is enabled
94
/// </summary>
95
public
bool
LiquidateEnabled
{
get
;
set
; }
96
97
/// <summary>
98
/// Gets/sets the minimum time span elapsed to consider a market fill price as stale (defaults to one hour)
99
/// </summary>
100
/// <remarks>
101
/// In the default fill models, a warning message will be added to market order fills
102
/// if this time span (or more) has elapsed since the price was last updated.
103
/// </remarks>
104
/// <seealso cref="FillModel"/>
105
/// <seealso cref="ImmediateFillModel"/>
106
public
TimeSpan
StalePriceTimeSpan
{
get
;
set
; }
107
108
/// <summary>
109
/// The warmup resolution to use if any
110
/// </summary>
111
/// <remarks>This allows improving the warmup speed by setting it to a lower resolution than the one added in the algorithm</remarks>
112
public
Resolution
?
WarmupResolution
{
get
;
set
; }
113
114
/// <summary>
115
/// The warmup resolution to use if any
116
/// </summary>
117
/// <remarks>This allows improving the warmup speed by setting it to a lower resolution than the one added in the algorithm.
118
/// Pass through version to be user friendly</remarks>
119
public
Resolution
?
WarmUpResolution
120
{
121
get
122
{
123
return
WarmupResolution
;
124
}
125
set
126
{
127
WarmupResolution
= value;
128
}
129
}
130
131
/// <summary>
132
/// Number of trading days per year for this Algorithm's portfolio statistics.
133
/// </summary>
134
/// <remarks>Effect on
135
/// <see cref="Statistics.PortfolioStatistics.AnnualVariance"/>,
136
/// <seealso cref="Statistics.PortfolioStatistics.AnnualStandardDeviation"/>,
137
/// <seealso cref="Statistics.PortfolioStatistics.SharpeRatio"/>,
138
/// <seealso cref="Statistics.PortfolioStatistics.SortinoRatio"/>,
139
/// <seealso cref="Statistics.PortfolioStatistics.TrackingError"/>,
140
/// <seealso cref="Statistics.PortfolioStatistics.InformationRatio"/>.
141
/// </remarks>
142
public
int
?
TradingDaysPerYear
{
get
;
set
; }
143
144
/// <summary>
145
/// True if daily strict end times are enabled
146
/// </summary>
147
public
bool
DailyPreciseEndTime
{
get
;
set
; }
148
149
/// <summary>
150
/// Gets the time span used to refresh the market hours and symbol properties databases
151
/// </summary>
152
public
TimeSpan
DatabasesRefreshPeriod
{
get
;
set
; }
153
154
/// <summary>
155
/// Initializes a new instance of the <see cref="AlgorithmSettings"/> class
156
/// </summary>
157
public
AlgorithmSettings
()
158
{
159
LiquidateEnabled
=
true
;
160
DailyPreciseEndTime
=
true
;
161
FreePortfolioValuePercentage
= 0.0025m;
162
// Because the free portfolio value has a trailing behavior by default, let's add a default minimum order margin portfolio percentage
163
// to avoid tiny trades when rebalancing, defaulting to 0.1% of the TPV
164
MinimumOrderMarginPortfolioPercentage
= 0.001m;
165
StalePriceTimeSpan
=
Time
.
OneHour
;
166
MaxAbsolutePortfolioTargetPercentage
= 1000000000;
167
MinAbsolutePortfolioTargetPercentage
= 0.0000000001m;
168
DatabasesRefreshPeriod
= _defaultDatabasesRefreshPeriod;
169
}
170
}
171
}
Common
AlgorithmSettings.cs
Generated by
1.8.17