Skip to content

Commit

Permalink
fixed symbol in priceitem inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Feb 21, 2024
1 parent e2df202 commit 07667bb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ python3 -m venv .venv
source .venv/bin/activate
```

You should now be in the virtual environment. Ready to install the required packages and build/install roboquant:
You should now be in the virtual environment and ready to install the required packages and build/install roboquant:

```shell
pip install -r requirements.txt
Expand Down
5 changes: 4 additions & 1 deletion roboquant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

__version__ = "0.2.1"

from .account import Account, OptionAccount, Position
from .roboquant import Roboquant

Expand Down Expand Up @@ -32,4 +35,4 @@
feedutil,
)

__version__ = "0.2.1"

11 changes: 7 additions & 4 deletions roboquant/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def volume(self, volume_type: str = "DEFAULT") -> float:

@dataclass(slots=True)
class Quote(PriceItem):
symbol: str
# symbol: str
data: array

def price(self, price_type: str = "DEFAULT") -> float:
Expand All @@ -35,6 +35,7 @@ def price(self, price_type: str = "DEFAULT") -> float:
case "BID":
return self.data[2]
case _:
# Default is the mid-point price
return (self.data[0] + self.data[2]) / 2.0

@property
Expand All @@ -52,12 +53,13 @@ def volume(self, volume_type: str = "DEFAULT") -> float:
case "BID":
return self.data[3]
case _:
# Default is the average volume
return (self.data[1] + self.data[3]) / 2.0


@dataclass(slots=True)
class Trade(PriceItem):
symbol: str
# symbol: str
trade_price: float
trade_volume: float

Expand All @@ -70,7 +72,7 @@ def volume(self, volume_type: str = "DEFAULT") -> float:

@dataclass(slots=True)
class Candle(PriceItem):
symbol: str
# symbol: str
ohlcv: array
frequency: str = "" # f.e 1s , 15m, 4h, 1d

Expand Down Expand Up @@ -99,6 +101,7 @@ class Event:
"""
An event represents zero of items of information happening at a certain moment in time.
An item can contain any type of information, but a common use-case are price-items like candles.
Time is always a datetime object with UTC timezone.
"""

def __init__(self, time: datetime, items: list):
Expand All @@ -114,7 +117,7 @@ def empty(time=None):
return Event(time, [])

def is_empty(self) -> bool:
"""return True if this is an empty event, False otherwise"""
"""return True if this is an empty event without any items, False otherwise"""
return len(self.items) == 0

@cached_property
Expand Down
6 changes: 3 additions & 3 deletions roboquant/feeds/yahoofeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def __init__(self, *symbols: str, start_date="2010-01-01", end_date: str | None
logger.warning("no data retrieved for symbol=%s", symbol)
continue

# yFinance one doesn't correct volume, so use this one instead
# yFinance one doesn't correct the volume, so we use this one instead
self.__auto_adjust(df)
for t in df.itertuples(index=True):
dt = t[0].to_pydatetime().astimezone(timezone.utc)
prices = t[1:6]
pb = Candle(symbol, array("f", prices), interval)
self._add_item(dt, pb)
candle = Candle(symbol, array("f", prices), interval)
self._add_item(dt, candle)

logger.info("retrieved symbol=%s items=%s", symbol, len(df))

Expand Down

0 comments on commit 07667bb

Please sign in to comment.