Alat yang lebih baik membuat kerja yang baik - belajar menggunakan persekitaran penyelidikan untuk menganalisis prinsip perdagangan

Penulis:Lydia, Dicipta: 2022-12-27 16:33:51, Dikemas kini: 2023-09-20 09:17:27

img

Alat yang lebih baik membuat kerja yang baik belajar menggunakan persekitaran penyelidikan untuk menganalisis prinsip perdagangan

Istilah hedging adalah konsep yang sangat asas dalam bidang perdagangan kuantitatif dan perdagangan program. Dalam perdagangan kuantitatif mata wang digital, strategi lindung nilai yang sering digunakan ialah: lindung nilai spot niaga hadapan, lindung nilai cross-period dan lindung nilai spot, yang pada dasarnya adalah transaksi untuk perbezaan harga. Mungkin ketika datang kepada konsep, prinsip dan butiran lindung nilai, ramai pelajar yang baru memasuki bidang perdagangan kuantitatif masih tidak begitu jelas. Tidak kira. Mari kita gunakan QuantAnalyze alat yang disediakan oleh platform Perdagangan FMZ untuk mempelajari dan menguasai pengetahuan ini dengan mudah.

Dalam Dasbor platform FMZ Quant, klik Analisis untuk melompat ke halaman alat:

img

Di sini saya memuat naik fail analisis secara langsung: Dokumen analisis ini adalah analisis proses pembukaan dan penutupan kedudukan lindung nilai spot niaga hadapan semasa backtesting.quarterpertukaran spot adalah OKX mata wang-mata wang urus niaga, dan pasangan dagangan adalahBTC_USDTUntuk menganalisis proses operasi lindung nilai spot niaga hadapan, anda boleh melihat fail persekitaran penyelidikan khusus berikut, yang ditulis dalam dua versi: versi bahasa Python, versi bahasa JavaScript.

Kawasan Penyelidikan fail bahasa Python

Analisis prinsip lindung nilai spot niaga hadapan.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]: {Balan : 0.0, FrozenBalan : 0.0, Stok : 1.0, FrozenStocks : 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]: {Balan : 10000.0, FrozenBalan : 0.0, Stok : 0.0, FrozenStocks : 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, Low : 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, High: 10156.60000002, Low: 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, jenis: 1, Offset: 0, Status: 1, Tip Kontrak: bseparuh}

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, jenis: 0, Offset: 0, Status: 1, ContractType: bBTC_USDT_OKX}

Anda dapat melihat bahawa pesanan suku Id1 dan pesanan spot Id1 telah dipenuhi sepenuhnya, iaitu lindung nilai kedudukan 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.

Selepas masa menunggu, bersedia untuk menutup kedudukan.quarterTicker2, spotTicker2dan cetak mereka. Arah urus niaga objek pertukaran niaga hadapan ditetapkan untuk menutup kedudukan pendek:exchanges[0].SetDirection("closesell")meletakkan perintah untuk menutup kedudukan. Mencetak butiran pesanan kedudukan penutupan, menunjukkan bahawa pesanan penutupan telah selesai, kedudukan 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, Low: 8497.2, Menjual: 8497.20002, Beli : 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

Dalam [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, jenis: 0, Offset: 1, Status: 1, Tip Kontrak: bseparuh}

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, jenis: 1, Offset: 0, Status: 1, ContractType: bBTC_USDT_OKX}

Dalam [15]:

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

Keluar[15]: {Balan: 0.0, FrozenBalance: 0.0, stok : 1.021786026184, FrozenStocks: 0.0}

Dalam [16]:

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

Keluar[16]: { Satupun: 9834.74705446, FrozenBalance: 0.0, Sedekah: 0.0, FrozenStocks: 0.0}

Dengan membandingkan akaun awal dengan akaun semasa, keuntungan dan kerugian operasi lindung nilai dikira.

