Skip to content

Commit

Permalink
Remove support for month timeframe.
Browse files Browse the repository at this point in the history
Specifying a month timeframe is incompatible with caching since months have variable lengths. Instead use a timeframe with consistent length e.g. 20d.
  • Loading branch information
edtechre committed Dec 10, 2023
1 parent f2f3a5d commit 351c2cf
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 14 deletions.
3 changes: 0 additions & 3 deletions src/pybroker/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"h": "hour",
"d": "day",
"w": "week",
"mo": "month",
}
_CENTS: Final = Decimal(".01")

Expand Down Expand Up @@ -225,7 +224,6 @@ def parse_timeframe(timeframe: str) -> list[tuple[int, str]]:
- ``"h"``/``"hour"``: hours
- ``"d"``/``"day"``: days
- ``"w"``/``"week"``: weeks
- ``"mo"``/``"month"``: months
An example timeframe string is ``1h 30m``.
Expand Down Expand Up @@ -261,7 +259,6 @@ def to_seconds(timeframe: Optional[str]) -> int:
- ``"h"``/``"hour"``: hours
- ``"d"``/``"day"``: days
- ``"w"``/``"week"``: weeks
- ``"mo"``/``"month"``: months
An example timeframe string is ``1h 30m``.
Expand Down
7 changes: 1 addition & 6 deletions src/pybroker/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_cached(
- ``"h"``/``"hour"``: hours
- ``"d"``/``"day"``: days
- ``"w"``/``"week"``: weeks
- ``"mo"``/``"month"``: months
An example timeframe string is ``1h 30m``.
start_date: Starting date of the cached data (inclusive).
Expand Down Expand Up @@ -126,7 +126,6 @@ def set_cached(
- ``"h"``/``"hour"``: hours
- ``"d"``/``"day"``: days
- ``"w"``/``"week"``: weeks
- ``"mo"``/``"month"``: months
An example timeframe string would be ``1h 30m``.
start_date: Starting date of the data to cache (inclusive).
Expand Down Expand Up @@ -191,7 +190,6 @@ def query(
- ``"h"``/``"hour"``: hours
- ``"d"``/``"day"``: days
- ``"w"``/``"week"``: weeks
- ``"mo"``/``"month"``: months
An example timeframe string is ``1h 30m``.
adjust: The type of adjustment to make.
Expand Down Expand Up @@ -275,7 +273,6 @@ def _fetch_data(
- ``"h"``/``"hour"``: hours
- ``"d"``/``"day"``: days
- ``"w"``/``"week"``: weeks
- ``"mo"``/``"month"``: months
An example timeframe string is ``1h 30m``.
adjust: The type of adjustment to make.
Expand Down Expand Up @@ -309,8 +306,6 @@ def _parse_alpaca_timeframe(
unit = TimeFrameUnit.Day
elif tf[1] == "week":
unit = TimeFrameUnit.Week
elif tf[1] == "month":
unit = TimeFrame.Month
else:
raise ValueError(f"Invalid Alpaca timeframe: {timeframe}")
return tf[0], unit
Expand Down
2 changes: 0 additions & 2 deletions src/pybroker/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,6 @@ def backtest(
- ``"h"``/``"hour"``: hours
- ``"d"``/``"day"``: days
- ``"w"``/``"week"``: weeks
- ``"mo"``/``"month"``: months
An example timeframe string is ``1h 30m``.
between_time: ``tuple[str, str]`` of times of day e.g.
Expand Down Expand Up @@ -1112,7 +1111,6 @@ def walkforward(
- ``"h"``/``"hour"``: hours
- ``"d"``/``"day"``: days
- ``"w"``/``"week"``: weeks
- ``"mo"``/``"month"``: months
An example timeframe string is ``1h 30m``.
between_time: ``tuple[str, str]`` of times of day e.g.
Expand Down
1 change: 0 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def test_bar_data_get_custom_data_when_no_attr_then_error():
("10week", [(10, "week")]),
("3d 20m", [(3, "day"), (20, "min")]),
("30s", [(30, "sec")]),
("2mo", [(2, "month")]),
],
)
def test_parse_timeframe_success(tf, expected):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def test_query_when_symbols_empty(self, empty_symbols):
):
alpaca.query(empty_symbols, START_DATE, END_DATE, TIMEFRAME)

@pytest.mark.parametrize("timeframe", ["1mo 2d", "30s"])
@pytest.mark.parametrize("timeframe", ["1w 2d", "30s"])
def test_query_when_invalid_timeframe_then_error(self, symbols, timeframe):
alpaca = Alpaca(API_KEY, API_SECRET)
with pytest.raises(
Expand Down Expand Up @@ -482,7 +482,7 @@ def test_query_when_empty_result(self, symbols, columns):
)
)

@pytest.mark.parametrize("timeframe", ["1mo 2d", "30s"])
@pytest.mark.parametrize("timeframe", ["1w 2d", "30s"])
def test_query_when_invalid_timeframe_then_error(self, symbols, timeframe):
crypto = AlpacaCrypto(API_KEY, API_SECRET)
with pytest.raises(
Expand Down

0 comments on commit 351c2cf

Please sign in to comment.