Skip to content

Instantly share code, notes, and snippets.

@aa403
Forked from yhilpisch/00_diy_quant_investing.md
Created November 10, 2024 20:26
Show Gist options
  • Save aa403/cdaae31ed9f36839a51e14c522cd5c72 to your computer and use it in GitHub Desktop.
Save aa403/cdaae31ed9f36839a51e14c522cd5c72 to your computer and use it in GitHub Desktop.

DIY Quant Investing

DIY Quantitative Stock Market Investing

Dr. Yves J. Hilpisch | The Python Quants & The AI Machine

Saarbruecken, 6. SaarPython Meetup, 30. August 2022

(short link to this Gist: http://bit.ly/spm_diy)

Slides

You find the slides under http://certificate.tpq.io/spm_diy.pdf

Resources

This Gist contains selected resources used during the talk.

Dislaimer

All the content, Python code, Jupyter Notebooks, and other materials (the “Material”) come without warranties or representations, to the extent permitted by applicable law.

None of the Material represents any kind of recommendation or investment advice.

The Material is only meant as a technical illustration.

Leveraged and unleveraged trading of financial instruments, and of contracts for difference (CFDs) in particular, involves a number of risks (for example, losses in excess of deposits). Make sure to understand and manage these risks.

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#
# Mean-Variance Portfolio Class
# Markowitz (1952)
#
# Python for Asset Management
# (c) Dr. Yves J. Hilpisch
# The Python Quants GmbH
#
import math
import numpy as np
import pandas as pd
def portfolio_return(weights, rets):
return np.dot(weights.T, rets.mean()) * 252
def portfolio_variance(weights, rets):
return np.dot(weights.T, np.dot(rets.cov(), weights)) * 252
def portfolio_volatility(weights, rets):
return math.sqrt(portfolio_variance(weights, rets))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment