예제 #1
0
import logging
"""
See http://qoppac.blogspot.co.uk/2015/11/using-random-data.html for more examples
"""

from matplotlib.pyplot import show
from commonrandom import threeassetportfolio

SRlist = [.5, 1.0, 0.0]
clist = [.9, .5, -0.5]

ans = threeassetportfolio(plength=5000, SRlist=SRlist, clist=clist)
ans.cumsum().plot()
show()

print "Standard deviation"

print ans.std()

print "Correlation"
print ans.corr()

print "Mean"
print ans.mean()

print "Annualised SR"

print 16 * ans.mean() / ans.std()
methods_by_cs = [
    "S00", "S30", "S60", "S10", "S03", "S33", "S63", "S13", "S06", "S36",
    "S66", "S16", "S01", "S31", "S61", "S11", "HC", "BS"
]

benchmarket = "S00"
sfactor_lookup = dict([("1", 1.0), ("0", 0.0), ("3", 0.333), ("6", 0.66)])

## For the shorter periods we just use earlier examples of data we've already tested
max_length_years = np.max(years_to_test) + 1
plength = max_length_years * DAYS_IN_YEAR + 100
test_period_days = test_period_years * DAYS_IN_YEAR

SRlist, clist = portfolio
all_returns = [
    threeassetportfolio(plength=plength, SRlist=SRlist, clist=clist)
    for notused in range(monte_length)
]

for data_length in years_to_test:
    print "Testing data length %d" % data_length
    in_sample_start = 0
    in_sample_end = data_length * DAYS_IN_YEAR
    out_sample_start = in_sample_end + 1
    out_sample_end = out_sample_start + test_period_days

    answers_this_port_SR = [np.nan]
    answers_this_port_degrade = [np.nan]

    returns_to_use_insample = [
        one_return_series.iloc[in_sample_start:in_sample_end]
## used for plot order
methods_ms=[ "S00", "S03", "S06", "S01", "S30", "S33", "S36",  "S31", "S60", "S63", "S66", "S61", "S10", "S13", "S16", "S11", "HC", "BS"]

methods_by_cs=[ "S00", "S30", "S60", "S10", "S03", "S33", "S63", "S13", "S06", "S36" ,"S66", "S16", "S01", "S31", "S61", "S11", "HC", "BS"]

benchmarket="S00"
sfactor_lookup=dict([("1",1.0), ("0", 0.0), ("3", 0.333), ("6", 0.66) ])

## For the shorter periods we just use earlier examples of data we've already tested
max_length_years=np.max(years_to_test)+1
plength=max_length_years*DAYS_IN_YEAR+100
test_period_days=test_period_years*DAYS_IN_YEAR

SRlist, clist=portfolio
all_returns=[threeassetportfolio(plength=plength, SRlist=SRlist, clist=clist) for notused in range(monte_length)]


for data_length in years_to_test:
    print "Testing data length %d" % data_length
    in_sample_start=0
    in_sample_end=data_length*DAYS_IN_YEAR
    out_sample_start=in_sample_end+1
    out_sample_end=out_sample_start+test_period_days
    
    
    answers_this_port_SR=[np.nan]
    answers_this_port_degrade=[np.nan]

    returns_to_use_insample=[one_return_series.iloc[in_sample_start:in_sample_end] for one_return_series in all_returns]
    returns_to_use_outsample=[one_return_series.iloc[out_sample_start:out_sample_end] for one_return_series in all_returns]
"""
See http://qoppac.blogspot.co.uk/2015/11/using-random-data.html for more examples
"""


from matplotlib.pyplot import show
from commonrandom import threeassetportfolio

SRlist=[.5, 1.0, 0.0]
clist=[.9,.5,-0.5]

ans=threeassetportfolio(plength=5000, SRlist=SRlist, clist=clist)
ans.cumsum().plot()
show()

print "Standard deviation"

print ans.std()

print "Correlation"
print ans.corr()

print "Mean"
print ans.mean()

print "Annualised SR"

print 16*ans.mean()/ans.std()