Ejemplo n.º 1
0
print(reg.rsquared_adj)

# a_beta = reg.params['BETA_F']
# a_smb = reg.params['SMB_F']
# a_hc = reg.params['HC_F']

a_beta = 0.744710
a_smb = 0.399662
a_hc = 0.244484
init_stock = Util.BILLION / 100

data_hedge = data.iloc[1:,:].copy()
# data_hedge = data_hedge[['index_top5', '000300.SH', '000905.SH', '000016.SH', 'HC.SHF']]
data_hedge = data_hedge[['index_top5', 'IF.CFE', 'IC.CFE', 'IH.CFE', 'HC.SHF']]
init_closes = np.array(data_hedge.iloc[0])
weights = np.array([1, -a_beta, -a_smb, a_smb, -a_hc])
init_mktvalues = weights*init_stock
init_capital = sum(np.array([1, a_beta*0.2, a_smb*0.2, a_smb*0.2, a_hc*0.2])*init_stock) # 五倍杠杆
units = init_mktvalues/init_closes
print(units)
print(np.array(data_hedge.iloc[0]))
print(np.array(data_hedge.iloc[1]))
data_hedge['hedged_mkv'] = data_hedge.apply(lambda x:sum(x*units),axis=1)
data_hedge['pnl'] = data_hedge['hedged_mkv'] -data_hedge.iloc[0]['hedged_mkv']
data_hedge['NPV'] = (data_hedge['pnl']+init_capital)/init_capital

account = BaseAccount(init_capital,rf=0.0)
res = account.get_netvalue_analysis(data_hedge['NPV'])
print(res)
data_hedge.to_csv('data/result_hedged_port.csv')
        ) * 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()
Ejemplo n.º 3
0
                    execute_type=c.ExecuteType.EXECUTE_ALL_UNITS)
            account.add_record(execution_record,
                               account.dict_holding[order.id_instrument])
            maturity1 = optionset.select_maturity_date(
                nbr_maturity=nbr_maturity, min_holding=min_holding)
            atm_put, premium = buy_put(moneyness, maturity1)
            total_premium += premium + execution_record[
                c.Util.TRADE_BOOK_VALUE]

        account.daily_accounting(optionset.eval_date)
        optionset.next()
        underlying.next()

    # series_npv = account.account[c.Util.PORTFOLIO_NPV]
    # series_npv.iloc[-1] = series_npv.iloc[-1] * (1+alpha) # plus alpha
    analysis = account.get_netvalue_analysis(
        account.account[c.Util.PORTFOLIO_NPV])
    analysis['权利金占比'] = total_premium / init_fund
    df_underlying_with_alpha.loc[:,
                                 'npv_50etf'] = df_underlying_with_alpha.loc[:, 'etf_close'] / df_underlying_with_alpha.loc[
                                     0, 'etf_close']
    analysis_50ETF = account.get_netvalue_analysis(
        df_underlying_with_alpha['npv_50etf'])
    df_underlying_with_alpha.loc[:,
                                 'npv_50etf_alpha'] = df_underlying_with_alpha.loc[:, c.Util.AMT_CLOSE] / df_underlying_with_alpha.loc[
                                     0, c.Util.AMT_CLOSE]
    analysis_50ETF_alpha = account.get_netvalue_analysis(
        df_underlying_with_alpha['npv_50etf_alpha'])

    df[str(d1) + ':hedged'] = analysis
    df[str(d1) + ':etf'] = analysis_50ETF
    df[str(d1) + ':etf_alpha'] = analysis_50ETF_alpha