예제 #1
0
    def getHistoricalAdjustedPriceData(self, symbol, start_date, end_date, time_interval):
        d1 = str(start_date.getDay())
        m1 = str(start_date.getMonth() - 1)
        y1 = str(start_date.getYear())
        d2 = str(end_date.getDay())
        m2 = str(end_date.getMonth() - 1)
        y2 = str(end_date.getYear())

        if time_interval == "daily":
            time_interval = "d"
        elif time_interval == "weekly":
            time_interval = "w"
        elif time_interval == "monthly":
            time_interval = "m"

        URL = "http://ichart.finance.yahoo.com/table.csv?s=" + symbol + "&b=" + d1
        URL += "&a=" + m1 + "&c=" + y1 + "&e=" + d2 + "&d=" + m2 + "&f=" + y2 + "&g="
        URL += time_interval + "&ignore=.cvs"

        csv_dict = self.getCSVDictForApiCall(URL)
        price_obj_list = []
        for index in csv_dict:
            if (str(index) == "0"):
                continue
            hist_price_obj = YAFIObjects.YAFIObjectHistoricalPrice(csv_dict[index])
            price_obj_list.append(hist_price_obj)
        return price_obj_list
예제 #2
0
    def getAdjustedPriceDataForDate(self, symbol, date):
        if symbol not in self.price_history_cache:
            successful = self.cachePriceData(symbol)
            if not successful:
                return None

        date_price_dict = self.symbol_date_price_hashmap[symbol]
        date_string = date.getAsString()
        if date_string not in date_price_dict:
            return None
        return YAFIObjects.YAFIObjectHistoricalPrice(date_price_dict[date_string])
예제 #3
0
    def getAdjustedPriceDataRangeStack(self, symbol, start_date, end_date):
        if symbol not in self.price_history_cache:
            successful = self.cachePriceData(symbol)
            if not successful:
                return None

        stack = YAFIObjects.HistoricalAdjustedPriceRangeStack()
        date_prices_map = self.symbol_date_price_hashmap[symbol]
        date_counter = end_date
        while True:
            date_string = date_counter.getAsString()
            if date_counter < start_date:
                break
            if date_string in date_prices_map:
                hist_price_obj = YAFIObjects.YAFIObjectHistoricalPrice(date_prices_map[date_string])
                stack.addPriceObject(hist_price_obj)
            date_counter = date_counter.getBeforeDayDate()
        return stack
예제 #4
0
    def getAdjustedPriceDataRangeStackForAmountOfDays(self, symbol, end_date,
                                                      days):
        if symbol not in self.price_history_cache:
            return None

        fail_counter = 0
        stack = YAFIObjects.HistoricalAdjustedPriceRangeStack()
        date_prices_map = self.symbol_date_price_hashmap[symbol]
        date_counter = end_date
        while True:
            date_string = date_counter.getAsString()
            if days == 0 or fail_counter >= 7:
                break
            if date_string in date_prices_map:
                hist_price_obj = YAFIObjects.YAFIObjectHistoricalPrice(
                    date_prices_map[date_string])
                stack.addPriceObject(hist_price_obj)
                days -= 1
                fail_counter = 0
            date_counter = date_counter.getBeforeDayDate()
            fail_counter += 1
        return stack