{"id":19956313,"url":"https://github.com/althk/spock","last_synced_at":"2025-03-01T15:43:32.765Z","repository":{"id":243660820,"uuid":"812433830","full_name":"althk/spock","owner":"althk","description":"Stock predictions via ML - live long and prosper","archived":false,"fork":false,"pushed_at":"2024-09-07T15:57:52.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-12T07:09:26.408Z","etag":null,"topics":["python-ml","stock-price-prediction"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/althk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-08T22:04:46.000Z","updated_at":"2024-09-07T15:57:55.000Z","dependencies_parsed_at":"2024-06-10T13:47:02.491Z","dependency_job_id":"99b6adaf-0ea7-4d34-b096-e80f2d4787f9","html_url":"https://github.com/althk/spock","commit_stats":null,"previous_names":["althk/spock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/althk%2Fspock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/althk%2Fspock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/althk%2Fspock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/althk%2Fspock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/althk","download_url":"https://codeload.github.com/althk/spock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241389103,"owners_count":19955105,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python-ml","stock-price-prediction"],"created_at":"2024-11-13T01:33:01.504Z","updated_at":"2025-03-01T15:43:32.711Z","avatar_url":"https://github.com/althk.png","language":"Jupyter Notebook","readme":"## Spock - Stock predictions via ML; live long and prosper 🖖🏻\n\n\u003e NOTE: The `data_downloader.py` is hardcoded for NSE stocks, but can\n\u003e easily be changed to any exchange with minimal effort.\n\n\nEvaluates models (traditional and neural network based) for stock predictions to find the best fit.\n\nThe following models are currently included in the evaluation:\n\n- Traditional models\n    - LinearRegression\n    - DecisionTreeRegressor\n    - RandomForestRegressor\n    - XGBoostRegressor\n\n### High level overview\n\n1. Download historical data\n2. Train and evaluate each model on each stock's data\n3. Find the overall best model across all stocks' evaluation\n4. Train that model on each stock and save the model per stock\n5. For real-time predictions, load the model instance for the requested ticker and make prediction\n\n### Steps to get started\n\n1. Install the pre-reqs:\n\n```shell\n$ pip install pandas pandas-ta scikit-learn xgboost  # for traditional ML models\n$ pip install tensorflow   # for deep learning models\n$ pip install absl-py\n```\n\n2. Download raw data (this project uses `yfinance`) using the `data_downloader.py` script:\n\n```shell\n$ python data_downloader.py --symbols_file=./nfo_symbols.csv --data_dir=./data --logtostderr\n```\n\n3. Run `prediction_research.py` which then loads the downloaded data, trains a few models, evaluates\n   them and finally stores some information about which model scored the best (`lowest RMSE`)\n\n```shell\n$ python prediction_research.py --data_dir='./data' --output_dir='./output' --logtostderr\n```\n\n### Interpreting the results\n\n1. The last step above dumps the evaluation results under the `output_dir/YYYYmmddHHMMSS/evaluation_results.csv`\n2. Run `parse_evaluation_results.py` to find out the best overall model\n\n```shell\n$ python parse_evaluation_results.py --evaluation_results_file=\u003cpath to the csv\u003e\n```\n\nThis will print out some statistics and highlight the best model overall for all stocks\n\u003e NOTE: the script currently picks the model with the min RMSE at p95\n\n### Training the selected/best model on all stocks\n\n1. Now that we have found the model that works best overall across all stocks,\n   we need to train it on all the stocks individually and save the model per stock. For example, if\nthe evaluation results were saved at `output/20240609185957/evaluation_results.csv` and the stock data is in\nthe `data` directory, running the following command would parse the model selected via grid search cv\nfor each stock and save the model and scaler objects under the same output directory.\n```shell\n$ python train_model.py --data_dir=data --results_file=output/20240609185957/evaluation_results.csv --logtostderr\n```\n2. For example, if the model selected was `XGBRegressor`, then in the dir `output/20240609185957` there will\nbe files of the format `{ticker}_XGBRegressor.pkl` and `{ticker}_Scaler.pkl`.\n\n### Making predictions\n\nTo predict values for a given ticker:\n1. Load the model and scaler for the specific ticker\n2. Scale the data using the loaded scaler\n3. Predict the price using the loaded model","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falthk%2Fspock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falthk%2Fspock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falthk%2Fspock/lists"}