熊猫对SPY与^ GSPC的使用情况

时间:2015-09-29 02:34:17

标签: python pandas

Pandas'corrwith与SPY合作得很好,但^ GSPC不行。 有谁能够帮我 ?提前谢谢。

import pandas.io.data as web                   
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import csv

Symbol = ['^GSPC','SPY','XLK','XLV','XLY','XLP','XLE','XLF','XLI','XLB','XLU']

STOCK = web.DataReader(name=Symbol,data_source='yahoo',start='2000-1-1',end='2009-3-1')

STOCK['PercentA'] = np.round(np.log(STOCK['Adj Close']/STOCK['Adj Close'].shift(1)),3)

### OK wiht SPY, but not OK wiht ^GSPC
STOCKCORR = np.round(STOCK['PercentA'].corrwith(STOCK['PercentA'].^GSPC),3)     

StockNan = STOCKCORR[~STOCKCORR.isnull()]
StockOrder = StockNan.order().iloc[::-1]
StockRows = StockOrder.iloc[:20]          
print StockRows

错误消息:

  
    
      

runfile('D:/ @@@ pg / yahoo_final_Chang / 150830__Revised / test.py',wdir ='D:/ @@@ pg / yahoo_final_Chang / 150830__Revised')

    
  

追踪(最近一次呼叫最后一次):

文件“”,第1行,

文件“C:\ Anaconda \ lib \ site-packages \ spyderlib \ widgets \ externalshell \ sitecustomize.py”,第682行,在runfile中     execfile(filename,namespace)

文件“C:\ Anaconda \ lib \ site-packages \ spyderlib \ widgets \ externalshell \ sitecustomize.py”,第71行,在execfile中     exec(compile(scripttext,filename,'e​​xec'),glob,loc)

档案“D:/ @@@ pg / yahoo_final_Chang / 150830__Revised / test.py”,第16行     STOCKCORR = np.round(STOCK ['PercentA']。corrwith(STOCK ['PercentA']。^ GSPC),3)
                                                                      ^ SyntaxError:语法无效

0 个答案:

没有答案