Differential Equations and Maximizing Functions in Python: Solving Simple Physics Problems (Part 2)
In this video, we look at optimizing a quantity that is part of a system of differential equations. We continue with simple physics problems, in this case projectile motion, and ask how far a baseball will travel when hit at a certain angle. Then we ask which angle will maximize the total horizontal distance traveled. We do this both with and without air resistance.
In the case of no air resistance, we check our numeric calculations by using the Sympy package to find the answer algebraically.
This video is part two of two.
Part 1: https://youtu.be/DSJj9rfHKPk
Githyb: https://github.com/kpmooney/numerical_methods_youtube/tree/master/physics/projectile_motion
Free Fall Problem: https://youtu.be/XPT3_L13RFM
Tip Jar: http://paypal.me/kpmooney
23
views
Differential Equations and Maximizing Functions in Python: Solving Simple Physics Problems (Part 1)
In this video, we look at optimizing a quantity that is part of a system of differential equations. We continue with simple physics problems, in this case projectile motion, and ask how far a baseball will travel when hit at a certain angle. Then we ask which angle will maximize the total horizontal distance traveled. We do this both with and without air resistance.
In the case of no air resistance, we check our numeric calculations by using the Sympy package to find the answer algebraically.
This video is part one of two.
Part 2: https://youtu.be/-hJc2zktxCs
Githyb: https://github.com/kpmooney/numerical_methods_youtube/tree/master/physics/projectile_motion
Free Fall Problem: https://youtu.be/XPT3_L13RFM
Tip Jar: http://paypal.me/kpmooney
41
views
Basic Vector Manipulation in Numpy. Dot Products and Cross Products.
We return to simple physics problems using Python and Numpy. Here, we look at simple vector manipulation. This is quite simple but I included it in the physics series for the sake of completeness.
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/physics/ch3_vectors
Tip Jar: http://paypal.me/kpmooney
34
views
Monte Carlo Techniques: Probability of Making 50% on Short Options Trades Using Python
We use the Monte Carlo techniques developed in a previous video that we used to model a stock’s price action and extend it calculate the probability of making 50% of the maximum potential profit on a short option trade, a short call to be specific. To help get the gist of this technique, we’ll first start off calculating the probability of making any profit assuming the contract is held until expiration. In a follow on video, we will extend this to more complicated spreads such as short strangles, iron condors, or verticals.
Probability of a Touch where we first showed a random walk model of a stock: https://youtu.be/PRLnusDWSW0
Linear Systems and Sparse Matrices: https://youtu.be/Xn35Ac_fGrA
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/prob_50
Donate: http://paypal.me/kpmooney
52
views
Linear Systems and Sparse Matrices with Numpy and Scipy
A lot of problems in numerical methods boil down to solving systems of linear equations. In many cases, the matrices involved are very large. Fortunately, often one finds most of the entries of these are zero. These are referred to as sparse matrices. There are many advantages to being able to use sparse systems. Memory storage is greatly reduced as well as the ability to use algorithms custom built to perform fasted than with dense matrices. I’ll show Numpy’s basic ability to solve systems of linear equations, the I’ll revisit the stock monte carlo code from a previous video and treat it as a system of linear equations and use sparse matrix capabilities that are built in to Scipy to generate a simulated run of stock prices.
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/sparse_matriices
Tip Jar: http://paypal.me/kpmooney
63
views
Using Numpy's Polynomial Functionality
I look at using Numpy’s built-in polynomial features. I solve a simple physics problem using these features directly. They are useful in cases where one has to repeatedly deal with polynomial systems (duh!). We will come back to this when we look at using polynomial interpolation techniques in solving various differential and partial differential equations.
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/physics/polynomial
Tip Jar: http://paypal.me/kpmooney
13
views
More Kinematics problems: Differential Equations and Event Detection using Python (Numpy and Scipy)
We continue with kinematics problems look at solving first and second order differential equations and using the solver’s built in event detection capabilities. This event detection is useful in real-world problems.
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/physics/fowles_1_1
Related Video: https://youtu.be/XPT3_L13RFM
Tip Jar: http://paypal.me/kpmooney
32
views
Solving Simple Physics Problems with Python/Scipy - Motion in one dimension
This will be the first in a series of videos whereby we work through freshman/sophomore physics problems using Python and the Numpy/Scipy packages. The purpose of these videos is get get comfortable using numerical methods and computation resources to solve problems. Because these problems can be solved by hand, it provides a nice way to double check our work. In some cases I will embellish the problems to make them more suitable for use with a computer.
The first video here is on motion if one dimension.We use trapz to perform numerical integration and use a spline to interpolate between data points.
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/physics/2_11
Tip Jar: http://paypal.me/kpmooney
33
views
Scipy's built-in root finding function: Solve nonlinear equations with Python
We look at using Python’s (via Scipy) built-in function to solve for the roots of an equation. We will return to the implied volatility problem as well as another equation used in previous videos to demonstrate Newton’s method for finding roots.
Previous Videos
Implied Volatility using Newton’s Method: https://youtu.be/Jpy3iCsijIU
Troubleshooting the Implied Volatility Script: https://youtu.be/2UJ9kFqQF-s
Extension to Put Options: https://youtu.be/4z_nOgl8oHU
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/root_finding/implied_volatility
Tip Jar: http://paypal.me/kpmooney
29
views
More on Regressions and Parameter Estimation in Python
We continue looking at curve fitting a extracting parameters from data with a more involved problem. We are looking at the lambda-transition in helium and attempting to pull parameters out of an expression for the specific heat. Aside from being very nonlinear, this is complicated because two of the parameters are different on either side of the transition while two other parameters are shared between both the warm and cold side.
While there are ways we could make the problem easier, we use a very direct approach for the sake of clarity.
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/curve_fitting/lambda_curve
Linear Regression in Python: https://youtu.be/jmKfDvk4k6g
More on Linear Regression: https://youtu.be/UX_b6ZuZLbI
Tip Jar: http://paypal.me/kpmooney
13
views
Calculating the Implied Volatility of a Put Option Using Python
In answer to a question, I wanted to show how to calculate the implied volatility of a put option. The code I had used previously was only for a call. I want to emphasize that the method used here is much more general than just a tool to calculate volatility and so before moving on to puts, I show how to modify the code for a function I made up on the spot.
Original Video on root-finding and implied volatility: https://youtu.be/Jpy3iCsijIU
Video on issues with ITM options whose price is less than its intrinsic value: https://youtu.be/2UJ9kFqQF-s
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/root_finding/implied_volatility
Tip Jar: http://paypal.me/kpmooney
9
views
Debugging the Python Implied Volatility Code
I wanted to go back and address some comments about the implied volatility root-finding code occasionally crashing for in-the-money options. Figuring out the cause of this is easy so while we’ll find the reason for the error, I wanted to do more of a conceptual video on how one might go about debugging code for numeric calculations. This is one of those “easier said than done” since this is often as much an art as a science as I say in the video. However, just by thinking about the numbers we are entering and doing a couple of simple plots, we can zero in on the source of the problem rapidly in this case.
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/root_finding/implied_volatility
Tip Jar: http://paypal.me/kpmooney
24
views
More on Linear Regression
I return to the linear regression problem from last video. There isn’t any coding in this one, but I want to make sure we are thinking of curve fitting as an optimization problem. First we will visualize the least squares error function. Then we will derive the equations for the slope and intercept using basic calculus. Lastly, we will take our derived equations and plug them, along with the raw data from the last video, into Excel and compare the results to what we got using Python’s built in linear regression routine.
I will put a PDF of the derivation up on the Github repo. That should be available by the end of the week this is uploaded. I will also include the MATLAB code used to plot the error function as well as the Excel sheet.
Previous video on linear regression: https://youtu.be/jmKfDvk4k6g
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/beta
Donate: http://paypal.me/kpmooney
20
views
Probability of a Touch in Finance using Python Monte Carlo Methods
We use Monte Carlo methods with Python to calculate the probability of a stock reaching a given price in a specified amount of time. The code simulates a large number of potential stock prices using the implied volatility to get the width of the normal distribution used to sample random numbers. The code then counts the number of runs where the target price is reached and estimates the probability by taking the ratio of that number with the total number of simulated runs.
Github: https://github.com/kpmooney/numerical_methods_youtube
Tip Jar: http://paypal.me/kpmooney
35
views
Linear Regression in Python: Finding a Stock's Beta Coefficient
We look at doing a simple linear regression in Python to calculate a stock’s beta coefficient. This will be the first video in a series covering the basics of curve fitting.
Source code: https://github.com/kpmooney/numerical_methods_youtube/tree/master/beta
SciPy documentation on lingress: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html
Donate: http://paypal.me/kpmooney
31
views
Solving Initial Value Problems with Python and SciPy
I introduce SScipy’s ODE solve solve_Ivp with a simple physics problem. I also make use of the solver’s event detection algorithm to determine the fall time of a parachutist.
Solve_ivp documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/free_fall
Donate: http://paypal.me/kpmooney
41
views
Intro to Monte Carlo Techniques: Using Python and Random Numbers to Estimate the Value of Pi
Let’s look at using random numbers to do some simple calculations. This in a very brief introduction to Monte Carlo techniques using Python and Numpy. We will calculate an approximate value of pi. This code is extremely simple, but will lay the groundwork for more complicated calculations. For the next Monte Carlo videos, we will look at calculating the probability of a stock reaching a given price in a set time interval, then look at the probability of making 50% of max profit on a short options position
Github: https://github.com/kpmooney/numerical_methods_youtube/tree/master/monte_carlo_pi
Donate: http://paypal.me/kpmooney
79
views
Calculating the Implied Volatility of an Option with Excel (or Google Sheets)
I look at solving for the implied volatility of an option given its price using a spreadsheet like MS Excel or Google Sheets. I don’t both reviewing the Black-Scholes model or root finding algorithm in this video. If you need a refresher, it is in the first seven minutes or so of this video: https://youtu.be/Jpy3iCsijIU
Edit (04/19/2020: A commenter noticed that I misspoke a couple of times in the video. I spoke the correct stock price but entered the wrong number. I also initially entered the wrong cell value for sigma when constructing the d1 field. I fixed these in the spreadsheet a long time ago, but never many an update here.
Github reop: https://github.com/kpmooney/numerical_methods_youtube
Original Blog Post: https://kevinpmooney.blogspot.com/2017/07/calculating-implied-volatility-from.html
Donate: http://paypal.me/kpmooney
79
views
Calculating Implied Volatility from an Option Price Using Python
I look at using Newton’s method to solve for the implied volatility of an option. This is done using the Black-Scholes model and a simple Python script.
My mouth and brain were apparently totally out of sync when discussing the numbers in the slide showing the spreadsheet results for the roots of a parabola. This is one of those situations where you should pay attention to what I am thinking rather than what I am saying. In any case, the numbers in the spreadsheet are correct.
Github: https://github.com/kpmooney/numerical_methods_youtube
Original Blog Post: https://kevinpmooney.blogspot.com/2017/07/calculating-implied-volatility-from.html
If you’re interested in trading and looking for a good broker in the US, checkout the possilbity of opening an account with tastyworks: https://start.tastyworks.com/#/login?referralCode=ERQ634TPPJ
Donate: http://paypal.me/kpmooney
92
views