Currently, there is a lot of repeated code within risk_models.py and expected_returns.py.
Almost all of the functions therein take prices as inputs, before processing them into returns, with the following couple of lines repeated a lot.
if not isinstance(prices, pd.DataFrame):
warnings.warn("prices are not in a dataframe", RuntimeWarning)
prices = pd.DataFrame(prices)
daily_returns = prices.pct_change().dropna(how="all")
In the spirit of DRY, I'd like to refactor this without complicating the API. Haven't decided the best way of proceeding. I suppose I could put these lines into a function, but that would probably need to go in a separate file (not very elegant IMO).
Currently, there is a lot of repeated code within risk_models.py and expected_returns.py.
Almost all of the functions therein take prices as inputs, before processing them into returns, with the following couple of lines repeated a lot.
In the spirit of DRY, I'd like to refactor this without complicating the API. Haven't decided the best way of proceeding. I suppose I could put these lines into a function, but that would probably need to go in a separate file (not very elegant IMO).