Home Implementing a for loop of share prices
Reply: 0

Implementing a for loop of share prices

user1374
1#
user1374 Published in April 26, 2018, 5:18 pm

I need to work out a value S(n) based on the equation

s(n) = (1 + r(1))(1+r(2))...(1+r(n))

The value of

S(after N days) = (1+r(after 1 day))*(1+r(after 2 days))...(1+r(after N days))

with r coming from:

r = return_daily + sig_daily

but calculated D times (see code below, D is calculated once for each day and is a random value)

I'm just not too sure how to implement the equation including a changing variable(r changes daily).

Thanks for any help

Relevant Code:

#import all modules required
import numpy as np # using different notation for easier writting
import scipy as sp 
import matplotlib.pyplot as plt
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#collect variables provided by the user

period = 63 # can be edited to an input() command for variable periods.
Return_annual = np.arange(0.00,0.15,0.05) # creates an array ??? not sure if helpful
sig_annual = np.arange(0.01,0.31,0.01) #use .31 as python doesnt include the upper range value.


#functions for variables of daily return and risk.

Return_daily = (1/252)*R_annual
sig_daily = (1/(np.sqrt(252)))*sig_annual

D=np.random.normal(size=period)

r_i=Return_daily + sig_daily # must be calculated D times
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30555 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO