Ok, my brain is about to explode. I'm sure someone with a little more knowledge than me can help. Most of my experience writing C# has been for small programs where I don't need to worry about inheritance and such. Fairly basic stuff.
So I have a few classes set up. One class has two values, the SymbolName and the data for that Symbol.
I have a sublist of that setup to house two different data sets of type SharePrices.
I am trying to figure out a way to add TradeBar data to the list of completeData for each symbolData for each corresponding SymbolName.
Basically I need to populate SharePrices, each minute, store that in list completeData which will happen for each symbolData corresponding to each SymbolName. I hope I explained that right. Any help is appreciated.
I have it set up to AddSecurity() correctly at initialization. But I can't seem to figure out how to add data more than one level deep.
public void AddSecurities()
{
for(int i = 0; i < symbolsList.Count; i++)
{
AddSecurity(SecurityType.Equity, symbolsList.ElementAt(i).ToString(), Resolution.Minute);
}
}
public void AddSymbols_toList()
{
for(int i = 0; i < SymbolsForAlgorithm.Length; i++)
{
symbolsList.Add(new SymbolList { SymbolName = SymbolsForAlgorithm[i]});
}
}
public class SymbolList
{
public string SymbolName { get; set; }
public List
public override string ToString()
{
return String.Format("{0}", SymbolName);
}
}
public class SymbolData
{
public List
public List
}
public class SharePrices
{
public DateTime Date { get; set; }
public decimal Price { get; set; }
public override string ToString()
{
return String.Format("{0}", "{1}", Date, Price);
}
}
Paul Saunders
public void OnData(TradeBars data) { foreach (var bar in data) { symbolsList.Single(x => SymbolName == bar.Symbol).symbolData.completeData.Add(new SharePrices{Date = bar.Time, Price = bar.Close}); } }
The first part is a bit of Linq to get the correct item from SymbolList, and may require ausing System.Linq;
at the top of your file.Paul Saunders
public void OnData(TradeBars data) { foreach (var bar in data) { symbolsList.Single(x => SymbolName == bar.Symbol) .symbolData .completeData .Add(new SharePrices{Date = bar.Time, Price = bar.Close}); } }
John Rewolinski
Paul Saunders
public List Test { get; set; } = new List();
what is really happening in the background is this:private List _test = new List();
public List Test
{
get { return _test; }
set { _test = value; }
}
which in turn is this:private List _test;
public List Test
{
get { return _test; }
set { _test = value; }
}
private ClassConstructor()
{
_test = new List();
}
And all that is really saying is: When I create an object, make sure that my "Test" property is instantiated with a new List of type int. This prevents you having to bother with tests for null all through the rest of your code. You may already have known that, but it may be helpful to someone else who's starting out.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!