0

如何将输出转换为数据框?它基本上是一本字典。试过_from dict。

Python代码:

startdate = datetime.date(2017,1,12)
expirydate = datetime.date(2017,1,19)
data = dict()

for x in range(0,3):
    for y in range(1,8):
        startdate += datetime.timedelta(days=1)
        if ((startdate.weekday() !=5) and (startdate.weekday() !=6)):

            data [(x,y)] = get_history(symbol="BANKNIFTY",
                        start= startdate,
                        end= startdate,
                        index=True,
                        option_type='CE',
                        strike_price= int(df['CE Strike'][y]),
                        expiry_date=expirydate)

    expirydate += datetime.timedelta(days=7)

输出:

{(0,
  1):                Symbol      Expiry Option Type  Strike Price   Open  High  Low  \
 Date                                                                            
 2017-01-13  BANKNIFTY  2017-01-19          CE       19400.0  24.45  26.4  8.5   

Close   Last  Settle Price  Number of Contracts      Turnover  \

 Date                                                                        
 2017-01-13   13.6  14.45          13.6                35094  2.725216e+10   

 Premium Turnover  Open Interest  Change in OI  Underlying  

 Date                                                                   
 2017-01-13        19213000.0         168360         85160     18912.1  ,
 (0,
  4):                Symbol      Expiry Option Type  Strike Price  Open  High   Low  \
 Date                                                                            
 2017-01-16  BANKNIFTY  2017-01-19          CE       19400.0  11.9  32.0  7.05   

             Close  Last  Settle Price  Number of Contracts      Turnover  \
 Date                                                                       
 2017-01-16  25.75  28.3         25.75                81059  6.296796e+10   

             Premium Turnover  Open Interest  Change in OI  Underlying  
 Date                                                                   
 2017-01-16        66171000.0         254920         86560    19096.45  ,
 (0,
  5):                Symbol      Expiry Option Type  Strike Price  Open  High  \
 Date                                                                      
 2017-01-17  BANKNIFTY  2017-01-19          CE       19300.0  47.0  67.8   

               Low  Close  Last  Settle Price  Number of Contracts  \
 Date                                                                
 2017-01-17  21.95   31.8  25.1          31.8               168465   

                 Turnover  Premium Turnover  Open Interest  Change in OI  \
 Date                                                                      
 2017-01-17  1.303265e+11       271486000.0         525800        233600   

             Underlying  
 Date                    
 2017-01-17    19067.05  ,
 (0,
  6):                Symbol      Expiry Option Type  Strike Price   Open  High  \
 Date                                                                       
 2017-01-18  BANKNIFTY  2017-01-19          CE       19300.0  26.35  75.6   

               Low  Close  Last  Settle Price  Number of Contracts  \
 Date                                                                
 2017-01-18  17.45  28.45  29.0         28.45               271954   

                 Turnover  Premium Turnover  Open Interest  Change in OI  \
 Date                                                                      
 2017-01-18  2.104234e+11       474900000.0         816520        290720   

             Underlying  
 Date                    
 2017-01-18     19164.5  ,
 (0,
  7):                Symbol      Expiry Option Type  Strike Price  Open  High   Low  \
 Date                                                                            
 2017-01-19  BANKNIFTY  2017-01-19          CE       19300.0  26.0  26.0  0.05   

             Close  Last  Settle Price  Number of Contracts      Turnover  \
 Date                                                                       
 2017-01-19    0.1  0.05           0.0               586259  4.526496e+11   

             Premium Turnover  Open Interest  Change in OI  Underlying  
 Date                                                                   
 2017-01-19        57618000.0        1461560        645040    19124.25 
4

0 回答 0