コード例 #1
0
    # 开仓
    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()

コード例 #2
0
while futureset.has_next():
    if not c_1.has_next():
        print(futureset.eval_date)
        order = account.create_trade_order(c_1, LongShort.SHORT, 10)
        record = c_1.execute_order(order)
        account.add_record(record, c_1)
        contracts = futureset.eligible_futures
        c_1 = futureset.select_higher_volume(contracts)
        print(c_1.id_instrument())
        order = account.create_trade_order(c_1, LongShort.LONG, 10)
        record = c_1.execute_order(order)
        account.add_record(record, c_1)
    account.daily_accounting(futureset.eval_date)
    futureset.next()
print(account.analysis())
print(account.trade_records)
"""
accumulate_yield     0.098943
annual_yield         0.207676
annual_volatility    0.094362
max_drawdown        -0.042301
prob_of_win(D)       0.523810
win_loss_ratio       1.301487
sharpe               2.200838
Calmar               4.909454
turnover             1.655823
avg_margin           0.113584
max_margin           0.118410
"""