Ejemplo n.º 1
0
    def __init__(self,
                 nominal,
                 initial,
                 knockIn,
                 knockOut,
                 highRate,
                 lowRate,
                 strike,
                 startDate,
                 endDate,
                 frequency,
                 currency,
                 dayCount="Act/365",
                 adjMethod="Mod. Following",
                 isStub=True):
        self.nominal = nominal
        self.startDate = startDate
        self.endDate = endDate
        self.frequency = frequency
        self.dayCount = dayCount
        self.adjMethod = adjMethod
        self.currency = currency
        self.isStub = isStub
        self.initial = initial
        self.knockInLevel = knockIn * initial
        self.knockOutLevel = knockOut * initial
        self.highRate = highRate
        self.lowRate = lowRate
        self.strikeLevel = strike * initial

        #""" Additional structure to store prices for different dates: Makes it faster and easier to run bootstrap """
        self.prices = {}

        if self.currency == "USD":
            self.holidayArray = holidays.UnitedStates()
        elif self.currency == "SEK":
            self.holidayArray = holidays.Sweden()
        elif self.currency == "JPY":
            self.holidayArray = holidays.Japan()

        self.cfDates = DateUtils.GenerateCashFlowDates(startDate, endDate,
                                                       None, frequency,
                                                       adjMethod, isStub,
                                                       self.holidayArray)
        self.pv = 0.0
        self.cfs = []
        self.cfPVs = []
        self.cfDays = []
        self.dfs = []
        self.pvTotal = 0.0
Ejemplo n.º 2
0
    def __init__(
            self,
            nominal,
            startDate,
            endDate,
            spread,
            frequency,
            currency,
            # koProb,
            dayCount="Act/365",
            adjMethod="Mod. Following",
            isStub=True):
        self.nominal = nominal
        self.startDate = startDate
        self.endDate = endDate
        self.spread = spread
        self.frequency = frequency
        self.dayCount = dayCount
        self.adjMethod = adjMethod
        self.currency = currency
        # self.koProb = koProb
        self.isStub = isStub

        #""" Additional structure to store prices for different dates: Makes it faster and easier to run bootstrap """
        self.prices = {}

        if self.currency == "USD":
            self.holidayArray = holidays.UnitedStates()
        elif self.currency == "SEK":
            self.holidayArray = holidays.Sweden()
        elif self.currency == "JPY":
            self.holidayArray = holidays.Japan()

        self.cfDates = DateUtils.GenerateCashFlowDates(startDate, endDate,
                                                       None, frequency,
                                                       adjMethod, isStub,
                                                       self.holidayArray)
        self.pv = 0.0
        self.cfs = []
        self.cfPVs = []
        self.cfDays = []
        self.dfs = []
        self.pvTotal = 0.0
Ejemplo n.º 3
0
 def get_holidays(self):
     
     """ 
         Holiday handling. Sets holiday effect to the interval of plus one 
         day minus the days before that in the week. And adds a specific
         effect to the fellesferie mondays
         """
     
     if self.country == "NO":
         hdays = holidays.Norway(years = range(2015,2021), include_sundays=False)
     if self.country == "SE":
         hdays = holidays.Sweden(years = range(2015,2021), include_sundays=False)
     hdays_array = []
     
     for dates, name in hdays.items():
         hdays_array.append([dates, name])   
         
     hdays_df = pd.DataFrame(hdays_array, columns=['ds', 'holiday'])
     hdays_df['lower_window'] = - hdays_df['ds'].apply(lambda x: x.weekday())
     hdays_df['upper_window'] = 2
 
     # Get fellesferie
     fellesferie_mondays = pd.DataFrame(columns=['ds', 'holiday'])
     i = 1
     for year in hdays.years:
         print(date(year, 7, 1))
         all_days = pd.date_range(start=date(year, 7, 1), end=date(year, 7, 31), freq='W-MON')[-3:]
         print(all_days)
         all_days_df = pd.DataFrame({'ds': all_days})
         all_days_df['holiday'] = 'felles_'+(all_days_df.index+1).astype(str)
         fellesferie_mondays = pd.concat([fellesferie_mondays, all_days_df])
 
     fellesferie_mondays['lower_window'] = 0
     fellesferie_mondays['upper_window'] = 6
     
     hdays_df = pd.concat([hdays_df, fellesferie_mondays])
     
     return hdays_df
    'NL': 16.570,
    'PL': 38.53,
    'SE': 9.341
}
holiday_op = [
    ('AT', holidays.Austria()),  # holidays for each country
    ('BE', holidays.Belgium()),  # implented this way because of bug in library
    ('CH', holidays.Switzerland()),
    ('CZ', holidays.Czech()),
    ('DE', holidays.Germany()),
    ('DK', holidays.Denmark()),
    ('FR', holidays.France()),
    ('LU', holidays.Luxembourg()),
    ('NL', holidays.Netherlands()),
    ('PL', holidays.Poland()),
    ('SE', holidays.Sweden())
]


