Created
April 13, 2023 20:19
-
-
Save timrprobocom/dde55c803562653d16cebf375e44c8a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
from datetime import datetime | |
# Define the component prices for each day | |
prices = { | |
datetime(2020, 1, 31): [197.2525, 253.2126, 653.266, 653.2678], | |
datetime(2020, 2, 3): [197.063, 253.2231, 652.3695, 652.3759], | |
datetime(2020, 2, 4): [196.6896, 252.9168, 649.9793, 649.9858], | |
datetime(2020, 2, 5): [197.3429, 252.8294, 653.5655, 653.5588], | |
datetime(2020, 2, 6): [197.4554, 252.7901, 652.3171, 652.3172], | |
datetime(2020, 2, 7): [196.7969, 252.944, 653.5571, 653.555], | |
datetime(2020, 2, 10): [196.9404, 253.3696, 656.0398, 656.0355], | |
datetime(2020, 2, 11): [196.9457, 253.3767, 653.6765, 653.6793], | |
datetime(2020, 2, 12): [196.8736, 253.1046, 653.1065, 653.1106] | |
} | |
# Calculate the strategy value for each day | |
I = [100] | |
N_tm1 = None | |
for date, price_list in prices.items(): | |
# Calculate the strategy value for this day | |
n = (date - max(prices.keys())).days | |
N_t = np.array(price_list) | |
if N_tm1 is not None: | |
ratio = N_t / N_tm1 - 1 | |
sumratio = 1 + ratio.sum() * (1 - n / (365*200)) | |
I.append( I[-1] * sumratio ) | |
N_tm1 = N_t | |
# Print the results | |
for date, value in zip(prices.keys(), I): | |
print(f"{date.strftime('%d-%b-%Y')}: {value:.4f}") | |
# Output: | |
# 31-Jan-2020: 100.0000 | |
# 03-Feb-2020: 99.6343 | |
# 04-Feb-2020: 98.5948 | |
# 05-Feb-2020: 99.9743 | |
# 06-Feb-2020: 99.6348 | |
# 07-Feb-2020: 99.7417 | |
# 10-Feb-2020: 100.7397 | |
# 11-Feb-2020: 100.0205 | |
# 12-Feb-2020: 99.7022 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment