Automatically calculate public holidays from 1900-2203

Optuma Forums Optuma Scripting Automatically calculate public holidays from 1900-2203

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #54047
    • Topics: 13
    • Replies: 25
    • Posts: 38

    Hello Optuma scripting community.

    Mathew, Matthew, Darren, the Optuma support team and the Optuma scripting community have always been very helpful to me, so I thought I might give something back.

    This post is about a script that automatically calculates public holidays and therefore when markets are closed.

    And you are welcomed to use it.

    I found that in backtesting of my trading strategies it became important to know when public holidays were or will be, but it was quite a distraction to be constantly searching the internet to get answers to questions like ‘when was Good Friday in 2005?’, or ‘why is there no bar in an Optuma daily chart for Friday 22 April, 2011?’

    So I developed a script that automatically calculates public holidays. The MS Excel community has been doing this for years, and I was able to ‘borrow’ the Excel formulas for calculating public holidays and apply them in an Optuma script. And, with Optuma 1.4, new essential script functions like MOD, and the new ‘Numbers’ feature of Show Bar made it possible.

    The attached screen shot (US Public Holidays on SPX) shows the outcome of the script, applied to a daily SPX chart. Each number on the chart corresponds to one of the nine annual public holidays in the US. (You will also see a ’10’ as well: that was an irregular holiday for the state funeral of George Bush Snr… the script handles those sorts of scenarios too).

    While I have not tested the whole range, the Excel community reckons that Excel calculates all public holidays accurately from 1900- 2203, even the tricky ones like Good Friday. I use this script on my live strategies, and have found it to be accurate from 1980 – present so far.

    Now the trick is that there is no data on a public holiday when markets are closed, so Optuma won’t show a daily bar for a public holiday. Fair enough. So to indicate a public holiday on a daily chart, you need to do something like indicating it the day or week before, which sort of makes sense because you really want to know in advance when the markets are closed. So this script gives you the option of indicating 1 day or 7 days before the public holiday.

    The script is intended to be ‘plug-n-play’ so you should be able to just copy the code of this post and try it out for yourself. If you do use it and have some problems I will try to support you as best I can through this forum, but there is always the possibility of issues that I can’t resolve because it is highly likely our environment setups are different. What I also can’t do is warrant the script, so please be aware that you are using it at your own risk. You should understand it, test it, and be satisfied that it is accurate before applying it to your live trading strategies.

    This script is possibly not for the faint-hearted. It’s almost 200 lines long but does have substantial explanatory commentary within it. You can copy and paste and follow the instructions of the Show Bar to get an output like the screen shot, but if that doesn’t work first up, you will need to roll up your sleeves and start debugging.

    You might notice some strange looking things like  ‘@alias’, ‘@constant’, ‘{integer}’, ‘{1|o}’ etc. in the comments. Don’t worry about them, they don’t affect the script. (They’re there because I am developing an auto-documentation generator for Optuma scripts, which is in an alpha-testing phase at the moment).

    As a final note, the script has been developed for US public holidays only, but if there is sufficient interest from the Optuma scripting community, I will build an Australia public holiday equivalent. Just reply to this post if you are interested in an Aussie version.

    Now, here it comes. It’s also attached in a file also for your convenience. Good luck, and I hope that some of you find it useful!

    Cheers, Dean






    • Topics: 13
    • Replies: 25
    • Posts: 38
    2 users thanked author for this post.
    Trevor R
    • Topics: 123
    • Replies: 356
    • Posts: 479

    Hi Dean

    Absolutely fantastic!! Many thanks for sharing.

    Australian Public Holidays would also be very useful for this Aussie.

    Then there are the holidays in UK, Europe (especially France and Germany), Singapore, Hong Kong, Japan, India and all the other markets that Optuma users watch.

    You could take a real whipping meeting world wide demand.



    • Topics: 40
    • Replies: 2,014
    • Posts: 2,054

    That’s Awesome Dean, thanks so much for sharing.

    • Topics: 40
    • Replies: 62
    • Posts: 102

    I guess we’ll see this in an Optuma update 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest