gammalist1 = [] gammalist2 = [] for spot in spotlist: delta = pricing_utl.get_blackcalculator(dt_date, spot, Option, rf, vol).Delta() # gamma = pricing_utl.get_blackcalculator(dt_date, spot, Option, rf, vol).Gamma() # gammalist1.append(gamma) deltalist_1.append(delta) delta2 = pricing_utl.get_blackcalculator(dt_date, spot, Option, 0.1, vol).Delta() # gamma2 = pricing_utl.get_blackcalculator(dt_date, spot, Option2, rf, vol).Gamma() deltalist_2.append(delta2) # gammalist2.append(gamma2) plot_utl = PlotUtil() plot_utl.plot_line_chart(spotlist, [deltalist_2, deltalist_1], ['Delta (rf=0.03)', 'Delta (rf=0.1)']) # plot_utl.plot_line_chart(spotlist, [gammalist2,gammalist1], ['Gamma(T=1M)','Gamma(T=3M)']) plt.show() df = pd.DataFrame() df['spot'] = spotlist df['delta'] = deltalist_1 df.to_excel('../delta.xlsx') # for spot in spotlist: # black1 = pricing_utl.get_blackcalculator(dt_date, spot, Option, rf, vol) # delta1 = black1.Delta() # gamma1 = black1.Gamma() # black2 = pricing_utl.get_blackcalculator(dt_date, spot, Option, rf, vol2) # delta2 = black2.Delta() # gamma2 = black2.Gamma() # gammalist1.append(gamma1) # deltalist_1.append(delta1)
) * delta_call + unit_p * atm_put.multiplier() * delta_put hedge_unit = hedging.get_hedge_rebalancing_unit( options_delta, buy_write) hedging.synthetic_unit += -hedge_unit if hedge_unit > 0: long_short = c.LongShort.LONG else: long_short = c.LongShort.SHORT order_u = account.create_trade_order(hedging, long_short, hedge_unit) record_u = hedging.execute_order(order_u, slippage=slippage) account.add_record(record_u, hedging) account.daily_accounting(optionset.eval_date) total_liquid_asset = account.cash + account.get_portfolio_margin_capital() print(optionset.eval_date, hedging.eval_date, account.account.loc[optionset.eval_date, c.Util.PORTFOLIO_NPV], int(account.cash), int(total_liquid_asset)) if not optionset.has_next(): break optionset.next() hedging.next() account.account.to_csv('account.csv') df_records = pd.DataFrame(account.list_records) df_records.to_csv('df_records.csv') res = account.get_netvalue_analysis(account.account[c.Util.PORTFOLIO_NPV]) print(res) dates = list(account.account.index) npv = list(account.account[c.Util.PORTFOLIO_NPV]) pu.plot_line_chart(dates, [npv], ['npv']) plt.show()
print('iv_avg : ', iv_avg) print('htb rate : ', htbr) # curve = optionset.get_implied_vol_curves(maturity) # curve_htbr = optionset.get_implied_vol_curves_htbr(maturity) curve_otm = optionset.get_otm_implied_vol_curve(maturity) # curve_htbr[Util.PCT_IV_CALL_BY_HTBR] = curve_htbr[Util.PCT_IV_CALL_BY_HTBR].apply(lambda x: None if x<0.05 else x) # curve_htbr[Util.PCT_IV_PUT_BY_HTBR] = curve_htbr[Util.PCT_IV_PUT_BY_HTBR].apply(lambda x: None if x<0.05 else x) curve_otm[Util.PCT_IV_OTM_BY_HTBR] = curve_otm[Util.PCT_IV_OTM_BY_HTBR].apply( lambda x: None if x < 0.05 else x) strikes = curve_otm[Util.AMT_APPLICABLE_STRIKE] # pu.plot_line_chart(strikes,[list(curve[Util.PCT_IV_CALL]),list(curve[Util.PCT_IV_PUT])],['CALL IV','PUT iv']) # pu.plot_line_chart(strikes,[list(curve_htbr[Util.PCT_IV_CALL_BY_HTBR]),list(curve_htbr[Util.PCT_IV_PUT_BY_HTBR])],['CALL IV adjusted','PUT IV adjusted']) pu.plot_line_chart(strikes, [list(curve_otm[Util.PCT_IV_OTM_BY_HTBR])], ['IV : ' + str(optionset.eval_date)]) ivs1 = list(curve_otm[Util.PCT_IV_OTM_BY_HTBR]) optionset.next() maturity = optionset.select_maturity_date(nbr_maturity, min_holding=min_holding) iv_htr = optionset.get_atm_iv_by_htbr(maturity) iv_avg = get_atm_iv_average(optionset, maturity) htbr = optionset.get_htb_rate(maturity) print('iv_htr : ', iv_htr) print('iv_avg : ', iv_avg) print('htb rate : ', htbr) # curve = optionset.get_implied_vol_curves(maturity) # curve_htbr = optionset.get_implied_vol_curves_htbr(maturity)
# plt.show() """""""" df_iv = get_data.get_iv_by_moneyness(dt_histvol,end_date,name_code_option) df_iv_call = df_iv[df_iv[c.Util.CD_OPTION_TYPE]=='call'] df_iv_put = df_iv[df_iv[c.Util.CD_OPTION_TYPE]=='put'] df_data = df_iv_call[[c.Util.DT_DATE,c.Util.PCT_IMPLIED_VOL]].rename(columns={c.Util.PCT_IMPLIED_VOL:'iv_call'}) df_data = df_data.join(df_iv_put[[c.Util.DT_DATE,c.Util.PCT_IMPLIED_VOL]].set_index(c.Util.DT_DATE),on=c.Util.DT_DATE,how='outer')\ .rename(columns={c.Util.PCT_IMPLIED_VOL:'iv_put'}) df_data = df_data.dropna().reset_index(drop=True) df_data.loc[:,'average_iv'] = df_data.loc[:,'iv_call'] + df_data.loc[:,'iv_put'] series_iv = df_data['average_iv'] dates = list(df_data[c.Util.DT_DATE]) r_20 = list(timebase.LLKSR(series_iv,20)) raw = list(series_iv) pu.plot_line_chart(dates,[raw,r_20],['raw','LLKSR']) df_iv_stats = df_data[[c.Util.DT_DATE, 'average_iv']] df_iv_stats.loc[:,'iv_std_60'] = c.Statistics.standard_deviation(df_iv_stats['average_iv'], n=60) df_iv_stats.loc[:,'ma_60'] = c.Statistics.moving_average(df_iv_stats['average_iv'], n=60) df_iv_stats.loc[:,'ma_20'] = c.Statistics.moving_average(df_iv_stats['average_iv'], n=20) df_iv_stats.loc[:,'ma_10'] = c.Statistics.moving_average(df_iv_stats['average_iv'], n=10) df_iv_stats.loc[:,'ma_3'] = c.Statistics.moving_average(df_iv_stats['average_iv'], n=3) # df_iv_stats = df_iv_stats.dropna() df_iv_stats.loc[:,'upper'] = upper = df_iv_stats.loc[:,'ma_60'] + df_iv_stats.loc[:,'iv_std_60'] df_iv_stats.loc[:,'lower'] = lower = df_iv_stats.loc[:,'ma_60'] - df_iv_stats.loc[:,'iv_std_60'] dates = list(df_iv_stats[c.Util.DT_DATE]) upper = list(upper)
# # plt.show() """5、With Delta Bounds""" # print('5.start') # cd_vol = '1M' # res_histvol, res_vix = analysis_strikes_with_delta_bounds(dt1, dt2, df_cf, df_cf_minute, df_vix, df_index, cd_vol) # print(res_histvol) # print(res_vix) # res_histvol.to_excel('../res_sh50future_histvol_with_delta_bounds_1M.xlsx') # res_vix.to_excel('../res_sh50future_vix_with_delta_bounds.xlsx') """ 6、Continuously hedging """ cd_vol = '1M' res = hedging_constant_ttm(dt1, dt2, df_cf, df_cf_minute, df_index, pct_strike=1.0, cd_vol=cd_vol) res.to_excel('../res.xlsx') analysis = Analysis.get_netvalue_analysis(res['npv']) analysis2 = Analysis.get_netvalue_analysis(res['benchmark']) print('-'*100) print('analysis hedged') print('-'*100) print(analysis) print('-'*100) print('analysis unhedged') print('-'*100) print(analysis2) plot_utl.plot_line_chart(res['dt_date'].tolist(),[res['npv'].tolist(),res['benchmark'].tolist()],['portfolio','sh300']) plt.show() """ Active vol signaled by vix change """ # df_histvol = get_hist_vol('1M',df_cf) # histvol_ivix_signal(df_histvol,df_vix)
# plt.plot(x_grid, pdf_cc,'r--', label='Estimate') # plt.hist(histvols, bins=30, normed=True, color=(0,.5,0,1), label='Histogram') # plt.figure(2) pdf_gk = kde_sklearn(garman_klass_vols, x_grid, bandwidth=0.03) # plt.plot(x_grid, pdf_gk,'r--', label='Estimate') # plt.hist(garman_klass_vols, bins=30, normed=True, color=(0,.5,0,1), label='Histogram') # plt.figure(3) pdf_p = kde_sklearn(parkinson_vols, x_grid, bandwidth=0.03) # plt.plot(x_grid, pdf_p,'r--', label='Estimate') # plt.hist(parkinson_vols, bins=30, normed=True, color=(0,.5,0,1), label='Histogram') plt.figure(1) pu.plot_line_chart(x_grid,[pdf_cc,pdf_gk,pdf_p],['Close-to-close','Garman_Klass','Parkinson']) plt.figure(2) vols_1w = np.array(df_data[c.Util.AMT_HISTVOL+'_5']) pdf_1w = kde_sklearn(vols_1w, x_grid, bandwidth=0.03) vols_1m = np.array(df_data[c.Util.AMT_HISTVOL+'_20']) pdf_1m = kde_sklearn(vols_1m, x_grid, bandwidth=0.03) vols_3m = np.array(df_data[c.Util.AMT_HISTVOL+'_60']) pdf_3m = kde_sklearn(vols_3m, x_grid, bandwidth=0.03) pu.plot_line_chart(x_grid,[pdf_1w,pdf_1m,pdf_3m],['Weekly kde','Monthly kde','Quarterly kde']) plt.show()
# 开仓 if empty_position: maturity = optionset.select_maturity_date(nbr_maturity=nbr_maturity, min_holding=min_holding) put = select_target_moneyness_put(c.OptionType.PUT,optionset,moneyness_put,maturity) unit_put = np.floor(account.portfolio_total_value/index.mktprice_close()/put.multiplier()) # unit_put = np.floor(unit_stock*stock.multiplier()*stock.mktprice_close() / put.multiplier()) order_put = account.create_trade_order(put, c.LongShort.LONG, unit_put, cd_trade_price=cd_price) record_put = put.execute_order(order_put, slippage=slippage) account.add_record(record_put, put) empty_position = False account.daily_accounting(optionset.eval_date) benchmark.append(index.mktprice_close()/init_index) benchmark1.append(stock.mktprice_close()/init_stock) if not optionset.has_next(): break optionset.next() index.next() stock.next() account.account['base_npv'] = benchmark account.account.to_csv('../account-protective_put1.csv') account.trade_records.to_csv('../records-protective_put1.csv') res = account.analysis() print(res) dates = list(account.account.index) npv = list(account.account[c.Util.PORTFOLIO_NPV]) pu.plot_line_chart(dates,[npv,benchmark,benchmark1],['npv','benchmark1','benchmark2']) plt.show()
print(res) # res_base = account1.get_netvalue_analysis(account1.account['base_npv']) # res_index = account1.get_netvalue_analysis(account1.account['index_npv']) # df_res['ih_hedged'] = res # df_res['ih'] = res_base # df_res['index'] = res_index # df_res.to_csv('../../accounts_data/res_ih_.csv') pu = PlotUtil() dates = list(account1.account.index) hedged_npv = list(account1.account[c.Util.PORTFOLIO_NPV]) base_npv = list(account1.account['base_npv']) index_npv = list(account1.account['index_npv']) pu.plot_line_chart(dates, [hedged_npv, base_npv], ['hedged_npv', 'base_npv']) # pu.plot_line_chart(dates, [index_npv, base_npv], ['index_npv', 'base_npv']) plt.show() # account1.account.to_csv('../../accounts_data/hedge_account_ih_' + cd_short_ma + '_' + cd_long_ma + '_' + cd_std + '.csv') # account1.trade_records.to_csv('../../accounts_data/hedge_records_ih_' + cd_short_ma + '_' + cd_long_ma + '_' + cd_std + '.csv') # for cd_std in ['std_5','std_10','std_15','std_20']: # # # for P_mdd in [-0.09,-0.08, -0.07, -0.06,-0.05,-0.04]: # for P_mdd in [-0.07]: # # df_account = pd.read_excel('../../accounts_data/hedge_account_'+cd_short_ma+'_'+cd_long_ma+'_'+cd_std+'.xlsx') # # df_account['date'] = df_account[c.Util.DT_DATE].apply(lambda x: x.date()) # hedging = HedgeIndexByOptions(df_index, df_metrics, # cd_direction_timing=cd_direction_timing, # cd_strategy=cd_strategy, cd_volatility=cd_volatility,
iv_avg = get_atm_iv_average(optionset, maturity) htbr = optionset.get_htb_rate(maturity) print('iv_htr : ', iv_htr) print('iv_avg : ', iv_avg) print('htb rate : ', htbr) curve = optionset.get_implied_vol_curves(maturity) curve_htbr = optionset.get_implied_vol_curves_htbr(maturity) curve_otm = optionset.get_otm_implied_vol_curve(maturity) curve_htbr[Util.PCT_IV_CALL_BY_HTBR] = curve_htbr[ Util.PCT_IV_CALL_BY_HTBR].apply(lambda x: None if x < 0.05 else x) curve_htbr[Util.PCT_IV_PUT_BY_HTBR] = curve_htbr[ Util.PCT_IV_PUT_BY_HTBR].apply(lambda x: None if x < 0.05 else x) curve_otm[Util.PCT_IV_OTM_BY_HTBR] = curve_otm[Util.PCT_IV_OTM_BY_HTBR].apply( lambda x: None if x < 0.05 else x) strikes = curve[Util.AMT_APPLICABLE_STRIKE] pu.plot_line_chart( strikes, [list(curve[Util.PCT_IV_CALL]), list(curve[Util.PCT_IV_PUT])], ['CALL IV', 'PUT iv']) pu.plot_line_chart(strikes, [ list(curve_htbr[Util.PCT_IV_CALL_BY_HTBR]), list(curve_htbr[Util.PCT_IV_PUT_BY_HTBR]) ], ['CALL IV adjusted', 'PUT IV adjusted']) pu.plot_line_chart(strikes, [list(curve_otm[Util.PCT_IV_OTM_BY_HTBR])], ['IV-' + str(optionset.eval_date)]) plt.show()
american_binomial_tree.step_back(0) list_bm_ame.append(american_binomial_tree.NPV()) # print(american_binomial_tree.T) # print("american binomial_tree price", american_binomial_tree.NPV()) european_binomial_tree = BinomialTree(steps, dt_eval, dt_maturity, OptionType.PUT, OptionExerciseType.EUROPEAN, spot_price, strike_price, volatility) european_binomial_tree.initialize() european_binomial_tree.step_back(0) # print("european binomial_tree price", european_binomial_tree.NPV()) list_bm_euro.append(european_binomial_tree.NPV()) # black = BlackCalculator(dt_eval, dt_maturity, strike_price, OptionType.PUT, spot_price, volatility) # print("european blackcalculator price", black.NPV()) binomial_engine = ql.BinomialVanillaEngine(bsm_process, "crr", steps) black_engine = ql.AnalyticEuropeanEngine(bsm_process) american_option.setPricingEngine(binomial_engine) # print("american quantlib price(BinomialVanillaEngine)", american_option.NPV()) european_option.setPricingEngine(binomial_engine) # print("european quantlib price(BinomialVanillaEngine)", european_option.NPV()) # european_option.setPricingEngine(black_engine) # print("european quantlib price(blackcalculator)", european_option.NPV()) list_ql_euro.append(european_option.NPV()) list_ql_ame.append(american_option.NPV()) pu.plot_line_chart(x, [list_bm_euro, list_ql_euro], ['bimonial euro', 'quantpib euro'], 'steps') pu.plot_line_chart(x, [list_bm_ame, list_ql_ame], ['bimonial ame', 'quantpib ame'], 'steps') plt.show()
data['BETA_S'] = hv.arithmetic_yield(data['000300.SH']) data['SMB_F'] = hv.arithmetic_yield(data['IC.CFE']) - hv.arithmetic_yield(data['IH.CFE']) data['SMB_S'] = hv.arithmetic_yield(data['000905.SH']) - hv.arithmetic_yield(data['000016.SH']) # data['RB_F'] = hv.arithmetic_yield(data['RB.SHF']) # data['RB_S'] = hv.arithmetic_yield(data['RB']) data['HC_F'] = hv.arithmetic_yield(data['HC.SHF']) # data['HC_S'] = hv.arithmetic_yield(data['HC']) # data['I_F'] = hv.arithmetic_yield(data['I.DCE']) # data['J_F'] = hv.arithmetic_yield(data['J.DCE']) # data['LC_S'] = hv.arithmetic_yield(data['LC']) # data['GC_S'] = hv.arithmetic_yield(data['GC']) # data['RB_PROFIT_F'] = hv.arithmetic_yield(data['steel_profit']) # 期货 data = data.set_index('date') pu = PlotUtil() data_reg = data.copy() data_reg['y'] = hv.arithmetic_yield(data_reg['index_top5']) data_reg = data_reg[['y', 'BETA_S', 'SMB_S', 'HC_F']].dropna() x_s = data_reg[['BETA_S', 'SMB_S', 'HC_F']] y = data_reg['y'] reg = Statistics.linear_regression(x_s, y) print(reg.params) print(reg.pvalues) print(reg.rsquared) print(reg.rsquared_adj) rsd = reg.resid cum_rsd= (1+rsd).cumprod() pu.plot_line_chart(list(data_reg.index),[cum_rsd]) plt.show()
print(reg.rsquared_adj) rsd = reg.resid cum_rsd = (1 + rsd).cumprod() dates = list(data_reg.index) df_cum_yield = pd.DataFrame(index=data.index) # for col in top_five: # r = hv.arithmetic_yield(data[col]) # df_cum_yield[col] = (1 + r).cumprod() # df_cum_yield['BETA'] = (1+data['BETA_S']).cumprod() # df_cum_yield['cum_rsd_801041'] = (1+rsd).cumprod() df_cum_yield['cum_rsd_index_bysales'] = (1 + rsd).cumprod() df_cum_yield['cum_rsd_beta'] = (1 + data['BETA_S']).cumprod() df_cum_yield['cum_rsd_smb'] = (1 + data['SMB_S']).cumprod() df_cum_yield.to_csv('data/df_cum_yield.csv') pu.plot_line_chart(dates, [cum_rsd], ['cum_rsd']) def steel_stock_factoring(): df_res1 = pd.DataFrame(index=data.index) df_res2 = pd.DataFrame(index=data.index) df_res3 = pd.DataFrame(index=data.index) df_params_s = pd.DataFrame() df_params_f = pd.DataFrame() for id_stock in col_names: data_reg = data.copy() data_reg['y'] = hv.arithmetic_yield(data_reg[id_stock]) data_reg_s = data_reg[['y', 'BETA_S', 'SMB_S', 'HC_S']].dropna() x_s = data_reg_s[['BETA_S', 'SMB_S', 'HC_S']] y = data_reg_s['y']
# print(account.account.iloc[-3,:]) # print('-'*50) # print(account.account.iloc[-2,:]) # print('-'*50) # print(account.account.iloc[-1,:]) # print('-'*50) df_res_d.to_csv('../data/df_res_close.csv') df_mdd_d.to_csv('../data/df_mdd_close.csv') df_yield_d.to_csv('../data/df_yield_close.csv') pu = PlotUtil() dates = list(account.account.index) npvs.append(list(account.account['benchmark'])) methods.append('benchmark') deltas = list(account.account['position_delta']) pu.plot_line_chart(dates, npvs, methods) # pu.plot_line_chart(dates, [deltas], ['仓位占比']) plt.show() ######### Delta Bounds ################### # npvs = [] # df_yield_d = pd.DataFrame() # df_mdd_d = pd.DataFrame() # df_res_d = pd.DataFrame() # for u in [0.9,0.95,0.99,1]: # print(u) # sythetic = SytheticOption(df_index=df_base) # sythetic.k = 1.05 # sythetic.d = 50 # sythetic.cd_model = 'ww'
def hist_vol(dt_start, df_future_c1_daily): m = 100 df_future_c1_daily.loc[:, 'histvol_10'] = Histvol.hist_vol(df_future_c1_daily[c.Util.AMT_CLOSE], n=10) * m df_future_c1_daily.loc[:, 'histvol_20'] = Histvol.hist_vol(df_future_c1_daily[c.Util.AMT_CLOSE], n=20) * m df_future_c1_daily.loc[:, 'histvol_30'] = Histvol.hist_vol(df_future_c1_daily[c.Util.AMT_CLOSE], n=30) * m df_future_c1_daily.loc[:, 'histvol_60'] = Histvol.hist_vol(df_future_c1_daily[c.Util.AMT_CLOSE], n=60) * m df_future_c1_daily.loc[:, 'histvol_90'] = Histvol.hist_vol(df_future_c1_daily[c.Util.AMT_CLOSE], n=90) * m df_future_c1_daily.loc[:, 'histvol_120'] = Histvol.hist_vol(df_future_c1_daily[c.Util.AMT_CLOSE], n=120) * m return df_future_c1_daily pu = PlotUtil() end_date = datetime.date(2018,12,31) start_date = datetime.date(2010, 1, 1) writer = ExcelWriter('../data/histvol_data_python.xlsx') name_codes = [c.Util.STR_CF, c.Util.STR_C, c.Util.STR_RU, c.Util.STR_M,c.Util.STR_CU] for (idx, name_code) in enumerate(name_codes): print(name_code) # df_res = pd.DataFrame() df_future_c1_daily = get_data.get_gc_future_c1_daily(start_date, end_date, name_code) pu.plot_line_chart(list(df_future_c1_daily[c.Util.DT_DATE]),[list(df_future_c1_daily[c.Util.AMT_CLOSE])],['close_'+name_code]) df_future_c1_daily = hist_vol(start_date, df_future_c1_daily) df_future_c1_daily = df_future_c1_daily.sort_values(by=c.Util.DT_DATE, ascending=False) df_future_c1_daily.to_excel(writer, 'hv_'+name_code) # pu.plot_line_chart(list(df_future_c1_daily[c.Util.DT_DATE]),[list(df_future_c1_daily['histvol_30'])],['histvol_'+name_code]) # plt.show() writer.save()
df_iv_stats['KALMAN_5'] = KALMAN(df_iv_stats['average_iv'], 5) df_iv_stats['diff_20'] = df_iv_stats['KALMAN_20'].diff() df_iv_stats['diff_10'] = df_iv_stats['KALMAN_10'].diff() df_iv_stats['diff_5'] = df_iv_stats['KALMAN_5'].diff() """ 4. Filtration : LLT """ df_iv_stats['LLT_20'] = LLT(df_iv_stats['average_iv'], 20) df_iv_stats['LLT_10'] = LLT(df_iv_stats['average_iv'], 10) df_iv_stats['LLT_5'] = LLT(df_iv_stats['average_iv'], 5) df_iv_stats['diff_20'] = df_iv_stats['LLT_20'].diff() df_iv_stats['diff_10'] = df_iv_stats['LLT_10'].diff() df_iv_stats['diff_5'] = df_iv_stats['LLT_5'].diff() df_iv_stats = df_iv_stats.set_index(c.Util.DT_DATE) pu.plot_line_chart(list(df_iv_stats.index), [list(df_iv_stats['average_iv']), list(df_iv_stats['std'])], ['iv', 'chg of vol']) pu.plot_line_chart(list(df_iv_stats.index), [ list(df_iv_stats['ma_5']), list(df_iv_stats['KALMAN_5']), list(df_iv_stats['LLKSR_5']), list(df_iv_stats['LLT_5']) ], ['ma_5', 'KALMAN_5', 'LLKSR_5', 'LLT_5']) pu.plot_line_chart(list(df_iv_stats.index), [ list(df_iv_stats['ma_20']), list(df_iv_stats['KALMAN_20']), list(df_iv_stats['LLKSR_20']), list(df_iv_stats['LLT_20']) ], ['ma_20', 'KALMAN_20', 'LLKSR_20', 'LLT_20']) plt.show()
# if not hedged and upward_tangent(optionset.eval_date, df_iv_llt): if not hedged: print('1. buy option', optionset.eval_date) maturity = optionset.select_maturity_date(nbr_maturity=nbr_maturity, min_holding=min_holding) atm_put, premium = buy_put(moneyness, maturity) total_premium += premium hedged = True account.daily_accounting(optionset.eval_date) print(optionset.eval_date, account.account.loc[optionset.eval_date, c.Util.PORTFOLIO_NPV]) optionset.next() underlying.next() df_records = pd.DataFrame(account.list_records) # df_records.to_csv('df_records.csv') analysis = account.get_netvalue_analysis(account.account[c.Util.PORTFOLIO_NPV]) analysis['total_premium'] = total_premium print(analysis) dates = list(account.account.index) npv = list(account.account[c.Util.PORTFOLIO_NPV]) df_underlying.loc[:, 'npv_50etf'] = df_underlying.loc[:, c.Util.AMT_CLOSE] / \ df_underlying.loc[0, c.Util.AMT_CLOSE] analysis_50ETF = account.get_netvalue_analysis(df_underlying['npv_50etf']) pu.plot_line_chart(dates, [npv], ['npv']) pu.plot_line_chart(list(df_underlying[c.Util.DT_DATE]), [list(df_underlying['npv_50etf'])], ['npv base']) plt.show()