Exemplo n.º 1
0
def _get_alt_price(i):
    print('Calculating alternating prices for %s ' % i)
    univ_ib_ret = mkt_retrieve(i, 'Stats', 'Returns')
    univ_ib_op = univ_ib_ret['Open'].values
    univ_ib_cl = univ_ib_ret['Close'].values

    univ_ib_sprc = univ_ib_ret[['Contract', 'Date']]
    for smth in _smth:  # range(6, _smth + 1, 3)
        _sp = smth_param(smth)
        for days in range(1, _days+1):
            nb = filt.fst_nan(univ_ib_cl)
            ne = len(univ_ib_cl)
            univ_ib_ord = np.ones(ne, dtype=int) * 99
            univ_ib_ap = np.zeros(ne) * np.nan
            for k in range(0, days):
                univ_ib_ord[nb + days + k - 1:ne:days] = k
            for k in range(0, days):
                zk = np.where(univ_ib_ord == k)[0]
                cl_ = univ_ib_cl[list(zk)]
                op_ = univ_ib_op[list(zk - days + 1)]
                univ_ib_ap[list(zk)] = filt.smth_price(op_, cl_, _sp[0], _sp[1], _sp[2], _sp[3], 0, _sp[4])
            univ_ib_ap = filt.sma(univ_ib_ap, days)
            univ_ib_ap = filt.fill(univ_ib_ap)
            if (days < 10) and (smth < 10):
                univ_ib_sprc['D0'+str(days)+'S0'+str(smth)] = univ_ib_ap
            elif (days >= 10) and (smth < 10):
                univ_ib_sprc['D'+str(days)+'S0'+str(smth)] = univ_ib_ap
            elif (days < 10) and (smth >= 10):
                univ_ib_sprc['D0'+str(days)+'S'+str(smth)] = univ_ib_ap
            else:
                univ_ib_sprc['D'+str(days)+'S'+str(smth)] = univ_ib_ap
    del univ_ib_sprc['Contract']
    mkt_store(i, 'Stats', 'AltReturns', univ_ib_sprc)
from CrazyCod.Utilities.pkgstdy import *
import CrazyCod.Utilities.quantreg5 as qreg5
from CrazyCod.Futures.Collect.step4_getreturns import get_all_equity_index_names
from multiprocessing import Pool
from CrazyCod.Utilities.smth_price_results import smth_param
import warnings
from CrazyCod.Utilities.frames import DataFrame
import matplotlib.pyplot as plt
import CrazyCod.Utilities.boosting as bst

_eq_idx = get_all_equity_index_names()

_sm_pr = [8, 11, 14, 17, 20, 23, 26, 29]
_sm_pr_sum = []
for i in _sm_pr:
    _sm_pr_sum.append(np.sum(np.array(smth_param(i))))

_sig_set_95_lvl = ['D04S26_429_QRB', 'D04S26_156_LRB', 'D04S29_236_LRB', 'D10S26_521_QRB', 'D10S11_521_QRG',
                   'D09S23_349_QRB', 'D03S29_285_QRB', 'D03S29_107_LRB', 'D09S23_107_LRB', 'D07S29_349_LRB',
                   'D03S17_349_QRG', 'D09S29_005_QRG', 'D01S08_009_QRB', 'D01S08_005_LRB', 'D10S17_070_LRB',
                   'D10S23_349_QRG', 'D09S29_008_QRG', 'D02S08_007_QRB', 'D01S08_015_QRB', 'D01S14_005_QRB',
                   'D10S29_236_QRB', 'D10S11_059_LRB', 'D04S26_285_QRG', 'D08S29_193_QRB', 'D09S14_005_QRG',
                   'D01S08_021_QRB', 'D09S17_007_QRG', 'D10S26_012_QRG', 'D03S08_008_QRB', 'D02S17_193_QRB',
                   'D03S29_005_QRB', 'D03S29_070_LRB', 'D01S11_048_QRG', 'D10S29_005_QRG', 'D01S08_005_QRB',
                   'D08S26_285_QRG', 'D01S08_021_QRG', 'D03S08_012_QRB', 'D08S11_005_QRB', 'D01S08_038_QRB',
                   'D09S08_005_QRG', 'D01S08_027_QRG', 'D10S29_521_LRB', 'D07S23_015_QRG', 'D02S17_059_QRG',
                   'D09S29_129_QRB', 'D03S20_059_QRG', 'D01S08_009_QRG', 'D08S29_005_QRG', 'D01S08_012_QRG',
                   'D01S08_070_QRG', 'D04S29_027_QRG', 'D07S26_236_QRG', 'D09S11_012_QRG', 'D09S08_007_QRG',
                   'D03S14_012_QRB', 'D03S14_236_QRG', 'D01S29_070_LRB', 'D01S20_021_QRG', 'D07S08_007_QRG',
                   'D01S08_007_QRG', 'D09S14_005_QRB', 'D10S14_005_QRG', 'D06S11_017_QRB', 'D06S11_021_QRG',
                   'D04S11_015_QRB', 'D07S23_005_QRG', 'D07S14_009_QRG', 'D01S11_015_QRG', 'D04S14_032_QRB',