-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
139 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
from roboquant.event import Event | ||
from .eventchannel import EventChannel | ||
from .feed import Feed | ||
|
||
|
||
class CollectorFeed(Feed): | ||
"""Collect events into one new event if they occur close to eachother. | ||
Close to eachother is defined by the timeout is seconds. If there is no new | ||
event in the specified timeout, all previous events will be bundled together and | ||
put on the channel. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
feed: Feed, | ||
timeout=5.0, | ||
): | ||
super().__init__() | ||
self.feed = feed | ||
self.timeout = timeout | ||
|
||
def play(self, channel: EventChannel): | ||
src_channel = self.feed.play_background(channel.timeframe, channel.maxsize) | ||
items = [] | ||
while event := src_channel.get(self.timeout): | ||
if event.is_empty() and items: | ||
new_event = Event(event.time, items) | ||
channel.put(new_event) | ||
items = [] | ||
|
||
items.extend(event.items) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# %% | ||
from datetime import timedelta | ||
import logging | ||
import roboquant as rq | ||
from roboquant.alpaca import AlpacaLiveFeed | ||
|
||
# %% | ||
logging.basicConfig() | ||
logging.getLogger("roboquant").setLevel(level=logging.INFO) | ||
|
||
# Connect to Alpaca and subscribe to some IEX stocks 1-minute bars | ||
symbols = ["TSLA", "MSFT", "NVDA", "AMD", "AAPL", "AMZN"] | ||
alpaca_feed = AlpacaLiveFeed(market="iex") | ||
alpaca_feed.subscribe_bars(*symbols) | ||
|
||
feed = rq.feeds.CollectorFeed(alpaca_feed, 10.0) | ||
# %% | ||
# Let run an EMACrossover strategy | ||
strategy = rq.strategies.EMACrossover(5, 13) | ||
timeframe = rq.Timeframe.next(minutes=60) | ||
journal = rq.journals.BasicJournal() | ||
account = rq.run(feed, strategy, journal=journal, timeframe=timeframe) | ||
|
||
# %% | ||
print(account) | ||
print(journal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters