Ejemplo n.º 1
0
def main():
    # read data
    
    key_word = 'rare earths'
    debt_data = pd.read_csv('../Data/%s_google_trend.csv' %key_word,header = 1)
    nasdaq = pd.read_csv('../Data/nasdaq_historical_quotes.csv',header = 0)[['Date','Open','Close']]
    
    # preprocess data
    preprocess_raw_data = m.preprocessData(debt_data, key_word, nasdaq)
    
    # strategy excution
    trade_data = m.excuteStrategy(preprocess_raw_data,key_word, excute_random_strategy = False)
    
    #print trade_data.describe()
    
    # process trade result data
    trade_data = processTradingData(trade_data)

    # hmm model analyze
    hmmtest(trade_data, trade_data[['Nasdaq_Close_RDP_5','Strategy_Gross_Return_RDP_5']])
    columnName = []
    period = [1,2,5,15,30]
    column = ['Nasdaq_Close','Strategy_Gross_Return','Strategy_Cumulative_Return_R']
    for col in column:
        for i in period:
            col_name = str('%s_RDP_%s' % (col, str(i))) 
            columnName.append(col_name)
def hmmAnalyze(key_word, result_csv):
    # Acquiring data
    fileName = ('../Data/%s_google_trend.csv'%key_word)
    key_word_data = pd.read_csv(fileName,header = 1)
    nasdaq = pd.read_csv('../Data/nasdaq_historical_quotes.csv',header = 0)[['Date','Open','Close']]
    
    # Processing data
    preprocess_raw_data = ma.preprocessData(key_word_data,key_word, nasdaq)
    
    # add indicator into data for trading strategy
    trade_data = ma.excuteStrategy(preprocess_raw_data, key_word)
    
    # preprocess data
    trade_data = hmm.processTradingData(trade_data)
    
    # hmm model analyze
    print ('%s is under test' %key_word)
    result_model = hmm.hmmtest(trade_data, trade_data[['Nasdaq_Close_RDP_5','Strategy_Gross_Return_RDP_5']])
    columnName = []
    period = [1,2,5,15,30]
    column = ['Nasdaq_Close','Strategy_Gross_Return','Strategy_Cumulative_Return_R']
    for col in column:
        for i in period:
            col_name = str('%s_RDP_%s' % (col, str(i))) 
            columnName.append(col_name)
    
    outputResult(key_word,result_model, result_csv,trade_data)
    
    print('-------------------------')