Created
March 27, 2024 15:42
-
-
Save lantos1618/0830ee6e879c1d78c56ae2dbf47d07f9 to your computer and use it in GitHub Desktop.
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 numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
import pandas as pd | |
from scipy.signal import argrelextrema | |
eth = pd.read_csv("./financial_data/eth.csv") | |
priceData = pd.DataFrame() | |
priceData["price"] = eth["Value"] | |
priceData["date"] = eth["Date(UTC)"] | |
priceData.index = pd.to_datetime(priceData["date"]) | |
n=30 # number of points to be checked before and after | |
# Find local peaks | |
priceData['min'] = priceData.iloc[argrelextrema(priceData.price.values, np.less_equal, order=n)[0]]['price'] | |
priceData['max'] = priceData.iloc[argrelextrema(priceData.price.values, np.greater_equal, order=n)[0]]['price'] | |
priceDataFiltered = priceData[priceData.index >= "2016"] | |
# Plot results | |
figure, axes = plt.subplots(figsize=(30, 10)) | |
plt.scatter(priceDataFiltered.index, priceDataFiltered['min'], c='r') | |
plt.scatter(priceDataFiltered.index, priceDataFiltered['max'], c='g') | |
plt.plot(priceDataFiltered.index, priceDataFiltered['price']) | |
axes.xaxis.set_major_locator(mdates.MonthLocator()) | |
axes.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m')) | |
axes.tick_params(axis='x', rotation=45) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment