Can anyone tell me which part of this algorithm needs to be added into an existing algorithm in order to cancel out the transaction fees?
using QuantConnect.Orders.Fees;
namespace QuantConnect
{
/*
* QuantConnect University: Zero Fee Transaction Model
*
* Transaction model with zero fees.
*/
public class OverrideTransactionModelsAlgorithm : QCAlgorithm
{
string _symbol = "IBM";
bool _boughtToday = false;
/// <summary>
/// Initialize your algorithm configuration (cash, dates, securities)
/// </summary>
public override void Initialize()
{
//Set the start and end dates for backtest:
SetStartDate(2013, 06, 01);
SetEndDate(DateTime.Now.Date.AddDays(-1));
//Set algorithm cash:
SetCash(200000);
//Add all the securities you'd like:
AddSecurity(SecurityType.Equity, _symbol, Resolution.Minute);
//Set your own fee model: Securities is the collection of company objects
Securities[_symbol].FeeModel = new ConstantFeeModel(0);
}
/// <summary>
/// TradeBars Data Event Handler - all IBM data passed into the data object: data["IBM"].Close
/// </summary>
public void OnData(TradeBars data)
{
//Meaningless algorithm which buys on the 15th day of the month:
// Using this we can test our $5,000 order fee :)
if (Time.Day % 15 == 0 && _boughtToday == false) {
Order(_symbol, 5);
Debug("Sent order for " + _symbol + " on " + Time.ToShortDateString());
_boughtToday = true;
} else if (Time.Day % 15 != 0) {
_boughtToday = false;
}
}
}
}
JayJayD
Hey Ryan,
I’m not sure what do you mean by “cancel out the transaction fees”.
Do you mean running the algorithm without transaction cost? The algorithm you shared is exactly the example of how you can configure Lean to run with a fixed fees and commission (in this case zero).
In case you want to simulate some brokerage model you can change line 31 from:
Securities[_symbol].FeeModel = new ConstantFeeModel(0);
to:
SetBrokerageModel(new InteractiveBrokersBrokerageModel());
As in the attached backtest.
For more information, please read the docs.
JJD
Ryan Quinley
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!