I have the following AMM OnEndPeriod code I want to run always EOM, even if weekend or no marketdata (different exchanges). How can I make sure the Roc and comp() functions evaluate always the last available close price, so that ranking always includes all symbols even if some have no data?
Looking for something like Roc(12,LASTDATA), guess you have a trick for this?
- What happens with comp() if not all symbols have data on this date?
It will use only symbols that have data. The other symbols are not analyzed at all since they don't have data on that date.
One quick tip: Use the screener to check and verify these kind of things. Type your formula, select your symbols, select a date then check the result.
- In order to include all symbols even if they do not have data, you can use:
getseries("Symbol Name", close)
and parse the formula using the same symbol (the one that has all the data).
Thanks! Tried different versions in below screener, but none includes symbols if they have no data on the selected date. I would like to get the last available close if current bar no data.
LB_Momo = 84;
a = comp(log(GetSeries(Name(),close,LastData)/ ref(GetSeries(Name(),close,LastData),LB_Momo )),"rank!");
b= comp(log(close/ ref(close,LB_Momo)),"rank!");
c = GetSeries(Name(),close,LastData);
addColumn("comp with GetSeries", a);
addColumn("comp without GetSeries", c[3]);
addColumn("GetSeries", c);
filter = 1;
I had some strange switches in my rotation systems, and just figured out it is because of some holidays.. Little tricky thing..
.. and one follow-up question / thought: If prices have different "time gaps" due to different holiday schedules or just missing prices, this then also affects for example correlation / covariance analysis, where "aligned" price / performance data is crucial. For this, the performance data would then need a clean-up, e.g. eliminate prices or set equal to previous if not all tickers have market data this date before calculating performance.
Have looked in the forum, but not found any topic in this line.. Maybe worth a function for more accurate analysis.
What you are trying to do cannot be done in the screener.
Name() will get the current analyzed symbol so "GetSeries(Name(),close)" is equivalent to "close"
In the MM Script, you can type for example:
string[] symbols = Data.GetSymbols();
foreach(string symbol in symbols)
{
MMParser parser= Data.ParseFormula("a = getseries('" + symbol + "', close);");
TimeSeries a = parser.GetTimeSeries("GOOG", "a"); // Symbol that has all the data
}
For other functions such as correlation, getseries..., the data is automatically aligned.
The "comp" function is different since it analyzes all symbols at once.
Sorry, once more. Below works, e.g. last price even if no market data. But next question is how to get this into comp() like in first post, e.g. to generate ranking by symbol. I use Top5, so checking just highest score is not an option. If you have a trick, it would be appreciated, if not I build a custom sorting function.
string[] symbols = Data.GetSymbols();
foreach(string symbol in symbols)
{
MMParser parser= Data.ParseFormula("a = getseries('" + symbol + "', close);");
TimeSeries a = parser.GetTimeSeries("GOOG", "a"); // Symbol that has all the data
}
Jus use the "comp" function. Example:
MMParser parser= Data.ParseFormula("a = comp(getseries('" + symbol + "', close), ' rank');");
Since calculation is based on one symbol here (GOOG), the same bars will be used for all other referenced symbols (GetSeries)
Great, this works great for ranking! Last question to this topic :-)
Now I obviously have some zero values in the return timeseries c below, a.g. at least one of symbols no close data, but set to LastDate and dates are aligned perfectly for comp(). Now, before passing returns to solver, is there any any smart way in QS language to eliminate the c return bars where at least one return is zero, but keeping dates aligned ? If not will do in c# array, but means quite some looping..
MMParser parser= Data.ParseFormula("a = getseries('" + symbolclose + "', close, LastData); b= comp(a,'rank!\); c = log(a/ref(a,1));"); // Get time series aligned to first symbol, but still contains 0 values..
TimeSeries ts = parser.GetTimeSeries(symbolclosefixed, "b"); // Symbol that has all the data
Usually you will get 0 when it is the first bar or there is no data for a certain security.
If you "A" has data from 2000 to 2010 and you align symbol "C" with data from 2001 to 2010, you will get 0 or Nan data for period 2000-2001 for "C".
You can eliminate first bars only using C#. Needs just two loops here. (one for the securities and one for each trading bar - TimeSeries)
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.