Skip to content

Instantly share code, notes, and snippets.

@StuartGordonReid
Created June 15, 2015 14:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save StuartGordonReid/4bf2ec416a0fa562226a to your computer and use it in GitHub Desktop.
Save StuartGordonReid/4bf2ec416a0fa562226a to your computer and use it in GitHub Desktop.
def convert_to_returns(log_returns):
"""
This method exponentiates a sequence of log returns to get daily returns.
:param log_returns: the log returns to exponentiated
:return: the exponentiated returns
"""
return numpy.exp(log_returns)
def convert_to_prices(param, log_returns):
"""
This method converts a sequence of log returns into normal returns (exponentiation) and then computes a price
sequence given a starting price, param.all_s0.
:param param: the model parameters object
:param log_returns: the log returns to exponentiated
:return:
"""
returns = convert_to_returns(log_returns)
# A sequence of prices starting with param.all_s0
price_sequence = [param.all_s0]
for i in range(1, len(returns)):
# Add the price at t-1 * return at t
price_sequence.append(price_sequence[i - 1] * returns[i - 1])
return numpy.array(price_sequence)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment