Skip to main content

montecarlo simulations/analysis library for finance

Project description

Montecarlo simulations/analysis for finance (equity simulator)

PyPI status Build Status codecov Codacy Badge Maintainability PyPI Maintenance PyPI license

An inspiration of the book BUILDING WINNING ALGORITHMIC TRADING SYSTEMS of 'Kevin J. Davey' (chapter 7 detailed analysis)

What's happened if your trades happened in an other order and you do that many times to produce statistics ? What are your chances to be ruin ? What's maximum drawdown you may met ?

Giving the trade results to the library and it will help you to manage the risk.

CAUTION : The simulator include assumption that your trades are independent one from the others : it may be the case if your bots make more than one trade at the same time on correlated markets (you can use a durbin watson statistic from statsmodels library to see that)

Installation

Use the package manager pip to install montecarlo simulation finance.

pip install mc-sim-fin

Usage

For the code example below you have 5000 dollar for trading, you stop trading if you capital go below 4000. Your backtest results show that you bot make one trade per day and alternate a win trade of 200 then a lose trade of 150 during the 2017 year.

By default it simulate 1 year of trading with 10000 iterations (look at the documentation to modify this params).

import pandas as pd
import numpy as np
from mc_sim_fin.mc import mc_analysis


date_results = pd.date_range(start='1/1/2017', end='31/12/2017').tolist()
profit_results = np.resize([200, -150], 365)

results = pd.DataFrame({'date_results': date_results, 'profit_results': profit_results})

mc_sims_results = mc_analysis(results, start_equity=5000, ruin_equity=4000)


print(mc_sims_results)

# print output
{
'risk_of_ruin_percent': 0.156,
'med_max_drawdown_percent': 0.36,
'med_profit_percent': 1.83,
'prob_profit_is_positive': 0.9979
}

So I have 15.6% changes to be ruin, I can expect 36% max drawdown and 183% profit and I have 99.79% change to win money during the first year.

Documentation

You need more information about how the simulation work? You would like to contribute ?

Look at the documentation

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mc-sim-fin-1.0.0.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file mc-sim-fin-1.0.0.tar.gz.

File metadata

  • Download URL: mc-sim-fin-1.0.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for mc-sim-fin-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3c416ccecf1e4441fceaa1568f460708c9d1a092fd436b736adb735e9b788a24
MD5 697d2987a7ddd70bedda146a0badde50
BLAKE2b-256 eb75f43fa7f6ddc18c527652f3a6933a926a26b752ed5c18ddb62ac45c5a3044

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page