Skip to content

Commit

Permalink
Fix precision of 10Cap price.
Browse files Browse the repository at this point in the history
Before: ten_cap("NVDA") = 10.834

After: ten_cap("NVDA") = 10.83
  • Loading branch information
kocielnik committed Dec 12, 2024
1 parent 85c9add commit 16ee5fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion isthisstockgood/DataFetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def fetchDataForTickerSymbol(ticker):
'cash': msn_money.free_cash_flow_growth_rates if msn_money and msn_money.free_cash_flow_growth_rates else [],
'total_debt' : msn_money.total_debt,
'free_cash_flow' : computed_free_cash_flow,
'ten_cap_price' : ten_cap_price,
'ten_cap_price' : round(ten_cap_price, 2),
'debt_payoff_time' : round(float(msn_money.total_debt) / computed_free_cash_flow),
'debt_equity_ratio' : msn_money.debt_equity_ratio if msn_money and msn_money.debt_equity_ratio >= 0 else -1,
'margin_of_safety_price' : margin_of_safety_price if margin_of_safety_price else 'null',
Expand Down
16 changes: 14 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@ def test_get_data():

with app.test_client() as test_client:
test_client = app.test_client()

res = test_client.get('/api/ticker/nvda')
data = res.text
assert json.loads(data)['debt_payoff_time'] >= 0
assert res.status_code == 200

assert res.json['debt_payoff_time'] >= 0

def test_get_ten_cap_price():
app = create_app(fetchDataForTickerSymbol)

with app.test_client() as test_client:
test_client = app.test_client()
res = test_client.get('/api/ticker/nvda')
assert res.json['ten_cap_price'] > 0

def test_ten_cap_price_has_two_places_precision():
app = create_app(fetchDataForTickerSymbol)

with app.test_client() as test_client:
test_client = app.test_client()
res = test_client.get('/api/ticker/nvda')

price = res.json['ten_cap_price']

assert round(price, 2) == price

0 comments on commit 16ee5fc

Please sign in to comment.