本文整理汇总了Python中transaction.Transaction.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.to_dict方法的具体用法?Python Transaction.to_dict怎么用?Python Transaction.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.to_dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: take_position
# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import to_dict [as 别名]
def take_position(self):
option_gamma = {}
left = self.hsi_price * (1 - bandwidth)
right = self.hsi_price * (1 + bandwidth)
if self.maturity in [call_month, put_month]:
for call_option_dict in db.find_all_option(call_month, 'call'):
# call = util.to_HSIOption(call_option_dict)
call = call_option_dict
strike_price = call.get_strike_price()
put_option_dict = db.find_option(call_month, strike_price, 'put')
if put_option_dict is not None:
# put = util.to_HSIOption(db.find_option('W', strike_price, 'put'))
put = put_option_dict
if None not in [call, put] and 999999.0 not in [call.get_option_price(),put.get_option_price()] \
and util.range_in_defined(left, strike_price, right):
time_to_maturity = util.time_to_maturity(self.maturity, self.date)
c_volatility = bs.get_volatility_quick(self.hsi_price, strike_price, R, time_to_maturity,
call.get_option_price(), 'call')
call_delta = bs.get_delta(self.hsi_price, strike_price, R, time_to_maturity, c_volatility, 'call')
p_volatility = bs.get_volatility_quick(self.hsi_price, strike_price, R, time_to_maturity,
put.get_option_price(), 'put')
put_delta = bs.get_delta(self.hsi_price, strike_price, R, time_to_maturity, p_volatility, 'put')
if (strike_price, call_month, 'call') not in self.today_volatility:
self.today_volatility[(strike_price, call_month, 'call')] = [c_volatility]
else:
self.today_volatility[(strike_price, call_month, 'call')].append(c_volatility)
if (strike_price, put_month, 'put') not in self.today_volatility:
self.today_volatility[(strike_price, put_month, 'put')] = [p_volatility]
else:
self.today_volatility[(strike_price, put_month, 'put')].append(p_volatility)
if True and (c_volatility > mean_vol and p_volatility > mean_vol):
if abs(call_delta + put_delta) < 0.1:
if ts.compare_volatility(ts.fn(yesterday, (strike_price, call_month, 'call'), (strike_price, put_month, 'put'),[init_vol_k, init_vol_w]), c_volatility + p_volatility):
option_gamma[(call, put)] = bs.get_gamma(self.hsi_price, strike_price, R, time_to_maturity, c_volatility) + bs.get_gamma(self.hsi_price, strike_price,R, time_to_maturity,p_volatility)
if option_gamma == {}:
return None
call, put = ts.get_max_gamma(option_gamma)
calls = map(lambda x:call.generate_option(1),range(0,2))
puts = map(lambda x:put.generate_option(1),range(0,2))
tran = Transaction([],calls,puts,3,self.tick,self.date)
db.insert_position(tran.to_dict())
return tran