# trendpy¶

trendpy is a bayesian filtering micro library.

The library also supports bayesian regression models (Lasso and Ridge).

Models are fitted using MCMC algorithms.

## User’s Guide¶

### Requirements¶

trendpy is build on top of the following libraries:

### Issues¶

Should you encounter any issue with the library you can raise them here: https://github.com/ronsenbergVI/trendpypy/issues

### Installing trendpy¶

#### Installation from GitHub¶

trendpy releases are also available on github (https://github.com/ronsenbergVI/trendpy). You first need to clone (or fork if you want to modify it) and

$git clone https://github.com/ronsenbergVI/trendpy.git$ cd trendpy
$python setup.py build$ python setup.py install


### Introduction to filtering theory¶

Consider $$(y_t)_{t \in [0,T]}$$ the (continuous), normalized price process of a stock, verifying the decomposition:



where $$x$$ is the price trend and $$\epsilon$$ a stochastic noise. The process of trend filtering consists in recovering $$x$$ from the observations of $$y$$. Under regularity conditions, the first derivative of $$x$$ indicates up or down price trends:

$\mu_t = \dfrac{dx_t}{dt}$

The trend filtering equation becomes:

$dy_t = \mu_tdt + d\epsilon_t$

A common assumption on the dynamic of the noise is:

$d\epsilon_t = \sigma_t dW_t$

with $$\sigma>0$$ and $$W$$ a standard Brownian motion. From a theoretical point of view trend filtering is equivalent to finding the functional form:

$x_t = \textbf{f}(t,y)$

### Quickstart¶

To create a new Series() instance from a csv file:

>>> from trendpy.series import Series
>>> data = Series.from_csv('data.csv')
>>> data.plot()


The MCMC class containts the generic structure of any MCMC algorithm:

• definition of the parameters (posterior distribution, dimensions)
• initialisation of the parameters to be estimated
• random simulation of the parameters from their respective posterior distributions

Thus any new algorithm can be added to the library by subclassing the Strategy class:

class BlackScholes(Strategy):

def __init__():
pass


Then the new MCMC instance just needs to be initialized with the new strategy and ran:

>>> new_mcmc = MCMC(self, SamplerFactory.create("BlackScholes",data))
>>> mcmc.run(number_simulations=50)
>>> estimation = mcmc.output()


## API Reference¶

If you are looking for information on a specific function, class or method, this part of the documentation is for you.

### Factory¶

Factory class handling the creation of bayesian algorithms.

### Mcmc¶

Generic structure of the algorithms implemented.

### Series¶

Class implementing time series analysis.

### Samplers¶

Samplers tell the mcmc algorithm how to simulate the Markov chain.

## Trendpy Changelog¶

We detail here the changes made to the library

### Version 0.1.1¶

Release day: August 24 2017

• Initial public release.

### Version 0.1.2¶

Release day: September 6 2017

• Some bug fixes
• Deleted the Series class

trendpy is licensed under the MIT Licence. It means that the source code provided in the binaries can be used, modified, or distributed freely for commercial or personal use with conditions only requiring preservation of copyright and license notices.

### Authors¶

trendpy is written and maintained by Rene-Jean Corneille

### Contributing¶

Contribution will be welcomed once a first stable release is ready.

The following section contains the full license texts for trendpy and the documentation.

• “AUTHORS” hereby refers to all the authors listed in the authors section.
• The “trendpy-license” applies to all the source code shipped as part of trendpy (trendpy itself as well as the examples and the unittests) as well as documentation.