stochastic-process

Generate a Dataframe that follow a mathematical function for each column / row

南笙酒味 提交于 2021-02-19 08:24:22
问题 Is there a way to create/generate a Pandas DataFrame from scratch, such that each record follows a specific mathematical function? Background: In Financial Mathematics, very basic financial-derivatives (e.g. calls and puts) have closed-form pricing formulas (e.g. Black Scholes). These pricing formulas can be called stochastic functions (because they involve a random term) I'm trying to create a Monte Carlo simulation of a stock price (and subseuqently an option payoff and price based on the

Python: Integral and funcion nested in another integral using scipy quad

梦想的初衷 提交于 2021-01-29 09:40:28
问题 I have managed to write a few lines of code using scipy.integrate.quad for my stochastic process class I have the Markov transition function for standard Brownian motion import numpy as np def p(x,t): return (1/np.sqrt(2*np.pi*t))*np.exp(-x**2/(2*t)) But I want to compute the following that I am going to write in code that would not work. I write it like this so we can understand the problem without the use of latex. from scipy.integrate import quad integral = quad(quad(p(y-x),1,np.inf)*p(x,1

Computing autocorrelation of vectors with numpy

末鹿安然 提交于 2020-01-16 14:32:42
问题 I'm struggling to come up with a non-obfuscating, efficient way of using numpy to compute a self correlation function in a set of 3D vectors. I have a set of vectors in a 3d space, saved in an array a = array([[ 0.24463039, 0.58350592, 0.77438803], [ 0.30475903, 0.73007075, 0.61165238], [ 0.17605543, 0.70955876, 0.68229821], [ 0.32425896, 0.57572195, 0.7506 ], [ 0.24341381, 0.50183697, 0.83000565], [ 0.38364726, 0.62338687, 0.68132488]]) their self correlation function is defined as in case

scikit multilabel classification: ValueError: bad input shape

丶灬走出姿态 提交于 2019-12-23 01:21:10
问题 I beieve SGDClassifier() with loss='log' supports Multilabel classification and I do not have to use OneVsRestClassifier. Check this Now, my dataset is quite big and I am using HashingVectorizer and passing result as input to SGDClassifier . My target has 42048 features. When I run this, as follows: clf.partial_fit(X_train_batch, y) I get: ValueError: bad input shape (300000, 42048) . I have also used classes as the parameter as follows, but still same problem. clf.partial_fit(X_train_batch,

How do I generate a Poisson Process?

≡放荡痞女 提交于 2019-12-21 08:25:12
问题 Original Question: I want to generate a Poisson process. If the number of arrivals by time t is N(t) and I have a Poisson distribution with parameter λ how do I generate N(t) ? How would I do this in C++? Clarification: I originally wanted to generate the process using a Poisson distribution. But, I was confused about what parameter from the process I needed; I thought I could use N(t) but that tells me how many arrivals have occurred on the interval (0,t] which wasn't what I wanted. So, then

Generate and plot the empirical joint pdf and CDF [closed]

懵懂的女人 提交于 2019-12-17 06:49:09
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Given a pair of two variables (X,Y), how can you generate and plot the empirical joint PDF and CDF in vanilla MATLAB (no toolboxes)? 回答1: Original answer (Matlab R2015a or lower) The data are: The random variables X, Y: defined as vectors of samples X , Y . The bin edges at the x, y axes: defined by vectors x

What is the significance of the stationary distribution of a markov chain given it's initial state?

て烟熏妆下的殇ゞ 提交于 2019-12-13 07:08:57
问题 Let X_n be a MC, P not regular Say we have a stationary dist (pi_0, ..., pi_n) and P(X_0 = i) = 0.2, does this say anything? To be more clear: I ask because Karlin says when a stationary dist is not a limiting dist, P(X_n = i) is dependent on the initial distribution. What does this exactly mean? 回答1: Your title's question requires a lengthy answer; I'd have to just provide some references for you to read more on Markov chains and ergodic theory. However, your specific question: "...when a

How can I obtain stationary distribution of a Markov Chain given a transition probability matrix

故事扮演 提交于 2019-12-12 20:00:31
问题 I'm trying to write mpow(P, 18) in vector form & matrix form. Can anyone help me with that? Also, I'm trying to find the stationary distribution of each state. Pi_0 = ? Pi_1 = ? Pi_2 = ? ... Pi_5 = ? Here is the code I've written: P <- matrix(c(0, 0, 0, 0.5, 0, 0.5, 0.1, 0.1, 0, 0.4, 0, 0.4, 0, 0.2, 0.2, 0.3, 0, 0.3, 0, 0, 0.3, 0.5, 0, 0.2, 0, 0, 0, 0.4, 0.6, 0, 0, 0, 0, 0, 0.4, 0.6), nrow = 6, ncol = 6, byrow = TRUE) mpow <- function(P, n) { if (n == 0) diag(nrow(P)) else if (n == 1) P else

Dynamic (i.e. variable size) Fenwick Tree?

给你一囗甜甜゛ 提交于 2019-12-04 23:48:10
问题 Questions: I have stumbled upon Fenwick trees (Binary index trees) that allow to calculate cumulative sums easily. However, I have only found implementations where the number of leeves (summands) is constant (but their value can change). Is there something like a generalised Fenwick tree that allows for the number of leeves (summands) to change, i.e. to have a variable size? Background I am currently writing some stochastic simulation code (in C++): There are balls in an urn and each ball i

How do I generate a Poisson Process?

こ雲淡風輕ζ 提交于 2019-12-04 01:44:49
Original Question: I want to generate a Poisson process. If the number of arrivals by time t is N(t) and I have a Poisson distribution with parameter λ how do I generate N(t) ? How would I do this in C++? Clarification: I originally wanted to generate the process using a Poisson distribution. But, I was confused about what parameter from the process I needed; I thought I could use N(t) but that tells me how many arrivals have occurred on the interval (0,t] which wasn't what I wanted. So, then I thought I could use N(t2)-N(t1) to get the number of arrivals on the interval [t1,t2] . Since N(t)