LU Decomposition in Python
In this video, we look at the LU matrix factorization in Scipy. We will show how it can be used to solve systems of linear equations and discuss why one may want to use this over the bult-in solve function.
Guthub: https://github.com/kpmooney/numerical_methods_youtube/blob/master/matrix_decomposition/LU%20Decomposition.ipynb
Tip jar: https://paypal.me/kpmooney
31
views
Implementing the Bachelier Option Pricing model in Python (Part 2)
In this video, we show how we can use put-call parity to build on our previous work and get the Bachelier put price. In the second part, we will play around with Sympy, Python’s symbolic algebra library. We will evaluate the call pricing model as we did numerically, but will use Sympy’s capabilities to get an analytical expression for Delta using the Bachelier model. We’ll compare that number to that we’d get using the Black-Scholes formula.
Part 1: https://youtu.be/L-YRF2A9MHE
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/bachelier_model/Bachelier%20Model%202.ipynb
Tipjar: https://paypal.me/kpmooney
26
views
Impromptu Video: Calculating IV for Indian stocks and Indices
A viewer asked if I could do a video on calculating the implied volatility of options that trade in India. The process is identical to that of US options. The math involved is explained in my first video on the topic (https://youtu.be/Jpy3iCsijIU). Please consult that if the concepts are unfamiliar.
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/root_finding/implied_volatility/IV%20of%20Indian%20Stocks.ipynb
Tipjar: https://paypal.me/kpmooney
32
views
Implementing the Bachelier Option Pricing model in Python (Part 1)
I recently received a question about the Bachelier model, a historical model from around 1900. It has regained some use as of late, with the CME using it since it allows for negative commodity prices. In this video, we’ll build out a Python function to return the Bacheleier price of a call. We’ll then compare this to the Back Scholes model. Lastly we will show to to numerically calculate the greeks associated with this model and use vega to calculate the volatility given the price of a call.
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/bachelier_model/Bachelier%20Model%201.ipynb
Tip Jar: https://paypal.me/kpmooney
189
views
Numerically Solve Boundary Value Problems: The Shooting Method with Python (Part 1)
In this video, I’ll show how to use an initial value problem ODE solver such as Scipy’ solve_ivp to solve boundary value problems. This is a simple iterative technique called the shooting method which allows us to adjust one of the unknown initial conditions until we satisfy the specified boundary values to within some tolerance. This will be part one of two. Here I will solve a simple equation as a proof-of-concept. In part two I will address a real-world problem.
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/bvp/Shooting%20Method.ipynb
Tipjar: https://paypal.me/kpmooney
112
views
Numerically Integrating Differential Equations in Excel and Python: Runge Kutta Method
I want to go over an implementation of the 4th-order Runge Kutta algorithm in both Python and Excel. This algorithm is used extensively in scientific computing. MATLAB’s ODE45 solver, as well as the solve_ivp function from Scipy use a variation of this technique. The goal of this video is to show how simple it is to make use of this method when one doesn’t gave access to canned routines such as those in MATLAB or Scipy. This video was inspired by an engineer I worked with years ago who ran into this issue. He had an ODE to solve, but the only software he had easy access to was Excel.
Tip Jar: https://paypal.me/kpmooney
Video on Euler’s Method: https://youtu.be/G7vJ8X1EnRg
Wikipedia Page on Runge Kutta: https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/runge_kutta.
40
views
Numerically Integrating Differential Equations in Excel and Python: Euler's Method
As a prelude to discussing the Runge Kutta algorithm, I’d like to start slightly simpler with the Euler method. We’ll discuss the pros and cons of this method for numerically solving ordinary differential equations (initial value problems) and set up some examples with both first and second order equations in both Python and Excel.
Tip Jar: https://paypal.me/kpmooney
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/runge_kutta
15
views
Lognormal Distributions: Calculating the Probability of a Stock Range with Excel and Python
In response to a viewer question, we look at how to calculate the probability a stock will be in a given price range at a certain time given its implied volatility. We will compare this against our Monte Carlo simulations worked out last year. We will do the calculation both in Excel and Python.
Tip Jar: https://paypal.me/kpmooney
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/lognormal
Stock Monte Carlo and Linear Systems: https://youtu.be/AC_4gjSYzu0
35
views
Gradient Descent (part 2)
In part two, we look at the effects of the parameter gamma, the possibility of getting stuck in a local minimum, and the ability to use a numerical approximation for the derivative or gradient.
Part 1: https://youtu.be/trvgzYjUr-Y
Part 3: https://youtu.be/Twxe59IjHDk
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/gradient_descent
Tip Jar: https://paypal.me/kpmooney
13
views
Gradient Descent (Part 1)
Gradient descent is an algorithm for finding the local minimum of a function. Many problems in machine learning, mathematical modeling, physics, etc. involve optimization-- finding the minimum or maximum-- of a function. Gradient descent, or variations of it , is a common algorithm used for optimization in all the fields noted above. We’ll go over the basics of gradient descent and implement a simple version in Python. In parts one and two, we will restrict ourselves to functions of only one variable, but in parts three and perhaps four, we will look at functions of multiple variables that more closely resemble real-world applications.
Part 2: https://youtu.be/J1ghebX8XGY
Part 3: https://youtu.be/Twxe59IjHDk
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/gradient_descent
Tip Jar: https://paypal.me/kpmooney
15
views
Playing with Singular Value Decomposition: Differences between Numpy & MATLAB (Image Compression)
This is a somewhat spur-of-the-moment video. I was revisiting some old MATLAB code that involved the singular value decomposition and since we are using Python more and more, I wanted to familiarize myself with the Numpy implementation thereof. Normally, the two languages are pretty similar, but in this case, there are enough differences that I wanted to note them down for future reference. So this video is essentially me detailing some of the major differences them.
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/svd
Tip Jar: https://paypal.me/kpmooney
25
views
1
comment
Calculating the Correlations Between Stocks Using Python
In the previous video, we looked at beta-weighting our deltas to a particular index, the SPY in that case. In addition to beta-weighting, it is also important to look at the correlations between underlyings to get a sense of how valid that beta number is. It is also useful to see if we are overweighting our portfolios to a specific underlying or sector. In this video, I will show a simple way to calculate the correlation between stocks using Python.
Beta-weighted Deltas: https://youtu.be/PNnOCKHJh8U
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/correlation
Tip Jar: http://paypal.me/kpmooney
53
views
The Trapezoid Rule: Estimating the value of a definite integral (using Python and Excel)
The trapezoid rule is a simple method for quick estimation of a definite integral. We’ll go over the algorithm and implement it both in Python and Excel. We’ll also demonstrate the built-in trapz function in Numpy .
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/numerical_integration
Tip Jar: https://paypal.me/kpmooney
15
views
More Curve Fitting with Python: Complicated Models with Vastly Varying Parameters
We return to the topic of curve fitting. We will fit a complicated nonlinear differential algebraic equation system to experimental data. This problem is compounded by the fact the parameters we are searching for vary by over 10 orders of magnitude. We can fit such a system in the usual way using the curve_fit or minimize function, but the vast difference in the parameters will cause problems with the algorithms. One needs to rescale these numbers in such a way as to be roughly the same order of magnitude. We will accomplish this (for this case), by coding to fit the log of the parameters instead.
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/curve_fitting/battery_model/Curve%20Fitting%20Battery%20Model.ipynb
Paper Referenced in this Video: https://iopscience.iop.org/article/10.1149/1.2422896
Tip Jar: https://paypal.me/kpmooney
62
views
Q&A: Customizing mplfinance Charts and how to Calculate Crossovers
The format of this video is a bit different. This is an answer to a question left in the comments so I am going to talk though a notebook I already wrote rather than doing it live on the recording. The question was on accessing mplfinance figures and customizing the plots. A secondary question was how to calculate some trading signals based on various crossovers. As I have said before, I don’t believe in technical analysis so I am presenting this for education purposes only.
Original mplfinance video: https://youtu.be/wiV_nXPdu60
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/market_analysis/mplfinance%20and%20crossover%20signals.ipynb
Tip Jar: https://paypal.me/kpmooney
17
views
An Introduction to Logistic Regression
In a previous video, we tested our gradient descent algorithm using logistic regression. In that video, linked to below, I was mostly interested in testing the minimization code on a problem we hadn’t done before. In this video, per a viewer request, I want to discuss logistic regression more detail and explain some of the math and assumptions underlying it. This builds on the things we discussed in the video on gradient descent and multivariate linear regression. Please see the links below for those videos.
Gradient Descent 3: https://youtu.be/Twxe59IjHDk
Multivariate Linear Regression: https://youtu.be/RRbcSozxLts
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/logistic_regression/Logistic%20Regression.ipynb
Tip Jar: https://paypal.me/kpmooney
39
views
Using Scipy to Find the Prices of a Stock and its Volatility from a Call Spread Price
In a previous video, we looked at how to calculate the stock price based on an option price assuming we knew the volatility. In a comment, someone asked if the same could be done using a short call spread rather than a single option. I wasn't going to do a video on this but then after thinking about it some more, there are some interesting aspects to this problem. After writing up some test code, I realize there was a potential issue that could cause a solution to fail under certain circumstances.
In this video I will consider two scenarios. The first is where we know the price of each individual leg of the spread. We do not know the stock price or the implied volatility. In the second case, we will consider the situation where we know the price of the spread but not the individual legs. In this case we wouldn't need to know the implied volatility.
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/root_finding/fsolve/option_spread/Price%20From%20Call%20Spread.ipynb
Finding Stock Prices from Option Prices: https://youtu.be/NF-XMP8RjJo
Finding Implied Volatility Using Newton’s Method: https://youtu.be/Jpy3iCsijIU
Fsolve documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html
Minimize documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
Tip Jar: https://paypal.me/kpmooney
31
views
Multivariate Regression and Gradient Descent
In a previous video, we used linear and logistic regressions as a means of testing the gradient descent algorithm. I was asked to do a video on logistic regression, when I realized the example I used in the gradient descent video was rather complex. Not only is the model more complicated than linear regression, I was using multiple features as well. This would be akin to fitting a plane to 3-d data rather than a line to 2-d in the case of linear regression. In addition there is a lot of matrix manipulation to vectorize the code. In this video, I want to go over that matrix manipulation using the simple case of linear regression and show how by doing this, we can not only get a speed benefit by vectorizing, but also generalize our code to handle multiple parameters with a single gradient function.
Gradient Descent Part 1: https://youtu.be/trvgzYjUr-Y
Gradient Descent Part 2: https://youtu.be/J1ghebX8XGY
Gradient Descent Part 3:https://youtu.be/Twxe59IjHDk
Linear Regression: https://youtu.be/jmKfDvk4k6g
More on Linear Regression: https://youtu.be/UX_b6ZuZLbI
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/linear_regression/Multivariate%20Regression.ipynb
Tip Jar: https://paypal.me/kpmooney
32
views
Repurposing our Excel Newton’s Method Spreadsheet to Solve for Stock Price Given Vol
Recently, we did a video where we repurposed our Newton's method code where we solved for the implied volatility and used it to calculate a stock price assuming we already knew the volatility. Someone requested that I do the same calculation with a spreadsheet. So this is a quick video demonstrating how to do the same calculation with a spreadsheet and also at the end I will briefly show how to use goal seek to solve the same problem.
Original Newton’s Method Video: https://youtu.be/Jpy3iCsijIU
Original Newton’s Method Spreadsheet Video: https://youtu.be/ljlqGWz1xDY
Original Stock Calculation Video: https://youtu.be/NF-XMP8RjJo
Github:https://github.com/kpmooney/numerical_methods_youtube/tree/master/root_finding/implied_volatility
Spreadsheet: https://github.com/kpmooney/numerical_methods_youtube/blob/master/root_finding/implied_volatility/find_stock.xlsx
Tip Jar: https://paypal.me/kpmooney
16
views
Solving Banded Linear Systems in Python (Part 4)
We’ve talked at length about sparse matrices in the previous videos. It turns out that a lot of practical problems produce systems that have a fairly specific shape- a banded matrix. I had assumed Scipy’s sparse solver would reconginze the matrix is banded and use an appropriate algorithm. Evidently, this is not the case. There is, however, a banded solver that can be called specifically. In this video, I briefly go over how to use it and show the performance enhancement over the generic spsolve command.
Part 1: https://youtu.be/v_S7cOL5ZWU
Part 2: https://youtu.be/qo-WzsVnXGE
Part 3: https://youtu.be/qSBqgKVD6EA
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/prob_50/More%20on%20Linear%20Systems.ipynb
Tip Jar: https://paypal.me/kpmooney
32
views
Numpy and Scipy: Using Sparse Matrices in our Monte Carlo Simulation (part 3)
We review our Monte Carlo code for simulating a large number of stick runs. This is a detailed breakdown on how the matrices involved are built.
Part 1: https://youtu.be/v_S7cOL5ZWU
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/prob_50/More%20on%20Linear%20Systems.ipynb
Tip Jar: https://paypal.me/kpmooney
8
views
Sparse Matrices to Speed up Calculations (Part 2): Partial Differential Equations - 1-D Diffusion
We continue to dive in using sparse matrices in Numpy and Scipy to speed up calculations. In this video, we will solve a thermal diffusion problem in one dimension, turning the partial differential equation into a system of ordinary differential equations for which we have readily available solvers. We will compare the performance differences between generating our equation system with a for loop and generating it via sparse matrix multiplication.
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/pde/1d_diffusion/1-d%20Diffusion.ipynb
Tip Jarhttps://paypal.me/kpmooney
38
views
Numpy and Scipy: Using Sparse Matrices to Speed up Calculations (part 1)
In response to a comment on the videos dealing with Monte Carlo models of stocks market movement, and how to calculate the probability of making 50% of max profit on an options trade, I want to revisit some of the concepts presented in those videos. In particular the concept of linear systems which can be represented by matrix equations where the coefficient matrix is sparse. I will go through the calculations used in these videos and show, step-by-step, how the matrices involved are generated. This will be part one of three where we show how sparse matrices and linear algebra are used to speed up calculations. Part two will deal with solving a partial differential equation. Part three will return to to the matrices used in the Monte Carlo calculation.
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/prob_50/More%20on%20Linear%20Systems.ipynb
Probability of making 50%: https://youtu.be/yGlkRpqMDVk
Probability of a Touch: https://youtu.be/PRLnusDWSW0
Tip Jar: https://paypal.me/kpmooney
22
views
Repurposing our IV code to solve for Stock Price.
I received a question in the comments on whether one could use the Black-Scholes model to solve for the price of a stock. The answer is yes given one knows the implied volatility and price of the corresponding option (we will use calls in this video). The process and code is essentially the same as we used to calculate the volatility. This is a quick video detailing the process. I recommend watching the original Newton’s Method video for most of the details.
Original Newton’s Method Video: https://youtu.be/Jpy3iCsijIU
Github: https://github.com/kpmooney/numerical_methods_youtube/blob/master/root_finding/implied_volatility/vectorized/Stock%20Price%20Root%20Finding.ipynb
Tip Jar: https://paypal.me/kpmooney
4
views
Revisiting Calculation of Option Greeks (Theta & Vega): Units Used in the Black-Scholes Model
This is a somewhat impromptu video. I had received several questions on the calculating option greeks video regarding why the computation of theta is a bit different from the other values. The answer boils down to the units the programmers of various trading platforms choose to use to display the information. In this video, I will go over the calculation of theta and vega and explain the units used in the Black-Sholes formula and those typically used on trading platforms to display those particular greeks.
Original option greeks video: https://youtu.be/pa2zNZ3FHH8
GithubL Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/option_greeks
Donate: paypal.me/kpmooney
33
views