Alat yang lebih baik membuat pekerjaan yang baik - belajar menggunakan lingkungan penelitian untuk menganalisis prinsip perdagangan

Penulis:Lydia, Dibuat: 2022-12-27 16:33:51, Diperbarui: 2023-09-20 09:17:27

img

Alat yang lebih baik membuat pekerjaan yang baik belajar menggunakan lingkungan penelitian untuk menganalisis prinsip perdagangan

Istilah hedging adalah konsep yang sangat dasar dalam bidang perdagangan kuantitatif dan perdagangan program. Dalam perdagangan kuantitatif mata uang digital, strategi lindung nilai yang sering digunakan adalah: hedging spot futures, hedging cross-period dan hedging spot, yang pada dasarnya adalah transaksi untuk perbedaan harga. Mungkin ketika datang ke konsep, prinsip dan rincian lindung nilai, banyak siswa yang baru memasuki bidang perdagangan kuantitatif masih tidak terlalu jelas. Tidak masalah. Mari kita gunakan QuantAnalyze alat yang disediakan oleh platform Trading FMZ untuk mempelajari dan menguasai pengetahuan ini dengan mudah.

Di Dashboard platform FMZ Quant, klik Analisis untuk melompat ke halaman alat:

img

Di sini saya mengunggah file analisis langsung: Dokumen analisis ini adalah analisis proses pembukaan dan penutupan posisi lindung nilai spot futures selama backtesting.quarterBursa spot adalah transaksi mata uang-mata uang OKX, dan pasangan perdagangan adalahBTC_USDT. Untuk menganalisis proses operasi hedging spot berjangka, Anda dapat melihat file lingkungan penelitian spesifik berikut, ditulis dalam dua versi: versi bahasa Python, versi bahasa JavaScript.

Lingkungan penelitian File bahasa Python

Analisis pada prinsip hedging spot futures.ipynb Dalam [1]:

from fmz import *
task = VCtx('''backtest
start: 2019-09-19 00:00:00
end: 2019-09-28 12:00:00
period: 15m
exchanges: [{"eid":"Futures_OKCoin","currency":"BTC_USD", "stocks":1}, {"eid":"OKX","currency":"BTC_USDT","balance":10000,"stocks":0}]
''')
# Create backtesting environment
import matplotlib.pyplot as plt
import numpy as np
# Import the plot library matplotlib and library numpy

Dalam [2]:

exchanges[0].SetContractType("quarter")    # The first exchange object OKX Futures (eid: Futures_OKCoin) calls the function to set the current contract as a quarterly contract
initQuarterAcc = exchanges[0].GetAccount() # The initial account information of OKX Futures Exchange is recorded in the variable initQuarterAcc
initQuarterAcc

Keluar[2]: {Balance: 0.0, FrozenBalance: 0.0, Stock: 1.0, FrozenStock: 0.0}

Dalam [3]:

initSpotAcc = exchanges[1].GetAccount()    # The initial account information of the OKX Spot Exchange is recorded in the variable initSpotAcc
initSpotAcc

Keluar[3]: {Balanse: 10000.0, FrozenBalance: 0.0, Stock: 0.0, FrozenStock: 0.0}

Dalam [4]:

quarterTicker1 = exchanges[0].GetTicker()  # Get the futures exchange ticker, recorded in the variable quarterTicker1
quarterTicker1

Keluar[4]: Waktu: 1568851210000, High: 10441.25002, Rendah : 10441.25, Menjual: 10441.25002, Beli : 10441.25, Terakhir : 10441.25001, Volume: 1772.0, OpenInterest: 0.0}

Dalam [5]:

spotTicker1 = exchanges[1].GetTicker()     # Get the spot exchange ticker, recorded in the variable spotTicker1
spotTicker1

Keluar[5]: Waktu: 1568851210000, tinggi : 10156.60000002, Rendah : 10156.6, Menjual: 10156.60000002, Beli : 10156.6, Terakhir : 10156.60000001, Volume: 7.4443, OpenInterest: 0.0}

