Skip to content

Commit

Permalink
can use long only constraint in dynamic optimisation now
Browse files Browse the repository at this point in the history
  • Loading branch information
rob committed Nov 6, 2023
1 parent f2dbe31 commit 9397726
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ def __init__(self, obj_instance: "objectiveFunctionForGreedy"):
self.weights_optimal = obj_instance.weights_optimal
self.per_contract_value = obj_instance.per_contract_value
self.costs = obj_instance.costs
self.long_only = obj_instance.long_only

if obj_instance.constraints is arg_not_supplied:
reduce_only_keys = no_trade_keys = arg_not_supplied
long_only_keys = reduce_only_keys = no_trade_keys = arg_not_supplied

else:
no_trade_keys = obj_instance.constraints.no_trade_keys
reduce_only_keys = obj_instance.constraints.reduce_only_keys
long_only_keys = obj_instance.constraints.long_only_keys

self.no_trade_keys = no_trade_keys
self.reduce_only_keys = reduce_only_keys
self.long_only_keys = long_only_keys

self.weights_prior = obj_instance.weights_prior
self.maximum_position_weights = obj_instance.maximum_position_weights
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class constraintsForDynamicOpt:
reduce_only_keys: list = arg_not_supplied
no_trade_keys: list = arg_not_supplied
long_only_keys: list = arg_not_supplied


class objectiveFunctionForGreedy:
Expand All @@ -39,7 +40,6 @@ def __init__(
previous_positions: portfolioWeights = arg_not_supplied,
constraints: constraintsForDynamicOpt = arg_not_supplied,
maximum_positions: portfolioWeights = arg_not_supplied,
long_only: list = arg_not_supplied,
log: pst_logger = get_logger("objectiveFunctionForGreedy"),
):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_data_and_calculate_for_code(
if input_data.long_only is arg_not_supplied:
long_only = False
else:
long_only = instrument_code in input_data.long_only
long_only = instrument_code in input_data.long_only_keys

max_position = input_data.maximum_position_weight_for_code(instrument_code)
weight_prior = input_data.prior_weight_for_code(instrument_code)
Expand Down

0 comments on commit 9397726

Please sign in to comment.