ভাল সরঞ্জাম ভাল কাজ করে -- ট্রেডিং নীতি বিশ্লেষণের জন্য গবেষণা পরিবেশ ব্যবহার করতে শিখুন

লেখক:লিডিয়া, তৈরিঃ 2022-12-27 16:33:51, আপডেটঃ 2023-09-20 09:17:27

img

ট্রেডিং নীতি বিশ্লেষণের জন্য গবেষণা পরিবেশ ব্যবহার করতে শিখুন

হেজিং শব্দটি পরিমাণগত ট্রেডিং এবং প্রোগ্রাম ট্রেডিংয়ের ক্ষেত্রে একটি খুব প্রাথমিক ধারণা। ডিজিটাল মুদ্রার পরিমাণগত ট্রেডিংয়ে, প্রায়শই ব্যবহৃত হেজিং কৌশলগুলি হ'লঃ ফিউচার-স্পট হেজিং, ক্রস-পিরিয়ড হেজিং এবং স্পট হেজিং, যা মূলত মূল্য পার্থক্যের জন্য লেনদেন। সম্ভবত যখন হেজিংয়ের ধারণা, নীতি এবং বিবরণ আসে, তখনও অনেক শিক্ষার্থী যারা মাত্র পরিমাণগত ট্রেডিংয়ের ক্ষেত্রে প্রবেশ করেছেন তারা এখনও খুব পরিষ্কার নন। এটি কোন ব্যাপার না। আসুন এই জ্ঞানটি সহজেই শিখতে এবং আয়ত্ত করতে এফএমজেড ট্রেডিং প্ল্যাটফর্ম দ্বারা সরবরাহিত কোয়ান্টানালিজ সরঞ্জামটি ব্যবহার করি।

FMZ Quant প্ল্যাটফর্মের ড্যাশবোর্ডে, টুলের পাতায় যাওয়ার জন্য Analyze ক্লিক করুনঃ

img

এখানে আমি সরাসরি বিশ্লেষণ ফাইল আপলোড করিঃ এই বিশ্লেষণ নথিটি ব্যাকটেস্টিং চলাকালীন একটি ফিউচার-স্পট হেজিং পজিশনের খোলার এবং বন্ধের প্রক্রিয়া বিশ্লেষণ। ফিউচার এক্সচেঞ্জটি OKX ফিউচার, এবং চুক্তিটি একটিquarterস্পট এক্সচেঞ্জ হল OKX মুদ্রা-মুদ্রা লেনদেন, এবং ট্রেডিং জোড়া হলBTC_USDT. ফিউচার-স্পট হেজিং এর অপারেশন প্রক্রিয়া বিশ্লেষণ করার জন্য, আপনি নিম্নলিখিত নির্দিষ্ট গবেষণা পরিবেশ ফাইল দেখতে পারেন, দুটি সংস্করণে লিখিতঃ একটি পাইথন ভাষা সংস্করণ, একটি জাভাস্ক্রিপ্ট ভাষা সংস্করণ।

গবেষণা পরিবেশ পাইথন ভাষা ফাইল

ফিউচার-স্পট হেজিং নীতির বিশ্লেষণ.ipynb [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

[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

আউট[2]: {ব্যালেন্সঃ ০.০, ফ্রোজেনব্যালেন্সঃ ০.০, স্টকঃ ১.০, ফ্রোজেনস্টকঃ ০.০}

[3] এঃ

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

আউট[3]: {ব্যালেন্স : 10000.0, ফ্রোজেনব্যালেন্স : 0.0, স্টক : 0.0, ফ্রোজেনস্টক : 0.0}

[4] এঃ

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

আউট[4]: সময়ঃ ১৫৬৮৮৫১২১০০০, উচ্চ : ১০৪৪১.২৫০০২, নিম্ন : 10441.25, বিক্রয় : ১০৪৪১.২৫০০২, কেনা : 10441.25, শেষ : 10441.25001, ভলিউম : ১৭৭২.০, ওপেন ইন্টারেস্ট : 0.0}

[5] এঃ

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

আউট[5]: সময়ঃ ১৫৬৮৮৫১২১০০০, উচ্চ : ১০১৫৬.৬০০০০০০২, নিম্ন : ১০১৫৬.৬, বিক্রয় : ১০১৫৬৬০০০০০০২, কেনা : ১০১৫৬.৬, শেষ : ১০১৫৬৬০০০০০০১, ভলিউম : ৭.৪৪৪৩, ওপেন ইন্টারেস্ট : 0.0}

