Skip to content

Commit

Permalink
small bugfixed and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Apr 4, 2024
1 parent 21ec131 commit 5558280
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
3 changes: 3 additions & 0 deletions roboquant/journals/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ def track(self, event: Event, account: Account, signals: list[Signal], orders: l
"""invoked at each step of a run that provides the journal with the opportunity to
track and log various metrics."""
...

def reset(self):
"""reset the state of the journal, default is to do nothing"""
2 changes: 1 addition & 1 deletion roboquant/journals/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
class Metric(Protocol):
"""Metric calculates zero or more values during each step of a run"""

def calc(self, event: Event, account: Account, signals: dict[str, Signal], orders: list[Order]) -> dict[str, float]:
def calc(self, event: Event, account: Account, signals: list[Signal], orders: list[Order]) -> dict[str, float]:
"""Calculate zero or more metrics and return the result as a dict."""
...
7 changes: 4 additions & 3 deletions roboquant/ml/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import logging
import numpy as np
from numpy.typing import NDArray
from stable_baselines3.common.policies import BasePolicy
import torch
from torch.utils.data import DataLoader, Dataset

from roboquant.event import Event
from roboquant.ml.envs import Action2Signals, StrategyEnv, TraderEnv
from roboquant.ml.envs import Action2Orders, Action2Signals, StrategyEnv, TraderEnv
from roboquant.ml.features import Feature, NormalizeFeature
from roboquant.order import Order
from roboquant.signal import Signal
Expand All @@ -19,7 +20,7 @@

class SB3PolicyStrategy(Strategy):

def __init__(self, obs_feature: Feature, action_2_signals: Action2Signals, policy):
def __init__(self, obs_feature: Feature, action_2_signals: Action2Signals, policy: BasePolicy):
super().__init__()
self.obs_feature = obs_feature
self.action_2_signals = action_2_signals
Expand All @@ -44,7 +45,7 @@ def reset(self):

class SB3PolicyTrader(Trader):

def __init__(self, obs_feature: Feature, action_2_orders, policy):
def __init__(self, obs_feature: Feature, action_2_orders: Action2Orders, policy: BasePolicy):
super().__init__()
self.obs_feature = obs_feature
self.action_2_orders = action_2_orders
Expand Down
2 changes: 1 addition & 1 deletion samples/forwardtest_alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# %%
# Let run an EMACrossover strategy
strategy = rq.strategies.EMACrossover(13, 26)
timeframe = rq.Timeframe.next(minutes=60)
timeframe = rq.Timeframe.next(minutes=30)
journal = rq.journals.BasicJournal()
account = rq.run(feed, strategy, journal=journal, timeframe=timeframe)

Expand Down
3 changes: 0 additions & 3 deletions samples/papertrade_alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,3 @@
# %%
print(account)
print(journal)


# %%
13 changes: 6 additions & 7 deletions samples/talib_strategy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# %%
import talib.stream as ta
import roboquant as rq
from roboquant.strategies import BarStrategy

# %%
class MyStrategy(BarStrategy):
class MyStrategy(rq.strategies.BarStrategy):
"""Example using talib to create a combined RSI/BollingerBand strategy"""

def _create_signal(self, symbol, ohlcv):
Expand All @@ -16,12 +15,12 @@ def _create_signal(self, symbol, ohlcv):
close, timeperiod=self.size-1, nbdevup=2, nbdevdn=2
)

price = close[-1]
latest_price = close[-1]

if rsi < 30 and price < lower:
return rq.BUY
if rsi > 70 and price > upper:
return rq.SELL
if rsi < 30 and latest_price < lower:
return rq.Signal.buy(symbol)
if rsi > 70 and latest_price > upper:
return rq.Signal.sell(symbol)

return None

Expand Down

0 comments on commit 5558280

Please sign in to comment.