Hi Team,
I was wondering if we could get an example algorithm using a List
I always learn best from reading other code. It took me a little bit of thinking to get TradeBar data for a list of symbols.
QUANTCONNECT COMMUNITY
Hi Team,
I was wondering if we could get an example algorithm using a List
I always learn best from reading other code. It took me a little bit of thinking to get TradeBar data for a list of symbols.
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.
Nicholas Stein
Nicholas Stein
John Rewolinski
Jared Broad
// In Initialize List _symbols = new List { "IBM", "SPY", "AAPL" };
foreach (var symbol in _symbols) {
AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
}
public override void OnData(Slice data)
{
foreach (var bar in data.Bars)
{
//Every _symbols trade bar will appear here every minute: bar.Close
}
//Also can access via Securities:
var price = Securities["IBM"].Close;
}
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.
Rob Sauce
Rob Sauce
Nicholas Stein
Xenmind
Hi All,
I'm taking a look at @Nicholas Stein's great template above. I'm getting an error at the following line:
foreach (string t in symbolarray) { Symbols.Add(new Symbol(t)); }The error is: There is no argument given that corresponds to the required formal parameter 'value' of 'Symbol.Symbol(SecurityIdentifier, string)'
How should I modify this line to get it working please?
Thanks,
Gavin.
Nicholas Stein
Hi Gavin,
I wrote the algorithm back in December 2015. The platform has evolved quite a bit since then. Make sure you are using the latest build of the QC Engine. Here is what I used to run the attached back test. Older versions of the engine used a different Symbol class.
I just compiled and ran a back test of the attached algorithm and it ran fine, except for the horrible returns. :0)
Xenmind
Thanks so much Nicholas, love your work!
G
Xenmind
@Nicholas Stein and anyone else with insight:
I'm using Nicholas' framework above. I'm trying to modify it to trade off custom minute tradebars in Lean. While it uses minute tradebars as input, it seems to consolidate the data to daily frequency, and then trades at the following open.
The problem is I can't see any consolidator code. Which part of the code is doing the consolidation, and what needs to change to pass the minute data through?
Any help would be appreciated.
Thanks,
Gavin.
Alexandre Catarino
Hi Gavin,
After checking the code and the generated trades, it doesn't seem to me that data is consolidated. Yes, some trades happen on the following open/day, but most of the happen on the same day and several minutes after the open. Minute data is being passed through.
Here is a code snippet where we set custom minute bars and set up indicators with automatic updates:
class Example : QCAlgorithm { private SimpleMovingAverage fast; private SimpleMovingAverage slow; public override void Initialize() { SetEndDate(DateTime.Today.AddDays(-1)); SetStartDate(EndDate.AddYears(-1)); SetCash(100000); AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute); // TradeBar consolidator for a 10 minutes bar var minConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(10)); // Attach the event handler (function that will be called each time we produce a new consolidated piece of data). minConsolidator.DataConsolidated += OnTenMinutes; // Adds our consolidator to the manager in order to receive updates from the engine SubscriptionManager.AddConsolidator("SPY", minConsolidator); fast = new SimpleMovingAverage(2); slow = new SimpleMovingAverage(4); // Manually register these indicators for automatic updates RegisterIndicator("SPY", fast, minConsolidator); RegisterIndicator("SPY", slow, minConsolidator); } private void OnTenMinutes(object sender, TradeBar bar) { if(fast > slow) { SetHoldings("SPY", 1); } else { SetHoldings("SPY", -1); } } public void OnData(TradeBar data) { // } }
Xenmind
Hi,
Thanks for taking a look man, I thought I had posted yesterday that I'd solved it (or at least know what the issue is), but no post is present. I wrote some custom code to input IB data, but I think the index must be off, hence the behaviour of 1 value in any day and fillforward data for the remainder of the day. Default data inputs properly.
Cheers,
Gavin.
John Rewolinski
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!