Dalam [6]:

quarterTicker1.Buy - spotTicker1.Sell      # The price difference between going short on futures and going long on spot.

Keluar[6]: 284.6499999799999985

Dalam [7]:

exchanges[0].SetDirection("sell")                       # Set up a futures exchange and trade in the direction of going short
quarterId1 = exchanges[0].Sell(quarterTicker1.Buy, 10)  # Futures go short to place orders. The order quantity is 10 contracts. The returned order ID is recorded in the variable quarterId1.
exchanges[0].GetOrder(quarterId1)                       # Check the details of the order with futures order ID quarterId1.

Keluar[7]: {Id: 1, Harga: 10441.25, Jumlah: 10.0, DealAmount: 10.0, Rata-rata Harga : 10441.25, Tipe: 1, Offset: 0, Status: 1, Tip Kontrak: bkuartal}

Dalam [8]:

spotAmount = 10 * 100 / quarterTicker1.Buy                 # Calculate the currency equivalent of 10 contracts as the order quantity of the spot.
spotId1 = exchanges[1].Buy(spotTicker1.Sell, spotAmount)   # Place orders on the spot exchange
exchanges[1].GetOrder(spotId1)                             # Check the order details of the spot order ID of spotId1

Keluar[8]: {Id: 1, Harga : 10156.60000002, Jumlah : 0,0957, DealAmount: 0,0957, Rata-rata Harga : 10156.60000002, Tipe: 0, Offset: 0, Status: 1, ContractType: bBTC_USDT_OKX}

Anda dapat melihat bahwa pesanan quarterId1 dan order spotId1 telah dipenuhi sepenuhnya, yaitu lindung nilai posisi terbuka telah selesai.

Dalam [9]:

Sleep(1000 * 60 * 60 * 24 * 7)       # Hold the position for a while and wait for the price difference to become smaller to close the position.

Setelah waktu tunggu, bersiap untuk menutup posisi.quarterTicker2, spotTicker2dan mencetak mereka. Arah transaksi dari obyek pertukaran berjangka diatur untuk menutup posisi pendek:exchanges[0].SetDirection("closesell")menempatkan perintah untuk menutup posisi. Cetak rincian pesanan posisi penutupan, menunjukkan bahwa pesanan penutupan telah selesai, posisi penutupan selesai.

Dalam [10]:

quarterTicker2 = exchanges[0].GetTicker()     # Get the current futures exchange ticker, recorded in the variable quarterTicker2
quarterTicker2

Keluar[10]: Waktu: 1569456010000, High: 8497.20002, Rendah : 8497.2, Menjual: 8497.20002, Buy: 8497.2, Terakhir : 8497.20001, Volume: 4311.0, OpenInterest: 0.0}

Dalam [11]:

spotTicker2 = exchanges[1].GetTicker()       # Get the current ticker of the spot exchange, recorded in the variable spotTicker2
spotTicker2

Keluar[11]: {Time: 1569456114600, High: 8444.70000001, Low: 8444.69999999, Menjual: 8444.70000001, Buy: 8444.69999999, Terakhir: 8444.7, Volume: 78.6273, OpenInterest: 0.0}

Dalam [12]:

quarterTicker2.Sell - spotTicker2.Buy        # The price difference between closing a short futures position and closing a long spot position.

Keluar[12]: 52.5000200100003

Di [13]:

exchanges[0].SetDirection("closesell")                   # Set the current trading direction of the futures exchange to close short positions.
quarterId2 = exchanges[0].Buy(quarterTicker2.Sell, 10)   # The futures exchange places an order to close a position and records the order ID to the variable quarterId2.
exchanges[0].GetOrder(quarterId2)                        # Check futures close out order details

Keluar[13]: 2 tahun. Harga: 8497.20002, Jumlah: 10.0, DealAmount: 10.0, Rata-rata Harga : 8493.95335, Tipe: 0, Offset: 1, Status: 1, Tip Kontrak: bkuartal}

