Giter Club home page Giter Club logo

algorithmic_trading's Introduction

Here's a README for your code:

Momentum-Based Stock Selection Strategy

This Python script is designed to implement a momentum-based stock selection strategy using historical stock price data obtained from Yahoo Finance. The strategy selects stocks with high momentum by considering their price returns over different time periods.

Table of Contents

Introduction

The script uses the yfinance library to fetch historical stock price data for a list of S&P 500 stocks. It calculates various price returns, including 1-year,6-months price returns, and assigns a percentile score to each stock based on its returns. The stocks are then ranked by their percentile scores to identify high-quality momentum stocks.

Dependencies

The script relies on the following Python libraries:

  • numpy
  • pandas
  • scipy.stats
  • math
  • yfinance
  • threading
  • concurrent.futures
  • datetime

You can install these libraries using pip if you haven't already:

pip install numpy pandas scipy yfinance

Usage

  1. Clone or download the repository to your local machine.

  2. Make sure you have the required dependencies installed (see the Dependencies section).

  3. Prepare a CSV file containing the list of S&P 500 stock tickers (e.g., "sp_500_stocks.csv").

  4. Run the script by executing the momentum_strategy.py file.

python Quant_Momentum_Strategy.py
  1. Follow the on-screen instructions to enter the size of your investment portfolio.

  2. The script will generate a CSV file named "Final_Strategy.csv" containing the selected stocks and the number of shares to buy for each stock based on your portfolio size.

Strategy Overview

The strategy ranks stocks based on their percentile scores for different time periods, including 1-year price returns. High percentile scores indicate strong momentum. The selected stocks are then allocated to your portfolio based on your specified portfolio size.

Code Structure

  • Data Extraction: The script uses yfinance to extract historical stock price data for the S&P 500 stocks in parallel using multi-threading.

  • Returns Calculation: It calculates various price returns (e.g., 1-year returns) for each stock.

  • Percentile Ranking: Stocks are ranked by their percentile scores for different time periods, and the scipy.stats library is used for percentile calculations.

  • Portfolio Allocation: The script determines the number of shares to buy for each selected stock based on your portfolio size.

  • Output: The final list of selected stocks and their allocation details are saved in a CSV file for your reference.

This script provides a simple yet effective way to identify high-quality momentum stocks based on historical price returns.

algorithmic_trading's People

Contributors

yajanth avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.