/
UniversalEngine_examples.py
46 lines (39 loc) · 1.89 KB
/
UniversalEngine_examples.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
# Examples
import azapy as az
print(f"azapy version {az.version()}", flush=True)
#==============================================================================
# Collect market data
mktdir = '../../MkTdata'
sdate = '2012-01-01'
edate = 'today'
symb = ['GLD', 'TLT', 'XLV', 'IHI', 'VGT']
mktdata = az.readMkT(symb, sdate=sdate, edate=edate, file_dir=mktdir)
#==============================================================================
# build a fixing schedule
fixing_schedule = az.schedule_simple(sdate, edate,
freq='M', noffset=-5, fixoffset=0)
#==============================================================================
# compute weights
# using uniformly distributed random vectors in n-simplex
puniv = az.UniversalEngine(mktdata, schedule=fixing_schedule)
ww = puniv.getWeights(mc_paths=100, nr_batches=10, mc_seed=42, verbose=True)
print(f"weights\n{ww}")
# using Flat Dirichlet distribution (equivalent to above uniform distribution)
dirichlet_alpha = [1] * len(symb)
puniv = az.UniversalEngine(mktdata, schedule=fixing_schedule,
dirichlet_alpha=dirichlet_alpha)
ww = puniv.getWeights(mc_paths=100, nr_batches=10, mc_seed=42, verbose=True)
print(f"weights\n{ww}")
# using Dirichlet distribution with all alpha equal to 1/2
dirichlet_alpha = [0.5] * len(symb)
puniv = az.UniversalEngine(mktdata, schedule=fixing_schedule,
dirichlet_alpha=dirichlet_alpha)
ww = puniv.getWeights(mc_paths=100, nr_batches=10, mc_seed=42, verbose=True)
print(f"weights\n{ww}")
# using Dirichlet distribution with all alpha equal to the inverse number of
# portfolio symbols
dirichlet_alpha = [1 / len(symb)] * len(symb)
puniv = az.UniversalEngine(mktdata, schedule=fixing_schedule,
dirichlet_alpha=dirichlet_alpha)
ww = puniv.getWeights(mc_paths=100, nr_batches=10, mc_seed=42, verbose=True)
print(f"weights\n{ww}")