Giter Site home page Giter Site logo

go-calendar-fork's Introduction

SCM logo Exchange Calendars

Build Status License: MIT

A Golang package of Exchange Calendars

Exchange calendars are defined by their ISO-10383 Market Identifier Code (MIC).

Usage

// Get pre-defined exchange +/- 5 years around current year
nyse := XNYS()
// Or starting on specfic year, end on year + 10
nyse := XNYS(2010)
// Or between a start year and an end year (both included)
nyse := XNYS(2010, 2025)

now := time.Now()

nyse.IsBusinessDay(now)
nyse.IsHoliday(now)
nyse.IsEarlyClose(now)

nyse.IsOpen(now)

t := nyse.NextBusinessDay(now)
t, h := nyse.NextHoliday(now)
t := nyse.NextClose(now)

nyse.SetYears(2020,2021)

fmt.Print(nyse)

Calendar New York Stock Exchange:
	2020-Jan-01 Wed    New Year's Day
	2020-Jan-20 Mon    Martin Luther King Jr. Day
	2020-Feb-17 Mon    Presidents' Day
	2020-Apr-10 Fri    Good Friday
	2020-May-25 Mon    Memorial Day
	2020-Jul-03 Fri    Independence Day
	2020-Sep-07 Mon    Labor Day
	2020-Nov-26 Thu    Thanksgiving Day
	2020-Nov-27 Fri ec Black Friday
	2020-Dec-24 Thu ec Christmas Eve
	2020-Dec-25 Fri    Christmas Day
	2021-Jan-01 Fri    New Year's Day
	2021-Jan-18 Mon    Martin Luther King Jr. Day
	2021-Feb-15 Mon    Presidents' Day
	2021-Apr-02 Fri    Good Friday
	2021-May-31 Mon    Memorial Day
	2021-Jul-05 Mon    Independence Day
	2021-Sep-06 Mon    Labor Day
	2021-Nov-25 Thu    Thanksgiving Day
	2021-Nov-26 Fri ec Black Friday
	2021-Dec-24 Fri    Christmas Day

Existing Calendar

Market place Exchange MIC
New York New York Stock Exchange XNYS
New York NASDAQ XNAS
Chicago CBOE XCBO
Chicago CBOE Futures Exchange XCBF
Toronto Toronto Stock Exchange XTSE
Mexico Mexican Stock Exchange XMEX
Sao Paulo BMF Bovespa BVMF
London London Stock Exchange XLON
Amsterdam Euronext Amsterdam XAMS
Brussels Euronext Brussels XBRU
Lisbon Euronext Lisbon XLIS
Paris Euronext Paris XPAR
Milan Euronext Milan - Borsa Italiana XMIL
Madrid Bolsa de Madrid XMAD
Franckfurt Deutsche Boerse XFRA
Franckfurt Xetra XETR
Zurich SIX Swiss Exchange XSWX
Mumbai Bombay Stock Exchange XBOM
Bangkok Stock Exchange of Thailand XBKK
Singapore Singapore Exchange XSES
Hong Kong Hong Kong Stock Exchange XHKG
Shenzhen Shenzhen Stock Exchange XSHE
Shanghai Shanghai Stock Exchange XSHG
Seoul Korea Exchange XKRX
Tokyo Japan Exchange Group XJPX
Sidney Austrialian Securities Exchange XASX

Creating Holidays & Calendars

// Create Recurring Holidays
MemorialDay = &Holiday{
    Name:       "Memorial Day",
    Month:      time.May,
    Weekday:    time.Monday,
    NthWeekday: -1,
    calc:       CalcNthWeekday,
}
IndependenceDay = &Holiday{
    Name:       "Independence Day",
    Month:      time.July,
    Day:        4,
    observance: nearestWorkday,
    calc:       CalcDayOfMonth,
}

// Create Non Recurring Holidays
// September 11 - september 11, 2001
SeptemberEleven = &Holiday{
    Name:   "Sepember 11",
    Month:  time.September,
    Day:    11,
    OnYear: 2001,
    calc:   CalcDayOfMonth,
}

// September 11 -14 range
SeptemberElevenDays = []*Holiday{
    SeptemberEleven,
    SeptemberEleven.Copy("Sepember 11 day 2").SetOffset(1),
    SeptemberEleven.Copy("Sepember 11 day 3").SetOffset(2),
    SeptemberEleven.Copy("Sepember 11 day 4").SetOffset(3),
}

// Copy an Holiday and set observance
NewYear.Copy("New Year's Day").SetObservance(sundayToMonday)

// Create a Calendar
c := NewCalendar("New York Stock Exchange", NewYork, 2010, 2025)
// Set Session
c.SetSession(&Session{
    EarlyOpen:  7 * time.Hour,
    Open:       9*time.Hour + 30*time.Minute,
    Close:      16 * time.Hour,
    EarlyClose: 13 * time.Hour,
    LateClose:  20 * time.Hour,
})
// Add Recurring Holidays
c.AddHolidays(
    NewYear.Copy().SetObservance(sundayToMonday),
    MLKDay,
    PresidentsDay,
    GoodFriday,
    MemorialDay,
    IndependenceDay,
    LaborDay,
    ThanksgivingDay,
    ChristmasDay.Copy().SetObservance(nearestWorkday),
)
// Add Non Recurring Holidays
c.AddHolidays(USNationalDaysOfMourning...)
c.AddHolidays(SeptemberElevenDays...)
c.AddHolidays(HurricaneSandyDays...)
// Early Closing
c.AddEarlyClosingDays(
    BeforeIndependenceDay.Copy().SetObservance(onlyOnWeekdays(time.Monday, time.Tuesday, time.Thursday)),
    AfterIndependenceDay.Copy().SetBeforeYear(2013).SetObservance(onlyOnWeekdays(time.Friday)),
    BeforeIndependenceDay.Copy().SetAfterYear(2013).SetObservance(onlyOnWeekdays(time.Wednesday)),
    BlackFriday,
    ChristmasEve.Copy().SetObservance(exeptOnWeekdays(time.Friday)), // Overlap Christmas day observance if friday
)

go-calendar-fork's People

Contributors

pchavanne avatar

Watchers

 avatar

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.