def timedata(dt):
    # create time data extra information for influxDB (makes sorting easier)
    timestamp = datetime.fromtimestamp(dt)
    year = timestamp.year
    month = timestamp.month
    hour = timestamp.hour
    minute = timestamp.minute
    weekday = timestamp.weekday()

    # determine the holiday export weight
    # for DE only holiday, holiday = 1.0
    # for DE+ others holidays, holiday > 1.0
Ejemplo n.º 5
0
    def _get_fridays(self, N, start_date=None):
        """
        Get a list of the Fika Fridays.

        If a start date is not supplied, the current date
        is assumed

        Holidays are also defined here for now, due to a bug in
        the holidays package.

        :param N: the number of Fridays that you need
        :param start_date: the starting date
        """

        if not start_date:
            # get current date
            start_date = date.today()

        self.fikaholidays = holidays.Sweden()

        # DEFINE HOLIDAYS
        month = start_date.month
        if month <= 9:
            summer_year = start_date.year
            winter_year = start_date.year
        else:
            summer_year = start_date.year + 1
            winter_year = start_date.year

        # add summer for the coming midsummer and August
        day = date(summer_year, 6, 20)
        while day.month < 9:
            if day not in holidays.Sweden():
                self.fikaholidays.append(day)
            day = day + timedelta(days=1)

        # add winter for the coming Christmas period
        day = date(winter_year, 12, 20)
        weeks_off = 3
        end_day = day + timedelta(weeks=3)
        while day < end_day:
            if day not in holidays.Sweden():
                self.fikaholidays.append(day)
            day = day + timedelta(days=1)

        # GET FRIDAYS
        # index of week
        friday_index = 4

        # Find the next Friday after the start date
        while start_date.weekday() != friday_index:
            start_date = start_date + timedelta(days=1)

        friday = start_date
        while len(self.fikafridays) < N:
            # check for holidays (also on the thursday before)
            thursday = friday - timedelta(days=1)
            if (friday not in self.fikaholidays
                    and thursday not in self.fikaholidays):
                #if friday not in holidays.Sweden() and thursday not in holidays.Sweden():
                self.fikafridays.append(friday)

            # go to the next week
            friday = friday + timedelta(days=7)
Ejemplo n.º 6
0
import datetime as dt
import holidays
import random
from time import sleep
from configparser import ConfigParser
import psycopg2
from psycopg2 import extras
import logging

swe_holidays = holidays.Sweden()


# first define how to read config
# read config files
def read_config(filename='database.ini', section='postgresql'):
    # create a parser

    parser = ConfigParser()
    # read config file
    parser.read(filename)

    # get section, default to postgresql
    db = {}
    if parser.has_section(section):
        params = parser.items(section)
        for param in params:
            db[param[0]] = param[1]
    else:
        raise Exception('Section {0} not found in the {1} file'.format(
            section, filename))
Ejemplo n.º 7
0
 def setUp(self):
     self.holidays_without_sundays = holidays.Sweden(include_sundays=False)
     self.holidays_with_sundays = holidays.Sweden()