shivamsouravjha / stock-backend

36 stars 23 forks source link

feature: add F-Score in the stock ranking #1

Closed shivamsouravjha closed 1 month ago

shivamsouravjha commented 1 month ago

Value Investing: Using the Piotroski F-Score to Identify Winning Stocks

This README provides a simplified explanation of Joseph D. Piotroski's research paper titled "Value Investing: The Use of Historical Financial Statement Information to Separate Winners from Losers." The paper introduces the Piotroski F-Score, a scoring system that helps investors identify undervalued stocks with strong financial health.


Introduction

Value investing involves buying stocks that appear undervalued based on financial ratios like the book-to-market (BM) ratio. However, not all high BM stocks are good investments—some are financially distressed and continue to underperform.

Objective of the Study:


The Piotroski F-Score

The F-Score is a 9-point scoring system based on specific financial criteria derived from a company's financial statements. Each criterion adds 1 point if positive, with a maximum score of 9.

Components of the F-Score:

1. Profitability Criteria (4 points)

2. Leverage, Liquidity, and Source of Funds (3 points)

3. Operating Efficiency Criteria (2 points)


How to Calculate the F-Score

For each criterion:

  1. Evaluate the Condition: Check if the company meets the criterion based on its financial statements.
  2. Assign Points: Give 1 point for each positive criterion.
  3. Sum the Points: Add up all the points to get the F-Score (ranging from 0 to 9).

Interpretation:


Applying the F-Score in Investment Strategy

Step 1: Identify high BM (value) stocks.

Step 2: Calculate the F-Score for each stock.

Step 3: Select stocks with high F-Scores for your portfolio.

Benefits:


Research Findings


Practical Example

Imagine you're evaluating two companies, both with high BM ratios:

Company A:

Company B:

Investment Decision: Choose Company A for your portfolio due to its high F-Score, indicating strong financial health.


Limitations and Considerations


Conclusion

The Piotroski F-Score is a valuable tool for investors seeking to enhance their value investing strategy by focusing on financially strong companies. By systematically applying this scoring system, investors can improve portfolio performance and reduce the risk of investing in financially distressed firms.


References


naineel1209 commented 1 month ago

Hi @shivamsouravjha, can I work on this one?

shivamsouravjha commented 1 month ago

Sure @naineel1209 feel free to work on it!

naineel1209 commented 1 month ago

Thanks @shivamsouravjha! I was going through the codebase and was wondering what should be the value of the COMPANY_URL env variable?

shivamsouravjha commented 1 month ago

Its for the case when we dont have the data in database so we scrap it out from the source website

naineel1209 commented 1 month ago

Thanks for your response, Just to clarify, is there any specific site that you are using to scrape the data?

shivamsouravjha commented 1 month ago

Just for basic detail like name and etc.

naineel1209 commented 1 month ago

I meant to ask any specific external API endpoint that I should I set in the environment variable.

shivamsouravjha commented 1 month ago

Nope you wont be needing that most of data is fetched from mongodb whose sample of 1 stock dump is present on dump.txt

naineel1209 commented 1 month ago

Hi @shivamsouravjha, I was working on this issue and created a structure to calculate the F-score, but while accessing the document returned from MongoDB, I encountered a strange problem. When I try to access a key like Net Profit +, the map cannot locate the key, even though it is present.

image

But when I access key like Total Assets - then it is being located.

image

Am I possibly missing something in the code? Here's a link to the relevant part of the code: Code Link

shivamsouravjha commented 1 month ago

ideally this Net Profit + should help you access the map, perhaps there's issue with + sign try replicating the same in a small code section

naineel1209 commented 1 month ago

Hi @shivamsouravjha,

I was able to resolve the issue of accessing the key Net Profit +. The problem occurred because the preceding spaces in keys with a + sign contained a non-breaking space (NBSP) instead of a regular space. I've addressed this for now.

image

However, I encountered another issue today. Some of the stock data in the MongoDB restore document you added to the Git repository has a different structure than expected. For example, under profitLoss > Net Profit +, we expect an array of strings, but in some cases, it's an array of objects containing quarterly data.

For HDFC Bank:

image

There are approximately 199 documents with this issue, while 4,553 documents match the expected format. The remaining documents don't have any data.

image

shivamsouravjha commented 1 month ago

actually the HDFC format is the needed one. Reason is that it has months mentioned.

There are the keys

  | Mar 2015 | Mar 2016 | Mar 2017 | Mar 2018 | Mar 2019 | Mar 2020 | Mar 2021 | Mar 2022 | Mar 2023 | Mar 2024 | TTM

But seems like it is not needed as it can be used as array.

WIll try update the database! Thanks for pointing this out.