Skip to content

Instantly share code, notes, and snippets.

@yhilpisch
Last active February 20, 2024 13:45
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save yhilpisch/a4cf4507a82e79390702fe49ea5714ce to your computer and use it in GitHub Desktop.
Save yhilpisch/a4cf4507a82e79390702fe49ea5714ce 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
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
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
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