Question: Challenge 7: Portfolio Return Write a python code that returns expected portfolio return given two assets randomly allocated. Example You are given times series of
Challenge 7: Portfolio Return
Write a python code that returns expected portfolio return given two assets randomly allocated.
Example
You are given times series of two assets and randomly generated weights as allocated to this combined portfolio. Your task is to calculate and print() overall portfolio return rounded to 5 decimal places.
From theoretical standpoint we aiming to implement the following formula assuming no short sell and no additional borrowing being allowed
p=E(Iwiri)=IwiE(ri)=Iwii=wTp=E(Iwiri)=IwiE(ri)=Iwii=wT
Whereby, the weights w all add up to be equal to 1.
GIVEN CODE:
import numpy as np def portfolioReturn(df, w):
return sum(df*w)/len(df)
def main(): x=2
np.random.seed(88)
data = {
'Asset1' : 100*np.exp((-0.01-0.5*0.1**2)*1+0.1*np.sqrt(1)*np.random.standard_normal(252)),
'Asset2' : 1000*np.exp((-0.01-0.5*0.05**2)*1+0.05*np.sqrt(1)*np.random.standard_normal(252))
}
w = np.random.uniform(0,1,2)
w /= w.sum()
print(portfolioReturn(data, w))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
