예제 #1
0
 def parse_option_data_by_symbol(self, symbol):
     df = pd.read_hdf(self.option_data_file, symbol)
     if df is not None:
         print '{} data exists, parse it to object...'.format(symbol)
         equity = Equity()
         equity.symbol = symbol
         equity.tradeTime = self.trade_date
         self.equity_records.append(equity)
         for index, row in df.iterrows():
             equity.lastPrice = row['Underlying_Price']
             option = Option()
             option.symbol = symbol
             option.tradeTime = self.trade_date,
             option.expirationDate = row['Expiry']
             option.optionType = row['Type']
             option.strikePrice = row['Strike']
             option.bidPrice = row['Bid']
             option.lastPrice = row['Last']
             option.priceChange = row['Change']
             option.volatility = row['ImpliedVolatility']
             option.theoretical = row['TheoreticalValue']
             option.delta = row['Delta']
             option.gamma = row['Gamma']
             option.rho = row['Rho']
             option.theta = row['Theta']
             option.vega = row['Vega']
             option.openInterest = row['Open Int']
             option.volume = row['Volume']
             self.option_records.append(option)
     else:
         print 'Missing data for {} ...'.format(symbol)
예제 #2
0
 def combine_records(symbol, records):
     equity = Equity()
     equity.symbol = symbol
     equity.tradeTime = records[-1][0]
     equity.openPrice = records[0][1]
     equity.highPrice = max(map(lambda x:x[2], records))
     equity.lowPrice = min(map(lambda x:x[3],records))
     equity.lastPrice = records[-1][4]
     volume = sum(filter(lambda y: y is not None, map(lambda x: x[5], records)))
     if volume != 0:
         equity.volume = volume
     return equity