Esempio n. 1
0

baseDir = '/Users/eugene/Downloads/Data/'
# baseDir = '/Users/eugene/Downloads/marketQuotationData/'
# 沪深300 上证50 中证500
instruments = ['000300.SH', '000016.SH', '000905.SH']
instrument = instruments[0]
initCapital = 100000000.0  # 一亿
# startYear = 2015; yearNum = 1
startYear = 2014
yearNum = 2

df = readWSDFile(baseDir, instrument, startYear=startYear, yearNum=yearNum)
print 'Day count:', len(df)
dfi = readWSDIndexFile(baseDir, instrument, startYear, yearNum)
dfmacro = readAndCombineMacroEconomyFile(baseDir, startYear, yearNum=yearNum)
dfmoney = readMoneySupplyFile(baseDir,
                              'money_supply.csv',
                              startYear,
                              yearNum=yearNum)
X, y, actionDates = prepareData(df, dfi, dfmacro, dfmoney)
print np.shape(X), np.shape(y)

normalizer = preprocessing.Normalizer().fit(X)  # fit does nothing
X_norm = normalizer.transform(X)
gamma, C, score = optimizeSVM(X_norm, y, kFolds=10)
print 'gamma=', gamma, 'C=', C, 'score=', score
clf = svm.SVC(kernel='rbf', gamma=gamma, C=C)

pathName, df = readAndReWriteCSV(baseDir,
                                 instrument,
Esempio n. 2
0
    return math.pow(portfolio/C, D/T) - 1


baseDir = '/Users/eugene/Downloads/Data/'
# baseDir = '/Users/eugene/Downloads/marketQuotationData/'
# 沪深300 上证50 中证500
instruments = ['000300.SH', '000016.SH', '000905.SH']
instrument = instruments[2]
initCapital = 100000000.0 # 一亿
startYear = 2015; yearNum = 1
# startYear = 2014; yearNum = 2

df = readWSDFile(baseDir, instrument, startYear=startYear, yearNum=yearNum)
print 'Day count:', len(df)
dfi = readWSDIndexFile(baseDir, instrument, startYear, yearNum)
dfmacro = readAndCombineMacroEconomyFile(baseDir, startYear, yearNum=yearNum)
dfmoney = readMoneySupplyFile(baseDir, 'money_supply.csv', startYear, yearNum=yearNum)
X, y, actionDates = prepareData(df, dfi, dfmacro, dfmoney)
print np.shape(X), np.shape(y)

normalizer = preprocessing.Normalizer().fit(X)  # fit does nothing
X_norm = normalizer.transform(X)
# gamma, C, score = optimizeSVM(X_norm, y, kFolds=10); print 'gamma=',gamma, 'C=',C, 'score=',score
# clf = svm.SVC(kernel='rbf', gamma=2048, C=8)
# clf = svm.SVC(kernel='rbf', gamma=512, C=512)
# clf = svm.SVC(kernel='rbf', gamma=2048, C=32)
# clf = svm.SVC(kernel='rbf', gamma=2048, C=32)
# clf = svm.SVC(kernel='rbf', gamma=2048, C=2)
clf = svm.SVC(kernel='rbf', gamma=2048, C=32768)

from EnsembleTest import optimizeEnsemble