def test_portfolio_adx_rank(self, mock_get_zipline_hist):
        '''
        test adx ranking using random numbers and partial and empty series
        '''

        a = Portfolio('GE', log=Logger('test'))

        b = Series([random.rand()*10 for i in range(0, 28)])
        mock_get_zipline_hist.return_value = b
        self.assertTrue(a.adx_rank(Timestamp.utcnow()))

        b = Series([random.rand()*10 for i in range(0, 27)])
        mock_get_zipline_hist.return_value = b
        self.assertEqual(a.adx_rank(Timestamp.utcnow()), [])

        b = Series([nan for i in range(0, 28)])
        mock_get_zipline_hist.return_value = b
        self.assertEqual(a.adx_rank(Timestamp.utcnow()), [])
示例#2
0
    def test_class_ops_dateutil(self):
        def compare(x, y):
            assert (int(np.round(Timestamp(x).value / 1e9)) ==
                    int(np.round(Timestamp(y).value / 1e9)))

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now('UTC'), datetime.now(tzutc()))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(Timestamp.utcfromtimestamp(current_time),
                datetime.utcfromtimestamp(current_time))
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(Timestamp.combine(date_component, time_component),
                datetime.combine(date_component, time_component))
示例#3
0
    def adx_rank(self, asof=None, bar_count=28):
        '''
        returns `Portfolio` object instruments ordered by descending ADX rating

        :rtype: `list` of `tuple` objects
        :param asof: as-of date
        :param bar_count: ADX calculation window
        :type asof: `datetime.datetime` type object (default=now)
        :type bar_count: `int`
        '''

        asof = Timestamp.utcnow() if asof is None else Timestamp(asof)
        result = dict()

        for i in self.portfolio:
            f = get_zipline_hist
            b = self.bundle
            c = self.calendar
            dp = self.dataportal
            input = {
                'high': f(i, 'high', asof, bar_count, '1d', b, c, dp),
                'low': f(i, 'low', asof, bar_count, '1d', b, c, dp),
                'close': f(i, 'close', asof, bar_count, '1d', b, c, dp),
            }
            # set ADX or log that we don't have data
            try:
                adx = ADX(input)[-1]
                if isnan(adx):
                    self.log.warn('adx for %s on %s is NaN' % (i.symbol, asof))
                else:
                    result[i] = ADX(input)[-1]
            except Exception as e:
                if 'inputs are all NaN' in str(e):
                    self.log.warn('NaN inputs for %s on %s' % (i.symbol, asof))
                else:  # pragma: no cover
                    raise

        return sorted(result.items(), key=lambda t: t[1], reverse=True)
示例#4
0
    def test_class_ops_pytz(self):
        def compare(x, y):
            assert int(Timestamp(x).value / 1e9) == int(
                Timestamp(y).value / 1e9)

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now("UTC"), datetime.now(timezone("UTC")))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        compare(
            Timestamp.utcfromtimestamp(current_time),
            datetime.utcfromtimestamp(current_time),
        )
        compare(Timestamp.fromtimestamp(current_time),
                datetime.fromtimestamp(current_time))

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(
            Timestamp.combine(date_component, time_component),
            datetime.combine(date_component, time_component),
        )
示例#5
0
    def test_class_ops_pytz(self):
        def compare(x, y):
            assert int((Timestamp(x).value - Timestamp(y).value) / 1e9) == 0

        compare(Timestamp.now(), datetime.now())
        compare(Timestamp.now("UTC"), datetime.now(timezone("UTC")))
        compare(Timestamp.utcnow(), datetime.utcnow())
        compare(Timestamp.today(), datetime.today())
        current_time = calendar.timegm(datetime.now().utctimetuple())
        msg = "timezone-aware Timestamp with UTC"
        with tm.assert_produces_warning(FutureWarning, match=msg):
            # GH#22451
            ts_utc = Timestamp.utcfromtimestamp(current_time)
        compare(
            ts_utc,
            datetime.utcfromtimestamp(current_time),
        )
        compare(
            Timestamp.fromtimestamp(current_time), datetime.fromtimestamp(current_time)
        )
        compare(
            # Support tz kwarg in Timestamp.fromtimestamp
            Timestamp.fromtimestamp(current_time, "UTC"),
            datetime.fromtimestamp(current_time, utc),
        )
        compare(
            # Support tz kwarg in Timestamp.fromtimestamp
            Timestamp.fromtimestamp(current_time, tz="UTC"),
            datetime.fromtimestamp(current_time, utc),
        )

        date_component = datetime.utcnow()
        time_component = (date_component + timedelta(minutes=10)).time()
        compare(
            Timestamp.combine(date_component, time_component),
            datetime.combine(date_component, time_component),
        )
示例#6
0
 def test_zipline_hist(self):
     t = Timestamp.utcnow()
     self.assertTrue(isinstance(get_zipline_hist('GE', 'close', t), Series))
 def truncate_to_alert_timeframe(self, df):
     # Truncate to only data in the timeframe
     return df[Timestamp.utcnow()-self.alert.timeframe_pd<df.index].dropna()
示例#8
0
vacancy_viewer.click()

nav_button_next = driver.find_element_by_id('NavButtonNext')
nav_button_next.click()

driver.implicitly_wait(10) # Wait up to 10 seconds to wait for elements to load on page

apartments = driver.find_elements_by_xpath('//*[@rmssellevel="Building"]') #Finally at vacancy viewer, find all clickable building menus to display information for each
#print(apartments)
count_buildings = 0

apartment_information = pd.DataFrame(columns=['room_id', 'room_type', 'available_spaces', 'apt_building', 'floor', 'suite_id', 'bed_spaces', 'timestamp'])

while True:
        start_time = time.time()
        timestamp = Timestamp.utcnow()
        for building in apartments: #For each building we can click, click it and begin diving deeper and scraping its information
            if building != driver.find_element_by_id('ELAIDBuilding'):
                count_buildings+=1
                building.click()
                time.sleep(.05)
                driver.implicitly_wait(10) # Wait up to 10 seconds to wait for elements to load on page
                num_rows_opened = 0
                initial_rows_reported = len(driver.find_elements_by_xpath('//*//tr[@rmsrowmode="RoomRowCollapsed"]//td//img[@class="cbExpandRoomDetails"]'))
                ###print('initial recorded length: ', initial_rows_reported)
                while len(driver.find_elements_by_xpath('//*//tr[@rmsrowmode="RoomRowCollapsed"]//td//img[@class="cbExpandRoomDetails"]')) !=0:
                        ###print('room dropdowns to open: ',len(driver.find_elements_by_xpath('//*//tr[@rmsrowmode="RoomRowCollapsed"]//td//img[@class="cbExpandRoomDetails"]')))

                        try:
                                driver.implicitly_wait(0)
                                for room in driver.find_elements_by_xpath('//*//tr[@rmsrowmode="RoomRowCollapsed"]//td//img[@class="cbExpandRoomDetails"]'):