[6] এঃ

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

আউট[6]: ২৮৪.৬৪.৬৪৯৯৯৯৯৭৯৯৯৯৮৫

[৭] এঃ

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.

আউট[7]: {Id: 1, মূল্য : ১০৪৪১.২৫, অর্থ : ১০.০, DealAmount: 10.0, অভারেজ প্রাইস : 10441.25, টাইপ : ১, অফসেট : 0, অবস্থা : ১, কন্ট্রাক্ট টাইপ : টার্মাল }

[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

আউট[8]: {Id: 1, মূল্য : ১০১৫৬,৬০০,০০০২, অংশ : ০.০৯৫৭, ডিলের পরিমাণ : ০.০৯৫৭, অভারেজ প্রাইস : 10156.60000002, টাইপ : 0, অফসেট : 0, অবস্থা : ১, ContractType: bBTC_USDT_OKX}

আপনি দেখতে পাচ্ছেন যে অর্ডারগুলি চতুর্থাংশId1 এবং স্পটId1 অর্ডারগুলি সম্পূর্ণরূপে পূরণ করা হয়েছে, অর্থাৎ খোলা অবস্থানের হেজিং সম্পন্ন হয়েছে।

[৯] এঃ

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.

অপেক্ষা সময় পরে, অবস্থান বন্ধ করার জন্য প্রস্তুত. বর্তমান টিকার পানquarterTicker2, spotTicker2এবং সেগুলো মুদ্রণ করুন। ফিউচার এক্সচেঞ্জ অবজেক্টের লেনদেনের দিকটি শর্ট পজিশন বন্ধ করার জন্য সেট করা আছেঃexchanges[0].SetDirection("closesell")পজিশন বন্ধ করার অর্ডার দিন। ক্লোজিং পজিশন অর্ডারের বিবরণ মুদ্রণ করুন, যা দেখায় যে ক্লোজিং অর্ডার সম্পন্ন হয়েছে, ক্লোজিং পজিশন শেষ হয়েছে।

[১০] এঃ

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

আউট[10]: {Time: 1569456010000, উচ্চঃ ৮৪৯৭.২০০০২, নিম্ন : ৮৪৯৭.২, বিক্রয় : ৮৪৯৭.২০০০২, কেনা : ৮৪৯৭.২, শেষ : ৮৪৯৭.২০০০১ ভলিউমঃ ৪৩১১.০ ওপেন ইন্টারেস্ট : 0.0}

[11] এঃ

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

আউট[11]: সময় : 1569456114600, উচ্চ : ৮৪৪৪৭০০০০০০১, নিম্ন : ৮৪৪৪.৬৯৯৯৯৯৯, বিক্রয় : ৮৪৪৪৭০০০০০০১, Buy: 8444.69999999, শেষ : 8444.7, ভলিউম: ৭৮.৬২৭৩, ওপেন ইন্টারেস্ট : 0.0}

[১২] এঃ

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

আউট[১২]: 52.5000200100003

