Powerfolio
πͺπ Powerfolio! is a stock screener and portfolio analysis. Backtest buy-and-hold vs. trading on RSI. Build a portfolio using efficient frontier and map hierarchical clustering results.
Install / Use
/learn @illyanyc/PowerfolioREADME
Creators:
- Illya Nayshevsky, Ph.D.
- Nathan S. Froemming, Ph.D.
- Ludovic Schneider
- Chandra Kandiah
Table of Contents
About
What is Powerfolio!?
Powerfolio! is screener, portfolio builder and analyzer for S&P 500 securities. Powerfolio! implements fundamental analysis, technical analysis and traditional portfolio analysis methods such as Sharpe Ratio and Efficient Frontier in order to allow you to select the best power-folio for your financial needs.
<img src="images/powerfolio_welcome.png" width="800" title="powerfolio_welcome"> <br>Theory
Fundamental Analysis
P/E - Price to Earnings Ratio
The price-to-earnings ratio (P/E ratio) is a method used to value a company by comparing the share price to the Earnings per Share (EPS). The price-to-earnings ratio is used a multiplier for company earnings. High P/E ratio means that the stock value is high compared to corporate earnings, and that the company may be overvalues, and vis-versa.
<img src="https://latex.codecogs.com/png.latex?\inline&space;\dpi{300}&space;\bg_white&space;\huge&space;\frac{P}{E}=\frac{Share\:Price}{Earnings\:Per\:Share}" title="\huge \frac{P}{E}=\frac{Share\:Price}{Earnings\:Per\:Share}" width=220/> <br>EPS - Earnings per Share
Earnings per share (EPS) is generally calculated by dividing company's profit by the outstanding shares of its common stock. EPS is a general way for a company to report it's profitability adjusted to it's marker capitalization. It is one of the general ways to evaluate corporate earnings.
<img src="https://latex.codecogs.com/png.latex?\inline&space;\dpi{300}&space;\bg_white&space;\huge&space;EPS=\frac{Net\:Income-Preferred\:Dividends}{Common\:Shares\:Outstanding}" title="\huge EPS=\frac{Net\:Income-Preferred\:Dividends}{Common\:Shares\:Outstanding}" width=280/> <br>Dividend
A dividend is the distribution of a company's earnings to its shareholders. Dividends are paid directly to shareholders of the company on periodic basis and the amount is determined by the board of directors. <br> <br>
Technical Analysis
RSI - Relative Strength Index
Relative Strength Index, better known as RSI is a technical indicator used to determine is a particular security is overbought or oversold. It measures the magnitude of price change of the asset; and is an oscillator that moves between 0 and 100. RSI was developed by J. Welles Wilder Jr. in 1978.
<img src="https://latex.codecogs.com/png.latex?\inline&space;\dpi{300}&space;\bg_white&space;\huge&space;RSI_{step\:one}&space;=&space;\left(\frac{100}{1+\frac{Average\:&space;gain}{Average\:loss}}\right)" title="\huge RSI_{step\:one} = \left(\frac{100}{1+\frac{Average\: gain}{Average\:loss}}\right)" width=220/> <img src="https://latex.codecogs.com/png.latex?\inline&space;\dpi{300}&space;\bg_white&space;\huge&space;RSI_{step\:two}&space;=&space;\left(\frac{100}{1+\frac{(Previous\:average\:gain\:\times\:13)\:+\:Current\:gain}{-((Previous\:average\:loss\:\times\:13)\:+\:Current\:loss)}}\right)" title="\huge RSI_{step\:two} = \left(\frac{100}{1+\frac{(Previous\:average\:gain\:\times\:13)\:+\:Current\:gain}{-((Previous\:average\:loss\:\times\:13)\:+\:Current\:loss)}}\right)" width=400 /> <br>RSI indicator, indicates that a stock is overbought then the indicator crosses above 70%, and oversold when the indicator drops below 30%. Additionally, a trader may want to enter a position when RSI crosses above 30%, indicating bullish reversal, and exit a position when RSI drops below 70%, indicating bearish reversal.
<img src="images/rsi_plot_example.png" width="1500" title="rsi_plot_example"> <br>MACD
Moving average convergence divergence (MACD) is a trend-following momentum indicator that shows the relationship between two moving averages of a securityβs price. The MACD is calculated by subtracting the 26-period exponential moving average (EMA) from the 12-period EMA.
<img src="https://latex.codecogs.com/png.latex?\inline&space;\dpi{300}&space;\bg_white&space;\huge&space;MACD&space;=&space;{12\:Period\:EMA\:}-{\:26\:Period\:EMA}" title="\huge MACD = {12\:Period\:EMA\:}-{\:26\:Period\:EMA}" width=380/> <br>Exponential moving average is a moving average that places a greater weight to most recent data points and less to the older data points. In finance, EMA reacts more significantly to recent price changes than a [simple moving average (SMA)](, which applies an equal weight to all observations in the period. In statistics, a moving average (MA), also known as simple moving average (SMA) in finance, is a calculation used to analyze data points by creating a series of averages of different subsets of the full data set.
<img src="https://latex.codecogs.com/png.latex?\inline&space;\dpi{300}&space;\bg_white&space;\huge&space;EMA_{today}&space;=&space;\left(&space;Value_{today}&space;*&space;\left(\frac{Smoothing}{1\:+\:Days}\right)&space;\right)\:+\:EMA_{yesterday}\:*\:\left(1\:-\:\frac{Smoothing}{1\:+\:Days}\right)" title="\huge EMA_{today} = \left( Value_{today} * \left(\frac{Smoothing}{1\:+\:Days}\right) \right)\:+\:EMA_{yesterday}\:*\:\left(1\:-\:\frac{Smoothing}{1\:+\:Days}\right)" width=330/> <br>MACD is used by traders to indicate bullish and bearish reversals when the EMA trendlines cross.
<br> <img src="images/macd_plot_example.png" width="1500" title="macd_example"> <br>Traditional Analysis
Sharpe Ratio
Sharpe Ratio allows user understand the return of an investment compared to the risk of the investment. Sharpe Ratio is the average return earned above the risk-free rate compared to volitility of the investment. Volatility is a measure of the price fluctuations of an asset or portfolio. The Sharpe ratio was developed by Nobel laureate William F. Sharpe in 1966.
<br> <img src="https://latex.codecogs.com/png.latex?\inline&space;\dpi{300}&space;\bg_white&space;\huge&space;Sharpe\:Ratio=\frac{R_p\:-\:R_f}{\sigma_p}" title="\huge Sharpe\:Ratio=\frac{R_p\:-\:R_f}{\sigma_p}" width=200/>where:
- R<sub>p</sub> = return of portfolio
- R<sub>f</sub> = risk-free rate
- Ο<sub>p</sub> = standard deviation of the portfolioβs excess return
Subtracting the risk-free rate from the retuns allows the user to isolate the profits from the cost of money. The risk-free rate of return usually identified by the 10-year U.S. Government Bond Yield, although in some instances risk-free rate may be identified as passive returns from investment in an index such as S&P 500, as that kind of investment may be considered the true cost of money.
Greater Sharpe Ratio is accosiated with a greater rist-adjusted return. <br>
Efficient Frontier
The Efficient Frontier is the collection of portfolios optimized for the highest expected return normalized to a specified level of risk. Portfolios that lie below the efficient frontier are sub-optimal because they do not provide enough return for the level of risk. Portfolios that cluster to the right of the efficient frontier are sub-optimal because they have a higher level of risk for the defined rate of return.
The plot was taken from TheWealthyFinn.com:
<img src="images/efficient_frontier_example_1.png" width="550" title="efficient_frontier" style="background-color:white;"> <br>Harry Markowitz has introduced the Efficient Frontier in 1952 and made it the cornerstone of modern portfolio theory (MPT).
<br>Hierarchical Clustering
Hierarchial Rist Clustering utilizes hierarchial risk parity ...
The plot was taken from QuantPedia.com:
<img src="images/hierarchial_risk_parity.jpg" width="550" title="hierarchial_risk_parity"> <br> <br>Installation
Anaconda
Anaconda is a package manager, an environment manager, a Python/R data science distribution, and a collection of over open-source packages.
Installation
<br>Jupyter
Powerfolio! is contained within a Jupyter Notebook. Project Jupyter exists to develop open-source software, open-stan