Dalam [14]:

spotId2 = exchanges[1].Sell(spotTicker2.Buy, spotAmount) # The spot exchange places an order to close a position and records the order ID, which is recorded to the variable spotId2.
exchanges[1].GetOrder(spotId2)      # Check spot close out order details

Keluar[14]: 2 tahun. Harga: 8444.69999999, Jumlah : 0,0957, DealAmount: 0,0957, Rata-rata Harga : 8444.69999999, Tipe: 1, Offset: 0, Status: 1, ContractType: bBTC_USDT_OKX}

Di [15]:

nowQuarterAcc = exchanges[0].GetAccount()   # Get the current futures exchange account information, recorded in the variable nowQuarterAcc.
nowQuarterAcc

Keluar[15]: { saldo: 0,0, FrozenBalance: 0,0, Stok: 1.021786026184, FrozenStocks: 0.0}

Di [16]:

nowSpotAcc = exchanges[1].GetAccount()      # Get the current spot exchange account information, recorded in the variable nowSpotAcc.
nowSpotAcc

Keluar[16]: { saldo : 9834.74705446, FrozenBalance: 0,0, Stock: 0,0, FrozenStocks: 0.0}

Dengan membandingkan rekening awal dengan rekening arus, laba rugi dari operasi lindung nilai dihitung.

Di [17]:

diffStocks = abs(nowQuarterAcc.Stocks - initQuarterAcc.Stocks)
diffBalance = nowSpotAcc.Balance - initSpotAcc.Balance
if nowQuarterAcc.Stocks - initQuarterAcc.Stocks > 0 :
    print("profits:", diffStocks * spotTicker2.Buy + diffBalance)
else :
    print("profits:", diffBalance - diffStocks * spotTicker2.Buy)

Keluar[17]: Keuntungan: 18,72350977580652

Sekarang mari kita lihat mengapa lindung nilai menguntungkan. kita dapat melihat grafik yang digambar. harga futures adalah garis biru dan harga spot adalah garis oranye. kedua harga menurun. harga futures menurun lebih cepat daripada harga spot. harga futures menurun lebih cepat daripada harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga futures. harga futures menurun lebih cepat dari harga spot. harga futures menurun dari harga harga yang lebih rendah dari harga yang lebih rendah. harga futures menurun dari harga yang lebih rendah dari harga yang lebih rendah. harga futures menurun dari harga yang lebih rendah dari harga yang

Dalam [18]:

xQuarter = [1, 2]
yQuarter = [quarterTicker1.Buy, quarterTicker2.Sell]

xSpot = [1, 2]
ySpot = [spotTicker1.Sell, spotTicker2.Buy]
plt.plot(xQuarter, yQuarter, linewidth=5)
plt.plot(xSpot, ySpot, linewidth=5)
plt.show()

Keluar[18]:

img

Perbedaan harga berkisar dari 284 pada saat posisi pembukaan lindung nilai (yaitu, berjangka pergi pendek, dan spot pergi panjang) hingga 52 pada saat posisi penutupan (posisi pendek berjangka ditutup, posisi panjang spot ditutup).

Dalam [19]:

xDiff = [1, 2]
yDiff = [quarterTicker1.Buy - spotTicker1.Sell, quarterTicker2.Sell - spotTicker2.Buy]
plt.plot(xDiff, yDiff, linewidth=5)
plt.show()

Keluar[19]:

img

