This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Output the current positions | |
print("Long position in security A:", long_A) | |
print("Short position in security B:", short_B) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long_A = 0 | |
short_B = 0 | |
# Check if the z-score is above the entry threshold | |
if z_score > entry_threshold: | |
# Enter a long position in security A and a short position in security B | |
long_A = 1000 | |
short_B = -1000 | |
# Check if the z-score is below the exit threshold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the threshold for entering and exiting trades | |
entry_threshold = 1.0 | |
exit_threshold = 0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the current z-score of the spread | |
current_spread = df_A['Close'].iloc[-1] - df_B['Close'].iloc[-1] | |
z_score = (current_spread - mean_spread) / std_spread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the mean and standard deviation of the spread | |
mean_spread = df_spread.mean() | |
std_spread = df_spread.std() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the spread between the two securities | |
df_spread = df_A['Close'] - df_B['Close'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# Load historical price data for securities A and B | |
df_A = pd.read_csv('data_A.csv') | |
df_B = pd.read_csv('data_B.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onERC721Received( | |
address operator, | |
address, | |
uint256, | |
bytes memory data | |
) public virtual override returns (bytes4) { | |
return this.onERC721Received.selector; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WETH.transfer(initiator, WETH.balanceOf(address(this))); | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
address[] memory uni_path = new address[](2); | |
uni_path[0] = address(NCT); | |
uni_path[1] = address(WETH); | |
ROUTER_V2.swapExactTokensForTokens( | |
NCT.balanceOf(address(this)), | |
0, | |
uni_path, | |
address(this), | |
block.timestamp + 1 | |
); |
NewerOlder