-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportfoliosimulation.py
66 lines (59 loc) · 1.53 KB
/
portfoliosimulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import datetime as dt
from openseries import (
OpenTimeSeries,
OpenFrame,
efficient_frontier,
prepare_plot_data,
sharpeplot,
ReturnSimulation,
)
if __name__ == "__main__":
seed = 55
simulated_weights = 5000
frontier_points = 30
simulations = ReturnSimulation.from_merton_jump_gbm(
number_of_sims=4,
trading_days=2512,
mean_annual_return=0.05,
mean_annual_vol=0.1,
jumps_lamda=0.1,
jumps_sigma=0.3,
jumps_mu=-0.2,
trading_days_in_year=252,
seed=seed,
)
assets = OpenFrame(
[
OpenTimeSeries.from_df(
simulations.to_dataframe(name="Asset", end=dt.date(2023, 12, 29)),
column_nmbr=serie,
)
for serie in range(simulations.number_of_sims)
],
).to_cumret()
current = OpenTimeSeries.from_df(
assets.make_portfolio(
name="Current Portfolio",
weight_strat="eq_weights",
),
)
frontier, simulated, optimum = efficient_frontier(
eframe=assets,
num_ports=simulated_weights,
seed=seed,
frontier_points=frontier_points,
)
plotframe = prepare_plot_data(
assets=assets,
current=current,
optimized=optimum,
)
simfigure, simfile = sharpeplot(
sim_frame=simulated,
line_frame=frontier,
point_frame=plotframe,
point_frame_mode="markers+text",
title=False,
add_logo=True,
auto_open=True,
)