[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

আউট[13]: {Id: 2, মূল্য : ৮৪৯৭.২০০০২, অর্থ : ১০.০, DealAmount: 10.0, গড় মূল্যঃ ৮৪৯৩.৯৫৩৩৫, টাইপ : 0, অফসেট : ১, অবস্থা : ১, কন্ট্রাক্ট টাইপ : টার্মাল }

[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

আউট[14]: {Id: 2, মূল্য : ৮৪৪৪.৬৯৯৯৯৯৯৯, অংশ : ০.০৯৫৭, ডিলের পরিমাণ : ০.০৯৫৭, অভারেজ প্রাইস : ৮৪৪৪.৬৯৯৯৯৯৯৯, টাইপঃ ১, অফসেট : 0, অবস্থা : ১, ContractType: bBTC_USDT_OKX}

[15] এঃ

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

আউট[15]: {বালান্স: ০.০, ফ্রোজেন ব্যালেন্স : ০.০ স্টক : ১.০২১৭৮৬০২৬১৮৪, ফ্রোজেন স্টক : ০.০}

[১৬] এঃ

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

আউট[16]: বালান্স : ৯৮৩৪.৭৪৭০৫৪৪৬, ফ্রোজেন ব্যালেন্স : ০.০ স্টকঃ ০.০ ফ্রোজেন স্টক : ০.০}

হিজিং অপারেশনের মুনাফা ও ক্ষতির হিসাব করা হয় প্রাথমিক হিসাবের সাথে বর্তমান হিসাবের তুলনা করে।

[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)

আউট[17]: মুনাফাঃ ১৮.৭২৩৫০৯৭৭৭৫৮০৬৫২

এখন আসুন দেখি কেন হেজিং লাভজনক। আমরা চার্ট আঁকতে পারি। ফিউচার মূল্য একটি নীল লাইন এবং স্পট মূল্য একটি কমলা লাইন। উভয় মূল্য হ্রাস পাচ্ছে। ফিউচার মূল্য স্পট মূল্যের চেয়ে দ্রুত হ্রাস পাচ্ছে।

[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()

আউট[18]:

img

আসুন দামের পার্থক্যের পরিবর্তনের দিকে নজর রাখি। দামের পার্থক্যটি হিজিং খোলার পজিশনের সময় 284 থেকে শুরু হয় (অর্থাৎ, ফিউচারগুলি শর্ট হয় এবং স্পট লং হয়) অবস্থান বন্ধের সময় 52 (ফিউচার শর্ট পজিশন বন্ধ, স্পট লং পজিশন বন্ধ) । দামের পার্থক্যটি বড় থেকে ছোট।

[19] এঃ

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

আউট[19]:

img

উদাহরণস্বরূপ, a1 হল সময় 1 এ ফিউচার মূল্য, এবং b1 হল সময় 1 এ স্পট মূল্য। A2 হল সময় 2 এ ফিউচার মূল্য, এবং b2 হল সময় 2 এ স্পট মূল্য।যতক্ষণ পর্যন্ত সময় 1 (a1-b1) এ ফিউচার স্পট মূল্যের পার্থক্য সময় 2 (a2-b2) এ ফিউচার স্পট মূল্যের পার্থক্যের চেয়ে বড়, a1 - a2>b1 - b2 প্রবর্তন করা যেতে পারে। এখানে তিনটি পরিস্থিতি রয়েছেঃ (ফ্যুচার এবং স্পট পজিশনের পরিমাণ একই)

  1. a1 - a2 0 এর চেয়ে বড়, b1 - b2 0 এর চেয়ে বড় a1 - a2 ফিউচার মুনাফার দামের পার্থক্যকে বোঝায়, এবং b1 - b2 স্পট ক্ষতির দামের পার্থক্যকে বোঝায় (কারণ স্পটটি দীর্ঘ হয়ে গেছে, পজিশন বন্ধ করার জন্য কেনার শুরু করার দাম বিক্রয়ের দামের চেয়ে বেশি, তাই অর্থ হারাতে হয়), তবে ফিউচার মুনাফা স্পট ক্ষতির চেয়ে বেশি। সুতরাং এটি সামগ্রিকভাবে লাভজনক। এই পরিস্থিতি ধাপ ইন [8] এর চার্টের সাথে মিলে যায়।

  2. a1 - a2 0 এর চেয়ে বড়, b1 - b2 0 এর চেয়ে ছোট a1 - a2 হল ফিউচার মুনাফার দামের পার্থক্য এবং b1 - b2 হল স্পট মুনাফার দামের পার্থক্য (b1 - b2 হল 0 এর চেয়ে কম, যা ইঙ্গিত করে যে b2 হল b1 এর চেয়ে বড়, অর্থাৎ, খোলা পজিশন এবং কেনার দাম কম, এবং বিক্রয় এবং বন্ধের দাম উচ্চ, তাই এটি লাভজনক) ।

  3. a1 - a2 কম 0, b1 - b2 কম 0 a1 - a2 হল ফিউচার ক্ষতির মূল্য পার্থক্য, এবং b1 - b2 হল স্পট মুনাফার মূল্য পার্থক্য। যেহেতু a1 - a2 > b1 - b2, a1 - a2 এর পরম মূল্য b1 - b2 এর পরম মূল্যের চেয়ে কম এবং স্পট মুনাফা ফিউচার ক্ষতির চেয়ে বড়। এটি সামগ্রিকভাবে লাভজনক।

যদি a1 - a2 > b1 - b2 সংজ্ঞায়িত করা হয়, তাহলে a1 - a2 এর মান 0 এর চেয়ে কম এবং b1 - b2 এর মান 0 এর চেয়ে বড় হয় না। একইভাবে, যদি a1 - a2 0 এর সমান হয়, কারণ a1 - a2 > b1 - b2 সংজ্ঞায়িত করা হয়, b1 - b2 এর মান 0 এর চেয়ে কম হতে হবে। অতএব, যতক্ষণ শর্ট ফিউচার এবং লং স্পট হিজিং পদ্ধতিটি a1 - b1 > a2 - b2 শর্ত পূরণ করে ততক্ষণ খোলা এবং বন্ধ হওয়া পজিশন অপারেশনগুলি মুনাফা হিজিং।

উদাহরণস্বরূপ, নিম্নলিখিত মডেলটি একটি ক্ষেত্রে রয়েছেঃ

[২০] এঃ

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()

আউট[20]:

img

অনুসন্ধান পরিবেশ জাভাস্ক্রিপ্ট ভাষা ফাইল

গবেষণা পরিবেশ শুধুমাত্র পাইথন নয়, জাভাস্ক্রিপ্টও সমর্থন করে আমি জাভাস্ক্রিপ্ট রিসার্চ এনভায়রনমেন্টের একটি উদাহরণও দেইঃ

ফিউচার-স্পট হেজিং নীতির বিশ্লেষণ (জাভাস্ক্রিপ্ট) [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}]
})

