GithubHelp home page GithubHelp logo

benmakesgames / marketholidays Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 10 KB

extends the DateTime class, adding methods to determine whether or not today is a "market holiday" (for stocks)

License: Creative Commons Zero v1.0 Universal

C# 100.00%

marketholidays's Introduction

Buy Me a Coffee at ko-fi.com

Why?

Determining whether or not a given day is a "market holiday" is tricky. The rules are as follows:

  • If the date is one of the observed holidays, and it's on a weekday, okay: it's a market holiday
  • If the date is one of the observed holidays, and it's on a Sunday, then the following Monday is a market holiday
  • If the date is one of the observed holidays, and it's on a Saturday, then the previous Friday is a market holiday, UNLESS you're checking for New Year's day, in which case New Year's day is not observed this year

And then there's the whole business of holidays being on the Xth Monday of whatever month, bla-bla-bla. And don't even get me started on calculating Easter/Good Friday!

More details can be found all over the internet. I happened to find these particularly useful:

I GUESS you could look up a list of dates and hand-code them in, years in advance, but... no thanks. Humans are too error-prone. Better to make the computer figure it out.

Example usage

using MarketHolidays;

...

DateTime tomorrow = DateTime.Today.AddDays(1);

if(tomorrow.IsChristmasHoliday()) // the 25th on most years, but the 24th or 26th on some
    Console.WriteLine("Tomorrow is Christmas Day (observed)");

if(tomorrow.IsMarketHoliday())
    Console.WriteLine("Tomrrow is some kind of market holiday.");

marketholidays's People

Contributors

benmakesgames avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

totalinferno

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.