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  public const decimal MarketUsaRate = 0.02m;
32  public const decimal DefaultRate = 0.02m;
33 
34  private readonly decimal _forexCommissionRate;
35 
36  /// <summary>
37  /// Creates a new instance
38  /// </summary>
39  /// <param name="forexCommissionRate">Commission rate for FX operations</param>
40  public ExanteFeeModel(decimal forexCommissionRate = 0.25m)
41  {
42  _forexCommissionRate = forexCommissionRate;
43  }
44 
45  /// <summary>
46  /// Gets the order fee associated with the specified order.
47  /// </summary>
48  /// <param name="parameters">A <see cref="OrderFeeParameters"/> object
49  /// containing the security and order</param>
50  /// <returns>The cost of the order in a <see cref="CashAmount"/> instance</returns>
51  public override OrderFee GetOrderFee(OrderFeeParameters parameters)
52  {
53  var order = parameters.Order;
54  var security = parameters.Security;
55 
56  decimal feeResult;
57  string feeCurrency;
58  switch (security.Type)
59  {
60  case SecurityType.Forex:
61  var totalOrderValue = order.GetValue(security);
62  feeResult = Math.Abs(_forexCommissionRate * totalOrderValue);
63  feeCurrency = Currencies.USD;
64  break;
65 
66  case SecurityType.Equity:
67  var equityFee = ComputeEquityFee(order);
68  feeResult = equityFee.Amount;
69  feeCurrency = equityFee.Currency;
70  break;
71 
72  case SecurityType.Option:
73  case SecurityType.IndexOption:
74  var optionsFee = ComputeOptionFee(order);
75  feeResult = optionsFee.Amount;
76  feeCurrency = optionsFee.Currency;
77  break;
78 
79  case SecurityType.Future:
80  case SecurityType.FutureOption:
81  feeResult = 1.5m;
82  feeCurrency = Currencies.USD;
83  break;
84 
85  default:
86  throw new ArgumentException(Messages.FeeModel.UnsupportedSecurityType(security));
87  }
88 
89  return new OrderFee(new CashAmount(feeResult, feeCurrency));
90  }
91 
92  /// <summary>
93  /// Computes fee for equity order
94  /// </summary>
95  /// <param name="order">LEAN order</param>
96  private static CashAmount ComputeEquityFee(Order order)
97  {
98  switch (order.Symbol.ID.Market)
99  {
100  case Market.USA:
101  return new CashAmount(order.AbsoluteQuantity * MarketUsaRate, Currencies.USD);
102 
103  default:
104  return new CashAmount(order.AbsoluteQuantity * order.Price * DefaultRate, Currencies.USD);
105  }
106  }
107 
108  /// <summary>
109  /// Computes fee for option order
110  /// </summary>
111  /// <param name="order">LEAN order</param>
112  private static CashAmount ComputeOptionFee(Order order)
113  {
114  return order.Symbol.ID.Market switch
115  {
116  Market.USA => new CashAmount(order.AbsoluteQuantity * 1.5m, Currencies.USD),
117  _ =>
118  // ToDo: clarify the value for different exchanges
119  throw new ArgumentException(Messages.ExanteFeeModel.UnsupportedExchange(order))
120  };
121  }
122  }
123 }