Misalnya, a1 adalah harga futures pada waktu 1, dan b1 adalah harga spot pada waktu 1. A2 adalah harga futures pada waktu 2, dan b2 adalah harga spot pada waktu 2.Selama perbedaan harga spot futures pada waktu 1 (a1-b1) lebih besar dari perbedaan harga spot futures pada waktu 2 (a2-b2), a1 - a2>b1 - b2 dapat diperkenalkan. Ada tiga situasi: (jumlah posisi berjangka dan spot adalah sama)

  1. a1 - a2 lebih besar dari 0, b1 - b2 lebih besar dari 0 a1 - a2 mengacu pada perbedaan harga keuntungan berjangka, dan b1 - b2 mengacu pada perbedaan harga kerugian spot (karena spot pergi panjang, harga mulai membeli lebih tinggi dari harga jual untuk menutup posisi, sehingga uang hilang), tetapi keuntungan berjangka lebih besar dari kerugian spot. Jadi menguntungkan secara keseluruhan. Situasi ini sesuai dengan grafik di langkah In [8].

  2. a1 - a2 lebih besar dari 0, b1 - b2 kurang dari 0 a1 - a2 adalah perbedaan harga keuntungan berjangka, dan b1 - b2 adalah perbedaan harga keuntungan spot (b1 - b2 kurang dari 0, menunjukkan bahwa b2 lebih besar dari b1, yaitu harga posisi pembukaan dan pembelian rendah, dan harga jual dan penutupan tinggi, sehingga menguntungkan).

  3. a1 - a2 kurang dari 0, b1 - b2 kurang dari 0 a1 - a2 adalah perbedaan harga kerugian berjangka, dan b1 - b2 adalah perbedaan harga keuntungan spot. Karena a1 - a2 > b1 - b2, nilai absolut a1 - a2 kurang dari nilai absolut b1 - b2, dan keuntungan spot lebih besar dari kerugian berjangka.

Tidak ada kasus di mana a1 - a2 kurang dari 0 dan b1 - b2 lebih besar dari 0, karena a1 - a2 > b1 - b2 telah didefinisikan. Demikian pula, jika a1 - a2 sama dengan 0, karena a1 - a2 > b1 - b2 telah didefinisikan, b1 - b2 harus kurang dari 0. Oleh karena itu, selama metode lindung nilai berjangka pendek dan spot panjang memenuhi kondisi a1 - b1 > a2 - b2, operasi posisi pembukaan dan penutupan adalah lindung nilai keuntungan.

Misalnya, model berikut adalah salah satu kasus:

Dalam [20]:

a1 = 10
b1 = 5
a2 = 11
b2 = 9

# a1 - b1 > a2 - b2 launches: a1 - a2 > b1 - b2

xA = [1, 2]
yA = [a1, a2]

xB = [1, 2]
yB = [b1, b2]
plt.plot(xA, yA, linewidth=5)
plt.plot(xB, yB, linewidth=5)
plt.show()

Keluar[20]:

img

Lingkungan pencarian File bahasa JavaScript

Lingkungan penelitian mendukung tidak hanya Python, tetapi juga JavaScript Saya juga memberikan contoh lingkungan penelitian JavaScript:

Analisis prinsip hedging spot futures (JavaScript).ipynb Dalam [1]:

// Import the required package, click "Save settings" on the FMZ's "Strategy editing page" to get the string configuration and convert it to an object.
var fmz = require("fmz")                           // Import the talib, TA, and plot libraries automatically after import
var task = fmz.VCtx({
start: '2019-09-19 00:00:00',
end: '2019-09-28 12:00:00',
period: '15m',
exchanges: [{"eid":"Futures_OKCoin","currency":"BTC_USD","stocks":1},{"eid":"OKX","currency":"BTC_USDT","balance":10000,"stocks":0}]
})

Dalam [2]:

exchanges[0].SetContractType("quarter")  // The first exchange object OKX Futures (eid: Futures_OKCoin) calls the function to set the current contract as a quarterly contract.
var initQuarterAcc = exchanges[0].GetAccount()  // The initial account information of OKX Futures Exchange is recorded in the variable initQuarterAcc.
initQuarterAcc

Keluar[2]: { Saldo: 0, FrozenBalanse: 0, Stok: 1, FrozenStocks: 0 }

Dalam [3]:

