Hi everyone!
I have a question about using external data (specifically a csv from dropbox). I have data about events that happen that impact different stocks. The format for my CSV file is:
"date", "symbol", "value"
While using the GetSource/Reader method it's apparent I can't have multiple symbols in my csv. Is there a way to use GetSource with a csv that has multiple symbols? Should I abandon this approach and use the `self.download` method? Where should I call this method if I want the file to be downloaded once for backtesting and everyday for live trading?
Thanks!
SLPAdvisory
I woudl've thought you could have got the symbol through this?
var index = new Custom(); try { string[] data = line.Split(','); index.Time = DateTime.Parse(data[0]); index.Symbol = Convert.ToString(data[1]); index.Value = Convert.ToDecimal(data[2]); } catch { } return index;
Gurumeher Sawhney
Using the GetSource and Reader methods while having multiple symbols is possible. This example below shows an example of overriding the GetSource and Reader methods and returning a list of stocks. The StockDataSource(PythonData) should be similar to the implementation needed in this case. A new list of stocks is read from the .csv file and returned every day to be traded. The dropbox links in the sample code above can still be accessed as a resource to see how the data is properly parsed.
Brett Elliot
Thanks guys! I will try the AddUniverse method! That looks promising!
William, in python you cannot set the symbol of the data source based on a value in the csv. I don't know why but it has to be set to `config.symbol`.
Brett Elliot
Thanks for the reply Gurumeher Sawhney. I've been playing with the algo and I have a question. My csv contains dates that occur on non-trading days. When this happens, the data is fed to the algo on the next trading day. I'm sure this is reasonable in many cases but not in mine.
How can I make the algo only trade the symbols in the csv on the date listed (and if the date listed is not a trading day, then skip it).
Ive tried this but it didn't work:
def stockDataSource(self, data):
list = []
for item in data:
if self.Time.date() == item.Time.date():
for symbol in item["Symbols"]:
list.append(symbol)
return list
Here I attempt to only add the symbols if the current date is equal to the date in the csv. This results in no symbols ever being added. How can I keep the symbols from being added if the simulation date is not the date in the CSV? Or how can I skip trading if the simulation date isn't the date the symbols were meant to be traded on?
Thanks!
Theo Wesley Sekgetho
Good day Mr Gurumeher Sawhney, I went through the algorithm you shared and I was wondering if you could please help me make it work with forex data. I basically want it to retrieve news events dates and time. Secondly it should execute stop odrders 3 minutes before the news realease. Thirdly it should be able to updaate the currency pairs and the next news event time and date. I am a novice in programming and anybody's input would be highly appreciated. Thank you.
Jack Simonson
Hi Theo,
You can make similar code work for Forex news/events data if you want to import your own, but you will need to work with the Reader and GetSource methods that Gurumeher linked to above to make sure the algorithm is correctly parsing your data.
Timing your Stop Order for before a news release will be tricky. If you have a custom data source that lists expected news release times, then you can add this as mentioned above and then you'd be able to place stop orders at a specific time before an anticipated news release. Otherwise, your algorithm will have to place orders as a reaction to news releases as they happen.
As for updating Forex data, this will happen automatically! If using QuantConnect Forex, then you have nothing to worry about. However, if you are using custom data, the algorithm relies on the GetSource and Reader methods to properly parse and feed data into the rest of the algorithm. Using the example above, in backtesting, the custom data would be read once from the Dropbox source and then passed into the algorithm automatically. In LiveMode (live trading), the algorithm would make a call to another Dropbox source containing files being updated in real-time. It would then parse these files and pass the most recent data into the rest of the algorithm as they occur.
Theo Wesley Sekgetho
Good day,
Mr Link Liang managed to help with adjusting the traading times. I still had a hard time trying to adjust the csv reading algo that Mr Gurumeher Sawhney posted above in order to use it for reading trading dates as my input. So I manually made a list of event dates within the algo instead, however I want to know how can I make the algo read the next dates on the list and not only the first one. With regards to the csv reader ,I don't know how to adjust it to read my dates from the csv as the template was mainly for choosing symbols to trade. It would have been better if the algo had some explainations in some lines.
Thank you
Amine Kouta
Hi Gurumeher Sawhney,
It doesn't seem that the links to dropbox can be accessed still in the link you provided:
https://github.com/QuantConnect/Lean/blob/cbd953437f987392f2c2e154adcb7d43d684b7f1/Algorithm.Python/DropboxBaseDataUniverseSelectionAlgorithm.py
I would like to know how the data is entered (tickers in dropbox file). I appreciate your help.
Thanks you,
Brett Elliot
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!