Skip to content

Commit

Permalink
implement #1018
Browse files Browse the repository at this point in the history
  • Loading branch information
rob committed Jul 5, 2023
1 parent 4d7cb01 commit 36b4a55
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 16 deletions.
23 changes: 21 additions & 2 deletions sysquant/optimisation/generic_optimiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,31 @@ def weights(self) -> pd.DataFrame:
## apply cost weight
return weights

@property
def fit_dates(self) -> list:
return self.optimiser.fit_dates

@property
def correlation_estimator(self):
return self.optimiser.correlation_estimator

@property
def mean_estimator(self):
return self.optimiser.mean_estimator

@property
def stdev_estimator(self):
return self.optimiser.stdev_estimator

def raw_weights(self) -> pd.DataFrame:
return self.optimiser.weights()

@property
def optimiser(self) -> optimiseWeightsOverTime:
optimiser = optimiseWeightsOverTime(
self.net_returns, log=self.log, **self.weighting_params
)

return optimiser.weights()
return optimiser

def weights_post_processing(self, weights: pd.DataFrame) -> pd.DataFrame:
# apply cost weights
Expand Down
12 changes: 12 additions & 0 deletions sysquant/optimisation/optimise_over_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def __init__(
def fit_dates(self) -> listOfFittingDates:
return self._fit_dates

@property
def correlation_estimator(self):
return self.optimiser.correlation_estimator()

@property
def mean_estimator(self):
return self.optimiser.mean_estimator()

@property
def stdev_estimator(self):
return self.optimiser.stdev_estimator()

@property
def optimiser(self) -> portfolioOptimiser:
return self._optimiser
Expand Down
38 changes: 24 additions & 14 deletions sysquant/optimisation/portfolio_optimiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,38 @@ def data_length_for_period(self, fit_period: fitDates) -> int:
def calculate_correlation_matrix_for_period(
self, fit_period: fitDates
) -> correlationEstimate:
return self.calculate_estimate_for_period(
fit_period, param_entry="correlation_estimate"
)
estimator = self.correlation_estimator()
estimate = estimator.calculate_estimate_for_period(fit_period)

return estimate

def calculate_stdev_for_period(self, fit_period: fitDates) -> stdevEstimates:
return self.calculate_estimate_for_period(
fit_period, param_entry="vol_estimate"
)
estimator = self.stdev_estimator()
estimate = estimator.calculate_estimate_for_period(fit_period)

def calculate_mean_for_period(self, fit_period: fitDates) -> meanEstimates:
return self.calculate_estimate_for_period(
fit_period, param_entry="mean_estimate"
)
return estimate

def calculate_estimate_for_period(
self, fit_period: fitDates, param_entry: str = "mean_estimate"
):
estimator = self._generic_estimator(param_entry)
def calculate_mean_for_period(self, fit_period: fitDates) -> meanEstimates:
estimator = self.mean_estimator()
estimate = estimator.calculate_estimate_for_period(fit_period)

return estimate

def correlation_estimator(self):
estimator = self._generic_estimator("correlation_estimate")

return estimator

def mean_estimator(self):
estimator = self._generic_estimator("mean_estimate")

return estimator

def stdev_estimator(self):
estimator = self._generic_estimator("vol_estimate")

return estimator

def _generic_estimator(
self, param_entry: str = "mean_estimate"
) -> genericEstimator:
Expand Down
17 changes: 17 additions & 0 deletions systems/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,23 @@ def get_raw_estimated_instrument_weights(self) -> pd.DataFrame:

return instrument_weights

def fit_periods(self):
# FIXME, NO GUARANTEE THIS OBJECT HAS AN ESTIMATOR UNLESS IT INHERITS FROM
# SOME KIND OF BASECLASS

weight_calculator = self.calculation_of_raw_instrument_weights()

return weight_calculator.fit_dates

@diagnostic()
def correlation_estimator_for_subsystem_returns(self):
# FIXME, NO GUARANTEE THIS OBJECT HAS AN ESTIMATOR UNLESS IT INHERITS FROM
# SOME KIND OF BASECLASS

weight_calculator = self.calculation_of_raw_instrument_weights()

return weight_calculator.correlation_estimator

@diagnostic(protected=True, not_pickable=True)
def calculation_of_raw_instrument_weights(self):

Expand Down

0 comments on commit 36b4a55

Please sign in to comment.