Simulate and Compare TQQQ and QQQ

This tutorial utilizes Python to simulate and compare the performance of TQQQ and QQQ. The fundamental observation is that TQQQ tends to outperform QQQ when the number of up days exceeds the number of down days. Conversely, if the market experiences an equal number of up days and down days, TQQQ is expected to underperform … Read more

What is a Statistic

This tutorial provides definitions and examples of a statistic. Further, it explains the relationship between a statistic and sampling distribution. The Definition of a Statistic A statistic is a function of observable random variables, T=t(X1, X2, …, Xn), which does not depend on any unknown parameters. script t is the function that we apply to … Read more

Major Python Packages for Hypothesis Testing

The 2 popular Python packages for hypothesis testing are scipy.stats and statsmodels. The following includes a brief introduction to each of them, along with simple examples. Introduction of Scipy.stats Based on scipy.stats official webpage, the module contains a large number of probability distributions, summary and frequency statistics, correlation functions and statistical tests, and more. Example … Read more

What Is Hypothesis Testing

Definition of Hypothesis Testing Hypothesis Testing isĀ an inferential statistical method using sample data to solve assumptions about population parameters. For instance, you want to test if people in New York City’s attitudes toward the new iPhone (e.g., iPhone 14) on a 7-point scale (1 = not at all, 7 = like it a lot) is … Read more

How to Subset Rows in Pandas Dataframes

There are at least 4 methods to subset row in Pandas dataframes. Method 1: loc[[Comma]] df.loc[[row_number1, row_number_2]] Method 2: loc[Colon] df.loc[row_number1: row_number_2] Method 3: iloc[[Comma]] df.iloc[[row_number1, row_number_2]] Method 4: iloc[Colon] df.iloc[[row_number1: row_number_2]] Example 1 for Method 1 The following uses loc[[Comma]] (i.e., loc[[0,2]])to subset rows in a Pandas dataframe. The following shows the original dataframe … Read more

Difference between NumPy Random and Python Random

NumPy Random is from NumPy, whereas Python Random is a module in Python. That is, Python random is NOT part of NumPy. This tutorial uses two examples to show the difference between NumPy Random and Python Random. Example 1 Python Random’s randint only has parameters of the range, whereas NumPy random’s randint has the additional … Read more

Poisson Regression in Python

The function of Poission() from statsmodels can be used to do Poisson regression in Python. The key Python code is as follows. import statsmodels.api as sm sm.GLM(Y, X, family=sm.families.Poisson()).fit() This tutorial uses a dataset posted by Paul Roback and Julie Legler. Two variables are the focus, namely age and total. The following are detailed explanations for … Read more

Linear Regression: Python Numpy Implementation from Scratch

This tutorial shows how you can conduct linear regression Python Numpy from scratch. 1. Math and Matrix of Linear Regression We can use just use pure matrix calculation to estimate the regression coefficients in a linear regression model. Below is the process. Thus, we can simplify the function above to the function below. We can … Read more