Untitled
unknown
plain_text
a month ago
1.1 kB
3
Indexable
Never
import pandas as pd from sklearn.linear_model import LinearRegression # Define your currency pair (e.g., 'EUR/USD') currency_pair = "EUR_USD" # Fetch historical data data = pd.read_csv(f"data/{currency_pair}_1d.csv") # Assuming daily data is available # Split the data into train and test sets train_data = data[:int(0.8 * len(data))] test_data = data[int(0.8 * len(data)) + 1:] # Define feature columns (e.g., open, high, low, close) and target column (e.g., volume) feature_cols = ["Open", "High", "Low", "Close"] target_col = "Volume" # Create a linear regression model model = LinearRegression() # Train the model on the train data model.fit(train_data[feature_cols], train_data[target_col]) # Generate predictions for the test data predictions = model.predict(test_data[feature_cols]) # Evaluate the model performance (e.g., mean absolute error) from sklearn.metrics import mean_absolute_error mae = mean_absolute_error(test_data[target_col], predictions) print(f"Mean Absolute Error: {mae:.2f}") # Use the trained model to predict future values and make trades based on your strategy
Leave a Comment