1

I want to simulate an array of stock prices by using simulated returns. For example, I set the initial stock price to be $70 and I created a panda series with 10 periods of returns:

returns = pd.Series([1.01,1.02,1.03,1.01,0.99,0.98,1.07,0.99,1.03,1.03])

How can I get a series of stock prices with 10 periods? (the 1st price data should be initial stock price(70) * 1.01; the 2nd should be 70 * 1.01 * 1.02; the 3rd should be ... till the 20th.)

initial stock price = 70
returns = pd.Series([1.01,1.02,1.03,1.01,0.99,0.98,1.07,0.99,1.03,1.03])
Zephyr
  • 9,885
  • 4
  • 28
  • 63
JackeyOL
  • 313
  • 2
  • 16

2 Answers2

5

IIUC, use cumprod:

initial_stock_price = 70
returns = pd.Series([1.01,1.02,1.03,1.01,0.99,0.98,1.07,0.99,1.03,1.03])

returns.cumprod() * initial_stock_price

Output:

0    70.700000
1    72.114000
2    74.277420
3    75.020194
4    74.269992
5    72.784592
6    77.879514
7    77.100719
8    79.413740
9    81.796153
dtype: float64
Scott Boston
  • 147,308
  • 15
  • 139
  • 187
4

You can use reduce to multiply all values in a list then multiple by the price:

from functools import reduce
import pandas as pd
inital_price = 70
returns = pd.Series([1.01,1.02,1.03,1.01,0.99,0.98,1.07,0.99,1.03,1.03])
[inital_price * reduce(lambda x, y: x*y, returns[0:i+1]) for i in range(len(returns))]

Output:

[70.7,
 72.114,
 74.27742,
 75.0201942,
 74.269992258,
 72.78459241284,
 77.8795138817388,
 77.10071874292142,
 79.41374030520907,
 81.79615251436535]
TomNash
  • 3,147
  • 2
  • 21
  • 57