I am new to the QuantConnect and I am compiling on the deskop via VS.NET 2013. I am trying to do two things
1 - I connect to local data for equity aapl in the folder Equity\usa data.
2 - I am trying to create a customdata feed via Yahoo
I have found that none of them has triggered the OnData event at all on the debug mode. It does not seem to pass the symbol into the custom data feed as well.
I just copied from the sample codes and also I put all codes in the initialize routine.
public override void Initialize()
{
SetStartDate(2011, 9, 13);
SetEndDate(DateTime.Now.Date.AddDays(-1));
SetCash(100000);
//AddData<Yahoo>("SPY", Resolution.Daily);
//Define the symbol and "type" of our generic data:
AddSecurity(SecurityType.Equity, "aapl", Resolution.Daily);
}
//Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
public void OnData(TradeBars data)
{
// "TradeBars" object holds many "TradeBar" objects: it is a dictionary indexed by the symbol:
//
// e.g. data["MSFT"] data["GOOG"]
if (!Portfolio.HoldStock)
{
int quantity = (int)Math.Floor(Portfolio.Cash / data["SPY"].Close);
//Order function places trades: enter the string symbol and the quantity you want:
Order("SPY", quantity);
//Debug sends messages to the user console: "Time" is the algorithm time keeper object
Debug("Purchased SPY on " + Time.ToShortDateString());
//You can also use log to send longer messages to a file. You are capped to 10kb
//Log("This is a longer message send to log.");
}
}
Jared Broad
Is your AAPL data in place in the data folder?
Does your AAPL data cover the range you've requested? 2011, 9,13 -> Present.
Are you infact getting a runtime error from requesting the SPY close price?
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.
Alexandre Catarino
Hi Leng,
I copied the code above and ran it locally. The OnData event handler is triggered.
Since you did not add "SPY" via AddSecurity method in Initialise, the data parameter does not have "SPY", therefore data["SPY"] does not exist (data does not have the "SPY" key) and the algorithm throws an error. It has APPL as expected.
Like Jared said, you need to check if you have aapl.zip on Data\equity\usa\daily folder. If not, you can get it on Github: aapl.zip.
About your custom data. Did you copy the Yahoo class from the docs?
public class Yahoo : BaseData { public decimal Open, High, Low, Close, AdjustedClose, Volume; // Return the URL external source for the data: public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLive) { // Using Quandl Wrapper on Yahoo Finance API to Sort Data: var url = "https://www.quandl.com/api/v1/datasets/YAHOO/" + config.Symbol + ".csv?sort_order=asc&exclude_headers=true"; return new SubscriptionDataSource(url, SubscriptionTransportMedium.RemoteFile); } // Convert each line of the file above into an object. public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLive) { Yahoo yBar = new Yahoo(); try { string[] data = line.Split(','); yBar.Symbol = config.Symbol; // Required. yBar.Time = DateTime.ParseExact(data[0], "yyyy-MM-dd", CultureInfo.InvariantCulture); yBar.Open = Convert.ToDecimal(data[1]); yBar.High = Convert.ToDecimal(data[2]); yBar.Low = Convert.ToDecimal(data[3]); yBar.Close = Convert.ToDecimal(data[4]); yBar.Volume = Convert.ToDecimal(data[5]); yBar.AdjustedClose = Convert.ToDecimal(data[6]); yBar.Value = yBar.AdjustedClose; // Required for portfolio calculations } catch { } return yBar; } }
Leng Dieb
Thank you. I have check that the data in my folder Data\Equity\usa\aapl.zip has everything from 1998. This is the example that come with the github that I download. I debug the intialization and found that they added the ticker aapl using AddSecurity function. I changed the SetEndDate just a few days after the start and found that the dates exist in the aapl.zip but the event OnData was NOT triggered still.
I found that
public override void Initialize() { SetStartDate(2011, 9, 13); SetEndDate(2011, 9, 25); SetCash(100000); AddSecurity(SecurityType.Equity, "aapl", Resolution.Daily); } public void OnData(TradeBars data) { if (!Portfolio.HoldStock) { int quantity = (int)Math.Floor(Portfolio.Cash / data["appl"].Close); Order("appl", quantity); Debug("Purchased appl on " + Time.ToShortDateString()); } }
It might be issue that I got this error on the start ? When I start running my codes I found this error. But when I debug the codes all folders are correctly read and see the below screen
It's really strange that it just does not trigger OnData event at all. I put debug point from the first line in this OnData but it just does not do anything.
I hope you can you help -
Jared Broad
Thank you for the additional information; can you put a breakpoint in TradeBars.Reader()
1 Watch the data coming into the method;
2 Make sure its parsed into a tradebar, check the time stamp on the bar.
What is your localization settings (datetime settings) on your PC? Can you change them to US Standard number format Eastern Time zone to see if that fixes it?
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.
Leng Dieb
Many thanks for your prompt support -
I have tried more by chaging tme-zone but it does not works at all. It does not go to the OnData at all. I just would like to ask you if I code a service that download data from the different market (the service like Yahoo) and the timezone is different and I just code using Online Terminal coding - shall that be ok to work the same way as it use the data from your server ?
I am not sure what is wrong with OnData event at all. I appreciate if you can link to any sample project for VS.Net so that I can give it a try to figure out what is wrong with my project.
Regards,
till. Please see the attached file -
Alexandre Catarino
Hi Leng,
Could you please reinstall Lean following the Contributor's Guide?
Initial Setup
- Setup a GitHub account
- Fork the repository of the project
- Clone your fork locally
$ git clone https://github.com/username/Lean.git- Navigate to the QuantConnect Lean directory and add the upstream remote
$ cd Lean $ git remote add upstream https://github.com/QuantConnect/Lean.gitThe remote upstream branch links your fork of Lean with our master copy, so when you perform a
git pull --rebase
you'll be getting updates from our repository.After install
QuantConnect.Lean.sln
in Visual Studioctrl-f5
to run without debugging. By default Visual Studio includes NuGet, if your version cannot find DLL references, install Nuget and build again.That will execute the BasicTemplateAlgorithm.
Edit BasicTemplateAlgorithm.cs with your code and rerun it.
Leng Dieb
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!