Cardano analysis
Import Libraries
import pandas_ta as ta
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
import datetime
from datetime import date, time
from math import sqrt 
import sklearn
from sklearn.neural_network import MLPClassifier
from sklearn.neural_network import MLPRegressor 
from sklearn.model_selection import train_test_split 
from sklearn.metrics import mean_squared_error 
from sklearn.metrics import r2_score 
from sklearn.metrics import classification_report,confusion_matrix 
import warnings 
warnings.filterwarnings("ignore")
     df = pd.read_csv('ADA-USD.csv')
df.head()
    | Date | Open | High | Low | Close | Adj Close | Volume | |
|---|---|---|---|---|---|---|---|
| 0 | 2017-11-09 | 0.025160 | 0.035060 | 0.025006 | 0.032053 | 0.032053 | 18716200.0 | 
| 1 | 2017-11-10 | 0.032219 | 0.033348 | 0.026451 | 0.027119 | 0.027119 | 6766780.0 | 
| 2 | 2017-11-11 | 0.026891 | 0.029659 | 0.025684 | 0.027437 | 0.027437 | 5532220.0 | 
| 3 | 2017-11-12 | 0.027480 | 0.027952 | 0.022591 | 0.023977 | 0.023977 | 7280250.0 | 
| 4 | 2017-11-13 | 0.024364 | 0.026300 | 0.023495 | 0.025808 | 0.025808 | 4419440.0 | 
  df.tail()
| Date | Open | High | Low | Close | Adj Close | Volume | |
|---|---|---|---|---|---|---|---|
| 2028 | 2023-05-30 | 0.379129 | 0.383068 | 0.375512 | 0.377934 | 0.377934 | 186645169.0 | 
| 2029 | 2023-05-31 | 0.377937 | 0.380359 | 0.371003 | 0.374403 | 0.374403 | 193309518.0 | 
| 2030 | 2023-06-01 | 0.374414 | 0.375474 | 0.361692 | 0.364724 | 0.364724 | 235187863.0 | 
| 2031 | 2023-06-02 | NaN | NaN | NaN | NaN | NaN | NaN | 
| 2032 | 2023-06-03 | 0.378149 | 0.378149 | 0.376950 | 0.377337 | 0.377337 | 197218784.0 | 
   #Description of the data
df.describe()
     | Open | High | Low | Close | Adj Close | Volume | |
|---|---|---|---|---|---|---|
| count | 2032.000000 | 2032.000000 | 2032.000000 | 2032.000000 | 2032.000000 | 2.032000e+03 | 
| mean | 0.480802 | 0.501045 | 0.459207 | 0.480965 | 0.480965 | 1.082908e+09 | 
| std | 0.601298 | 0.626942 | 0.573988 | 0.601294 | 0.601294 | 1.979570e+09 | 
| min | 0.023954 | 0.025993 | 0.019130 | 0.023961 | 0.023961 | 2.930550e+06 | 
| 25% | 0.070544 | 0.073276 | 0.068434 | 0.070921 | 0.070921 | 8.421186e+07 | 
| 50% | 0.210612 | 0.222707 | 0.198475 | 0.211688 | 0.211688 | 2.898286e+08 | 
| 75% | 0.552721 | 0.590249 | 0.522270 | 0.552757 | 0.552757 | 1.090055e+09 | 
| max | 2.966390 | 3.099186 | 2.907606 | 2.968239 | 2.968239 | 1.914198e+10 | 
  # to know more more information about the data
df.info()
    <class 'pandas.core.frame.DataFrame'>
RangeIndex: 2033 entries, 0 to 2032
Data columns (total 7 columns):
 #   Column     Non-Null Count  Dtype  
---  ------     --------------  -----  
 0   Date       2033 non-null   object 
 1   Open       2032 non-null   float64
 2   High       2032 non-null   float64
 3   Low        2032 non-null   float64
 4   Close      2032 non-null   float64
 5   Adj Close  2032 non-null   float64
 6   Volume     2032 non-null   float64
dtypes: float64(6), object(1)
memory usage: 111.3+ KB  # find null values
df.isnull().sum()
    Date         0
Open         1
High         1
Low          1
Close        1
Adj Close    1
Volume       1
dtype: int64  df = df.dropna()
   df.plot(y='Close', title='Cardano')
plt.show()
       Cardano technical analysis
df['RSI(2)'] = ta.rsi(df['Close'],length=2)
df['RSI(7)'] = ta.rsi(df['Close'],length=7)
df['RSI(14)'] = ta.rsi(df['Close'],length=14)
df['CCI(30)'] = ta.cci(close=df['Close'],length=30,high=df['High'],low=df['Low'])
df['CCI(50)'] = ta.cci(close=df['Close'],length=50,high=df['High'],low=df['Low'])
df['CCI(100)'] = ta.cci(close=df['Close'],length=100,high=df['High'],low=df['Low'])
df.head()
    | Date | Open | High | Low | Close | Adj Close | Volume | RSI(2) | RSI(7) | RSI(14) | CCI(30) | CCI(50) | CCI(100) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2017-11-09 | 0.025160 | 0.035060 | 0.025006 | 0.032053 | 0.032053 | 18716200.0 | NaN | NaN | NaN | NaN | NaN | NaN | 
