Lean  $LEAN_TAG$
Trade.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 
19 {
20  /// <summary>
21  /// Represents a closed trade
22  /// </summary>
23  public class Trade
24  {
25  /// <summary>
26  /// The symbol of the traded instrument
27  /// </summary>
28  public Symbol Symbol { get; set; }
29 
30  /// <summary>
31  /// The date and time the trade was opened
32  /// </summary>
33  public DateTime EntryTime { get; set; }
34 
35  /// <summary>
36  /// The price at which the trade was opened (or the average price if multiple entries)
37  /// </summary>
38  public decimal EntryPrice { get; set; }
39 
40  /// <summary>
41  /// The direction of the trade (Long or Short)
42  /// </summary>
43  public TradeDirection Direction { get; set; }
44 
45  /// <summary>
46  /// The total unsigned quantity of the trade
47  /// </summary>
48  public decimal Quantity { get; set; }
49 
50  /// <summary>
51  /// The date and time the trade was closed
52  /// </summary>
53  public DateTime ExitTime { get; set; }
54 
55  /// <summary>
56  /// The price at which the trade was closed (or the average price if multiple exits)
57  /// </summary>
58  public decimal ExitPrice { get; set; }
59 
60  /// <summary>
61  /// The gross profit/loss of the trade (as account currency)
62  /// </summary>
63  public decimal ProfitLoss { get; set; }
64 
65  /// <summary>
66  /// The total fees associated with the trade (always positive value) (as account currency)
67  /// </summary>
68  public decimal TotalFees { get; set; }
69 
70  /// <summary>
71  /// The Maximum Adverse Excursion (as account currency)
72  /// </summary>
73  public decimal MAE { get; set; }
74 
75  /// <summary>
76  /// The Maximum Favorable Excursion (as account currency)
77  /// </summary>
78  public decimal MFE { get; set; }
79 
80  /// <summary>
81  /// Returns the duration of the trade
82  /// </summary>
83  public TimeSpan Duration
84  {
85  get { return ExitTime - EntryTime; }
86  }
87 
88  /// <summary>
89  /// Returns the amount of profit given back before the trade was closed
90  /// </summary>
91  public decimal EndTradeDrawdown
92  {
93  get { return ProfitLoss - MFE; }
94  }
95 
96  /// <summary>
97  /// Returns whether the trade was profitable (is a win) or not (a loss)
98  /// </summary>
99  /// <returns>True if the trade was profitable</returns>
100  /// <remarks>
101  /// Even when a trade is not profitable, it may still be a win:
102  /// - For an ITM option buyer, an option assignment trade is not profitable (money was paid),
103  /// but it might count as a win if the ITM amount is greater than the amount paid for the option.
104  /// - For an ITM option seller, an option assignment trade is profitable (money was received),
105  /// but it might count as a loss if the ITM amount is less than the amount received for the option.
106  /// </remarks>
107  public bool IsWin { get; set; }
108  }
109 }