montecarlo

Utilizing Monte Carlo to Predict Revenue in Python

旧街凉风 提交于 2019-12-24 16:19:14
问题 I am trying to implement a Monte Carlo simulation into my python code that will help me determine the odds that we achieve various thresholds related to revenue targets. For example, what is the likelihood that we hit $6,000, $7,000, or $8,000 for each Fiscal Year. I'm able to calculate the expected value, but haven't had luck with coding a simulation. I've tried creating a function that runs 1000 simulations, but have not been able to get it (thanks to my very novice coding abilities).

Monte Carlo simulation of correlation between two Brownian motion (continuous random walk)

若如初见. 提交于 2019-12-24 08:15:17
问题 y <- cumsum(rnorm(100,0,1)) # random normal, with small (1.0) drift. y.ts <- ts(y) x <- cumsum(rnorm(100,0,1)) x x.ts <- ts(x) ts.plot(y.ts,ty= "l", x.ts) # plot the two random walks Regression.Q1 = lm(y~x) ; summary(lm2) summary(Regression.Q1) t.test1 <- (summary(Regression.Q1)$coef[2,3]) # T-test computation y[t] = y[t-1] + epsilon[t] epsilon[t] ~ N(0,1) set.seed(1) t=1000 epsilon=sample(c(-1,1), t, replace = 1) # Generate k random walks across time {0, 1, ... , T} N=T=1e3 y=t(apply(matrix

Manual simulation of Markov Chain in R (2)

六眼飞鱼酱① 提交于 2019-12-24 07:50:37
问题 Consider the Markov chain with state space S = {1, 2} , transition matrix and initial distribution α = (1/2, 1/2) . Simulate 5 steps of the Markov chain (that is, simulate X 0 , X 1 , . . . , X 5 ). Repeat the simulation 100 times. My solution: states <- c(1, 2) alpha <- c(1, 1)/2 mat <- matrix(c(1/2, 1/2, 0, 1), nrow = 2, ncol = 2) nextX <- function(X, pMat) { probVec <- vector() if(X == states[1]) { probVec <- pMat[1,] } if(X==states[2]) { probVec <- pMat[2,] } return(sample(states, 1,

How to parallelize monte carlo estimation of pi using pthreads?

时光毁灭记忆、已成空白 提交于 2019-12-23 19:26:55
问题 #include <math.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> int main(int argc, char **argv) { unsigned long long in = 1; unsigned long long total = 2; double tol , change, new, secs , old = 0.0; struct timeval start , end; int threads ; /* ignored */ if ( argc < 2) { exit (-1); } threads = atoi ( argv[1]); tol = atof ( argv[2]); if (( threads < 1) || ( tol < 0.0)) { exit (-1); } tol = tol *tol; srand48(clock()); gettimeofday (&start , NULL); do { double x, y

How to create a more efficient simulation loop for Monte Carlo in R

纵饮孤独 提交于 2019-12-21 02:56:10
问题 The purpose of this exercise is to create a population distribution of nutrient intake values. There were repeated measures in the earlier data, these have been removed so each row is a unique person in the data frame. I have this code, which works quite well when tested with a small number of my data frame rows. For all 7135 rows, it is very slow. I tried to time it, but I crashed it out when the elapsed running time on my machine was 15 hours. The system.time results were Timing stopped at:

Where can I learn more about “ant colony” optimizations?

安稳与你 提交于 2019-12-20 10:44:32
问题 I've been reading things here and there for a while now about using an "ant colony" model as a heuristic approach to optimizing various types of algorithms. However, I have yet to find an article or book that discusses ant colony optimizations in an introductory manner, or even in a lot of detail. Can anyone point me at some resources where I can learn more about this idea? 回答1: On the off chance that you know German (yes, sorry …), a friend and I have written an introduction with code about

Monte Carlo Simulation in VBA consistently underestimates the true value

瘦欲@ 提交于 2019-12-20 04:07:08
问题 I have a weird problem with a Monte Carlo Simulation that I built. It is a nested loop to calculate the expected value of investments (actually Poker Tournaments). To demonstrate, assume that we are talking about heads-up Poker Tournaments, which is equal to a coin flip. Assume that we have a 25% ROI per coin-flip and the buy-in is one, so the EV after 100 (500, 1000) coin-flips is 25 (125, 250) units. The simulation, however, returns 24,6, 123,6 and 246, respectively. The critical line in

Monte Carlo Simulation in VBA consistently underestimates the true value

末鹿安然 提交于 2019-12-20 04:07:06
问题 I have a weird problem with a Monte Carlo Simulation that I built. It is a nested loop to calculate the expected value of investments (actually Poker Tournaments). To demonstrate, assume that we are talking about heads-up Poker Tournaments, which is equal to a coin flip. Assume that we have a 25% ROI per coin-flip and the buy-in is one, so the EV after 100 (500, 1000) coin-flips is 25 (125, 250) units. The simulation, however, returns 24,6, 123,6 and 246, respectively. The critical line in

Minimize the number of cuRAND states stored during a MC simulation

℡╲_俬逩灬. 提交于 2019-12-19 11:54:28
问题 I am currently writing a Monte-Carlo simulation in CUDA. As such, I need to generate lots of random numbers on the fly using the cuRAND library. Each thread processes one element in a huge float array (omitted in the example) and generates 1 or 2 random numbers per kernel invocation. The usual approach (see example below) seems to be to allocate one state per thread. The states are reused in subsequent kernel invocations. However, this does not scale well when the number of threads increases

Can Random Number Generator of Fortran 90 be trusted for Monte Carlo Integration?

寵の児 提交于 2019-12-18 15:48:45
问题 I have written a short monte carlo integration algorithm to calculate an integral in Fortran 90. I once compared the result obtained by solving the integral with respect to some parameter using the intrinsic random number generator with the random number generator method ran1 presented in Numerical Recipes for Fortran90 Volume 2. Running the same algorithm twice, once calling the intrinsic random_seed(), then always call random_number() and once calling the ran1() method provided in the