FinanceIntermediate

Python for Finance

Price data, portfolio analytics and backtesting with pandas.

Taught by Dipesh Koirala · CFA, Financial Analyst

What you'll learn

  • Download, clean and align daily price data for stocks and ETFs with yfinance and pandas
  • Calculate simple, log and cumulative returns and annualise return and volatility correctly
  • Measure risk with rolling volatility, maximum drawdown, historical value at risk and beta
  • Build a portfolio from a covariance matrix and compute its expected return and volatility
  • Optimise portfolio weights for minimum variance and maximum Sharpe ratio with SciPy
  • Backtest a rules-based strategy with transaction costs and no look-ahead bias

About this course

Learn to analyse markets and portfolios with Python instead of wrestling with spreadsheets. This course is for analysts, finance students and investors who know basic Python and want to apply it to real price data. You will download stock and ETF prices with yfinance, clean them with pandas, calculate simple and log returns, and measure volatility, drawdowns, value at risk, beta and the Sharpe and Sortino ratios. You will then build portfolios from correlation and covariance matrices and use NumPy and SciPy to find minimum-variance and maximum-Sharpe weights along the efficient frontier. Finally you will backtest a moving-average strategy without look-ahead bias, include trading costs and produce a reusable performance report. You should know Python basics such as lists, functions and loops; no prior quant experience is needed. Everything here is for education and research, not investment advice.

Course content

7 lessons
  1. 1Setting Up and Loading Your First Price DataSet up a Python finance environment, download prices with yfinance and sanity-check them with pandas.Preview
  2. 2Returns: Simple, Log and CumulativeTurn prices into simple, log and cumulative returns and annualise them correctly.
  3. 3Volatility, Drawdowns and Value at RiskMeasure how risky an asset really is with rolling volatility, maximum drawdown and historical VaR.
  4. 4Correlation, Covariance and Portfolio MathsCombine assets into a portfolio and calculate its return and risk with a covariance matrix.
  5. 5Portfolio Optimisation with SciPyFind minimum-variance and maximum-Sharpe portfolios with constraints, and understand the limits of optimisation.
  6. 6Backtesting a Simple Trading StrategyBacktest a moving-average rule honestly, with trading costs and no look-ahead bias.
  7. 7Risk-Adjusted Performance and a Reusable ReportCalculate Sharpe, Sortino and beta, then package everything into a reusable performance report.