Skip to content

Instantly share code, notes, and snippets.

# Set the figure size
plt.figure(figsize=(15,7))
# Plot both the benchmark and strategy returns
plt.plot(df_results.index, df_results['Benchmark'], label = "Benchmark Cumulative Returns")
plt.plot(df_results.index, df_results['Stra_cum_returns'], label = "Strategy Returns", color='g')
# Set the title of the graph
plt.title('Benchmark and Strategy Cumulative Returns using a 1-year span', fontsize=16)
# Create the signal
df_results['signal'] = np.where(df_results['forecast']>=0.0,1,-1)
# Create the Buy and Hold returns
df_results['returns'] = np.log(df_results['Close']/df_results['Close'].shift(1))
# Create the Buy and Hold cumulative returns
df_results['Benchmark'] = df_results['returns'].cumsum()
# Create the strategy returns
# Subset the data
plot_data = data.iloc[initial_iloc:]
# Buy and hold strategy cumulative returns
plot_data['buy_and_hold_cum_returns'] = (1+plot_data['returns']).cumprod()
# Strategy returns
plot_data['strategy_returns'] = plot_data['returns'] * plot_data['signal']
# Strategy cumulative returns
import cudf
import cuml
import pyfolio as pf
import numpy as np
import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt
from hmmlearn import hmm
from sklearn.utils import check_random_state
# Import the libraries
import pandas as pd
import cudf
import cuml
from cuml.datasets import make_classification
from cuml.model_selection import train_test_split
# Generating a sample Pandas DataFrame
X, y = make_classification(n_samples=1000, n_features=4, n_classes=2, random_state=42)
# Import the libraries
from cuml.cluster import KMeans
import cudf
# Generate sample data
data = cudf.DataFrame()
data['feature1'] = cp.random.rand(1000)
data['feature2'] = cp.random.rand(1000)
# Perform KMeans clustering
# Import the libraries
import pandas as pd
import cudf
# Creating a Pandas DataFrame
pandas_data = {
'A': [1, 2, 3, 4, 5],
'B': [10, 20, 30, 40, 50],
'C': ['a', 'b', 'c', 'd', 'e']
}
# Import the corresponding library
import cudf
# Create a GPU DataFrame
data = {'A': [1, 2, 3], 'B': [4, 5, 6]}
df = cudf.DataFrame(data)
# Perform data manipulation
df['C'] = df['A'] + df['B']
print(df)
# Import the corresponding library
import cupy as cp
# Define matrices using CuPy arrays
matrix_a = cp.array([[1, 2], [3, 4]])
matrix_b = cp.array([[5, 6], [7, 8]])
# Perform a matrix multiplication using CuPy
result = cp.matmul(matrix_a, matrix_b)
print("Result of Matrix Multiplication:")
# Import the cupy library
import cupy as cp
# Create 10,000 random numbers
x = cp.random.rand(10000)
y = cp.random.rand(10000)
# Perform the multiplication of both arrays
result = cp.dot(x, y)