Value at Risk (VaR) In Python: Parametric Method

Sdílet
Vložit
  • čas přidán 4. 06. 2024
  • Dive into our comprehensive guide on "Value at Risk (VaR) In Python: Parametric Method". From installing essential libraries to interpreting the final VaR results, this video covers every step. Learn how to choose stock tickers, calculate daily log returns, set up confidence intervals, and more using Python. Master the art of financial risk management and enhance your portfolio analysis skills today.
    💻 Free Code Here: ryanoconnellfinance.com/estim...
    🎓 Tutor With Me: 1-On-1 Video Call Sessions Available
    ► Join me for personalized finance tutoring tailored to your goals: ryanoconnellfinance.com/finance-tutoring/
    👨‍💼 My Freelance Financial Modeling Services:
    ► Custom financial modeling solutions tailored for your needs: ryanoconnellfinance.com/freelance-finance-services/
    📚 CFA Exam Prep Discount - AnalystPrep:
    ► Get 20% off CFA Level 1, 2, and 3 complete courses with promo code "RYAN20". Explore here: analystprep.com/shop/all-3-levels-of-the-cfa-exam-complete-course-by-analystprep/?ref=mgmymmr
    📘 FRM Exam Prep Discount - AnalystPrep:
    ► Get 20% off FRM Part 1 and Part 2 complete courses with promo code "RYAN20". Explore here: analystprep.com/shop/frm-part-1-and-part-2-complete-course-by-analystprep/?ref=mgmymmr
    Chapters:
    0:00 - Intro to "Value at Risk (VaR) In Python: Parametric Method"
    0:19 - Installing Necessary Libraries
    0:48 - Set Time Range of Historical Returns
    1:59 - Choose Your Stock Tickers
    2:39 - Download Adjusted Close Prices from yFinance
    4:19 - Calculate Individual Stock Daily Log Returns
    6:11 - Create an Equally Weighted Portfolio
    7:15 - Calculate Total Portfolio Daily Returns
    8:10 - Find Portfolio Returns for a Range of Days
    9:22 - Create the Covariance Matrix
    10:05 - Calculate Portfolio Standard Deviation
    11:10 - Set Confidence Intervals for VaR
    11:39 - Calculate Value at Risk (VaR) In Python
    13:00 - Print and Interpret the VaR Results
    Disclosure: This is not financial advice and should not be taken as such. The information contained in this video is an opinion. Some of the information could be wrong. This channel is owned and operated by Portfolio Constructs LLC. Some of the links above are affiliate links, meaning, at no additional cost to you, I will earn a commission if you click through and make a purchase.

