@@ -2542,7 +2542,7 @@ def BS_VALUE(df, quote=None, r=0.025, v=None):
2542
2542
if not (quote and quote .ins_class .endswith ("OPTION" ) and quote .underlying_symbol == df ["symbol" ][0 ]):
2543
2543
return pd .DataFrame (np .full_like (df ["close" ], float ('nan' )), columns = ["bs_price" ])
2544
2544
if v is None :
2545
- v = tqsdk .tafunc ._get_volatility (df ["close" ], df ["duration" ], quote .trading_time , float ( 'nan' ) )
2545
+ v = tqsdk .tafunc ._get_volatility (df ["close" ], df ["duration" ], quote .trading_time )
2546
2546
if math .isnan (v ):
2547
2547
return pd .DataFrame (np .full_like (df ["close" ], float ('nan' )), columns = ["bs_price" ])
2548
2548
o = 1 if quote .option_class == "CALL" else - 1
@@ -2595,8 +2595,7 @@ def OPTION_GREEKS(df, quote=None, r=0.025, v=None):
2595
2595
o = 1 if quote .option_class == "CALL" else - 1
2596
2596
t = tqsdk .tafunc ._get_t_series (df ["datetime" ], df ["duration" ], quote ) # 到期时间
2597
2597
if v is None :
2598
- his_v = tqsdk .tafunc ._get_volatility (df ["close1" ], df ["duration" ], quote .trading_time , 0.3 )
2599
- v = tqsdk .tafunc .get_impv (df ["close1" ], df ["close" ], quote .strike_price , r , his_v , t , o )
2598
+ v = tqsdk .tafunc .get_impv (df ["close1" ], df ["close" ], quote .strike_price , r , 0.3 , t , o )
2600
2599
d1 = tqsdk .tafunc ._get_d1 (df ["close1" ], quote .strike_price , r , v , t )
2601
2600
new_df ["delta" ] = tqsdk .tafunc .get_delta (df ["close1" ], quote .strike_price , r , v , t , o , d1 )
2602
2601
new_df ["theta" ] = tqsdk .tafunc .get_theta (df ["close1" ], quote .strike_price , r , v , t , o , d1 )
@@ -2672,9 +2671,10 @@ def OPTION_IMPV(df, quote=None, r=0.025):
2672
2671
if not (quote and quote .ins_class .endswith ("OPTION" ) and quote .instrument_id == df ["symbol" ][0 ]
2673
2672
and quote .underlying_symbol == df ["symbol1" ][0 ]):
2674
2673
return pd .DataFrame (np .full_like (df ["close1" ], float ('nan' )), columns = ["impv" ])
2675
- init_v = tqsdk .tafunc ._get_volatility (df ["close1" ], df ["duration" ], quote .trading_time , 0.3 )
2674
+ his_v = tqsdk .tafunc ._get_volatility (df ["close1" ], df ["duration" ], quote .trading_time )
2675
+ his_v = 0.3 if math .isnan (his_v ) else his_v
2676
2676
o = 1 if quote .option_class == "CALL" else - 1
2677
2677
t = tqsdk .tafunc ._get_t_series (df ["datetime" ], df ["duration" ], quote ) # 到期时间
2678
2678
return pd .DataFrame (
2679
- data = list (tqsdk .tafunc .get_impv (df ["close1" ], df ["close" ], quote .strike_price , r , init_v , t , o )),
2679
+ data = list (tqsdk .tafunc .get_impv (df ["close1" ], df ["close" ], quote .strike_price , r , his_v , t , o )),
2680
2680
columns = ["impv" ])
0 commit comments