FMP

Enter

DCF model

target price

stock targets

valuation

stock analysis

stock targets

stock market

javascript

coding tutorial

# Calculate Stock Target Price Using Discounted Cash Flow Model and JavaScript.

-

#### Image credit: stock target price

Whether you are an experienced investment analyst or a novice trader, understanding how to determine a stock's target price is crucial. In addition to the simple valuation model Price-Income, another widely utilized method is the Discounted Cash Flow model (DCF). Let's delve into how the DCF model operates and learn how to construct a web-based application to calculate stock target prices using this model.

To employ the DCF model for calculating stock target prices and growth potential, you will need to forecast the company's free cash flow for the upcoming 5-10 years, compute the terminal value, and establish the discount rate. Subsequently, you divide the forecasted company free cash flow by the discount rate and also divide the company's terminal value by the discount rate. This process, known as discounted cash flow, necessitates determining the company's weighted average cost of capital (WACC), achieved by aggregating the cost of debt and equity. Following this, the discounted free cash flow and terminal value are summed up to obtain the enterprise value. Finally, adding cash to the enterprise value, subtracting debt, and dividing the result by the shares outstanding yields the stock's target price using the discounted cash flow model.

For those willing to learn how to build a web-based application for stock target price calculation, the process can be simplified. Rather than spending weeks on assumptions and calculations, leveraging the Financial Modeling Prep API can automate these tasks efficiently. Let's outline the development process:

Begin by setting up your development environment using VSCode. Download in here. Open VSCode and create an HTML file named "index.html" and a JavaScript file named "script.js" within the same folder.

Construct a simple layout for your project in the HTML file as shown in the picture below:

Add some designs to the same file, below the title tag as shown in the picture below

and proceed to populate the JavaScript file with the necessary code. Open your script.js file and input the below code

Implement functionality to retrieve data from HTML elements and add event listeners to detect user input changes, particularly when the "Calculate" button is pressed. Ensure to input your custom API key obtained from the Financial Modeling Prep website. Use my referral link to get a great discount on the Financial Modeling Prep API. After obtaining your API key, input it inside the variable where it says const apiKey = “"; for example your input may look something like this: const apiKey = "lkflvljbhflbbnlbnlbnlbn";

The next step is to add another piece of code, shown below, right below your initial lines of code.

Fetch relevant data using the Financial Modeling Prep API, ensuring the existence of essential data such as enterprise value and stock market price. As shown in the picture above.

Perform the actual calculations to determine the stock's target price by applying the appropriate formulae, including adjusting for cash, debt, and outstanding shares. As shown in the picture below. Display the calculated stock target price alongside the market price on the HTML file.

Upon completion, save both the script.js and index.html files by pressing command + S keys on your keyboard in both files. The last step is to open the index.html file in a web browser (drag your index.js file to the empty browser window) to test your web-based application. Congratulations, you now built your stock target price calculator using DCF model.

While investment analysts dedicate considerable time to research and calculations, this web-based application simplifies the process of determining stock fair value and growth potential. For those interested in accessing the code, it is available on the GitHub repository. Clone the repository to get a fully functional web app, but don't forget to input your custom API key. iPhone users can take advantage of the excellent iOS app Stock Target Price to calculate stock target prices.Thank you for reading, and I trust this article has been informative and useful in your investment endeavors.

### Other Blogs

Jan 16, 2024 4:18 PM - Samuel Abdelshahid

## Best Budget-Friendly Laptops for Financial Modeling and Stock Trading (2024)

Laptops for Financial Modeling and Stock Trading In the hustle and bustle of the trading world, having a trustworthy laptop is like having a reliable partner by your side. Making well-informed decisions and staying ahead of market trends become second nature with the right device.  However, th...

Jan 21, 2024 4:00 AM - Parth Sanghvi

## Understanding Profitability Metrics: Exploring ROE, ROA, and Net Profit Margin

Introduction: In the world of financial analysis, a profound grasp of essential profitability metrics is vital. This blog delves into three pivotal metrics—ROE (Return on Equity), ROA (Return on Assets), and Net Profit Margin—offering clear insights without unnecessary complexity. Exploring RO...

May 14, 2024 11:41 AM - Sanzhi Kobzhan

## The easiest way to calculate stock’s target price and why the target price is important.

A stock's target price, also known as its fair value, is an indication of what a share can cost based on the company’s forecasted financial statements. It is important to know a stock's fair value to find undervalued stocks with great growth potential. Let's consider how investment analysts calculat...

FMP

Financial Modeling Prep API provides real time stock price, company financial statements, major index prices, stock historical data, forex real time rate and cryptocurrencies. Financial Modeling Prep stock price API is in real time, the company reports can be found in quarter or annual format, and goes back 30 years in history.