![]() Notice that the returns of Bitcoin and Coinbase seem to closely follow each other, and when the returns do diverge, they tend to realign in the future. If we plot the cumulative returns of the two assets, we may begin to see a pattern emerge. # cumulative return is the product of each minutely returnītc = btc.add(1).cumprod().sub(1)Ĭoin = coin.add(1).cumprod().sub(1) # minutely return is the percent change of minute priceītc = btc.pct_change()Ĭoin = coin.pct_change() # Retrieve historical minute data for Bitcoin and Coinbase stock between August 1st 2021 and November 1st 2021ītc = alpaca.get_crypto_bars("BTCUSD", TimeFrame.Minute, "", "").dfĬoin = alpaca.get_bars("COIN", TimeFrame.Minute, "","").df With the historical data, let’s compute the minutely return of each asset and then their cumulative returns. It is better to compare their relative returns rather than their prices. Since Bitcoin and COIN have dramatically different prices (As of 11/09/21, Bitcoin is at $67,089.48 and COIN is at $357.39). We will use this data to study the past behavior of COIN and Bitcoin. Next let’s retrieve minute frame historical data over the 3 month period between August 2021 and November 2021. # Alpaca for dataįrom alpaca_trade_api.rest import TimeFrameĪlpaca = tradeapi.REST(API_KEY, API_SECRET) If you want to follow along and place paper trades, make sure to use your paper account’s API Keys. We can then use our API keys to access Alpaca’s APIs. We’ll use the alpaca-trade-api SDK to grab historical data, stream live data and place trades and Plotly to chart data. There are some libraries we will need to import. We can use our analysis of this historical data to understand pairs trading and formulate a trading strategy. Let’s compare the minutely returns of Bitcoin and COIN over September 2021. ![]() An example of two such assets can be Bitcoin and Coinbase stock (NASDAQ: COIN), whose prices may be correlated at times due to Coinbase's large crypto balance sheet, and its association with cryptocurrencies. Pairs trading attempts to find two highly correlated assets, and take simultaneous long and short positions when their prices deviate, betting that their prices will converge in the future. Pairs trading is an example of a market neutral strategy. The Trade API will help us to seamlessly trade cryptocurrencies and equities from the same brokerage account. Then we will use our analysis of market data to formulate a trading strategy across crypto and equity markets. In the following sections, we’ll look at historical data to analyze a type of market neutral trade called a pairs trade. This feature is what makes this strategy “market neutral”. Likewise, if the sector launches upwards, our shorts may decrease in value, which may limit our profits. By doing this, if the sector as a whole plummets, our shorts may increase in value and may help limit our losses. A common example of a market neutral strategy is to take 50% long and 50% short positions among stocks within a sector, like the technology sector. Market neutral strategies accomplish this by taking simultaneous long and short positions. Market neutral strategies aim to profit regardless of the broader market’s trend. Among these strategies is a special class called market neutral strategies. Listen Listen Listening - Resume Pause StopĪs markets toss and tumble, many opportunities for trades can be created, and there are a variety of strategies that can be employed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |