Monte Carlo Simulator for Pandas
Project description
pandas-montecarlo is a lightweight Python library for running simple Monte Carlo Simulations on Pandas Series data.
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%:
import pandas_montecarlo
mc = df['return'].montecarlo(sims=10, bust=-0.1)
Plot simulations
mc.plot("SPY Returns Monte Carlo Simulations")
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,
'bust': 0.0005411255411255411}
}
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 data
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
Python >=3.4
Pandas (tested to work with >=0.18.1)
Matplotlib (tested to work with >=1.5.3)
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pandas-montecarlo-0.0.1.tar.gz
.
File metadata
- Download URL: pandas-montecarlo-0.0.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57d335d7b90f0d1bb6c55e853a277871bbcc80635b8223d3faee46973105b146 |
|
MD5 | 0a426d434818bf6f2a0e5c0939705ac7 |
|
BLAKE2b-256 | 730d64060b4f9b52858d7c30ea01bf0140523fdef7331a2d13ee7ad71365692e |