Statistical approach to risk management - Python script

Updated
This script can be used to approximate a strategy, and find optimal leverage.
The output will consist of two columns, one for the median account size at end of trading, and one for the share of accounts liquidated.

The script assumes a 100% position size for the account.
This does not take into account size deviations for earnings and losses, so use with a grain of salt if your positions vary greatly in that aspect.

Code preview
cdn.discordapp.com/attachments/592684708551327764/848701541766529034/carbon.png
TradingView does not allow posting external links until you've reached a specific reputation, so i can't use the url feature

Input explanation
  • WINRATE : chance of winning trade
  • AVGWIN : average earning per winning trade
  • AVGLOSS : average loss per losing trade

  • MAX_LEVERAGE : maximum leverage available to you

  • TRADES : how many trades per account you want to simulate
  • ACCOUNTS : how many accounts you want to simulate

    the inputs used in the source code are from one of my older strategies, change them to suit your algorithm


Source code
pastebin.com/69EKdVFC

Good luck, Have fun
-Vin
Trade active
Left a mistake in the code, here's an updated version:

Preview:
cdn.discordapp.com/attachments/592684708551327764/849339593798582312/carbon.png

Source code:
pastebin.com/0Vst4uJW
leveragepositionsizepythonriskRisk ManagementscriptstatisticsTrading PlanTrading Tools

Disclaimer