Lean  $LEAN_TAG$
ExanteFeeModel.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;
18 
20 {
21  /// <summary>
22  /// Provides an implementation of <see cref="FeeModel"/> that models Exante order fees.
23  /// According to:
24  /// <list type="bullet">
25  /// <item>https://support.exante.eu/hc/en-us/articles/115005873143-Fees-overview-exchange-imposed-fees?source=search</item>
26  /// <item>https://exante.eu/markets/</item>
27  /// </list>
28  /// </summary>
29  public class ExanteFeeModel : FeeModel
30  {
31  /// <summary>
32  /// Market USA rate
33  /// </summary>
34  public const decimal MarketUsaRate = 0.02m;
35 
36  /// <summary>
37  /// Default rate
38  /// </summary>
39  public const decimal DefaultRate = 0.02m;
40 
41  private readonly decimal _forexCommissionRate;
42 
43  /// <summary>
44  /// Creates a new instance
45  /// </summary>
46  /// <param name="forexCommissionRate">Commission rate for FX operations</param>
47  public ExanteFeeModel(decimal forexCommissionRate = 0.25m)
48  {
49  _forexCommissionRate = forexCommissionRate;
50  }
51 
52  /// <summary>
53  /// Gets the order fee associated with the specified order.
54  /// </summary>
55  /// <param name="parameters">A <see cref="OrderFeeParameters"/> object
56  /// containing the security and order</param>
57  /// <returns>The cost of the order in a <see cref="CashAmount"/> instance</returns>
58  public override OrderFee GetOrderFee(OrderFeeParameters parameters)
59  {
60  var order = parameters.Order;
61  var security = parameters.Security;
62 
63  decimal feeResult;
64  string feeCurrency;
65  switch (security.Type)
66  {
67  case SecurityType.Forex:
68  var totalOrderValue = order.GetValue(security);
69  feeResult = Math.Abs(_forexCommissionRate * totalOrderValue);
70  feeCurrency = Currencies.USD;
71  break;
72 
73  case SecurityType.Equity:
74  var equityFee = ComputeEquityFee(order);
75  feeResult = equityFee.Amount;
76  feeCurrency = equityFee.Currency;
77  break;
78 
79  case SecurityType.Option:
80  case SecurityType.IndexOption:
81  var optionsFee = ComputeOptionFee(order);
82  feeResult = optionsFee.Amount;
83  feeCurrency = optionsFee.Currency;
84  break;
85 
86  case SecurityType.Future:
87  case SecurityType.FutureOption:
88  feeResult = 1.5m;
89  feeCurrency = Currencies.USD;
90  break;
91 
92  default:
93  throw new ArgumentException(Messages.FeeModel.UnsupportedSecurityType(security));
94  }
95 
96  return new OrderFee(new CashAmount(feeResult, feeCurrency));
97  }
98 
99  /// <summary>
100  /// Computes fee for equity order
101  /// </summary>
102  /// <param name="order">LEAN order</param>
103  private static CashAmount ComputeEquityFee(Order order)
104  {
105  switch (order.Symbol.ID.Market)
106  {
107  case Market.USA:
109 
110  default:
111  return new CashAmount(order.AbsoluteQuantity * order.Price * DefaultRate, Currencies.USD);
112  }
113  }
114 
115  /// <summary>
116  /// Computes fee for option order
117  /// </summary>
118  /// <param name="order">LEAN order</param>
119  private static CashAmount ComputeOptionFee(Order order)
120  {
121  return order.Symbol.ID.Market switch
122  {
123  Market.USA => new CashAmount(order.AbsoluteQuantity * 1.5m, Currencies.USD),
124  _ =>
125  // ToDo: clarify the value for different exchanges
126  throw new ArgumentException(Messages.ExanteFeeModel.UnsupportedExchange(order))
127  };
128  }
129  }
130 }