예제 #1
0
파일: sim.py 프로젝트: snowdj/fecon236
def simshow(repeat=3, mean=0 / 256., N=256, func=simug_mix, visual=True):
    '''Statistical and optional visual SUMMARY: repeat simulations of func.'''
    #  Function func should rely on all its default args, except for N.
    for i in range(repeat):
        istr = str(i)
        ratarr = func(N=N)
        prices = rates2prices(ratarr, mean, initialpx=100)
        if visual:
            plotn(prices, title='tmp-' + istr)
        gm2gem(prices, b=2)
        print('---------------------------------------' + istr)
    return
예제 #2
0
def simu_plots_spx(charts=1, N=N_PC_SPX, mean=MEAN_PC_SPX, std=STD_PC_SPX):
    '''Display simulated SPX price charts of N days, given mean and std.'''
    yarray = array_spx_returns(mean, std)
    #        Read in the data only once BEFORE the loop...
    for i in range(charts):
        px = simu_prices(N, yarray)
        plotn(px)
        #  Plot, then for the given prices, compute annualized:
        #           geometric mean, arithmetic mean, volatility.
        print('     georet: ' + str(georet(px)))
        print('   ____________________________________')
        print('')
    return
예제 #3
0
def gmixshow(N=256, mean=SPXmean, sigma=SPXsigma, yearly=256, repeat=1,
             visual=True, inprice=100, b=SPXb):
    '''Statistical and optional visual SUMMARY: repeat simulations of GM(2).'''
    for i in range(repeat):
        istr = str(i)
        prices = gmix2prices(N, mean, sigma, yearly, inprice)
        if visual:
            plotn(prices, title='tmp-gmixshow-'+istr)
        try:
            gm2gem(prices, yearly=yearly, b=b)
        except OverflowError:
            system.warn("Excessive kurtosis: Skipping gm2gem() print.")
        print('---------------------------------------' + istr)
    return
예제 #4
0
def simushow(N=256, mean=0, yearly=256, repeat=1, func=simug_mix, visual=True,
             b=SPXb, inprice=100):
    '''Statistical and optional visual SUMMARY: repeat simulations of func.
       Function func shall use all its default arguments, except for N.
    '''
    for i in range(repeat):
        istr = str(i)
        ratarr = func(N=N)
        prices = zerat2prices(ratarr, mean, yearly, inprice)
        if visual:
            plotn(prices, title='tmp-'+func.__name__+'-'+istr)
        try:
            gm2gem(prices, yearly=yearly, b=b)
        except OverflowError:
            system.warn("Excessive kurtosis: Skipping gm2gem() print.")
        print('---------------------------------------' + istr)
    return
예제 #5
0
def bootshow(N,
             poparr,
             yearly=256,
             repeat=1,
             visual=True,
             b=SPXb,
             inprice=100,
             replace=True):
    '''Statistical and optional visual SUMMARY: repeat bsret2prices().'''
    #  Also nice template for gathering SMALL-SAMPLE statistics...
    #  to be pursued elsewhere for different asset classes.
    for i in range(repeat):
        istr = str(i)
        prices = bsret2prices(N, poparr, inprice=inprice, replace=replace)
        if visual:
            plotn(prices, title='tmp-bootshow-' + istr)
        try:
            gm2gem(prices, yearly=yearly, b=b)
        except OverflowError:
            system.warn("Excessive kurtosis: Skipping gm2gem() print.")
        print('---------------------------------------' + istr)
    return