Git Product home page Git Product logo

pandas-montecarlo's Introduction

Monte Carlo Simulator for Pandas Series

Python version PyPi version PyPi status Travis-CI build status Patreon Status Star this repo Follow me on twitter

pandas-montecarlo is a lightweight Python library for running simple Monte Carlo Simulations on Pandas Series data.

Changelog »


Quick Start

Let's run a monte carlo simulation on the returns of SPY (S&P 500 Spider ETF).

First, let's download SPY's data and calculate the daily returns.

from pandas_datareader import data

df = data.get_data_yahoo("SPY")
df['return'] = df['Adj Close'].pct_change().fillna(0)

Next, we'll import pandas_montecarlo and run monte carlo simulation with 10 simulations (for demo simplifications) and bust/max drawdown set to -10.0% and goal threshhold set to +100.0% (defaults is >=0%):

import pandas_montecarlo
mc = df['return'].montecarlo(sims=10, bust=-0.1, goal=1)

Plot simulations

mc.plot(title="SPY Returns Monte Carlo Simulations")  # optional: , figsize=(x, y)

demo

Show test stats

print(mc.stats)

# prints
{
    'min':    0.98088401987146789,
    'max':    0.98088401987146934,
    'mean':   0.98088401987146911,
    'median': 0.98088401987146911,
    'std':    4.0792198665315552e-16,
    'maxdd': -0.17221175099828012,  # max drawdown
    'bust':   0.2,  # probability of going bust
    'goal':   0.0   # probability of reaching 100% goal
}

Show bust / max drawdown stats

print(mc.maxdd)

# prints
{
    'min':    -0.27743285515585991,
    'max':    -0.00031922711279186444,
    'mean':   -0.07888087155686732,
    'median': -0.06010335858432081,
    'std':     0.062172124557467685
}

Access raw simulations' DataFrame

print(mc.data.head())
    original          1          2          3          4  ...       10
0   0.000000   0.017745  -0.002586  -0.005346  -0.042107  ...  0.00139
1   0.002647   0.000050   0.000188   0.010141   0.007443  ...  0.00108
2   0.000704   0.002916   0.005324   0.000073  -0.003238  ...  0.00071
3   0.004221   0.008564   0.001397   0.007950  -0.006392  ...  0.00902
4   0.003328  -0.000511   0.005123   0.013491  -0.005105  ...  0.00252

Installation

Install pandas_montecarlo using pip:

$ pip install pandas_montecarlo --upgrade --no-cache-dir

Requirements

Legal Stuff

pandas-montecarlo is distributed under the GNU Lesser General Public License v3.0. See the LICENSE.txt file in the release for details.

P.S.

Please drop me an note with any feedback you have.

Ran Aroussi

pandas-montecarlo's People

Contributors

ranaroussi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.