Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion binder/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# required packages for backstroke
matplotlib>=3
numpy<2.3 # up to date as of 1/2025. v2.3 requires py >3.10. seems OK otherwise
pandas<2.3 # up to date as of 1/2025. v2.3 looks OK if no copy-on-write issues. v3 requires py >3.10 but seems OK otherwise
pandas<3 # last changed 4/2026. v3 requires py >3.10 but seems OK otherwise
requests>=2.32.2
python-dotenv
15 changes: 8 additions & 7 deletions simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def portfolio_value(self, date=None, main_portfolio=True, at_close=True):
Arguments
---------

date : `pandas.Timestamp` or `datetime.datetime`, optional
date : str or `pandas.Timestamp` or `datetime.datetime`, optional
The date whose price data is used in the value calculation. Will
cause an error if the date is not between the class' open and close
dates or if it is not a market day. [default: self.today]
Expand All @@ -297,7 +297,7 @@ def portfolio_value(self, date=None, main_portfolio=True, at_close=True):
raise ValueError("'at_close' must be a bool.")

# ensure that the requested date is within the class instance's range
date = self.today if date is None else date
date = self.today if date is None else pd.Timestamp(date)
if not self.open_date <= date <= self.end_date:
raise ValueError("`date` must occur between `self.open_date` and "
"`self.end_date`")
Expand Down Expand Up @@ -332,21 +332,22 @@ def call_tiingo(self, tick, open_date,
tick : str, required
The ticker of the asset whose data will be downloaded.

open_date : `pandas.Timestamp` or `datetime.datetime`, required
open_date : str or `pandas.Timestamp` or `datetime.datetime`, required
The earliest date of historical data to be downloaded. (Note that
when this method is called upon initializing HistoricalSimulator,
this argument is self.open_date, not self.start_date.)

end_date : `pandas.Timestamp` or `datetime.datetime`, optional
end_date : str or `pandas.Timestamp` or `datetime.datetime`, optional
The final date of historical data to be downloaded. (When this
method is called upon initializing HistoricalSimulator, this
argument is self.end_date.) [default: pandas.Timestamp.today()]

verbose : boolean, optional
Whether or not to print the download's progress. [default: True]
'''
open_date = open_date.strftime('%Y-%m-%d') # (e.g. '1998-07-13')
end_date = end_date.strftime('%Y-%m-%d')
open_date = pd.Timestamp(open_date).strftime('%Y-%m-%d')
end_date = pd.Timestamp(end_date).strftime('%Y-%m-%d')
# (e.g. '1998-07-13')
if verbose:
print(f"{tick} from {open_date} to {end_date}...")

Expand Down Expand Up @@ -383,7 +384,7 @@ def append_date(self, date, price_dict, verbose=False):
Arguments
---------

date : `pandas.Timestamp` or `datetime.datetime`, required
date : str or `pandas.Timestamp` or `datetime.datetime`, required
The new date to add to the simulation. Must be a weekday and must
not be timezone-aware.

Expand Down
Loading