In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this "python currency multi-currency hedging strategy case analysis" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "python currency multi-currency hedging strategy case analysis" article.
1. Strategic reasons
Many counterfeit coins have been put on the stock shelves in Yuan'an. Although they fluctuate in the short term, if you use the daily line to observe for a long time, you will find that basically all of them have fallen by more than 90%, and some of them even have a fraction of the highest price. However, there is no common means of short selling on the spot, and there is no special advice except not to touch counterfeit coins. In recent two months, Yuan'an Futures have launched more than 20 perpetual contracts, most of which are mainstream currencies, and some are unknown. This gives us the means to short these knockoff coin combinations. There is a high correlation coefficient between the use of fake coins for the decline of BTC and the trend of counterfeit coins, so two strategies can be designed.
two。 Principle of strategy
The first strategy: the strategy will spread the equivalent to short a selected basket of counterfeit coins, while waiting for positions to be long bitcoin hedges to reduce risk and volatility. With the price fluctuation, constantly adjust the position to keep the short value constant and the long position equal. In essence, it is short mountain coin-Bitcoin price index.
The second strategy: short currencies whose prices are higher than the counterfeit coin-Bitcoin price index, and long those currencies that are lower than the index. The greater the deviation, the larger the position. At the same time, unhedged positions are hedged with BTC (or not hedged).
3. Filter the required currency
The currency an perpetual contract is currently available in 23 currencies, which are obtained by API, excluding BTC. However, the research environment can not access the external network, here is a direct list.
First of all, let's study the price trend of shanzhai coin against Bitcoin in the past year. I have downloaded the data in advance and uploaded it to the forum, which can be quoted directly in the research environment.
First draw the prices of these currencies to see the trend, and the data should be normalized. It can be seen that except for four currencies, the price trends of other currencies are basically the same, showing a downward trend.
Put the final price change in order, and you can find several obviously different coins, namely LINK,XTZ,BCH and ETH. It shows that they can often get out of the independent market, shorting them is risky and needs to be excluded from the strategy. Draw a thermal map of the correlation coefficient for the remaining currencies and find that the trend of ETC,ATOM is also relatively special and can be excluded.
At last, the remaining currencies fell by an average of 66% a year, with plenty of room for shorting. Combining the trend of these coins into the Shanzhai coin price index, we found that it basically fell all the way down, was relatively stable in the second half of last year, and began to fall again this year. This study screened out that the 'LINK','XTZ','BCH',' ETH', 'ETC','ATOM','BNB','EOS','LTC' does not participate in the short selling of the first strategy, and the specific currencies can be tested by themselves. It should be noted that the current shanzhai currency index is at the middle and low level of the past year, which may not be a good opportunity to short, but can be long, depending on individual choice.
4. Currency security sustainable data
Similarly, the sustainable data of Yuan an has been sorted out, and you can also quote it directly in your notebook. The data is the 1h market K line from January 28 to March 31, 2020. Since most of the perpetual contracts are only in these two months, it is enough for the data to be used for back testing.
First of all, take a look at the overall trend of the normalized data. in the sharp fall in March, it is generally halved compared with the price at the beginning of February, which shows that the risk of sustainability is also very high, and this sharp fall is also a test of strategy.
Draw the index price of the coin we want to short relative to Bitcoin, the principle of the strategy is to short the curve, and the return is basically the reverse of the curve.
5. Backtest engine
Since FMZ local test does not have data in all currencies and does not support multi-currency test, it is necessary to implement a new test engine, which is relatively simple to write, but it is basically enough. The handling fee is taken into account, but the fund rate is basically ignored and the maintenance of margin is not taken into account. Record the history of total rights and interests, occupation of margin, leverage and so on. Since this strategy is basically empty and equivalent, the impact of capital rates is small.
The back test does not take into account the slippery price, so you can increase the handling fee simulation by yourself. considering that the handling fee of Yuan an maker is low, even the opening price difference of unpopular currencies is very small, the actual order can be issued by the way of iceberg entrustment, which should have little impact. When creating an exchange object, you need to specify the currency to be traded. Buy is long and Sell is short. Due to perpetual restrictions, long and short positions will be closed automatically, and the number of currencies will be negative when shorting. The parameters are as follows:
Trade_symbols: list of currencies to be traded
Leverage: leverage, influence margin
Commission: handling fee. Default is 10,000.
Initial_balance: initial assets, USDT denominated
Log: whether to print transactions
6. The first policy code
Policy logic:
1. Check the currency price, if it is not nan, you can trade
two。 Check the value of the counterfeit currency contract, if it is less than the target value trade_value, then short the corresponding difference, if greater, buy and close the corresponding amount.
3. Add up the short value of all the counterfeit coins and adjust the BTC position to hedge against it.
The value of shorting trade_value determines the size of the position. Setting log=True will print the transaction log
The final profits for each currency are as follows:
The following two pictures are the net worth curve and the leverage used. The yellow in the net value curve is the effect of double leverage shorting the shanzhai coin index, we can see that the strategy basically magnifies the fluctuation of the index, in line with expectations. The final two-month return of 60%, the maximum withdrawal of 20%, the maximum use of leverage of about 8 times, most of the time less than 6 times, or relatively safe. Most importantly, full hedging allowed the strategy to lose little in the crash on March 12th.
When the price of the short currency rises and the value of the contract increases, the position is reduced at this time, while the profit is increased. This keeps the total contract value constant, with limited losses even if it rises and falls sharply. But the risk also mentioned earlier, counterfeit coins are likely to come out of the independent market, and are likely to rise a lot from the bottom. It depends on how to use it. If you are bullish on counterfeit coins and think you have reached the bottom, you can operate in the direction and do the long index. Or you are bullish on certain currencies and can hedge against them.
Of course, because the price of counterfeit coins against USDT is also falling, the extreme plan is not hedging, directly naked, but the volatility is very large, the pullback is very high
7. The second policy code
Policy logic:
1. Check if there is a price, there is a price to trade
two。 Check the deviation of currency prices from the index
3. Be long and short according to deviation judgment, and judge position according to deviation size.
4. BTC hedging is used to calculate unhedged positions
The opening size is also controlled by trade_value. You can also modify the conversion factor of diff/0.001
The return of the strategy is much better than that of the first strategy, with a 100% return in the past two months, but still a 20% pullback, and the gain is not obvious in the most recent week due to small market volatility. Overall, there is not much leverage. This strategy is worth trying. According to the degree of deviation, the most opened more than 7800 USDT. Note that if a currency moves out of an independent market, for example, if it rises several times relative to the index, it will accumulate a large number of short positions in that currency, and the same sharp decline will also lead to a lot of long strategy, which can limit the maximum opening value.
If the results of non-hedging are as follows, in fact there is little difference. Because the long and empty is basically balanced.
If you refer to the price regression of USDT, the effect will be much worse.
If the maximum position value is limited, the performance will be worse.
The above is about the "python currency multi-currency hedging strategy case analysis" of this article, I believe we all have a certain understanding, I hope the editor to share the content to help you, if you want to know more related knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.