Lean  $LEAN_TAG$
BacktestNodePacket.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 
17 using System;
18 using System.Globalization;
19 using Newtonsoft.Json;
21 using QuantConnect.Util;
22 
23 namespace QuantConnect.Packets
24 {
25  /// <summary>
26  /// Algorithm backtest task information packet.
27  /// </summary>
29  {
30  // default random id, static so its one per process
31  private static readonly string DefaultId
32  = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
33 
34  /// <summary>
35  /// Name of the backtest as randomly defined in the IDE.
36  /// </summary>
37  public string Name { get; set; } = string.Empty;
38 
39  /// <summary>
40  /// BacktestId / Algorithm Id for this task
41  /// </summary>
42  public string BacktestId { get; set; } = DefaultId;
43 
44  /// <summary>
45  /// Optimization Id for this task
46  /// </summary>
47  public string OptimizationId { get; set; }
48 
49  /// <summary>
50  /// Backtest start-date as defined in the Initialize() method.
51  /// </summary>
52  public DateTime? PeriodStart { get; set; }
53 
54  /// <summary>
55  /// Backtest end date as defined in the Initialize() method.
56  /// </summary>
57  public DateTime? PeriodFinish { get; set; }
58 
59  /// <summary>
60  /// Backtest maximum end date
61  /// </summary>
62  public DateTime? OutOfSampleMaxEndDate { get; set; }
63 
64  /// <summary>
65  /// The backtest out of sample day count
66  /// </summary>
67  public int OutOfSampleDays { get; set; }
68 
69  /// <summary>
70  /// Estimated number of trading days in this backtest task based on the start-end dates.
71  /// </summary>
72  public int TradeableDates { get; set; }
73 
74  /// <summary>
75  /// True, if this is a debugging backtest
76  /// </summary>
77  public bool Debugging { get; set; }
78 
79  /// <summary>
80  /// Optional initial cash amount if set
81  /// </summary>
82  public CashAmount? CashAmount { get; set; }
83 
84  /// <summary>
85  /// Algorithm running mode.
86  /// </summary>
87  [JsonIgnore]
88  public override AlgorithmMode AlgorithmMode
89  {
90  get
91  {
92  return OptimizationId.IsNullOrEmpty() ? AlgorithmMode.Backtesting : AlgorithmMode.Optimization;
93  }
94  }
95 
96  /// <summary>
97  /// Default constructor for JSON
98  /// </summary>
100  : base(PacketType.BacktestNode)
101  {
102  Controls = new Controls
103  {
104  MinuteLimit = 500,
105  SecondLimit = 100,
106  TickLimit = 30
107  };
108  }
109 
110  /// <summary>
111  /// Initialize the backtest task packet.
112  /// </summary>
113  public BacktestNodePacket(int userId, int projectId, string sessionId, byte[] algorithmData, decimal startingCapital, string name)
114  : this (userId, projectId, sessionId, algorithmData, name, new CashAmount(startingCapital, Currencies.USD))
115  {
116  }
117 
118  /// <summary>
119  /// Initialize the backtest task packet.
120  /// </summary>
121  public BacktestNodePacket(int userId, int projectId, string sessionId, byte[] algorithmData, string name, CashAmount? startingCapital = null)
122  : base(PacketType.BacktestNode)
123  {
124  UserId = userId;
125  Algorithm = algorithmData;
126  SessionId = sessionId;
127  ProjectId = projectId;
128  Name = name;
129  CashAmount = startingCapital;
130  Language = Language.CSharp;
131  Controls = new Controls
132  {
133  MinuteLimit = 500,
134  SecondLimit = 100,
135  TickLimit = 30
136  };
137  }
138  }
139 }