Why FindNamedSeries returns 0 in Rotation strategy?
Author: changhengyiu
Creation Date: 5/13/2017 3:38 PM
profile picture

changhengyiu

#1
Using FindNamedSeries to plot or create trading signal in single or basket strategy is no problem for me. I have problem with the FindNamedSeries method in "Rotation" Strategy. Please tell me why the script can only create one time trading at the first beginning and Entry Name shows 0 . I post the script which is revised from "Weak-stock rotation[Rev.C]"
CODE:
Please log in to see this code.
profile picture

Eugene

#2
QUOTE:
Please tell me why the script can only create one time trading at the first beginning and Entry Name shows 0

Who knows. Currently there's not much to work with. Knowing this could bring more clues:

+ data provider,
+ does it affect just one (e.g. Database) or all (e.g. ASCII too) providers
+ data loading settings
+ symbols
+ bar scale
+ does the named series actually exist
+ is its bar scale different from the primary symbol's

and so forth.
profile picture

changhengyiu

#3
Much Thanks Eugene for the clues.
I thought it was coding error because of my limited coding knowledge just now.
I check following points you mentioned. the database is created by ASCII adding few fields and I just named them "1","2","3","4"...etc
I can see the ploting line for "4" this field so it means the data is exist .Please check the attached photo.
CODE:
Please log in to see this code.

Second, time scale setting is as same as txt data in the attached picture. I learned from user guid
QUOTE:
Custom Fields currently work only in the data's native time frame. For example, if you have a daily DataSet, Custom Field data is not available if you switch to Weekly scale from the toolbar.
I am curious the situation I still can see plotting line when adjusting time scale from daily to weekly or monthly

anyway, setting to daily still not working for creating signals.
Could you take glance on the script one more time to see if i make mistake inside?
CODE:
Please log in to see this code.


Is that correct putting "DataSeries MySeries2 ' in this section??
profile picture

Eugene

#4
Thanks Hank, that's cleared it. I think that you've re-encountered a bug. It was known but somehow slipped in and went unnoticed for a long time. (I'm not sure but it could have been introduced as early as in v6.6.)

Off the top of my head, there are two workarounds:

1. As exemplified here, use the overloaded call for GetExternalSymbol which accepts dataSetName:

Why FindNamedSeries in GetExternalSymbol doesn't return data?, post#2

CODE:
Please log in to see this code.


2. For some reason, GetAllDataForSymbol from Community Components isn't affected. You can use it like this:

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

Eugene

#5
P.S.

1. Added the two workarounds discovered to the Open Issues list.

2. Reported the issue to Fidelity.
profile picture

changhengyiu

#6
Thanks Eugene,that really helps!
It works perectly! I choose GetExternalSymbol method because it takes much less time to run.
profile picture

changhengyiu

#7
One more point, this way could backtest weekly or monthly time scale with daily txt data.
it seems break the limit that mentioned in user guid.
QUOTE:
Custom Fields currently work only in the data's native time frame. For example, if you have a daily DataSet, Custom Field data is not available if you switch to Weekly scale from the toolbar.
profile picture

Eugene

#8
Glad to have helped.

QUOTE:
it takes much less time to run

That's right: GetAllDataForSymbol heavily depends on System.Reflection which is resource consuming. GetExternalSymbol is a natural choice that comes w/o speed penalty.
profile picture

changhengyiu

#9

GetExternalSymbol method solve the problem.
There comes one more trouble. This way takes a lot of time to do one time backtesting.
With 500 symbols in dataset, and 14 fields in a ASCii txt for 7 years, it takes one hour to do one time backtesting.
Wen i try 40 fields, it takes endless time.
If there any sugestion for me to do stock backtesting with fundimental data out of US?
profile picture

Eugene

#10
ASCII data is cached by the provider so it's hardly a factor, and 7 years * 500 symbols doesn't look like a resource hog. So which step consumes the most time i.e. where does the strategy execution stuck the most? There might be an inefficiency in your code related to GetExternalSymbol or not. For example, check out tip #2 re: visualizers in this FAQ: Strategy runs slow, or provide us more detail to work with. Thanks.
profile picture

changhengyiu

#11
The code is following. thanks Eugene
Cache ASCII Data is checked also.
Is the bug in original post solved?

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

Eugene

#12
QUOTE:
Is the bug in original post solved?

There are no current plans to resolve this issue.

Kindly bear in mind that what you're using is a workaround so trade-offs like a slowdown may apply.

Fortunately for you, it's possible to speed this code up 2-3 times by omitting the resource-intensive task of calling SetContext (followed by RestoreContext) for queriying the named series because GetExternalSymbol does a SetContext under the hood.

EDITED

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

changhengyiu

#13
By doing that,there comes a error message.

CODE:
Please log in to see this code.



I type in here." Runtime error:Basis price for Position entry cannot be zero"
profile picture

Eugene

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

changhengyiu

#15
Hi Eugene
unfortunatetly it is still the same error message.
Runtime error:Basis price for Position entry cannot be zero
Is there any other way without using GetexternalSymbol?It really too much time consuming.
profile picture

Eugene

#16
Hi Hank,

QUOTE:
Is there any other way without using GetexternalSymbol?It really too much time consuming.

In my test, commenting out the SetContext resulted in a 2-3x speed gain. And at the risk of repeating, this a workaround. If you don't like it for whatever reason and can't load less stocks, data, or performance visualizers, there's another one: GetAllDataForSymbol. Both come with a speed penalty. Since there's no bug resolution we have to live with this.

QUOTE:
unfortunatetly it is still the same error message.

I cannot reproduce the error and the code above with my tweaks works correctly on Y! data with data sources like Quandl returning dummy NamedSeries data instead of your ASCII files. (However, ASCII is not the culprit - it's about the code or your data). Try this:
CODE:
Please log in to see this code.


Then try different data loading ranges (All Data, Fixed Bars) as opposed to "Most Recent X years".

If this doesn't work, here are some troubleshooting suggestions:
a) kindly review pointers to troubleshooting this error: Basis price for Position entry cannot be zero (Error message),
b) wrap relevant parts of code in try/catch block to understand where the error is rooted, and
c) debug your strategy using SharpDevelop or Visual Studio Community ed. as described in this KB article to instantly spot the error source: How can I debug my trading strategies in Wealth-Lab?

Good luck!
profile picture

Eugene

#17
P.S. Please keep in mind that according to our terms of use, visiting it from behind a proxy server of any kind is not something allowed.