-
Notifications
You must be signed in to change notification settings - Fork 103
/
OU.py
30 lines (24 loc) · 819 Bytes
/
OU.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
OU.py
"""
__author__ = "[email protected]"
__credits__ = ["https://github.com/yanpanlau", "https://gist.github.com/jimfleming/9a62b2f7ed047ff78e95b5398e955b9e"]
import numpy as np
from scipy.stats import norm
# Ornstein-Uhlenbeck Process
class OU(object):
def __init__(self, processes, mu=0, theta=0.15, sigma=0.3):
self.dt = 0.1
self.mu = mu
self.theta = theta
self.sigma = sigma
self.processes = processes
self.state = np.ones(self.processes) * self.mu
def reset(self):
self.state = np.ones(self.processes) * self.mu
def evolve(self):
X = self.state
dw = norm.rvs(scale=self.dt, size=self.processes)
dx = self.theta * (self.mu - X) * self.dt + self.sigma * dw
self.state = X + dx
return self.state