Stock price and statistics (mean, standard deviation)

Get stock price + α

Get stock price + α from Financial Modeling Prep

def get_df_stock_screener(exchange):
       requests_cache.install_cache("stock-screener")
       url = f"https://financialmodelingprep.com/api/v3/stock-screener?marketCapMoreThan=100000&volumeMoreThan=100&dividendLowerThan=10&betaLowerThan=10&betaMoreThan=-10&exchange={exchange}&apikey={apikey}"
       response = requests.get(url)
       content = response.content.decode()
       json_content = json.load(StringIO(content))
       return pd.DataFrame(json_content).set_index("symbol")

requests_cache Save to cache using How to access with cache when reading_json with pandas

Stock Screener Use stock-screener

[ 
    {
        "symbol" : "AAPL",
        "companyName" : "Apple Inc.",
        "marketCap" : 1382174560000,
        "sector" : "Technology",
        "beta" : 1.2284990000000000076596506914938800036907196044921875,
        "price" : 318.8899999999999863575794734060764312744140625,
        "lastAnnualDividend" : 3.0800000000000000710542735760100185871124267578125,
        "volume" : 51500795,
        "exchange" : "Nasdaq Global Select",
        "exchangeShortName" : "NASDAQ"
    }, 
    {
        "symbol" : "AMZN",
        "companyName" : "Amazon.com Inc.",
        "marketCap" : 1215457260000,
        "sector" : "Technology",
        "beta" : 1.5168630000000000723758830645238049328327178955078125,
        "price" : 2436.8800000000001091393642127513885498046875,
        "lastAnnualDividend" : 0,
        "volume" : 6105985,
        "exchange" : "Nasdaq Global Select",
        "exchangeShortName" : "NASDAQ"
    }
]

Will be returned in the form of

Beta value

Beta (finance)

r_a = \alpha + \beta r_b

$ r_a $ is the stock return $ r_b $ is the market return (eg S & P 500) $ \ beta $ is a factor for market returns If $ \ beta = 2 $, a 3% increase in market returns will increase stock returns by 6%. $ \ Alpha $ is the return of irrelevant stocks of market returns

lastAnnualDividend Dividend per share for the last year

Calculation of statistics

DataFrame creation

df_stock_screener_nasdaq = get_df_stock_screener("nasdaq")
df_stock_screener_nyse = get_df_stock_screener("nyse")
df_stock_screener = pd.concat([df_stock_screener_nasdaq, df_stock_screener_nyse])

df_stock_screener["sector"].replace("", np.nan, inplace=True)
df_stock_screener.dropna(subset=["sector"], inplace=True)

df_stock_screener_target = df_stock_screener[["price","beta","lastAnnualDividend","volume"]]

Missing value

sector may be empty ETF seems to be empty It is easier to interpret if you remove the ETF from the target, so drop it dropna does not drop empty strings, so replace empty strings with nan

describe You can get summary statistics with describe

df_stock_screener_target.describe()
               price         beta  lastAnnualDividend        volume
count    6153.000000  6153.000000         6153.000000  6.153000e+03
mean      130.651825     0.940899            0.589505  1.701368e+06
std      5257.505324     0.874763            1.033488  5.608641e+06
min         0.010000    -8.439448            0.000000  1.000000e+02
25%         5.730000     0.301854            0.000000  8.373300e+04
50%        13.770000     0.881456            0.000000  3.761930e+05
75%        34.160000     1.392074            0.840000  1.274612e+06
max    291621.000000     8.949109            9.680000  1.566431e+08

price Average $ 130, standard deviation $ 5257, maximum $ 291621 The presence of outliers makes little sense for the statistics The size of the stock price does not make sense because the stock split can be done arbitrarily.

beta Average is 0.94, standard deviation is 0.87, minimum is -8.43, maximum is 8.94 Beta seems to be correct in the sense that the average close to 1 from its derivation method matches the market

Dividend, number of shares

As long as the number of shares is arbitrary, the comparison of their absolute values does not make much sense.

Recommended Posts

Stock price and statistics (mean, standard deviation)
2. Mean and standard deviation with neural network!
[Statistics for programmers] Variance, standard deviation and coefficient of variation
Variance, statistics up to standard deviation
Fuzzing and statistics
"Creating a stock price dataset" and "Implementing AR (1)"
[Statistics] First "standard deviation" (to avoid frustration with statistics)
[Python] How to handle inf and NaN in numpy mean, standard deviation, maximum / minimum
Calculation of standard deviation and correlation coefficient in Python
Calculate mean, median, mode, variance, standard deviation in Python
Stock Price Forecast 2 Chapter 2
Stock Price Forecast 1 Chapter 1