Export OHLCV data for a range of dates
Author: akar
Creation Date: 3/11/2019 2:55 AM
profile picture

akar

#1
I want to export OHLCV data for a range of dates to CSV files. One csv file will hold OHLCV data for a particular day e.g. ALL_SYMS-2019-02-07.csv will hold OHLCV data for every stock only for Feb 7th

I got it working for a single date but it is not working for the range of dates. Can you please look at the code and tell me what I'm doing wrong.

CODE:
Please log in to see this code.
profile picture

Eugene

#2
Matching dates should be done using the .Date property rather than via string comparison but why complicate things at all? Simply choose a "Date Range" in data loading options e.g. 2019/2/1 to 2019/2/15. Case closed.
profile picture

akar

#3
It's not working. I'm getting the following error:

Error processing symbol AAPL Object reference not set to an instance of an object.

Can you please try this and see what I'm missing ?
profile picture

Eugene

#4
What should be working? Am I overlooking some updated code here without the ListOfDates and a .ToDate-based comparison? Can't find any.

As for the error in general please refer to the Knowledge Base (Wiki) article: Errors | Strategy > Object reference not set to an instance of an object.
profile picture

akar

#5
I rewrote the code and it' still giving the "Object reference not set to an instance of an object. ". So something somewhere is not getting initialized and I can't figure it out. I ran the GetDataRange after compiling it with csc.exe and it's returning the list. Can you please tell me what's going on or what's the best way to debug this:



CODE:
Please log in to see this code.
profile picture

Eugene

#6
Not sure if you've overlooked my reply #2 with the obvious solution. Since I haven't seen an explanation as to why the code has to work the way you're trying it to make then it's up to you to do your troubleshooting:

How can I debug my trading strategies in Wealth-Lab?
profile picture

akar

#7
I overlooked the #2 comment. What you suggested is a much better solution. I changed the code (listed below). However, the code only prints the data for the last date. I set the Date Range in WL to 2019-01-01 to 2019-01-04. However it only prints data for 2019-01-04.

CODE:
Please log in to see this code.
profile picture

Eugene

#8
QUOTE:
However, the code only prints the data for the last date.

No, it prints the data for the last two bars. There are 3 bars in that time span but for some reason you've modified the working code from Exporting to ASCII comma-separated files (CSV) to exclude the first bar:

CODE:
Please log in to see this code.

If you retract the unnecessary change it will output all the 3 bars. Run this in Multi-Symbol mode:

CODE:
Please log in to see this code.
profile picture

akar

#9
Oops my bad! Thanks for pointing it out.

Only one problem remains. All the data is getting written into the same file i.e. the one with the last date. How do I change the program to write the data to separate files ?

Thanks again for all your comments and help.
profile picture

Eugene

#10
QUOTE:
All the data is getting written into the same file i.e. the one with the last date.

That's how I gather your intention was. The file name clearly indicates that everything gets dumped into one file:
CODE:
Please log in to see this code.


QUOTE:
How do I change the program to write the data to separate files ?

Just revisit the Wiki article for the code example which already does just that - export to separate files:

Exporting to ASCII comma-separated files (CSV)
profile picture

akar

#11
I'm trying to get EOD data for every symbol on a file named after that date
i.e. 2019-01-05.csv will have the OHLCV data for every stock in the dataset for Jan 5, 2019

The challenge I'm facing is to how to write the output to the correct files i.e. how to match the file name with the date
e.g. let's say there are 2 symbols in the dataset AAPL FB

I want the Jan 03.2019 data for both FB and AAPL to go to 2019-01-03.csv.

AAPL
Jan 04, 2019 144.53 148.55 143.80 148.26 147.63 58,607,100 -> 2019-01-04.csv
Jan 03, 2019 143.98 145.72 142.00 142.19 141.58 91,312,200 -> 2019-01-03.csv
Jan 02, 2019 154.89 158.85 154.23 157.92 157.25 37,039,700 -> 2019-01-02.csv

FB
Jan 04, 2019 134.01 138.00 133.75 137.95 137.95 29,002,100 -> 2019-01-04.csv
Jan 03, 2019 134.69 137.17 131.12 131.74 131.74 22,717,900 -> 2019-01-03.csv
Jan 02, 2019 128.99 137.51 128.56 135.68 135.68 28,146,200 -> 2019-01-02.csv
profile picture

akar

#12
I replaced
CODE:
Please log in to see this code.

to
CODE:
Please log in to see this code.


and it works now.

Thank you so much for your time and help.

profile picture

Eugene

#13
You're welcome. I'm glad you got it working.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).