Skip to content

Commit

Permalink
more improved doc and minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Feb 23, 2024
1 parent 302fe1f commit fb8f2a3
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"test_*.py"
],
"python.testing.pytestArgs": [
"--ignore=tests/integration",
"--ignore=tests/integration"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
}
16 changes: 8 additions & 8 deletions roboquant/brokers/ibkrbroker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def openOrder(self, orderId: int, contract, order: IBKROrder, orderState):
rq_order.id = str(orderId)
self.orders[rq_order.id] = rq_order

def reqAccountSummary(self):
def request_account(self):
buyingpower_tag = AccountSummaryTags.BuyingPower
equity_tag = AccountSummaryTags.NetLiquidation
with self.__account_end:
Expand Down Expand Up @@ -101,9 +101,9 @@ def orderStatus(
mktCapPrice,
):
logger.debug("order status orderId=%s status=%s", orderId, status)
id = str(orderId)
orderId = str(orderId)
if id in self.orders:
order = self.orders[id]
order = self.orders[orderId]
match status:
case "Submitted":
order.status = OrderStatus.ACTIVE
Expand All @@ -112,12 +112,12 @@ def orderStatus(
case "Filled":
order.status = OrderStatus.FILLED
else:
logger.warn("recieved status for unknown order id=%s status=%s", orderId, status)
logger.warning("received status for unknown order id=%s status=%s", orderId, status)


class IBKRBroker(Broker):
"""
Atttributes
Attributes
==========
contract_mapping
store how symbols map to IBKR contracts. If a symbol is not found, the symbol is assumed to represent a US stock
Expand Down Expand Up @@ -158,7 +158,7 @@ def sync(self, event: Event | None = None) -> Account:

api.reqPositions()
api.reqOpenOrders()
api.reqAccountSummary()
api.request_account()

acc.positions = {k: v for k, v in api.positions.items() if not v.size.is_zero()}
acc.orders = [order for order in api.orders.values()]
Expand All @@ -181,9 +181,9 @@ def place_orders(self, *orders: Order):
if order.id is None:
order.id = self.__api.get_next_order_id()
self.__api.orders[order.id] = order
ibkrorder = self._get_order(order)
ibkr_order = self._get_order(order)
contract = self.contract_mapping.get(order.symbol) or self._get_default_contract(order.symbol)
self.__api.placeOrder(int(order.id), contract, ibkrorder)
self.__api.placeOrder(int(order.id), contract, ibkr_order)

def _get_default_contract(self, symbol: str) -> Contract:
"""If no contract can be found in the `contract_mapping` dict, this method is called to get a default IBKR contract
Expand Down
2 changes: 1 addition & 1 deletion roboquant/brokers/simbroker.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def sync(self, event: Event | None = None) -> Account:
prices = event.price_items if event else {}

if self.clean_up_orders:
self._orders = {id: state for id, state in self._orders.items() if not state.order.closed}
self._orders = {order_id: state for order_id, state in self._orders.items() if not state.order.closed}

self._process_modify_order()
self._process_create_orders(prices)
Expand Down
16 changes: 8 additions & 8 deletions roboquant/feeds/candlefeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ def play(self, channel: EventChannel):
src_channel = channel.copy()
candles: dict[str, Candle] = {}
play_background(self.feed, src_channel)
next = None
next_time = None
while event := src_channel.get():
if not next:
next = event.time + self.freq
elif event.time >= next:
if not next_time:
next_time = event.time + self.freq
elif event.time >= next_time:
items = list(candles.values())
evt = Event(next, items)
evt = Event(next_time, items)
channel.put(evt)
candles = {}
next += self.freq
next_time += self.freq

self.__aggr_trade2candle(event, candles)

if candles and self.send_remaining and next:
if candles and self.send_remaining and next_time:
items = list(candles.values())
evt = Event(next, items)
evt = Event(next_time, items)
channel.put(evt)
1 change: 0 additions & 1 deletion roboquant/feeds/csvfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def __init__(
self.adj_close = adj_close
self.endswith = endswith
self.freq = frequency
logger = logging.getLogger(__name__)

files = self._get_files(path)
logger.info("located %s files in path %s", len(files), path)
Expand Down
6 changes: 3 additions & 3 deletions roboquant/feeds/eventchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def put(self, event: Event):
self.close()

def get(self, timeout=None) -> Event | None:
"""returns the next event or None if this channel is just closed
"""Returns the next event or None if this channel is just closed
- timeout: the timeout in seconds to send a hearthbeat in case no other events were available, default is None.
A hearthbeat is an empty event.
- timeout: the timeout in seconds to send a heartbeat in case no other events were available, default is None.
A heartbeat is an empty event.
"""
try:
return self._queue.get(timeout=timeout)
Expand Down
2 changes: 1 addition & 1 deletion roboquant/feeds/feedutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_symbol_dataframe(feed: Feed, symbol: str, timeframe: Timeframe | None =

def print_feed_items(feed: Feed, timeframe: Timeframe | None = None, timeout: float | None = None):
"""Print the items in a feed to the console.
This is mostly usefull for debugging purposes to see what events a feed generates
This is mostly useful for debugging purposes to see what events a feed generates
"""

channel = EventChannel(timeframe)
Expand Down
8 changes: 4 additions & 4 deletions roboquant/feeds/randomwalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def __get_symbols(
symbol_len,
):
symbols = set()
ALPHABET = np.array(list(string.ascii_uppercase))
alphabet = np.array(list(string.ascii_uppercase))
while len(symbols) < n_symbols:
symbol = "".join(rnd.choice(ALPHABET, size=symbol_len))
symbol = "".join(rnd.choice(alphabet, size=symbol_len))
symbols.add(symbol)
return symbols

@staticmethod
def __price_path(rnd, n, scale, min, max):
def __price_path(rnd, n, scale, min_price, max_price):
change = rnd.normal(loc=1.0, scale=scale, size=(n,))
change[0] = rnd.uniform(min, max)
change[0] = rnd.uniform(min_price, max_price)
price = change.cumprod()
return price
4 changes: 2 additions & 2 deletions roboquant/feeds/tiingohistoricfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def retrieve_eod_stocks(
logger.debug("eod stock url is %s", url)
response = requests.get(url)
if not response.ok:
logger.warn(f"error symbol={symbol} {response.reason}")
logger.warning(f"error symbol={symbol} {response.reason}")
continue

rows = self.__get_csv_iter(response)
Expand All @@ -79,7 +79,7 @@ def retrieve_intraday_iex(self, *symbols: str, start_date="2023-01-01", end_date
logger.debug("intraday iex is %s", url)
response = requests.get(url)
if not response.ok:
logger.warn(f"error symbol={symbol} {response.reason}")
logger.warning(f"error symbol={symbol} {response.reason}")
continue

rows = self.__get_csv_iter(response)
Expand Down
4 changes: 2 additions & 2 deletions roboquant/strategies/rnnstrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def fit(
epochs: int = 10,
batch_size: int = 32,
validation_split: float = 0.2,
summaryWriter=None,
summary_writer=None,
):
"""
Trains the model for a fixed number of epochs (dataset iterations).
Expand All @@ -155,7 +155,7 @@ def fit(

self._fill_replay_buffer(feed, timeframe)

writer = summaryWriter
writer = summary_writer

# make the data stationary
x_data = self.pct_change(1)
Expand Down
2 changes: 1 addition & 1 deletion roboquant/traders/flextrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FlexTrader(Trader):
"""Implementation of a Trader that has configurable rules to modify its behavior. This implementation will not
generate orders if there is not a price in the event for the underlying symbol.
The configurable paramters include:
The configurable parameters include:
- one_order_only: don't create new orders for a symbol if there is already an open orders for that same symbol
- size_fractions: enable fractional order sizes (if size_fractions is larger than 0), default is 0
- min_buying_power: the minimal buying power that should remain available (to avoid margin calls), default is 0.0
Expand Down

0 comments on commit fb8f2a3

Please sign in to comment.