Komentáře • 35

  • @RyanOConnellCFA
    @RyanOConnellCFA  Před 8 měsíci +3

    CORRECTION: @11:46 when I calculated VaR, I made a mistake.
    The code I wrote was:
    VaR = portfolio_value * portfolio_std_dev * norm.ppf(cl) * np.sqrt(days/252)
    The corrected code is:
    VaR = portfolio_value * (norm.ppf(1 - cl) * portfolio_std_dev * np.sqrt(days / 252) - historical_returns.mean() * days)
    The original code does not account for the fact that the portfolio has an expected return for the time period in question and the downside risk must be subtracted from that. The new code does account for this.
    💻 Free Code Here: ryanoconnellfinance.com/estimating-value-at-risk-with-python/
    🎓 Tutor With Me: 1-On-1 Video Call Sessions Available
    ► Join me for personalized finance tutoring tailored to your goals: ryanoconnellfinance.com/finance-tutoring/
    👨‍💼 My Freelance Financial Modeling Services:
    ► Custom financial modeling solutions tailored for your needs: ryanoconnellfinance.com/freelance-finance-services/

    • @GilberTellez97
      @GilberTellez97 Před 3 měsíci +1

      Excellent video, loved it. You can also replace the for loop with a list comprehension statement: VaRs = [portfolio_value * (norm.ppf(1 - x) * portfolio_std_dev * np.sqrt(days / 252) - historical_returns.mean() * days) for x in confidence_levels]

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před měsícem

      @@GilberTellez97 Thank you for that tip!

    • @anejanemt-bk8oo
      @anejanemt-bk8oo Před 21 dnem

      Thank you for the v clear explanation!However, just thinking the coding should be having opposite sign? as the formula should be - [mu + Zscore x std dev] based on my understanding?
      that is:
      VaR = portfolio_value * (-(norm.ppf(1 - cl) * portfolio_std_dev * np.sqrt(days / 252) + historical_returns.mean() * days))

  • @prateekyadav964
    @prateekyadav964 Před 3 měsíci +3

    Excellent work Ryan. I was able to replicate the numbers above. However, I think that in the above code, instead of norm.ppf(1-cl), it should be norm.ppf(cl) as it should be a positive number based on how the formula is structured.

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 3 měsíci

      Thank you for your feedback! The use of norm.ppf(1 - cl) is indeed correct for calculating VaR, as it aligns with the convention of measuring the left tail risk, which corresponds to the lower percentile of the distribution

  • @gloriabukachi1
    @gloriabukachi1 Před 2 měsíci

    Very easy to understand from your teaching. Thank you!

  • @balchandrapaudel8202
    @balchandrapaudel8202 Před 7 měsíci +3

    I am learning a lot from your video keep posting its of great value for us. I am thankful for the video keep up the good work.

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 7 měsíci

      It is my pleasure! I appreciate the kind words and I will keep posting more

  • @ThinhNguyen-qe3jr
    @ThinhNguyen-qe3jr Před 5 měsíci +1

    I very much appreciate your effort putting into this video.

  • @laercioaugustocamara3263
    @laercioaugustocamara3263 Před 8 měsíci +2

    Hello Ryan! Many thanks for sharing all this knowledge! I really appreciate these rich contents and help me a lot for inducing Python on that usage.

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 8 měsíci

      It is my pleasure and I'm glad to see that you are getting value out of it! Thank you for the feedback

  • @PedroMacieira
    @PedroMacieira Před 2 měsíci

    Great content!!
    Why do you use 5 days , whats change If you use 1 for example?

  • @Panda-eye
    @Panda-eye Před 6 měsíci +1

    Loved your video. Could you please make a video on Full revaluation VaR calculation.

  • @eunikegracee
    @eunikegracee Před 7 měsíci +1

    Great video! One question though, do you use any distribution that best describes the data to calculate predicted VaR since you're using parametric method? Thanks!

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 7 měsíci

      In this video specifically, I just assumed a standard normal distribution. You could take the analysis a step further by first determining which distribution fits the data best however

  • @sahilk27
    @sahilk27 Před 6 měsíci +1

    Thanks!

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 6 měsíci +1

      Appreciate it! This is the first time I've gotten one of these Super Thanks donations 🙂

    • @sahilk27
      @sahilk27 Před 6 měsíci +1

      @@RyanOConnellCFA hopefully first of many. Thanks for your time and effort into making these videos!

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 6 měsíci

      @@sahilk27 It is my pleasure! And I hope so 🤞

  • @zakichet7493
    @zakichet7493 Před 5 měsíci +1

    thanks for this kind of videos ( VaR's method), they were so helpfu😀l. i hope you help us with the codes of backtesting in VaR.

  • @manuelchabierescolaperez9444
    @manuelchabierescolaperez9444 Před 6 měsíci +1

    Hi Ryan! Great videos, I am learning a lot.
    Quick question: in minute 12:00, you computed VaR as:
    portfolio_value * portfolio_std_dev * norm.ppf(cl) * np.sqrt(days/252)
    Shouldn't it be:
    portfolio_value * portfolio_std_dev * expected_returns * days/252 + portfolio_value * portfolio_std_dev * norm.ppf(1 - cl) * np.sqrt(days/252)
    Because if you computed as you did, aren't you assuming that the expected returns are 0? Note also that I wrote "1 - cl" instead of just cl.
    Thanks!!

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 6 měsíci +1

      Great catch, you are right about that! I'm going to update my pinned comment and the code on my website with your correction. Thank you!

    • @manuelchabierescolaperez9444
      @manuelchabierescolaperez9444 Před 6 měsíci +1

      @@RyanOConnellCFA great! Very happy to help

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 6 měsíci

      @@manuelchabierescolaperez9444 Thanks! I think this code best reflects the needed addition of the expected return for the day:
      VaR = portfolio_value * (norm.ppf(1 - cl) * portfolio_std_dev * np.sqrt(days / 252) - historical_returns.mean() * days)

  • @sayanbanerjee7214
    @sayanbanerjee7214 Před měsícem

    Can you please explain how to interpret it?

  • @redhothugo
    @redhothugo Před 6 měsíci +1

    First of all, thanks for this video. It's very enlighning and helpful. For learning purposes, I'm calculating the VaR of my personal portfolio and something odd is happening. The VaRs signals are negative and positive in the chart. It's like the VaR is positive. However, as far as I understand, the VaR is supposed to be a kind of loss figure, which means that the signal in he chart should be negative. Can you help me, please?

    • @RyanOConnellCFA
      @RyanOConnellCFA  Před 6 měsíci

      You are correct that you should not have both negative and positive VaRs. Its hard for me to tell whats going wrong without seeing your code. The best thing to do is to go back through and make sure you havent incorrectly typed a single thing. A negative sign in the wrong place could throw everything off

    • @prateekyadav964
      @prateekyadav964 Před 3 měsíci +1

      VaR is reported as a positive number. In the line where VaR is plotted, the signs are reversed, that's why the difference might be appearing.