GithubHelp home page GithubHelp logo

pouyaardehkhani / financialanalysis Goto Github PK

View Code? Open in Web Editor NEW
18.0 1.0 9.0 30.48 MB

This notebook provides some skills to perform financial analysis on economical data.

License: GNU General Public License v3.0

Jupyter Notebook 100.00%
finance stock-market stock quantitative-finance nlp-machine-learning nlp deep-learning machine-learning clustering time-series-analysis portfolio-asset-allocation capm montecarlo-simulation sentimental-analysis customer-segmentation-analysis customer-segmentation stock-data-visualization

financialanalysis's Introduction

FinancialAnalysis license releases

This notebook provides some skills to perform financial analysis on economical data.

NOTE : Details are provided in the notebook

Skills that are covered in the notebook

  1. Plotting stock data by both matplotlib and plotly Open In Colab

  2. Calculating stocks daily return

  3. Finding correlation between daily returns

  4. Portfolio Assets Allocation and Statistical Data Analysis Open In Colab

    Portfolio Assets Allocation

      For those who do not know what Portfolio Assets Allocation is: A portfolio is a collection of financial investments(assets) such as stocks, fixed income securities (bonds), cash, mutual funds and Exchange Traded Funds (ETFs).

    Types of assets(only 3 of them covered)

    1. EQUITIES (STOCKS):

      A stock simply represents an ownership of a certain percentage of a company. A stock gives the owner the right to some shares in a given company depending on how much stock (shares) they own. Stocks are traded on stock exchanges such as New York Stock Exchange (NYSE) and regular individuals can buy them via online brokerage firms. Stocks are generally liquid as compared to real estate which could take a much longer time to sell.

    2. FIXED INCOME SECURITIES (BONDS):

      Abond is a fixed income that are generally issued by governments or corporations and represents a loan made by an investor to the borrower. Bonds pay the investor a fixed stated interest rate. Bonds are used by companies and Governments to raise money to fund future projects. Bonds that are less risky such as U.S. Government Bonds pay less interest compared to high risk bonds. Bond coupons represent a semi-annual interest payments to the bond holder.

    3. EXCHANGE TRADED FUNDS (ETFs):

      ETFs are a type of security that includes a group of securities and possibly track an index such as the S&P500. ETFs are like mutual funds however they are marketable securities and are being traded on exchanges similar to any other stock. ETFs can include a collection of stocks, bonds, and commodities. ETFs have generally low management fees and offer a tool for risk diversification. Vanguard S&P 500 ETF (VOO): https://investor.vanguard.com/etf/profile/performance/voo

    Assets Allocation

      Asset allocation is an investment strategy that is used to allocate client's assets based on their risk tolerance, target returns and investment time span. The goal of portfolio managers is to maximize returns and reduce risks.

    common advice that financial advisors generally recommend to retired seniors when it comes to asset allocations

      The conventional wisdom is to subtract client's age from 100 to calculate the % of portolio that should be allocated to stocks For Example: If you're 30 years old, you should have 70% allocated to stocks If you are 75 years old, you should invest 25% in stocks (old retired seniors generally recommend a more stable low risk portfolio).

  5. PORTFOLIO STATISTICAL METRICS

    Daily Returns

    Stock daily return is a calculation of how much investors have gained or lost per day.

    Cummulative Return

    Cumulative return is a measure of the aggregate amount that the stock gained or lost over a period of time.

    Standard Deviation (Risk/Volatility)

    The standard deviation is a measurement of the dispersion away from the mean. The more spread the data is, the higher the standard deviation. Volatile stocks have high standard deviation and therefore standard deviation represent the risk associated with the security.

      where:

      * x = Value of data with the index i

      * x = mean value

      * n = total number of data points in the data set

    Sharpe Ratio

    Sharpe ratio is used by investors to calculate the return of an investment compared to its risk.

      Sharpe ratio is calculated as follows:

    Sharpe ratio is simply a calculation of the average return earned in excess of the risk free rate (U.S. government bonds) per unit of risk (volatility). Note that , is the risk-free rate of return which is the return on an investment with zero risk, meaning it's the return investors could expect for taking no risk. As Sharpe ratio increases, risk-adjusted return increases and security becomes more desired by investors.

  6. Portfolio Optimization using Monte Carlo Simulations Open In Colab

  7. Plotting MARKOWITZ EFFICIENT FRONTIER

  8. CAPITAL ASSET PRICING MODEL (CAPM) Open In Colab

    CAPITAL ASSET PRICING MODEL (CAPM)

    For those who do not know what CAPITAL ASSET PRICING MODEL (CAPM) is:

    Capital Assets Pricing Model (CAPM) is one of the most important models in Finance. CAPM is a model that describes the relationship between the expected return and risk of securities. CAPM indicates that the expected return on a security is equal to the risk-free return plus a risk premium.

    RISK FREE ASSET ()

    CAPM assumes that there exist a risk free asset with zero standard deviation. The risk free asset return is denoted as . Investors who are extremely risk averse would prefer to buy the risk free asset to protect their money and earn a low return . If investors are interested in gaining more return, they have to bear more risk compared to the risk free asset. A risk free asset could be a U.S. government 10 year Treasury bill. This is technically a risk free asset since it's backed by the US Government.

    MARKET PORTFOLIO ()

    Market portfolio includes all securities in the market. A good representation of the market portfolio is the S&P500 (Standard & Poor's 500 Index). The market overall return is denoted as . The S&P500 is a market-capitalization-weighted index of the 500 largest U.S. publicly traded companies. The index is viewed as a gauge of large-cap U.S. equities.

    WHAT IS BETA?

    Beta represents the slope of the line regression line(market return vs. stock return). Beta is a measure of the volatility or systematic risk of a security or portfolio compared to the entire market (S&P500). Beta is used in the CAPM and describes the relationship between systematic risk and expected return for assets. Tech stocks generally have higher betas than S&P500 but they also have excess returns.

    • Beta=1.0: this indicates that its price activity is strongly correlated with the market.
    • Beta<1(defensive): indicates that the security is theoretically less volatile than the market (Ex:Utility and consumer goods (P&G). If the stock is included, this will make the portfolio less risky compared to the same portfolio without the stock.
    • Beta>1 (aggressive): indicates that the security's priceis more volatile than the market. For instance, Tesla stock beta is 1.26 indicating that it's 26% more volatile than the market. It will do better if the economy is booming and worse in cases of recession.

    CAPM FORMULA

      Where:

    • EXPECTED RETURN OF A SECURITY
    • RISK FREE RATE OF RETURN
    • BETA BETWEEN THE STOCK AND THE MARKET
    • RISK PREMIUM (INCENTIVE FOR INVESTING IN A RISKY SECURITY)
  9. Trading Using Moving Average Open In Colab

  10. create buy (1) and sell (-1) signal

  11. Stock Price Predictions Using regression / LSTM Open In Colab

  12. Bank Customers Segmentation Open In Colab

  13. AUTOENCODERS (PERFORM DIMENSIONALITY REDUCTION USING AUTOENCODERS)

  14. Stocks Sentiment Analysis Using AI Open In Colab

    We live in a world where we are constantly bombarded with social media feeds, tweets, and news articles. This huge data could be leveraged to predict people sentiment towards a particular company or stock. Natural language processing (NLP) works by converting words (text) into numbers. These numbers are then used to train an Al/ML model to make predictions. AI/ML-based sentiment analysis models, can be used to understand the sentiment from public tweets, which could be used as a factor while making a buy/sell decision of securities.

  15. Text Data Cleaning(remove PUNCTUATIONS and STOPWORDS)

  16. Plot WORDCLOUD

  17. TOKENIZING AND PADDING

    TOKENIZER

    Tokenizer allows us to vectorize text corpus. Tokenization works by turning each text into a sequence of integers.

  18. EMBEDDING LAYER

    Embedding layers learn low-dimensional continuous representation of discrete input variables.

financialanalysis's People

Contributors

pouyaardehkhani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.