-
Notifications
You must be signed in to change notification settings - Fork 5
/
pyfolio.py
56 lines (41 loc) · 1.25 KB
/
pyfolio.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
# -*- coding: utf-8 -*-
# @Author: boyac
# @Date: 2018-08-27 19:28:58
# @Last Modified by: boyac
# @Last Modified time: 2018-08-27 20:26:33
def allocation_effect():
# positive contribution: OW in sector OP index, UW in sector UP index
sector = (portw-benchw)*(benchr-benchtotal)
return sector
def selection_effect():
# positive contribution: OP benchmark sector
selection = portw*(portr-benchr)
return selection
def interaction_effect():
# positive contribution: OW in port OP sector, UW in port UP sector
interaction = (portw-benchw)*(portr-benchr)
return interaction
def active_effect():
active = allocation_effect()+selection_effect()+interaction_effect()
return "{:.2%}".format(active)
def PME():
#ticker, trade_dt, quantity, unit_cost, cost_basis, start_yr, dt, adj_cost, ticker_return
#index_close, index_st_close, share_ytd, index_ytd, cum_invst, cum_tic_return
pass
if __name__ == "__main__":
#Benchmark S&P500
#Bechmark segment S&P500 Tech
#Benchmark return 9%
#Benchmark weight 7%
#Benchmark tech return 8%
#Benchmark tech weight 15%
#Total benchmark return 7%
benchr=0.09
benchw=0.07
portr=0.08
portw=0.15
benchtotal=0.07
print allocation_effect()
print selection_effect()
print interaction_effect()
print active_effect()