Getting the market code *inside* a script?

Hi all,

I want to implement this sort of logic inside a script, then display the next contract expiry date in a watchlist:

if code == 'MESVolSpot' then next_contract_expiry = '2022-09-13' 
else if code == 'MNQVolSpot' then next_contract_expiry = '2022-10-18' 
else if code == 'SVolSpot' then next_contract_expiry = '2022-08-22'
... 
else next_contract_expiry = '0000-00-00'

Hopefully that’s clear enough. Essentially it’s a simple lookup table of contract expiry dates for each of the markets I’m watching. If I don’t have the expiry date for a particular market, then I’ll just return some dummy value for the expiry date

I’ve found a source of contract expiry date data, but what I don’t know is how to get the code (e.g. MESVolSpot) for the market being processed in the script. I can’t find a function within Optuma that returns the market code for the current market being processed by the script.

Ideally I’d implement this logic inside a Python script, but I’m happy to use either the built-in Optuma scripting or Pascal if there’s no way to get the market code inside Python.

Any thoughts on how I can get the current market code from inside a running script?

Thanks in advance

Hi David,

Do you have Pro or Enterprise Services? If so, the fastest way to achieve the result you’re after is via the EDF system:

https://www.optuma.com/working-with-edfs-part1/

You can take the file you have with the contract dates / codes and upload it via EDFs. Those dates can then be referenced in Watchlists and other areas via scripting.

If you do not have EDFs, you can see an example of Ticker specific scripts on the following thread:

https://forum.optuma.com/topic/sector-wise-breadth-data-in-a-watch-list/

This should give you an example you can build your next contract date references from.

Closing this one off, here’s a brief example that shows how to retrieve & use the code of a market inside an Optuma script

contractsExpiringThirdWednesdayEveryThirdMonth = ISTICKER(CODE=ADSpot:CME) or ISTICKER(CODE=ADSpot:AFUT) or ISTICKER(CODE=ADVolSpot:AFUT) or ISTICKER(CODE=ADVolSpot:CME); 
thirdWednesdayEveryThirdMonth = (DAYOFWEEK() == 4) and (DAYNUM() >= 15 and DAYNUM()<=21) and (MONTHNUM()==3 or MONTHNUM() == 6 or MONTHNUM() == 9 or MONTHNUM() == 12);

contractsExpiringThirdWednesdayEveryThirdMonth and thirdWednesdayEveryThirdMonth

This script won’t do anything for markets I haven’t nominated in the first line, and can be used with ShowBar to show contract expiry dates for just those markets. Obviously you can extend this approach further to other use cases.