This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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