Ejemplo n.º 1
0
 def test_DateIndex_offset(self):
     'it should test DateIndex'
     holidays = load_holidays('ANBIMA.txt')
     di = DateIndex(holidays,
                    startdate=min(holidays),
                    enddate=max(holidays),
                    weekdays=(5, 6))
     self.assertEqual(di.offset('2011-01-07', 1).isoformat(), '2011-01-10')
     self.assertEqual(di.offset('2011-01-10', -1).isoformat(), '2011-01-07')
Ejemplo n.º 2
0
 def test_DateIndex_following_preceding(self):
     'it should test DateIndex'
     holidays = load_holidays('ANBIMA.txt')
     di = DateIndex(holidays,
                    startdate=min(holidays),
                    enddate=max(holidays),
                    weekdays=(5, 6))
     self.assertEqual(di.following('2011-01-01').isoformat(), '2011-01-03')
     self.assertEqual(di.following('2011-01-03').isoformat(), '2011-01-03')
     self.assertEqual(di.preceding('2011-01-09').isoformat(), '2011-01-07')
     self.assertEqual(di.preceding('2011-01-07').isoformat(), '2011-01-07')
Ejemplo n.º 3
0
 def test_DateIndex_seq(self):
     'it should test DateIndex'
     holidays = load_holidays('ANBIMA.txt')
     di = DateIndex(holidays,
                    startdate=min(holidays),
                    enddate=max(holidays),
                    weekdays=(5, 6))
     seq = di.seq('2011-01-03', '2011-01-14')
     self.assertEqual(seq[0].isoformat(), '2011-01-03')
     self.assertEqual(seq[-1].isoformat(), '2011-01-14')
     seq = di.seq('2011-01-03', '2011-01-03')
     self.assertEqual(len(seq), 1)
Ejemplo n.º 4
0
 def test_DateIndex_getdate2(self):
     holidays = load_holidays('ANBIMA.txt')
     di = DateIndex(holidays,
                    startdate=min(holidays),
                    enddate=max(holidays),
                    weekdays=(5, 6))
     self.assertEqual(
         di.getdate('first day', 2002, 1).isoformat(), '2002-01-01')
     self.assertEqual(
         di.getdate('first bizday before first day', 2002, 1).isoformat(),
         '2001-12-31')
     self.assertEqual(
         di.getdate('2nd bizday before first day', 2002, 1).isoformat(),
         '2001-12-28')
def get_calendar():
    holidays = load_holidays('ANBIMA.txt')
    return Calendar(holidays, ['Sunday', 'Saturday'])
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 20 18:07:18 2020

@author: massa
"""

import numpy as np
import pandas as pd
import requests
import urllib.request
from bs4 import BeautifulSoup
from tqdm import tqdm
from datetime import datetime
from bizdays import Calendar, load_holidays
holidays = load_holidays('Brazil.txt')
cal = Calendar(holidays, ['Sunday', 'Saturday'], name='Brazil')


def strip_date(date):
    """
    Recebe uma variável string e retorna uma tupla com os valores de dia, mês e
    ano.
    """
    d = datetime.strptime(date, "%Y-%m-%d")
    year = d.year
    month = d.month
    day = d.day
    if month < 10:
        month = '0' + str(month)
    if day < 10:
Ejemplo n.º 7
0
 def test_DateIndex_getdate(self):
     holidays = load_holidays('ANBIMA.txt')
     di = DateIndex(holidays,
                    startdate=min(holidays),
                    enddate=max(holidays),
                    weekdays=(5, 6))
     self.assertEqual(
         di.getdate('15th day', 2002, 1).isoformat(), '2002-01-15')
     self.assertEqual(
         di.getdate('first day before 15th day', 2002, 1).isoformat(),
         '2002-01-14')
     self.assertEqual(
         di.getdate('second day after 15th day', 2002, 1).isoformat(),
         '2002-01-17')
     self.assertEqual(
         di.getdate('second bizday before 15th day', 2002, 1).isoformat(),
         '2002-01-11')
     self.assertEqual(
         di.getdate('second bizday after 15th day', 2002, 1).isoformat(),
         '2002-01-17')
     self.assertEqual(
         di.getdate('first bizday', 2002, 1).isoformat(), '2002-01-02')
     self.assertEqual(
         di.getdate('second bizday', 2002, 1).isoformat(), '2002-01-03')
     self.assertEqual(
         di.getdate('third bizday', 2002, 1).isoformat(), '2002-01-04')
     self.assertEqual(
         di.getdate('second bizday before 10th bizday', 2002,
                    1).isoformat(), '2002-01-11')
     # zero is before, -1 is before and 1 is after
     self.assertEqual(
         di.getdate('first tue before first day', 2002, 1).isoformat(),
         '2001-12-25')
     self.assertEqual(
         di.getdate('first tue after first day', 2002, 1).isoformat(),
         '2002-01-08')
     # zero is before, -1 is before and 1 is after
     self.assertEqual(
         di.getdate('first tue before second day', 2002, 1).isoformat(),
         '2002-01-01')
     self.assertEqual(
         di.getdate('first tue after second day', 2002, 1).isoformat(),
         '2002-01-08')
     # closest
     self.assertEqual(
         di.getdate('15th day', 2002, 1).isoformat(), '2002-01-15')
     self.assertEqual(
         di.getdate('first bizday', 2002, 1).isoformat(), '2002-01-02')
     self.assertEqual(
         di.getdate('2nd bizday', 2002, 1).isoformat(), '2002-01-03')
     self.assertEqual(
         di.getdate('3rd bizday', 2002, 1).isoformat(), '2002-01-04')
     self.assertEqual(
         di.getdate('first tue', 2002, 1).isoformat(), '2002-01-01')
     self.assertEqual(
         di.getdate('last fri', 2002, 1).isoformat(), '2002-01-25')
     self.assertEqual(
         di.getdate('first day before first day', 2002, 1).isoformat(),
         '2001-12-31')
     self.assertEqual(
         di.getdate('2nd day before first day', 2002, 1).isoformat(),
         '2001-12-30')
     self.assertEqual(
         di.getdate('last day', 2002, 1).isoformat(), '2002-01-31')
     self.assertEqual(
         di.getdate('first bizday before last day', 2002, 1).isoformat(),
         '2002-01-30')
     self.assertEqual(
         di.getdate('second bizday before last day', 2002, 1).isoformat(),
         '2002-01-29')
     self.assertEqual(
         di.getdate('10th fri before 10th bizday', 2002, 5).isoformat(),
         '2002-03-08')
     self.assertEqual(
         di.getdate('first wed after 15th day', 2002, 5).isoformat(),
         '2002-05-22')
     self.assertEqual(
         di.getdate('first wed before 15th day', 2002, 5).isoformat(),
         '2002-05-08')