Lean  $LEAN_TAG$
IndiaFeeModel.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 
17 using System;
18 
20 {
21  /// <summary>
22  /// Provides the default implementation of <see cref="IFeeModel"/> Refer to https://www.samco.in/technology/brokerage_calculator
23  /// </summary>
24  public class IndiaFeeModel : IFeeModel
25  {
26  /// <summary>
27  /// Brokerage calculation Factor
28  /// </summary>
29  protected virtual decimal BrokerageMultiplier { get; set; }
30 
31  /// <summary>
32  /// Maximum brokerage per order
33  /// </summary>
34  protected virtual decimal MaxBrokerage { get; set; }
35 
36  /// <summary>
37  /// Securities Transaction Tax calculation Factor
38  /// </summary>
39  protected virtual decimal SecuritiesTransactionTaxTotalMultiplier { get; set; }
40 
41  /// <summary>
42  /// Exchange Transaction Charge calculation Factor
43  /// </summary>
44  protected virtual decimal ExchangeTransactionChargeMultiplier { get; set; }
45 
46  /// <summary>
47  /// State Tax calculation Factor
48  /// </summary>
49  protected virtual decimal StateTaxMultiplier { get; set; }
50 
51  /// <summary>
52  /// Sebi Charges calculation Factor
53  /// </summary>
54  protected virtual decimal SebiChargesMultiplier { get; set; }
55 
56  /// <summary>
57  /// Stamp Charges calculation Factor
58  /// </summary>
59  protected virtual decimal StampChargesMultiplier { get; set; }
60 
61  /// <summary>
62  /// Checks if Stamp Charges is calculated from order valur or turnover
63  /// </summary>
64  protected virtual bool IsStampChargesFromOrderValue { get; set; }
65 
66  /// <summary>
67  /// Gets the order fee associated with the specified order.
68  /// </summary>
69  /// <param name="parameters">
70  /// A <see cref="OrderFeeParameters"/> object containing the security and order
71  /// </param>
73  {
74  if (parameters.Security == null)
75  {
76  return OrderFee.Zero;
77  }
78  var orderValue = parameters.Order.GetValue(parameters.Security);
79 
80  var fee = GetFee(orderValue);
81  return new OrderFee(new CashAmount(fee, Currencies.INR));
82  }
83 
84  private decimal GetFee(decimal orderValue)
85  {
86  bool isSell = orderValue < 0;
87  orderValue = Math.Abs(orderValue);
88  var multiplied = orderValue * BrokerageMultiplier;
89  var brokerage = (multiplied > MaxBrokerage) ? MaxBrokerage : Math.Round(multiplied, 2);
90 
91  var turnover = Math.Round(orderValue, 2);
92 
93  decimal securitiesTransactionTaxTotal = 0;
94  if (isSell)
95  {
96  securitiesTransactionTaxTotal = Math.Round(orderValue * SecuritiesTransactionTaxTotalMultiplier, 2);
97  }
98 
99  var exchangeTransactionCharge = Math.Round(turnover * ExchangeTransactionChargeMultiplier, 2);
100  var clearingCharge = 0;
101 
102  var stateTax = Math.Round(StateTaxMultiplier * (brokerage + exchangeTransactionCharge), 2);
103 
104  var sebiCharges = Math.Round((turnover * SebiChargesMultiplier), 2);
105  decimal stampCharges = 0;
106  if (!isSell)
107  {
109  {
110  stampCharges = Math.Round((orderValue * StampChargesMultiplier), 2);
111  }
112  else
113  {
114  stampCharges = Math.Round((turnover * StampChargesMultiplier), 2);
115  }
116  }
117 
118  var totalTax = Math.Round(brokerage + securitiesTransactionTaxTotal + exchangeTransactionCharge + stampCharges + clearingCharge + stateTax + sebiCharges, 2);
119 
120  return totalTax;
121  }
122  }
123 }