Skip to main content

Monte Carlo simulations of the trading account evolution based on the winning ratio and risk-reward relation of a trading plan.

Project description

This package allows the user to estimate the evolution of a trading account after a prescribed number of trades using a Monte Carlo (MC) algorithm. The input of the algorithm is the winning ratio and the risk-reward relation associated with a trading plan, which supposedly has been extensively tested by the user.

The mc module implements a single class, Simulation, which should be instantiated by the user and which provides a number of methods and properties, such as the ones for calculating the average balance of the MC-generated trading paths, giving an estimate of the long run performance of a trading plan, and, perhaps more importantly, the probability of ruin, which is the probability of zeroing out a trading account when the trader strictly follows a trading plan.

Basic Usage Example


# Estimate of the probability of ruin of a trading strategy

# Input variables
winratio=0.40     # Winning ratio of the strategy (must be between 0 and 1)
capital=1000.0    # Initial capital
profit=20.0       # Profit per winning trade (must be a positive number)
loss=-10.0        # Loss per losing trade (must be a negative number)
npaths=1000       # Number of independent trading paths
ntrades=1000      # Maximum number of trades per trading path

# Run a Monte Carlo simulation
from BalanceEvolution import mc

s=mc.Simulation()
s.setparams(winratio,capital,profit,loss,npaths,ntrades)
s.run()

# Plot trading paths
s.plottradingpaths()

# Plot histogram of final account balances
s.plothist()

# Average balance, standard devation, maximum and minimum
s.getavgbalance()

# Avgerage consecutive wins, stdandard deviation, maximum and minimum
s.getavgconsecutivewins()

# Avgerage consecutive losses, stdandard deviation, maximum and minimum
s.getavgconsecutivelosses()

# Probability of ruin
print(s.ruinprob)

Project details


Release history Release notifications | RSS feed

This version

0.11

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

BalanceEvolution-0.11-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file BalanceEvolution-0.11-py3-none-any.whl.

File metadata

  • Download URL: BalanceEvolution-0.11-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for BalanceEvolution-0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5af558fdfdd19aa3996be111dfc8fa45df15ddd55c461e601757276542ebfcb2
MD5 cad4c3817e3918ee244d72d2593e608c
BLAKE2b-256 f2624e19971194fc4ee5503c4726bd82e81f5757ebc8e0cf499bd00766faf694

See more details on using hashes here.

Supported by

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