[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

আউট[2]: { ব্যালেন্সঃ ০, ফ্রিজেন ব্যালেন্সঃ ০, স্টকঃ ১, ফ্রিজেন স্টকঃ ০ }

[3] এঃ

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

আউট[3]: { ব্যালেন্সঃ ১০০০, ফ্রিজেন ব্যালেন্সঃ ০, স্টকঃ ০, ফ্রিজেন স্টকঃ ০ }

[4] এঃ

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

আউট[4]: সময়ঃ ১৫৬৮৮৫১২১০০০, উচ্চঃ ১০৪৪১.২৫০০২, নিম্নঃ ১০৪৪১.২৫, বিক্রি: ১০৪৪১.২৫০০২, কিনুনঃ ১০৪৪১.২৫, সর্বশেষঃ ১০৪৪১.২৫০০১, খণ্ড: ১৭৭২, ওপেন ইন্টারেস্ট: 0 }

[5] এঃ

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

আউট[5]: সময়ঃ ১৫৬৮৮৫১২১০০০০০ উচ্চঃ ১০১৫৬.৬০০০০০০২। নিম্নঃ ১০১৫৬.৬। বিক্রিঃ ১০১৫৬.৬০০.০০০০২, কিনুনঃ ১০১৫৬.৬, সর্বশেষঃ ১০১৫৬৬০০০০০০১, ভলিউমঃ ৭.৪৪৪৩, ওপেন ইন্টারেস্ট: 0 }

[6] এঃ

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

আউট[6]: ২৮৪.৬৪.৬৪৯৯৯৯৯৭৯৯৯৯৮৫ [৭] এঃ

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.

আউট[7]: { আইডিঃ ১, দামঃ ১০৪৪১.২৫, পরিমাণঃ ১০টি। চুক্তির পরিমাণঃ ১০টি। গড় মূল্যঃ ১০৪৪১.২৫, প্রকারঃ ১, অফসেটঃ ০ অবস্থাঃ ১, চুক্তির ধরন: প্রতিমাসিক }

