A Quick Tutorial on Python 3

After learning this quick tutorial on Python 3, you will accummulate confidence in writting your own Python codes.

1  Short Introduction

1.1  Numbers

  • /‘ always returns a float; ‘//‘ does floor division and returns an integer; ‘%‘ calculates the remainder; power calculation is done by ‘**
  • In interactive mode, the last printed expression is assigned to a special variable ‘_‘ (underscore), similar as ‘ans‘ in Matlab.

    The ‘_’ variable shall be treated as read-only. Assigning a value to it will invalidate its embedded magic behavior.

Read more A Quick Tutorial on Python 3

R in Time Series: Linear Regression With Harmonic Seasonality

This tutorial talks about linear regression with harmonic seasonality.

1  Underlying mathematics

In regression modeling with seasonality, we can use one parameter for each season. For instance, 12 parameters for 12 months in one year. However, seasonal effects often vary smoothly over the seasons, so that it may be more parameter-efficient to use a smooth function instead of separate indices. Sine and cosine functions can be used to build smooth variationinto a seasonal model. Read more R in Time Series: Linear Regression With Harmonic Seasonality

R in Time Series: Linear Regression with Seasonal Variables

This tutorial gives a short introduction about linear regression with seasonal variables.

A time series are observations measured sequentially in time, seasonal effects are often present in the data, especially annual cycles caused directly or indirectly by the Earth’s movement around the sun. Here we will present linear regression model with additive seasonal indicator variables included.

Suppose a time series contains s seasons. For example

  • For time series measured over each calendar month, s = 12.
  • For time series measured in six-month intevals, corresponding to summer and winter, s = 2.

Read more R in Time Series: Linear Regression with Seasonal Variables

Memory management of variables in Python

This tutorial illustrates memory management of variables in Python.

1  Variables in C

When you do an assignment like the following in C, it actually creates a block of memory space so that it can hold the value for that variable

You can think of it as putting the value assigned in a box with the variable name as shown below Read more Memory management of variables in Python

R in Time Series: Linear Regression

This tutorial talks about linear regression on time series and implementations in R.

1  Trend: stochastic vs deterministic

  • We may consider a trend to be stochastic when it shows inexplicale changes in direction, and we attribute apparent transient trends to high serial correlations with random errors.
  • When we have some plausible physical explanation for a trend, we usually wish to model it in some deterministic manner. Deterministic trends and seasonal variations can be modelled using regression.
  • The practical difference between stochastic and deterministic trends is that we extrapolate the latter when we make forecasts. We justify short-term extrapolation by claiming that underlying trends will usually change slowly in comparison with the forecast lead time. For the same reason, short-term extrapolation should be based on a line, maybe fitted to the more recent data only, rather than a high-order polynomial.

Read more R in Time Series: Linear Regression

Autocorrelation Affects Regression on Time Series

This post talks about how autocorrelation affects regressions on time series.

Time series regression usually differs from a standard regression analysis because the residuals form a time series and therefore tend to be serially correlated.

  • When the residual correlation is positive, the estimated standard deviation of the parameter estimates, read from the computer output of a standard regression analysis, will tend to be less than their true value. \(\,\Longrightarrow\,\) This will lead to erroneously high statistical significance being attributed to statistical tests in standard computer output. In other words, the obtained p values will be smaller than they should be.

Read more Autocorrelation Affects Regression on Time Series

Yale ECON 252 Lecture 9 – Corporate Stocks


Professor Shiller emphasizes the worldwide importance of corporations by looking at World Bank data for corporate stocks as traded on global stock markets. He then turns his attention to the concept of a corporation, elaborating on the role of shareholders, the board of directors, and the Chief Operating Officer. Following this, he compares and contrasts for-profit and nonprofit corporations. Next, he discusses equity financing of for-profit corporations, covering market capitalization, dividends, share repurchases, dilution, and the difference between common and preferred shares. In addition, he discusses and rejects claims that share issuance is not really important for capital raising in modern times. Professor Shiller concludes this lecture with a discussion of the balance sheets of two well-known corporations, Xerox and Microsoft. Read more Yale ECON 252 Lecture 9 – Corporate Stocks

Yale ECON 252 Lecture 8 – Theory of Debt, Its Proper Role, Leverage Cycles


Professor Shiller devotes the beginning of the lecture to exploring the theoretical determinants of the level of interest rates. Eugen von Boehm-Bawerk names technical progress, roundaboutness, and time preference as the crucial factors. Professor Shiller complements von Boehm-Bawerk’s analysis with two of Irving Fisher’s modeling approaches, the view of the interest rate as the equilibrium variable in the savings market and the perspective of simple Robinson Crusoe economies on the determination of interest rates. Subsequently, Professor Shiller focuses his attention on present discounted values and derives the price for discount bonds, consols, annuities, as well as corporate bonds. His treatment of the term structure of interest rates leads him to forward rates and the expectations theory of the term structure of interest rates. At the end of the lecture, he offers insights on usurious loan practices, from ancient times until today, and describes the improvements in consumer financial protection that have been made after the financial crisis of the 2000s.

Read more Yale ECON 252 Lecture 8 – Theory of Debt, Its Proper Role, Leverage Cycles

Yale ECON 252 lecture 7 – Efficient Markets


Initially, Professor Shiller looks back at David Swensen’s guest lecture, in particular with respect to the Sharpe ratio as a performance measure for investment strategies. He emphasizes the empirical difficulty to measure the standard deviation, specifically for illiquid asset classes, and elaborates on investment strategies that manipulate the Sharpe ratio. Subsequently, he focuses on the Efficient Markets Hypothesis. This theory states that markets efficiently incorporate all public information, which consequently renders beating the market impossible. For example, technical analysis fails to provide powerful, short-run profit opportunities. A consequence of the Efficient Markets Hypothesis is that stock prices follow a Random Walk, as innovations to the stock price must be solely attributable to news. Professor Shiller contrasts the behavior of a Random Walk with that of a First-Order Autoregressive Process, and concludes that the latter statistical process matches the reality of the stock market more closely. This conclusion, combined with the evidence that investment managers like David Swensen are capable of consistently outperforming the market leads Professor Shiller to the conclusion that the Efficient Markets Hypothesis is a half-truth.

Read more Yale ECON 252 lecture 7 – Efficient Markets

Yale ECON 252 lecture 6 – Guest Speaker David Swensen


This lecture is a guest lecture by Professor David Swensen, Yale University’s Chief Investment Officer. The starting point for Professor Swensen is an article entitled Crash Course, published in Barron’s in the wake of the financial crisis from 2007-2008. This article blames his endowment investment approach for a failure of diversification and an overemphasis on alternatives. Subsequently, Professor Swensen characterizes three major determinants of investment return–asset allocation, market timing, and security selection–and outlines the importance of asset allocation as the predominant component. Against the background of these three tenets, he revisits Barron’s criticism and defends the virtues of diversification against an exaggerated perception of the needs for safety in the immediate aftermath of a crisis. Moreover, he counters the critique of overemphasizing alternatives with a longer-term view on the performance of the Yale portfolio. In the concluding question-and-answer session, he elaborates on the difference between endowment management and fund management, recent developments in the hedge fund and private equity fund industry, and on measures of investment performance beyond the Sharpe ratio. Read more Yale ECON 252 lecture 6 – Guest Speaker David Swensen