MonkCode

Exploring the digital world!

Welcome to MonkCode, a developer-first site. Comment or contribute with your GitHub account.

MonkCode is dedicated to exploring the digital world with a focus on data extraction and visualization using tools like Leaflet and D3.

Building out the monkcode information system. This system is a set of components that will continuosly gather data. Actions can be taken and the data can become content.

Developing what I can with as much help as I can promt from ChatGPT.

How can I build my own Jarvis and share it with my friends and developers?

Learn how to create, store, process, and distribute information. Use github actions orbitbucket pipelines to start your own information system today. Zapier, provides automation at scale across most common accounts.

This is how I source the list of stocks in the S and P 500:

import bs4 as bs
import json
import requests
import time

def save_sp500_tickers():
    tic = time.perf_counter()
    resp = requests.get('http://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
    soup = bs.BeautifulSoup(resp.text, 'lxml')
    table = soup.find('table', {'class': 'wikitable sortable'})
    tickers = {"stocks":[]}
    for row in table.findAll('tr')[1:]:
        ticker = row.findAll('td')[0].text.strip()
        sector = row.findAll('td')[3].text.strip()
        industry = row.findAll('td')[4].text.strip()
        print(row.findAll('td')[2])
        #reports = row.findAll('td')[2].find('a')['href'].strip()
        tickers['stocks'].append({"ticker":ticker,"sector":sector,"industry":industry})#,"reports":reports})
        print(ticker)
        
    with open("wiki_stocks/sp500tickers.json","w") as f:
        json.dump(tickers,f)
    toc = time.perf_counter()
    print(f"Retrieved sp500 tickers in {toc - tic:0.4f} seconds")
    return tickers

save_sp500_tickers()

Then we use the list to query what we need for valuation:

V^* = the value expected from the growth formulas over the next 7 to 10 years

EPS = the company’s last 12-month earnings per share

8.5 = P/E base for a no-growth company

g = reasonably expected 7 to 10 Year Growth Rate of EPS

4.4 = the average yield of AAA corporate bonds in 1962 (Graham did not specify the duration of the bonds, though it has been asserted that he used 20 year AAA bonds as his benchmark for this variable[5])

Y = the current yield on AAA corporate bonds.

The intended valuation:

Intrinsic Value (IV) = (EPS * (8.5 + 2 * g) * 4.4) / Y

A python attempt:

def calculate_intrinsic_value(eps, growth_rate, current_yield):
    graham_constant = 8.5
    bond_yield = 4.4

    intrinsic_value = (eps * (graham_constant + 2 * growth_rate) * bond_yield) / current_yield
    return intrinsic_value

# Example values (you should replace these with actual data)
eps = 5.0  # Replace with the actual EPS of the company
growth_rate = 0.05  # Replace with the expected growth rate
current_yield = 0.035  # Replace with the current yield on AAA corporate bonds

intrinsic_value = calculate_intrinsic_value(eps, growth_rate, current_yield)

print(f"The intrinsic value of the stock is: ${intrinsic_value:.2f}")

In this script, you can replace the eps, growth_rate, and current_yield variables with the actual values for the stock you want to evaluate. When you run the script, it will calculate and print the estimated intrinsic value of the stock based on the Benjamin Graham method.

XML Sitemap