Dalam [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 adalah menguntungkan. kita boleh melihat carta yang digambar. harga niaga hadapan adalah garis biru dan harga spot adalah garis oren. kedua-dua harga menurun. harga niaga hadapan menurun lebih cepat daripada harga spot.

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 [1]:

img

Mari kita lihat perubahan perbezaan harga. Perbezaan harga berkisar dari 284 pada masa kedudukan pembukaan lindung nilai (iaitu, niaga hadapan pergi pendek, dan tempat pergi panjang) kepada 52 pada masa kedudukan penutupan (posisi masa hadapan pendek ditutup, kedudukan tempat panjang ditutup). Perbezaan harga adalah dari besar ke kecil.

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

Sebagai contoh, a1 adalah harga niaga hadapan pada masa 1, dan b1 adalah harga spot pada masa 1. A2 adalah harga niaga hadapan pada masa 2, dan b2 adalah harga spot pada masa 2.Selagi perbezaan harga spot niaga hadapan pada masa 1 (a1-b1) lebih besar daripada perbezaan harga spot niaga hadapan pada masa 2 (a2-b2), a1 - a2>b1 - b2 boleh diperkenalkan. Terdapat tiga situasi: (jumlah niaga hadapan dan kedudukan spot adalah sama)

  1. a1 - a2 lebih besar daripada 0, b1 - b2 lebih besar daripada 0 a1 - a2 merujuk kepada perbezaan harga keuntungan niaga hadapan, dan b1 - b2 merujuk kepada perbezaan harga kerugian spot (kerana spot pergi panjang, harga mula membeli lebih tinggi daripada harga jual untuk menutup kedudukan, jadi wang hilang), tetapi keuntungan niaga hadapan lebih besar daripada kerugian spot. jadi ia menguntungkan secara keseluruhan. situasi ini sepadan dengan carta di langkah In [8].

  2. a1 - a2 lebih besar daripada 0, b1 - b2 kurang daripada 0 a1 - a2 adalah perbezaan harga keuntungan niaga hadapan, dan b1 - b2 adalah perbezaan harga keuntungan segera (b1 - b2 kurang daripada 0, menunjukkan bahawa b2 lebih besar daripada b1, iaitu harga kedudukan pembukaan dan pembelian rendah, dan harga jual dan penutupan tinggi, jadi ia menguntungkan).

  3. a1 - a2 kurang daripada 0, b1 - b2 kurang daripada 0 a1 - a2 adalah perbezaan harga kerugian niaga hadapan, dan b1 - b2 adalah perbezaan harga keuntungan segera. Oleh kerana a1 - a2 > b1 - b2, nilai mutlak a1 - a2 adalah kurang daripada nilai mutlak b1 - b2, dan keuntungan segera lebih besar daripada kerugian niaga hadapan. Ia menguntungkan secara keseluruhan.

Tidak ada kes di mana a1 - a2 kurang daripada 0 dan b1 - b2 lebih besar daripada 0, kerana a1 - a2 > b1 - b2 telah ditakrifkan. Begitu juga, jika a1 - a2 sama dengan 0, kerana a1 - a2 > b1 - b2 ditakrifkan, b1 - b2 mesti kurang daripada 0. Oleh itu, selagi kaedah lindung nilai niaga hadapan pendek dan tempat panjang memenuhi syarat a1 - b1 > a2 - b2, operasi kedudukan pembukaan dan penutupan adalah lindung nilai keuntungan.

Sebagai contoh, model berikut adalah salah satu kes:

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

Kawasan carian fail bahasa JavaScript

Kawasan penyelidikan menyokong bukan sahaja Python, tetapi juga JavaScript Saya juga memberikan contoh persekitaran penyelidikan JavaScript:

Analisis prinsip lindung nilai spot niaga hadapan (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, FrozenBalanse: 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, Jilid: 1772, Terbuka Minat: 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, Terbuka Minat: 0 }

Dalam [6]:

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

Keluar[6]: 284.64999997999985 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 tawaran: 10, Purata Harga: 10441.25, Jenis: 1, Penghujung: 0, Status: 1, Jenis kontrak: suku }

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, Purata Harga: 10156.60000002, Jenis: 0, Penghujung: 0, Status: 1, Jenis Kontrak: BTC_USDT_OKX }

Anda dapat melihat bahawa pesanan quarterId1 dan spotId1 telah dipenuhi sepenuhnya, iaitu lindung nilai kedudukan 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.

Selepas masa menunggu, bersedia untuk menutup kedudukan.quarterTicker2, spotTicker2dan cetak mereka. Arah urus niaga objek pertukaran niaga hadapan ditetapkan untuk menutup kedudukan pendek:exchanges[0].SetDirection("closesell")meletakkan perintah untuk menutup kedudukan. Mencetak butiran pesanan kedudukan penutupan, menunjukkan bahawa pesanan penutupan telah selesai, kedudukan 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, Sedikit: 8497.2, Jual: 8497.20002, Beli: 8497.2, Terakhir: 8497.20001, Jilid: 4311, Terbuka Minat: 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, rendah: 8444.69999999, Jual: 8444.70000001, Beli: 8444.69999999, Terakhir: 8444.7, Volume: 78.6273, Terbuka Minat: 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

