Making cross-sectional statistics and scalar outputs #319
-
Thank you for making In
I have made some progress with
I am stuck with two problems. First, I must be using the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Here is the corrected version of the code with comments as to the changes. import numpy as np
import csp
from datetime import timedelta, datetime
from csp.random import brownian_motion
number_of_products = 10
@csp.graph
def graph():
trigger = csp.timer(timedelta(minutes=1), 1)
prices = [csp.random.brownian_motion_1d(trigger=trigger, drift=csp.const(0.0), variance=csp.const(1.0/60**.5), seed=p) for p in range(number_of_products)]
prices = csp.stats.list_to_numpy(prices)
# Use csp.apply to "apply" the np.max/np.min functions to each individual value in "prices"
# Note that np.min and np.max cannot be called directly since 'prices' is an Edge here
# We want to apply the min/max functions to the values (at runtime), not the graph-time Edge
max_minus_min = csp.apply(prices, np.max, float) - csp.apply(prices, np.min, float)
# We can use stats.max to compute the current max value of the ts
max_of_max_minus_min = csp.stats.max(max_minus_min)
# We can use tick_count=1 to avoid storing a full history
csp.add_graph_output("final_value_of_max_minus_min", max_minus_min, tick_count=1)
csp.add_graph_output("max_of_max_minus_min", max_of_max_minus_min, tick_count=1)
results = csp.run(graph, starttime=datetime(2020, 1, 1), endtime=datetime(2020, 1, 2))
print(results) |
Beta Was this translation helpful? Give feedback.
-
Thank you so much @AdamGlustein! I can’t wait to build something more general on this logic. |
Beta Was this translation helpful? Give feedback.
Here is the corrected version of the code with comments as to the changes.