harbor run -t LiteCoder/pytorch-rnn-stock-predictionharbor download LiteCoder/pytorch-rnn-stock-predictionBuild a PyTorch-based RNN model to predict the next-day closing price of Apple stock using synthetic historical price data. Generate the data, train the model, evaluate it against a naïve baseline, and persist all artifacts.
42 for all random number generators (numpy, torch) to ensure reproducibilityCreate a synthetic 30-day AAPL OHLCV dataset and save it to /app/aapl_30d.csv.
CSV columns (in order): Date, Open, High, Low, Close, Volume
Date: 30 consecutive business days starting from 2024-01-02Volume: integer values, realistic daily trading volumes (e.g., in the millions range)Open, High, Low, Close) must be float values rounded to 2 decimal placesImplement an RNN model in PyTorch with the following structure:
(batch, 5, 1) (5 timesteps, 1 feature per step)nn.RNN layer with nonlinearity='tanh', hidden_size=16, num_layers=1, batch_first=Truenn.Linear) mapping from 16 hidden units to 1 outputEvaluate the trained model on the test set and compare against a naïve baseline (predicted price = previous day's close).
Compute for both the RNN model and the naïve baseline:
Save the following files:
/app/aapl_30d.csv — the synthetic dataset (from Step 1)
/app/model.pt — the trained model's state_dict saved via torch.save()
/app/actual_vs_predicted.png — a plot showing:
/app/report.json — a JSON file with the following exact top-level keys:
{
"model": {
"type": "RNN",
"hidden_size": 16,
"num_layers": 1,
"nonlinearity": "tanh",
"lookback": 5,
"epochs": <int>,
"learning_rate": <float>,
"optimizer": "Adam",
"loss_function": "MSE"
},
"metrics": {
"rnn": {
"mae": <float>,
"rmse": <float>
},
"naive_baseline": {
"mae": <float>,
"rmse": <float>
}
},
"data": {
"total_samples": 30,
"train_size": <int>,
"test_size": 5,
"start_date": "2024-01-02",
"end_date": "<last business day>"
}
}
All float values in the JSON must be rounded to 4 decimal places.