Skip to content

Commit

Permalink
Merge pull request #63 from cvxgrp/final-touches
Browse files Browse the repository at this point in the history
Some final touches
  • Loading branch information
phschiele authored Jan 10, 2024
2 parents ec8fb78 + 7a52817 commit 6439dba
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 7,058 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ Please run all experiments using
make experiments
```

Before the experiments start the virtual environment defined in 'requirements.txt'
is replicated locally.
This first replicates the virtual environment defined in 'requirements.txt'
locally and then runs the experiments defined in 'experiments.py'.

## Reproducibility

The main packages used are specified in 'requirements.txt', with a frozen
version of all packages and their sub-dependencies in 'requirements_frozen.txt'.
We used Python 3.10.13 to run the experiments.
2 changes: 1 addition & 1 deletion experiments/markowitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def markowitz(data: Data, param: Parameters) -> tuple[np.ndarray, float, cp.Prob
w, c = cp.Variable(data.n_assets), cp.Variable()

z = w - data.w_prev
T = cp.norm1(z)
T = cp.norm1(z) / 2
L = cp.norm1(w)

# worst-case (robust) return
Expand Down
5 changes: 4 additions & 1 deletion experiments/scaling_small.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def plot_timings(timings: list[Timing]) -> None:
plt.ylabel("Time (s)")
plt.legend()
plt.savefig(figures_path() / "timing_parametrized.pdf")
plt.show()

show_plot = False
if show_plot:
plt.show()


def initialize_problem(n_assets: int, sigma_target: float) -> None:
Expand Down
18 changes: 10 additions & 8 deletions experiments/taming.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ def main(from_checkpoint: bool = False) -> None:
robust_result,
)

generate_per_year_tables(
equal_weights_results,
basic_result,
weight_limited_result,
leverage_limit_result,
turnover_limit_result,
robust_result,
)
show_yearly_metrics = False
if show_yearly_metrics:
generate_per_year_tables(
equal_weights_results,
basic_result,
weight_limited_result,
leverage_limit_result,
turnover_limit_result,
robust_result,
)


def run_all_strategies(annualized_target: float) -> None:
Expand Down
14 changes: 10 additions & 4 deletions experiments/tuning_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def plot_results(
turnovers_train: np.ndarray,
turnovers_test: np.ndarray,
) -> None:
show_plot = False

# sharpe
plt.plot(backtests, sharpe_ratios_train, label="in-sample", marker="o")
plt.plot(backtests, sharpe_ratios_test, label="out-of-sample", marker="o")
Expand All @@ -172,7 +174,8 @@ def plot_results(
plt.legend()
plt.ylim(3, 7)
plt.savefig(experiment_path() / "tuning_results/tuning_SR.pdf", bbox_inches="tight")
plt.show()
if show_plot:
plt.show()

# vola
plt.plot(backtests, volas_train, label="train", marker="o")
Expand All @@ -183,7 +186,8 @@ def plot_results(
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(5))
plt.ylim(0.0, 0.12)
plt.savefig(experiment_path() / "tuning_results/tuning_vola.pdf", bbox_inches="tight")
plt.show()
if show_plot:
plt.show()

# leverage
plt.plot(backtests, leverages_train, label="train", marker="o")
Expand All @@ -194,7 +198,8 @@ def plot_results(
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(5))
plt.ylim(1, 2)
plt.savefig(experiment_path() / "tuning_results/tuning_lev.pdf", bbox_inches="tight")
plt.show()
if show_plot:
plt.show()

# turnover
plt.plot(backtests, turnovers_train, label="train", marker="o")
Expand All @@ -205,7 +210,8 @@ def plot_results(
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(5))
plt.ylim(20, 50)
plt.savefig(experiment_path() / "tuning_results/tuning_turn.pdf", bbox_inches="tight")
plt.show()
if show_plot:
plt.show()


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 6439dba

Please sign in to comment.