Using results of a daily screen on an intraday strategy
Author: rmandel00
Creation Date: 12/5/2009 11:47 AM
profile picture

rmandel00

#1
I have written a daily screen that I run after the close that gives me a relatively small list of stocks to test the next morning on an intraday strategy. I can export the results of that screen to a csv file but would then like to use that symbol list directly in the intraday strategy by having the strategy read the file as its list of stocks. The csv file is in the format symbol, date, close, volume. I realize that I can open the csv file, copy the list of symbols, paste them into a new data set using data manager and then run it. I would like however, to more directly access the screened symbol file.

The strategy as originally written did both screening and intraday alert operations together. However, the list of stocks is around 400, which runs too slowly on intraday bars. Splitting the strategy into an initial screen and secondary scan would be a more efficient way of receiving alerts for trades. I could then run the strategy in real time and make entry decisions quickly.

I have looked on the site and have not found any examples and would appreciate any help in this matter.
Thanks in advance.
Rich Man
profile picture

Eugene

#2
An easy solution is to write a simple class that would accept source file name as a parameter in its constructor. A method for parsing the CSV file. Put the symbols found in the file in a list e.g. public List<string>. And a boolean function that accepts a symbol string and checks if this string is contained within the List.

Next, in your intraday strategy you would create an instance of that class, passing the source CSV file name. Using the boolean function, check if the symbol being processed by the strategy is from your short list of stocks. Otherwise skip the symbol using "return".
profile picture

rmandel00

#3
I have been looking for examples of how to parse a csv file here and haven't found anything useful. I have changed the file construction so that it consists of symbols separated by commas. Are there any examples around of parsing such a file and using the string to compare with the symbol being processed. I am not an experienced C# programmer and need help.
Thanks,
Rich Man
profile picture

Eugene

#4
For sure, our Wealth-Lab 5 Wiki has a couple of examples:

Knowledge Base > HowTo | Access Internet sites and collect historical data on-the-fly
Or download the source code of Community.Components and review the FillSeriesFromFile method

And think .NET: there should be tons of examples of CSV file parsing in C# out there on the internet.
profile picture

rmandel00

#5
Eugene:
My problem was: I have written a daily screen using a data set of 400 ETFs. I run it after the close that gives me a relatively small list of stocks to test the next morning on an intraday strategy. I want to run these screened stocks, not the complete data set the next morning to trade intraday.

My simple solution is: I took my daily screen and added StreamWriter commands to create an xml file with the format required for a data set, resident in the same folder where the WLP data sets reside. I can run the daily screen on my global data set and export those stocks that satisfy the screen into a new data set. The next morning I can run my intraday strategy live using 1 or 5 minute bars on the screened data set. I found this to be a simple solution to my problem.

Thanks for your help.
Rich Man
profile picture

Eugene

#6
Rich,

If using StreamWriter to serialize a DataSet into an XML file was a "simple" solution for you, then you have my respect. Also an interesting and creative approach, although it requires restarting WLP to read the new DataSet.
profile picture

rmandel00

#7
Eugene,
Thanks again. I noticed that it was necessary to restart WLP to see the new file so I wondered if there was a way to update the data set list without a restart. That is not really a problem since the screen is run in the evening and is used the next morning. I usually turn the computer off when I go to sleep.
Rich Man
profile picture

Eugene

#8
Unfortunately, altering many of the Wealth-Lab's XML files such as strategies, datasets or Symbol Info Mgr config requires a restart.
profile picture

thodder

#9
Eugene,

On 12/5/2009 12:15 PM you wrote:

QUOTE:
check if the symbol being processed by the strategy is from your short list of stocks. Otherwise skip the symbol using "return".


I like this simple approach with one exception, an intraday strategy run at a scale of 1 minute with 400 symbols would most likely cause me to run out of memory during the collecting data stage of running the strategy against a dataset. I would never get to the point of running my intraday strategy. I believe this is part of the reason why Rich needs to create a dataset with a subset of the original 400 symbols.

I have a 3G RAM XP machine, so I do not have the maximum configuration (4G RAM with the 3G boot switch set), but it still shows that intraday strategies need to be run on a smaller dataset than daily strategies. A 64-bit Windows 7 machine with at least 4G RAM might have a little more wiggle room, but I believe Fidelity's WLP is still limited to 4G as it is treated as a 32-bit application.

Having the capability to generate a dynamic dataset from within a strategy would be a cool feature.
profile picture

Eugene

#10
QUOTE:
Having the capability to generate a dynamic dataset from within a strategy would be a cool feature.

Robert and yours truly have been constantly pushing the idea to Fidelity.
QUOTE:
but I believe Fidelity's WLP is still limited to 4G as it is treated as a 32-bit application.

That's right. :/ They have to rewrite Fidelity Server as a managed component first to jump out of the WOW64 subsystem.
profile picture

thodder

#11
QUOTE:
Robert and yours truly have been constantly pushing the idea to Fidelity.

I thought you might. Hopefully this will give you more fuel to push. ;-)
profile picture

Cone

#12
Not really. You guys (customers) need to call Fidelity to tell them what you need. If only a dozen of you guys would call in about the same thing, they'll get the picture.
profile picture

thodder

#13
When I backtest against a dataset, can I tell when the test starts and ends within my strategy script? Basically I'd like to be able to do the following:

1) Clear a list of symbols when my backtest starts;
2) Add each symbol that passes my criteria and give it a priority;
3) At the end of the backtest on the dataset, review all the symbols that passes my criteria and only pick the top 5 or 10. These will be written to my dynamic dataset or list.

At the moment my script can only do option #2. I'd like to know when the test starts and ends so I can do #1 and #3.

One thought was to look at the DataSetSymbols. If I'm processing symbol DataSetSymbols[0], then this must be the first; if I'm processing DataSetSymbols[DataSetSymbols.Count - 1], then I must be processing the last. For that to work, I'd have to know that the order of DataSetSymbols matches the order the that the strategy code is called.

Any thoughts?
profile picture

Eugene

#14
You got it right: DataSetSymbols is the answer to when the test starts and ends within a strategy:

WealthScript Techniques | Executing some code only once

The order of DataSetSymbols is alphabetical and matches the order that the strategy code is called.
profile picture

thodder

#15
Thanks, Eugene! I used this logic in your link:
CODE:
Please log in to see this code.


This technique only works if a backtest is run against the entire dataset. If only a single symbol is run, then it doesn't work as planned.

* Only first symbol, it hits only the "First run on" logic;
* Only last symbol, it hits only the "Last run on" logic;
* Symbols other than the first and last will not hit either of these conditions.

Since I am attempting to modify a dataset in the "Last run on" logic, this is the step that can cause some confusion as it will replace my dataset symbols when I may not have expected it.

It would be nice to know in my strategy if this is a single symbol run or a run against a dataset of symbols. The only time I want to update my dynamic dataset is if I run against all the symbols in the dataset. I don't believe there is a property or method to tell me the type of run.

Fyi, Eugene you are right that the symbols are in alphabetical order when the dataset is updated by WLP. Since I am hacking the dataset list of symbols, I need to put them in sorted order if I want them to be in sorted order when WLP retrieves them. Just a little note in case someone else tries to do this hack.
profile picture

Eugene

#16
QUOTE:
It would be nice to know in my strategy if this is a single symbol run or a run against a dataset of symbols.

I don't know if there's a property exposed (or not) that tells it.
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).