gpt-4-1106-preview· openai
Suzhen/CodeChat
Create a ClojureScript function that generates 30 days' worth of stock prices.
- User
Create a ClojureScript function that generates 30 days' worth of stock prices.
- Assistant
Certainly! To simulate 30 days' worth of stock prices in ClojureScript, we can create a function that generates random prices based on a starting price and fluctuates the price by a random percentage each day. Below is an example of such a function using ClojureScript:
(ns stock-price-generator.core) (defn generate-stock-prices "Generates 30 days' worth of stock prices, given an initial price." [initial-price] (let [days 30 max-change-percentage 0.05] ; maximum daily percentage change (up or down) (take days (iterate (fn [price] (let [change-factor (+ 1 (- (* 2 (rand)) max-change-percentage))] ; random factor between 1-max_change_percentage and 1+max_change_percentage (* price change-factor))) initial-price)))) ;; Example usage: (def initial-price 100.00) ; Let's suppose the stock starts at $100.00 (println (generate-stock-prices initial-price))