| 1 | 2017-11-10 | 0.032219 | 0.033348 | 0.026451 | 0.027119 | 0.027119 | 6766780.0 | NaN | NaN | NaN | NaN | NaN | NaN | 
| 2 | 2017-11-11 | 0.026891 | 0.029659 | 0.025684 | 0.027437 | 0.027437 | 5532220.0 | 11.418312 | NaN | NaN | NaN | NaN | NaN | 
| 3 | 2017-11-12 | 0.027480 | 0.027952 | 0.022591 | 0.023977 | 0.023977 | 7280250.0 | 3.276662 | NaN | NaN | NaN | NaN | NaN | 
| 4 | 2017-11-13 | 0.024364 | 0.026300 | 0.023495 | 0.025808 | 0.025808 | 4419440.0 | 44.876387 | NaN | NaN | NaN | NaN | NaN | 
 #Create a plot showing some of our indicators 
df.plot(y='RSI(2)')
df.plot(y='CCI(100)')
    <AxesSubplot:>
  df['LABEL'] = np.where( df['Open'].shift(-2).gt(df['Open'].shift(-1)),"1","0")
df = df.dropna()
df.head()
    | Date | Open | High | Low | Close | Adj Close | Volume | RSI(2) | RSI(7) | RSI(14) | CCI(30) | CCI(50) | CCI(100) | label | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 99 | 2018-02-16 | 0.410142 | 0.412404 | 0.392676 | 0.403810 | 0.403810 | 192420000.0 | 62.563977 | 48.621949 | 43.259957 | -52.419423 | -85.774875 | 1.793763 | 1 | 
| 100 | 2018-02-17 | 0.402403 | 0.428074 | 0.401056 | 0.419883 | 0.419883 | 341415008.0 | 84.868071 | 53.778234 | 45.256687 | -41.407653 | -79.123300 | 4.472773 | 0 | 
| 101 | 2018-02-18 | 0.418355 | 0.420010 | 0.380787 | 0.385618 | 0.385618 | 251314000.0 | 23.972251 | 43.036056 | 41.873633 | -50.814224 | -83.434954 | -2.400970 | 1 | 
| 102 | 2018-02-19 | 0.386930 | 0.396608 | 0.386224 | 0.391472 | 0.391472 | 169966000.0 | 38.942088 | 45.217173 | 42.662228 | -50.390640 | -81.358376 | -4.642194 | 0 | 
| 103 | 2018-02-20 | 0.390942 | 0.404329 | 0.377539 | 0.378779 | 0.378779 | 281249984.0 | 21.005952 | 41.224257 | 41.352215 | -50.828816 | -79.685546 | -7.093281 | 0 | 
  Neural Network
X = df[df.columns[6:-1]].values 
y = df['LABEL'].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) 
mlp = MLPClassifier(hidden_layer_sizes=(8,8,8), activation='relu', 
solver='adam', max_iter=1000) 
mlp.fit(X_train,y_train) 
predict_train = mlp.predict(X_train) 
predict_test = mlp.predict(X_test)
print(' Train Data Accuracy ')
print(classification_report(y_train,predict_train)) 
print( ' Testing Data Accuracy ' )
print( classification_report(y_test,predict_test) )
     Train Data Accuracy 
              precision    recall  f1-score   support
           0       0.00      0.00      0.00       673
           1       0.50      1.00      0.67       680
    accuracy                           0.50      1353
   macro avg       0.25      0.50      0.33      1353
weighted avg       0.25      0.50      0.34      1353
 Testing Data Accuracy 
              precision    recall  f1-score   support
           0       0.00      0.00      0.00       298
           1       0.49      1.00      0.65       282
    accuracy                           0.49       580
   macro avg       0.24      0.50      0.33       580
weighted avg       0.24      0.49      0.32       580
Backtesting Model
df['Prediction'] = np.append(predict_train,predict_test)
df['Strategy Returns'] = np.where( df['Prediction'].eq("1"), 
df['Open'].shift(-2)-df['Open'].shift(-1),0)
df['Strategy Returns'] = df['Strategy Returns'].cumsum() 
df.plot(y='Strategy Returns')
plt.plot()
     []  
  prediction = df.iloc[-1]['Prediction'] 
if prediction=="1":
  print("Today's return forecast: UP")
else: 
  print("Today's return forecast: DOWN")
    Today's return forecast: UP 
The full example is on my Kaggle account. This is the link.
https://www.kaggle.com/code/mixmore/cardano-analysis
This is just an explanation of the example on Kaggle.