Can you please help me to confirm if my calculations are correct or need improvement, or (too simplistic...) :
- portfolio return,
- portfolio standard deviation,
- portfolio sharpe ratio
- portfolio Value At Risk
This is coded in python and I am supposing the year is 252 business days.

Thank you very much.

w : weights of assets in the portfolio. I.e. for a 2 assets portfolio, w = [0.5, 0.5]
µ : average of the daily asset return. I.e. for 2 assets portfolio, µ = [0.012, 0.009] on period T
covariance_matrix : simple covariance matrix from assets return .cov()
z : 0.95 for the Value At Risk 95%

function to calculate the ptf return

import numpy as np
import math
from scipy.stats import norm

def calcPftReturn(w, µ, yearly = False):
    if yearly:
        ptfReturn = np.matmul(w, µ * 252) 
    else :
        ptfReturn = np.matmul(w, µ)        
    return ptfReturn

function to calculate the ptf std

def calcPftStd(w, covariance_matrix, yearly = False):
    if yearly:
        ptfStd = math.sqrt(
            np.matmul(np.matmul(w, covariance_matrix), w)
            ) * math.sqrt(252)
        ptfStd = math.sqrt(
            np.matmul(np.matmul(w, cov), w)
    return ptfStd

function to calculate ptf sharpe ratio

def calcPtfSharpeRatio(ptfReturn, ptfStd, rf=0.0):
    return (ptfReturn - rf) / ptfStd

function to calculate ptf parametric VaR

def calcVaR(ptfStd, z):
    return (ptfStd* norm.ppf(z))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.