Apologies for the confusion. Assuming you already have the technical indicators calculated, let's focus on extracting additional non-indicator based features from BTC closing prices for machine learning purposes. Here are some examples with coding explanations:
- Price Statistics: Calculate basic statistical features such as the mean, median, minimum, and maximum prices over different time periods. These features provide insights into the overall price range and distribution.
# Example: Mean price over the last 30 days
mean_price = btc_closing_prices[-30:].mean()
- Price Changes: Calculate the percentage change in price over various time intervals. These features represent the relative price movements and can help identify trends or periods of volatility.
# Example: Price change over the last 7 days
price_change_7d = (btc_closing_prices[-1] - btc_closing_prices[-8]) / btc_closing_prices[-8] * 100
- Rolling Window Statistics: Compute rolling window statistical features, such as the standard deviation or mean of closing prices over a specific window. These features capture the volatility or central tendency of prices within a defined period.
# Example: Standard deviation of prices over the last 14 days
rolling_std_dev = btc_closing_prices[-14:].std()
- Lagged Price Data: Include lagged versions of the closing prices to capture historical dependencies. These features represent the price at previous time steps and can be useful for time series forecasting.
# Example: Closing price 1 day ago
lagged_price_1d = btc_closing_prices[-2]
- Price Trends: Calculate features to capture trends in BTC closing prices, such as the average slope or regression line over a certain time period. These features help identify the overall direction of the price series.
# Example: Linear regression slope over the last 30 days
trend_slope_30d = np.polyfit(range(len(btc_closing_prices[-30:])), btc_closing_prices[-30:], 1)[0]
- Moving Window Ratios: Compute ratios of closing prices between different moving windows to capture relative performance and momentum.
# Example: Ratio of moving average over 14 days to moving average over 50 days
ma_ratio = btc_closing_prices[-14:].mean() / btc_closing_prices[-50:].mean()
- Price Volatility: Calculate features related to price volatility, such as the average true range (ATR) or the difference between high and low prices.
# Example: Average True Range over the last 14 days
high_prices = btc_high_prices[-14:] # Assuming you have high prices as well
low_prices = btc_low_prices[-14:] # Assuming you have low prices as well
atr = np.mean(high_prices - low_prices)
- Seasonality: Include features that capture any potential seasonal patterns in BTC closing prices. For example, you can calculate the average prices for each day of the week or month.
# Example: Average closing price for Mondays
mondays_prices = btc_closing_prices[bitcoin_data.index.weekday == 0]
avg_monday_price = mondays_prices.mean()
These are just a few examples of features you can extract from BTC closing prices. The choice of features ultimately depends on the specific problem you are trying to solve and the insights you believe may be relevant for predicting BTC price movements.