{"id":22774915,"url":"https://github.com/prem07a/sma_backtesting","last_synced_at":"2025-04-15T09:47:01.764Z","repository":{"id":142379658,"uuid":"603419926","full_name":"Prem07a/SMA_Backtesting","owner":"Prem07a","description":"This Python Code can do SMA back testing on a particular stock and also give optimzed SMA statergy.","archived":false,"fork":false,"pushed_at":"2023-11-04T16:54:06.000Z","size":331,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T18:54:31.231Z","etag":null,"topics":["backtesting-trading-strategies","python","simple-moving-average","stock-market"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Prem07a.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}},"created_at":"2023-02-18T13:06:38.000Z","updated_at":"2024-01-08T09:32:49.000Z","dependencies_parsed_at":"2023-11-04T06:30:08.536Z","dependency_job_id":null,"html_url":"https://github.com/Prem07a/SMA_Backtesting","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prem07a%2FSMA_Backtesting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prem07a%2FSMA_Backtesting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prem07a%2FSMA_Backtesting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Prem07a%2FSMA_Backtesting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Prem07a","download_url":"https://codeload.github.com/Prem07a/SMA_Backtesting/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249048271,"owners_count":21204303,"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":["backtesting-trading-strategies","python","simple-moving-average","stock-market"],"created_at":"2024-12-11T18:18:09.569Z","updated_at":"2025-04-15T09:47:01.742Z","avatar_url":"https://github.com/Prem07a.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SMA_Backtesting\nThis is a Python back tester for a simple moving average (SMA) crossover trading strategy. The backtested calculates the performance metrics of the strategy and visualizes the results.\n\n## REQUIREMENTS:\nTo use this backtest, you need:\n1. A folder named data in the same location as your Python code file.\n\n2. A CSV file named stock.csv is in the data folder. The file should contain at least two columns: timestamp and close. The timestamp column should contain dates in the format yyyy-mm-dd and the close column should contain the closing prices of the stock.\n\n## INSTALLATION:\nTo use this back tester, simply download the SMABacktester.py file and save it in the same location as your Python code file. Then, import the SMABacktester class in your code.\u003cbr\u003e\nor \u003cbr\u003e\nelse clone the repo:\n```\ngit clone https://github.com/Prem07a/SMA_Backtesting\n```\nMake a new folder inside in the same location as that of SMA_Backtesting and name it as data\n\nAdd the stock.csv file to that folder\n### Note:\nYou can add any stock data just put it in the data folder and name it stock.csv\n## USAGE\n\nImport the SMABACKTESTER:\n```\nfrom SMABacktester import SMABacktester\n```\nTo use the back tester, create an instance of the SMABacktester class and pass the following parameters:\n\n* symbol: the stock symbol to be backtested\n* SMA_S: the short-term moving average window size\n* SMA_L: the long-term moving average window size\n* start: the start date of the backtesting period (format: 'yyyy-mm-dd')\n* end: the end date of the backtesting period (format: 'yyyy-mm-dd')\n\n## Available Method:\n\nThe SMABacktester class has the following methods:\n\n    get_data(): retrieves the stock price data from the stock.csv file and calculates the logarithmic returns\n    \n    prepare_data(): calculates the short-term and long-term moving averages\n    \n    set_parameters(SMA_S=None, SMA_L=None): updates the short-term and/or long-term moving average window sizes\n    \n    test_strategy(): backtests the strategy and calculates the performance metrics\n    \n    plot_results(): visualize the stock price, cumulative returns, and cumulative strategy returns\n    \n    optimize_parameters(SMA_S_range, SMA_L_range): find the optimal short-term and long-term moving average window sizes by exhaustively testing all combinations\n    \n## EXAMPLE USAGE:\n\n```\nbacktester = SMABacktester(symbol='SBI', SMA_S=50, SMA_L=200, start='Any', end='Any') *Note- Select date as per the data\nbacktester.test_strategy()\nbacktester.plot_results()\n```\n\n*    Note: This is only for Educational Purpose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprem07a%2Fsma_backtesting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprem07a%2Fsma_backtesting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprem07a%2Fsma_backtesting/lists"}