Skip to content

Commit 143524f

Browse files
committed
Add Company Discounted Cash FLow Value API
1 parent 83504c0 commit 143524f

File tree

6 files changed

+152
-0
lines changed

6 files changed

+152
-0
lines changed

FinancialModelingPrepApi/Abstractions/CompanyValuation/ICompanyValuation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public interface ICompanyValuation
99
{
1010
public Task<ApiResponse<CompanyProfileResponse>> GetCompanyProfileAsync(string symbol);
1111

12+
public Task<ApiResponse<DCFResponse>> GetDiscountedCashFlowAsync(string symbol);
13+
public Task<ApiResponse<List<HistoricalDCFResponse>>> GetHistoricalDiscountedCashFlowAsync(string symbol, Period period = Period.Annual);
14+
public Task<ApiResponse<List<HistoricalDailyDCFResponse>>> GetHistoricalDiscountedCashFlowDailyAsync(string symbol, int limit = 100);
15+
1216
public Task<ApiResponse<List<SymbolResponse>>> GetSymbolsListAsync();
1317
public Task<ApiResponse<List<SymbolResponse>>> GetTradableSymbolsListAsync();
1418
public Task<ApiResponse<List<SymbolResponse>>> GetETFListAsync();

FinancialModelingPrepApi/Core/CompanyValuation/CompanyValuation.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,62 @@ public Task<ApiResponse<List<CompanyRatingResponse>>> GetHistoricalCompanyRating
215215

216216
return client.GetAsync<List<CompanyRatingResponse>>(url, pathParams, queryString);
217217
}
218+
219+
public async Task<ApiResponse<DCFResponse>> GetDiscountedCashFlowAsync(string symbol)
220+
{
221+
const string url = "[version]/discounted-cash-flow/[symbol]";
222+
223+
var pathParams = new NameValueCollection()
224+
{
225+
{ "version", ApiVersion.v3.ToString() },
226+
{ "symbol", symbol }
227+
};
228+
229+
var result = await client.GetAsync<List<DCFResponse>>(url, pathParams, null);
230+
231+
if (result.HasError)
232+
{
233+
return ApiResponse.FromError<DCFResponse>(result.Error);
234+
}
235+
236+
return ApiResponse.FromSucces(result.Data.First());
237+
}
238+
239+
public Task<ApiResponse<List<HistoricalDCFResponse>>> GetHistoricalDiscountedCashFlowAsync(string symbol, Period period = Period.Annual)
240+
{
241+
const string url = "[version]/historical-discounted-cash-flow-statement/[symbol]";
242+
243+
var pathParams = new NameValueCollection()
244+
{
245+
{ "version", ApiVersion.v3.ToString() },
246+
{ "symbol", symbol }
247+
};
248+
249+
var queryString = new QueryStringBuilder();
250+
251+
if (period != Period.Annual)
252+
{
253+
queryString.Add("period", period.ToString().ToLower());
254+
}
255+
256+
return client.GetAsync<List<HistoricalDCFResponse>>(url, pathParams, queryString);
257+
}
258+
259+
public Task<ApiResponse<List<HistoricalDailyDCFResponse>>> GetHistoricalDiscountedCashFlowDailyAsync(string symbol, int limit = 100)
260+
{
261+
const string url = "[version]/historical-discounted-cash-flow-statement/[symbol]";
262+
263+
var pathParams = new NameValueCollection()
264+
{
265+
{ "version", ApiVersion.v3.ToString() },
266+
{ "symbol", symbol }
267+
};
268+
269+
var queryString = new QueryStringBuilder();
270+
271+
queryString.Add("limit", limit);
272+
273+
return client.GetAsync<List<HistoricalDailyDCFResponse>>(url, pathParams, queryString);
274+
}
218275
}
219276
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace MatthiWare.FinancialModelingPrepApi.Model.CompanyValuation
4+
{
5+
public class DCFResponse
6+
{
7+
[JsonPropertyName("symbol")]
8+
public string Symbol { get; set; }
9+
10+
[JsonPropertyName("date")]
11+
public string Date { get; set; }
12+
13+
[JsonPropertyName("dcf")]
14+
public double Dcf { get; set; }
15+
16+
[JsonPropertyName("StockPrice")]
17+
public double StockPrice { get; set; }
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
using System.Text.Json.Serialization;
3+
4+
namespace MatthiWare.FinancialModelingPrepApi.Model.CompanyValuation
5+
{
6+
public class HistoricalDCFResponse
7+
{
8+
[JsonPropertyName("symbol")]
9+
public string Symbol { get; set; }
10+
11+
[JsonPropertyName("date")]
12+
public string Date { get; set; }
13+
14+
[JsonPropertyName("price")]
15+
public double Price { get; set; }
16+
17+
[JsonPropertyName("dcf")]
18+
public double? Dcf { get; set; }
19+
}
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace MatthiWare.FinancialModelingPrepApi.Model.CompanyValuation
4+
{
5+
public class HistoricalDailyDCFResponse
6+
{
7+
[JsonPropertyName("symbol")]
8+
public string Symbol { get; set; }
9+
10+
[JsonPropertyName("date")]
11+
public string Date { get; set; }
12+
13+
[JsonPropertyName("dcf")]
14+
public double Dcf { get; set; }
15+
}
16+
}

Tests/CompanyValuation/CompanyValuationTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,41 @@ public async Task GetHistoricalCompanyRatingAsync()
157157
Assert.Equal(5, result.Data.Count);
158158
Assert.All(result.Data, data => Assert.Equal("AAPL", data.Symbol));
159159
}
160+
161+
[Fact]
162+
public async Task GetDiscountedCashFlowAsync()
163+
{
164+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
165+
166+
var result = await api.CompanyValuation.GetDiscountedCashFlowAsync("AAPL");
167+
168+
result.AssertNoErrors();
169+
Assert.Equal("AAPL", result.Data.Symbol);
170+
}
171+
172+
[Fact]
173+
public async Task GetHistoricalDiscountedCashFlowAsync()
174+
{
175+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
176+
177+
var result = await api.CompanyValuation.GetHistoricalDiscountedCashFlowAsync("AAPL", Period.Quarter);
178+
179+
result.AssertNoErrors();
180+
Assert.NotEmpty(result.Data);
181+
Assert.All(result.Data, data => Assert.Equal("AAPL", data.Symbol));
182+
}
183+
184+
[Fact]
185+
public async Task GetHistoricalDiscountedCashFlowDailyAsync()
186+
{
187+
var api = ServiceProvider.GetRequiredService<IFinancialModelingPrepApiClient>();
188+
189+
var result = await api.CompanyValuation.GetHistoricalDiscountedCashFlowDailyAsync("AAPL", 5);
190+
191+
result.AssertNoErrors();
192+
Assert.NotEmpty(result.Data);
193+
Assert.Equal(5, result.Data.Count);
194+
Assert.All(result.Data, data => Assert.Equal("AAPL", data.Symbol));
195+
}
160196
}
161197
}

0 commit comments

Comments
 (0)