[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.

আউট[8]: { আইডিঃ ১, দামঃ ১০১৫৬.৬০০.০০,০০০২ পরিমাণঃ ০.০৯৫৭, লেনদেনের পরিমাণঃ ০.০৯৫৭, গড় মূল্যঃ ১০১৫৬.৬০০০০০০২, প্রকারঃ ০ অফসেটঃ ০ অবস্থাঃ ১, BTC_USDT_OKX }

আপনি দেখতে পাচ্ছেন যে অর্ডার quarterId1 এবং spotId1 সম্পূর্ণরূপে পূরণ করা হয়েছে, অর্থাৎ খোলা পজিশনের হিজিং সম্পন্ন হয়েছে।

[৯] এঃ

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.

অপেক্ষা সময় পরে, অবস্থান বন্ধ করার জন্য প্রস্তুত. বর্তমান টিকার পানquarterTicker2, spotTicker2এবং সেগুলো মুদ্রণ করুন। ফিউচার এক্সচেঞ্জ অবজেক্টের লেনদেনের দিকটি শর্ট পজিশন বন্ধ করার জন্য সেট করা আছেঃexchanges[0].SetDirection("closesell")পজিশন বন্ধ করার অর্ডার দিন। ক্লোজিং পজিশন অর্ডারের বিবরণ মুদ্রণ করুন, যা দেখায় যে ক্লোজিং অর্ডার সম্পন্ন হয়েছে, ক্লোজিং পজিশন শেষ হয়েছে।

[১০] এঃ

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

আউট[10]: সময়ঃ ১৫৬৯৪৫৬০১০০০০, উচ্চঃ ৮৪৯৭.২০০০২, নিম্নঃ ৮৪৯৭.২। বিক্রি: ৮৪৯৭.২০০০২, কিনুনঃ ৮৪৯৭.২, সর্বশেষঃ ৮৪৯৭.২০০০১। ভলিউমঃ ৪৩১১, ওপেন ইন্টারেস্ট: 0 }

[11] এঃ

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

আউট[11]: { সময়ঃ ১৫৬৯৪৫৬১১৪৬০০, উচ্চঃ ৮৪৪৪৭০০০০০০১, নিম্নঃ ৮৪৪৪.৬৯৯৯৯৯৯৯, বিক্রয়ঃ ৮৪৪৪৭০০০০০০১, কিনুনঃ ৮৪৪৪.৬৯৯৯৯৯৯৯, সর্বশেষঃ ৮৪৪৪.৭ ভলিউম: ৭৮.৬২৭৩ ওপেন ইন্টারেস্ট: 0 }

[১২] এঃ

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

আউট[১২]: 52.5000200100003

[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.

আউট[১৩]: { আইডিঃ ২, দামঃ ৮৪৯৭.২০০০২। পরিমাণঃ ১০টি। চুক্তির পরিমাণঃ ১০টি। গড় মূল্যঃ ৮৪৯৩.৯৫৩৩৫, প্রকারঃ ০ অফসেটঃ ১, অবস্থাঃ ১, চুক্তির ধরন: প্রতিমাসিক }

[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.

আউট[14]: { আইডিঃ ২, দামঃ ৮৪৪৪.৬৯৯৯৯৯৯৯৯, পরিমাণঃ ০.০৯৫৭, লেনদেনের পরিমাণঃ ০.০৯৫৭, গড় মূল্যঃ ৮৪৪৪.৬৯৯৯৯৯৯৯, টাইপঃ ১, অফসেটঃ ০ অবস্থাঃ ১, BTC_USDT_OKX }

[15] এঃ

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

আউট[15]: { ব্যালেন্সঃ 0, ফ্রিজেন ব্যালেন্সঃ ০ স্টকঃ ১.০২১৭৮৬০২৬১৮৪ ফ্রোজেন স্টকস: 0 }

[১৬] এঃ

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

আউট[16]: { ব্যালেন্স: ৯৮৩৪.৭৪৭০৫৪৪৬, ফ্রিজেন ব্যালেন্সঃ ০ মজুদঃ 0, ফ্রোজেন স্টকস: 0 } হিজিং অপারেশনের মুনাফা ও ক্ষতির হিসাব করা হয় প্রাথমিক হিসাবের সাথে বর্তমান হিসাবের তুলনা করে।

[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)
}

আউট[17]: মুনাফাঃ ১৮.৭২৩৫০৯৭৭৭৫৮০৬৫২

এখন আসুন দেখি কেন হেজিং লাভজনক। আমরা চার্ট আঁকতে পারি। ফিউচার মূল্য একটি নীল লাইন এবং স্পট মূল্য একটি কমলা লাইন। উভয় মূল্য হ্রাস পাচ্ছে। ফিউচার মূল্য স্পট মূল্যের চেয়ে দ্রুত হ্রাস পাচ্ছে।

[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}])

