-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
c7e4ec3
commit 23f3715
Showing
4 changed files
with
129 additions
and
102 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,46 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from pandas import DataFrame | ||
from datetime import date | ||
from src.abacus.utils.instrument import Instrument | ||
|
||
|
||
|
||
class Universe: | ||
|
||
def __init__(self, instrument_specifications: dict[str:DataFrame], date_today: str=str(date.today())): | ||
self._instrument_specifications = instrument_specifications | ||
self._date_today = date_today | ||
self._instruments = None | ||
self._instrument_build_date = None | ||
|
||
@property | ||
def date_today(self): | ||
return self._date_today | ||
|
||
@date_today.setter | ||
def date_today(self, new): | ||
self._date_today = new | ||
|
||
@property | ||
def instrument_identifiers(self): | ||
return sorted(self._instrument_specifications.keys()) | ||
|
||
@property | ||
def instruments(self) -> list[Instrument]: | ||
if self.has_updated_cache(): | ||
return self._instruments | ||
|
||
built_instruments = [] | ||
for id, identifier in enumerate(self.instrument_identifiers): | ||
time_series = self._instrument_specifications[identifier].loc[:str(self.date_today)] | ||
ins = Instrument(id, identifier, "Stock", time_series) | ||
built_instruments.append(ins) | ||
return built_instruments | ||
|
||
def has_updated_cache(self) -> bool: | ||
has_cache = self._instruments is not None | ||
has_last_build = self._instrument_build_date is not None | ||
updated_date = self._date_today == self._instrument_build_date | ||
conditions = has_cache, has_last_build, updated_date | ||
return any(conditions) |