var initSpotAcc = exchanges[1].GetAccount()     // The initial account information of the OKX Spot Exchange is recorded in the variable initSpotAcc.
initSpotAcc

Keluar[3]: { Saldo: 10 000, FrozenSaldo: 0, Stok: 0, FrozenStocks: 0 }

Dalam [4]:

var quarterTicker1 = exchanges[0].GetTicker()   // Get the futures exchange ticker, recorded in the variable quarterTicker1.
quarterTicker1

Keluar[4]: { Waktu: 1568851210000, Tinggi: 10441.25002, Rendah: 10441.25, Jual: 10441.25002, Beli: 10441.25, Terakhir: 10441.25001, Volume: 1772, OpenInterest: 0

Dalam [5]:

var spotTicker1 = exchanges[1].GetTicker()     // Get the spot exchange ticker, recorded in the variable spotTicker1.
spotTicker1

Keluar[5]: { Waktu: 1568851210000, Tinggi: 10156.60000002, Rendah: 10156.6, Jual: 10156.60000002, Beli: 10156.6, Terakhir: 10156.60000001, Volume: 7.4443, OpenInterest: 0

Dalam [6]:

quarterTicker1.Buy - spotTicker1.Sell         // The price difference between going short on futures and going long on spot.

Keluar[6]: 284.6499999799999985 Dalam [7]:

exchanges[0].SetDirection("sell")             // Set up a futures exchange and trade in the direction of going short
var quarterId1 = exchanges[0].Sell(quarterTicker1.Buy, 10)  // Go short futures to place orders. The order quantity is 10 contracts. The returned order ID is recorded in the variable quarterId1.
exchanges[0].GetOrder(quarterId1)                           // Check the details of the order with futures order ID quarterId1.

Keluar[7]: {Id: 1, Harga: 10441.25, Jumlah: 10, Jumlah transaksi: 10, Rata-rata Harga: 10441.25, Jenis: 1, Offset: 0, Status: 1, Kontrak Tipe: kuartal }

Dalam [8]:

var spotAmount = 10 * 100 / quarterTicker1.Buy                  // Calculate the currency equivalent of 10 contracts as the order quantity of the spot.
var spotId1 = exchanges[1].Buy(spotTicker1.Sell, spotAmount)    // Place orders on the spot exchange.
exchanges[1].GetOrder(spotId1)                                  // Check the order details of the spot order ID of spotId1.

Keluar[8]: {Id: 1, Harga: 10156.60000002, Jumlah: 0,0957, DealAmount: 0.0957, Rata-rata Harga: 10156.60000002, Jenis: 0, Offset: 0, Status: 1, ContractType: BTC_USDT_OKX }

Anda dapat melihat bahwa pesanan quarterId1 dan spotId1 telah diisi sepenuhnya, yaitu lindung nilai posisi pembukaan telah selesai.

Dalam [9]:

Sleep(1000 * 60 * 60 * 24 * 7)            // Hold the position for a while and wait for the price difference to become smaller to close the position.

Setelah waktu tunggu, bersiap untuk menutup posisi.quarterTicker2, spotTicker2dan mencetak mereka. Arah transaksi dari obyek pertukaran berjangka diatur untuk menutup posisi pendek:exchanges[0].SetDirection("closesell")menempatkan perintah untuk menutup posisi. Cetak rincian pesanan posisi penutupan, menunjukkan bahwa pesanan penutupan telah selesai, posisi penutupan selesai.

Dalam [10]:

var quarterTicker2 = exchanges[0].GetTicker()    // Get the current futures exchange ticker, recorded in the variable quarterTicker2.
quarterTicker2

Keluar[10]: { Waktu: 1569456010000, Tinggi: 8497.20002, Rendah: 8497.2, Jual: 8497.20002, Beli: 8497.2, Terakhir: 8497.20001, Volume: 4311, OpenInterest: 0

Dalam [11]:

var spotTicker2 = exchanges[1].GetTicker()       // Get the current ticker of the spot exchange, recorded in the variable spotTicker2.
spotTicker2

Keluar[11]: { Waktu: 1569456114600, Tinggi: 8444.70000001, Sedikit: 8444.69999999, Jual: 8444.70000001, Beli: 8444.69999999, Terakhir: 8444.7, Volume: 78.6273, OpenInterest: 0

Dalam [12]:

quarterTicker2.Sell - spotTicker2.Buy            // The price difference between closing short position of futures and closing long position of spot.

Keluar[12]: 52.5000200100003

Di [13]:

exchanges[0].SetDirection("closesell")           // Set the current trading direction of the futures exchange to close short positions.
var quarterId2 = exchanges[0].Buy(quarterTicker2.Sell, 10)       // The futures exchange places an order to close the position, and records the order ID to the variable quarterId2.
exchanges[0].GetOrder(quarterId2)                                // Check futures closing position order details.

Keluar[13]: {Id: 2, Harga: 8497.20002, Jumlah: 10, DealAmount: 10, Rata-rata Harga: 8493.95335, Jenis: 0, Offset: 1, Status: 1, Kontrak Tipe: kuartal }

Dalam [14]:

var spotId2 = exchanges[1].Sell(spotTicker2.Buy, spotAmount)     // The spot exchange places an order to close the position, and records the order ID to the variable spotId2.
exchanges[1].GetOrder(spotId2)                                   // Check spot closing position order details.

Keluar[14]: {Id: 2, Harga: 8444.69999999, Jumlah: 0,0957, DealAmount: 0.0957, Rata-rata Harga: 8444.69999999, Jenis: 1, Offset: 0, Status: 1, ContractType: BTC_USDT_OKX }

Di [15]:

var nowQuarterAcc = exchanges[0].GetAccount()     // Get the current futures exchange account information, recorded in the variable nowQuarterAcc.
nowQuarterAcc                                     

Keluar[15]: { Saldo: 0, FrozenBalance: 0, Persediaan: 1.021786026184, FrozenStocks: 0 }

Di [16]:

var nowSpotAcc = exchanges[1].GetAccount()        // Get the current spot exchange account information, recorded in the variable nowSpotAcc.
nowSpotAcc

Keluar[16]: { saldo: 9834.74705446, FrozenBalance: 0, Stok: 0, FrozenStocks: 0 } Dengan membandingkan rekening awal dengan rekening arus, laba rugi dari operasi lindung nilai dihitung.

Di [17]:

var diffStocks = Math.abs(nowQuarterAcc.Stocks - initQuarterAcc.Stocks)
var diffBalance = nowSpotAcc.Balance - initSpotAcc.Balance
if (nowQuarterAcc.Stocks - initQuarterAcc.Stocks > 0) {
    console.log("profits:", diffStocks * spotTicker2.Buy + diffBalance)
} else {
    console.log("profits:", diffBalance - diffStocks * spotTicker2.Buy)
}

Keluar[17]: Keuntungan: 18,72350977580652

Sekarang mari kita lihat mengapa lindung nilai menguntungkan. kita dapat melihat grafik yang digambar. harga futures adalah garis biru dan harga spot adalah garis oranye. kedua harga menurun. harga futures menurun lebih cepat daripada harga spot. harga futures menurun lebih cepat daripada harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga spot. harga futures menurun lebih cepat dari harga futures. harga futures menurun lebih cepat dari harga spot. harga futures menurun dari harga harga yang lebih rendah dari harga yang lebih rendah. harga futures menurun dari harga yang lebih rendah dari harga yang lebih rendah. harga futures menurun dari harga yang lebih rendah dari harga yang

Dalam [18]:

var objQuarter = {
    "index" : [1, 2],                                          // The index is 1, that is, the first time, the opening time, and 2 is the closing time.
    "arrPrice" : [quarterTicker1.Buy, quarterTicker2.Sell],
}
var objSpot = {
    "index" : [1, 2],
    "arrPrice" : [spotTicker1.Sell, spotTicker2.Buy],
}
plot([{name: 'quarter', x: objQuarter.index, y: objQuarter.arrPrice}, {name: 'spot', x: objSpot.index, y: objSpot.arrPrice}])

Keluar[18]: Perbedaan harga berkisar dari 284 pada saat hedging posisi pembukaan (yaitu, berjangka pergi pendek, dan spot pergi panjang) hingga 52 pada saat penutupan (penutupan posisi pendek berjangka, dan penutupan posisi panjang spot).

Dalam [19]:

var arrDiffPrice = [quarterTicker1.Buy - spotTicker1.Sell, quarterTicker2.Sell - spotTicker2.Buy]
plot(arrDiffPrice)

Keluar[19]:Misalnya, a1 adalah harga futures pada waktu 1, dan b1 adalah harga spot pada waktu 1. A2 adalah harga futures pada waktu 2, dan b2 adalah harga spot pada waktu 2.Selama perbedaan harga spot futures pada waktu 1 (a1-b1) lebih besar dari perbedaan harga spot futures pada waktu 2 (a2-b2), a1 - a2>b1 - b2 dapat diperkenalkan. Ada tiga situasi: (jumlah posisi berjangka dan spot adalah sama)

  1. a1 - a2 lebih besar dari 0, b1 - b2 lebih besar dari 0 a1 - a2 mengacu pada perbedaan harga keuntungan berjangka, dan b1 - b2 mengacu pada perbedaan harga kerugian spot (karena spot pergi panjang, harga mulai membeli lebih tinggi dari harga jual untuk menutup posisi, sehingga uang hilang), tetapi keuntungan berjangka lebih besar dari kerugian spot. Jadi menguntungkan secara keseluruhan. Situasi ini sesuai dengan grafik di langkah In [8].

  2. a1 - a2 lebih besar dari 0, b1 - b2 kurang dari 0 a1 - a2 adalah perbedaan harga keuntungan berjangka, dan b1 - b2 adalah perbedaan harga keuntungan spot (b1 - b2 kurang dari 0, menunjukkan bahwa b2 lebih besar dari b1, yaitu harga posisi pembukaan dan pembelian rendah, dan harga jual dan penutupan tinggi, sehingga menguntungkan).

  3. a1 - a2 kurang dari 0, b1 - b2 kurang dari 0 a1 - a2 adalah perbedaan harga kerugian berjangka, dan b1 - b2 adalah perbedaan harga keuntungan spot. Karena a1 - a2 > b1 - b2, nilai absolut a1 - a2 kurang dari nilai absolut b1 - b2, dan keuntungan spot lebih besar dari kerugian berjangka.

Tidak ada kasus di mana a1 - a2 kurang dari 0 dan b1 - b2 lebih besar dari 0, karena a1 - a2 > b1 - b2 telah didefinisikan. Demikian pula, jika a1 - a2 sama dengan 0, karena a1 - a2 > b1 - b2 telah didefinisikan, b1 - b2 harus kurang dari 0. Oleh karena itu, selama metode lindung nilai berjangka pendek dan spot panjang memenuhi kondisi a1 - b1 > a2 - b2, operasi posisi pembukaan dan penutupan adalah lindung nilai keuntungan.

Misalnya, model berikut adalah salah satu kasus:

Dalam [20]:

var a1 = 10
var b1 = 5
var a2 = 11
var b2 = 9

// a1 - b1 > a2 - b2 launches: a1 - a2 > b1 - b2

var objA = {
    "index" : [1, 2],
    "arrPrice" : [a1, a2],
}
var objB = {
    "index" : [1, 2],
    "arrPrice" : [b1, b2],
}
plot([{name : "a", x : objA.index, y : objA.arrPrice}, {name : "b", x : objB.index, y : objB.arrPrice}])

Keluar[20]:

Cobalah, kawan-kawan!


Berkaitan

Lebih banyak