Background
I'm trying to implement the Black-Litterman model as a subclass of my already implemented Markowitz model. The main idea of Markowitz model is: you loop through a date_list, on each date you use the moving average approach to estimate the expected returns mu and the covariance matrix sigma, then you compute the mean-variance portfolio using the mean-variance optimiser mean_variance(mu, sigma). Conceptually, the Markowitz model is like this
class Markowitz(object):
def __init__(self, params):
self.price_data = ...
self.date_list = ...
def estimate_mu_and_sigma(self, date):
mu = ...
sigma = ...
return mu, sigma
@staticmethod
def mean_variance_optimiser(mu, sigma):
w = ...
return w
def back_test(self):
for date in self.date_list:
mu, sigma = self.estimate_mu_and_sigma(date)
w = Markowitz.mean_variance_optimiser(mu, sigma)
# do some other stuff
pass
The only difference between Black-Litterman and Markowitz is that BL uses a different estimate method for mu and sigma than Markowitz, but the subsequent mean-variance optimisation procedure is identical. Naturally I want to subclass Markowitz to get a BL model. The problem is that in BL, the estimates of mu and sigma need additional parameters. Not only that, but this set of additional parameters also depend dynamically on date, so I can't just override Markowitz.back_test to give it additional parameters. In fact, a BL model is like this:
class BlackLitterman(Markowitz):
def __init__(self, params, more_parms):
super().__init__(params)
self.some_auxiliary_data = ...
def estimate_mu_and_sigma(self, date, dynamic_params):
mu = ...
sigma = ...
return mu, sigma
def back_test(self, more_params):
for date in self.date_list:
dynamic_params = ... # depends both on date and more params
mu, sigma = self.estimate_mu_and_sigma(date, dynamic_params)
w = Markowitz.mean_variance_optimiser(mu, sigma)
# do some other stuff
pass
When I try this, the IDE already complains about BlackLitterman.estimate_mu_and_sigma overriding Markowtiz.estimate_mu_and_sigma with inconsistent signature. Also, this doesn't actually reuse the reusable code in back_test.
Could anybody tell me how to more elegantly inherit from Markowitz? Thanks!