আউট[18]: আসুন দামের পার্থক্যের পরিবর্তনের দিকে নজর রাখি। দামের পার্থক্যটি হিজিং খোলার পজিশনের সময় 284 থেকে শুরু হয় (অর্থাৎ, ফিউচারগুলি শর্ট হয়ে যায় এবং স্পটটি দীর্ঘ হয়ে যায়) বন্ধের সময় 52 (ফিউচারের বন্ধ শর্ট পজিশন এবং স্পটের বন্ধ লং পজিশন) । দামের পার্থক্যটি বড় থেকে ছোট।

[19] এঃ

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

আউট[19]:উদাহরণস্বরূপ, a1 হল সময় 1 এ ফিউচার মূল্য, এবং b1 হল সময় 1 এ স্পট মূল্য। A2 হল সময় 2 এ ফিউচার মূল্য, এবং b2 হল সময় 2 এ স্পট মূল্য।যতক্ষণ পর্যন্ত সময় 1 (a1-b1) এ ফিউচার স্পট মূল্যের পার্থক্য সময় 2 (a2-b2) এ ফিউচার স্পট মূল্যের পার্থক্যের চেয়ে বড়, a1 - a2>b1 - b2 প্রবর্তন করা যেতে পারে। এখানে তিনটি পরিস্থিতি রয়েছেঃ (ফ্যুচার এবং স্পট পজিশনের পরিমাণ একই)

  1. a1 - a2 0 এর চেয়ে বড়, b1 - b2 0 এর চেয়ে বড় a1 - a2 ফিউচার মুনাফার দামের পার্থক্যকে বোঝায়, এবং b1 - b2 স্পট ক্ষতির দামের পার্থক্যকে বোঝায় (কারণ স্পটটি দীর্ঘ হয়ে গেছে, পজিশন বন্ধ করার জন্য কেনার শুরু করার দাম বিক্রয়ের দামের চেয়ে বেশি, তাই অর্থ হারাতে হয়), তবে ফিউচার মুনাফা স্পট ক্ষতির চেয়ে বেশি। সুতরাং এটি সামগ্রিকভাবে লাভজনক। এই পরিস্থিতি ধাপ ইন [8] এর চার্টের সাথে মিলে যায়।

  2. a1 - a2 0 এর চেয়ে বড়, b1 - b2 0 এর চেয়ে ছোট a1 - a2 হল ফিউচার মুনাফার দামের পার্থক্য এবং b1 - b2 হল স্পট মুনাফার দামের পার্থক্য (b1 - b2 হল 0 এর চেয়ে কম, যা ইঙ্গিত করে যে b2 হল b1 এর চেয়ে বড়, অর্থাৎ, খোলা পজিশন এবং কেনার দাম কম, এবং বিক্রয় এবং বন্ধের দাম উচ্চ, তাই এটি লাভজনক) ।

  3. a1 - a2 কম 0, b1 - b2 কম 0 a1 - a2 হল ফিউচার ক্ষতির মূল্য পার্থক্য, এবং b1 - b2 হল স্পট মুনাফার মূল্য পার্থক্য। যেহেতু a1 - a2 > b1 - b2, a1 - a2 এর পরম মূল্য b1 - b2 এর পরম মূল্যের চেয়ে কম এবং স্পট মুনাফা ফিউচার ক্ষতির চেয়ে বড়। এটি সামগ্রিকভাবে লাভজনক।

যদি a1 - a2 > b1 - b2 সংজ্ঞায়িত করা হয়, তাহলে a1 - a2 এর মান 0 এর চেয়ে কম এবং b1 - b2 এর মান 0 এর চেয়ে বড় হয় না। একইভাবে, যদি a1 - a2 0 এর সমান হয়, কারণ a1 - a2 > b1 - b2 সংজ্ঞায়িত করা হয়, b1 - b2 এর মান 0 এর চেয়ে কম হতে হবে। অতএব, যতক্ষণ শর্ট ফিউচার এবং লং স্পট হিজিং পদ্ধতিটি a1 - b1 > a2 - b2 শর্ত পূরণ করে ততক্ষণ খোলা এবং বন্ধ হওয়া পজিশন অপারেশনগুলি মুনাফা হিজিং।

উদাহরণস্বরূপ, নিম্নলিখিত মডেলটি একটি ক্ষেত্রে রয়েছেঃ

[২০] এঃ

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}])

আউট[20]:

চেষ্টা করো, ছেলেরা!


সম্পর্কিত

আরো