Dalam [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, Jumlah tawaran: 10, Purata Harga: 8493.95335, Jenis: 0, Pengurangan: 1, Status: 1, Jenis kontrak: suku }

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, Purata Harga: 8444.69999999, Jenis: 1, Penghujung: 0, Status: 1, Jenis Kontrak: BTC_USDT_OKX }

Dalam [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, Stok: 1.021786026184, FrozenStocks: 0

Dalam [16]:

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

Keluar[16]: { baki: 9834.74705446, FrozenBalance: 0, Stok: 0, FrozenStocks: 0 Dengan membandingkan akaun awal dengan akaun semasa, keuntungan dan kerugian operasi lindung nilai dikira.

Dalam [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 adalah menguntungkan. kita boleh melihat carta yang digambar. harga niaga hadapan adalah garis biru dan harga spot adalah garis oren. kedua-dua harga menurun. harga niaga hadapan menurun lebih cepat daripada harga spot.

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]: Mari kita lihat perubahan perbezaan harga. Perbezaan harga berkisar dari 284 pada masa lindung nilai kedudukan pembukaan (iaitu, niaga hadapan pergi pendek, dan tempat pergi panjang) kepada 52 pada masa penutupan (penutupan kedudukan pendek niaga hadapan, dan penutupan kedudukan panjang tempat). Perbezaan harga adalah dari besar hingga kecil.

Dalam [19]:

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

Keluar[19]:Sebagai contoh, a1 adalah harga niaga hadapan pada masa 1, dan b1 adalah harga spot pada masa 1. A2 adalah harga niaga hadapan pada masa 2, dan b2 adalah harga spot pada masa 2.Selagi perbezaan harga spot niaga hadapan pada masa 1 (a1-b1) lebih besar daripada perbezaan harga spot niaga hadapan pada masa 2 (a2-b2), a1 - a2>b1 - b2 boleh diperkenalkan. Terdapat tiga situasi: (jumlah niaga hadapan dan kedudukan spot adalah sama)

  1. a1 - a2 lebih besar daripada 0, b1 - b2 lebih besar daripada 0 a1 - a2 merujuk kepada perbezaan harga keuntungan niaga hadapan, dan b1 - b2 merujuk kepada perbezaan harga kerugian spot (kerana spot pergi panjang, harga mula membeli lebih tinggi daripada harga jual untuk menutup kedudukan, jadi wang hilang), tetapi keuntungan niaga hadapan lebih besar daripada kerugian spot. jadi ia menguntungkan secara keseluruhan. situasi ini sepadan dengan carta di langkah In [8].

  2. a1 - a2 lebih besar daripada 0, b1 - b2 kurang daripada 0 a1 - a2 adalah perbezaan harga keuntungan niaga hadapan, dan b1 - b2 adalah perbezaan harga keuntungan segera (b1 - b2 kurang daripada 0, menunjukkan bahawa b2 lebih besar daripada b1, iaitu harga kedudukan pembukaan dan pembelian rendah, dan harga jual dan penutupan tinggi, jadi ia menguntungkan).

  3. a1 - a2 kurang daripada 0, b1 - b2 kurang daripada 0 a1 - a2 adalah perbezaan harga kerugian niaga hadapan, dan b1 - b2 adalah perbezaan harga keuntungan segera. Oleh kerana a1 - a2 > b1 - b2, nilai mutlak a1 - a2 adalah kurang daripada nilai mutlak b1 - b2, dan keuntungan segera lebih besar daripada kerugian niaga hadapan. Ia menguntungkan secara keseluruhan.

Tidak ada kes di mana a1 - a2 kurang daripada 0 dan b1 - b2 lebih besar daripada 0, kerana a1 - a2 > b1 - b2 telah ditakrifkan. Begitu juga, jika a1 - a2 sama dengan 0, kerana a1 - a2 > b1 - b2 ditakrifkan, b1 - b2 mesti kurang daripada 0. Oleh itu, selagi kaedah lindung nilai niaga hadapan pendek dan tempat panjang memenuhi syarat a1 - b1 > a2 - b2, operasi kedudukan pembukaan dan penutupan adalah lindung nilai keuntungan.

Sebagai contoh, model berikut adalah salah satu kes:

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]:

Cubalah, kawan-kawan!


Berkaitan

Lebih lanjut