def test_type_mismatch(self): if sys.version_info.major < 3: self.assertIsNotNone(Asset(3) < 'a') self.assertIsNotNone('a' < Asset(3)) else: with self.assertRaises(TypeError): Asset(3) < 'a' with self.assertRaises(TypeError): 'a' < Asset(3)
def symbol(self, symbol_str): # This method works around the problem of not being able to trade # assets which does not have ingested data for the day of trade. # Normally historical data is loaded to bundle and the asset's # end_date and auto_close_date is set based on the last entry from # the bundle db. LiveTradingAlgorithm does not override order_value(), # order_percent() & order_target(). Those higher level ordering # functions provide a safety net to not to trade de-listed assets. # If the asset is returned as it was ingested (end_date=yesterday) # then CannotOrderDelistedAsset exception will be raised from the # higher level order functions. # # Hence, we are increasing the asset's end_date by 10,000 days. # The ample buffer is provided for two reasons: # 1) assets are often stored in algo's context through initialize(), # which is called once and persisted at live trading. 10,000 days # enables 27+ years of trading, which is more than enough. # 2) Tool - 10,000 Days is brilliant! asset = super(self.__class__, self).symbol(symbol_str) tradeable_asset = asset.to_dict() tradeable_asset['end_date'] = (pd.Timestamp('now', tz='UTC') + pd.Timedelta('10000 days')) tradeable_asset['auto_close_date'] = tradeable_asset['end_date'] return Asset.from_dict(tradeable_asset)
def test_asset_object(self): self.assertEquals({5061: 'foo'}[Asset(5061)], 'foo') self.assertEquals(Asset(5061), 5061) self.assertEquals(5061, Asset(5061)) self.assertEquals(Asset(5061), Asset(5061)) self.assertEquals(int(Asset(5061)), 5061) self.assertEquals(str(Asset(5061)), 'Asset(5061)')
def test_gt(self): self.assertFalse(Asset(3) > Asset(4)) self.assertFalse(Asset(4) > Asset(4)) self.assertTrue(Asset(5) > Asset(4))
def test_eq(self): self.assertFalse(Asset(3) == Asset(4)) self.assertTrue(Asset(4) == Asset(4)) self.assertFalse(Asset(5) == Asset(4))
def test_le(self): self.assertTrue(Asset(3) <= Asset(4)) self.assertTrue(Asset(4) <= Asset(4)) self.assertFalse(Asset(5) <= Asset(4))