Jump to content
PilotFish

Quick and Dirty Python Script to Show Risk

Recommended Posts

Maybe you will tell me this is all easily done with buttons..but I haven't looked into the button calculations yet. It takes a share price and based on your account size will show you the max shares you can afford as well as display the money you'd lose/gain for each .05 interval up to 50 cents.

account_size = 30000
from decimal import Decimal

print("Welcome Tom, your account size is set to " + str(account_size))
share_price = input("\r\nPlease enter share price... ")

shares = account_size//Decimal(share_price)

print("**************************************")
print("\r\nYou can afford " + str(shares) + " shares.")
print("**************************************\r")

stoploss = Decimal('0.05')
while(stoploss <= .5):
    risk = 0
    risk = int(shares)*stoploss
    print("stop loss of " + str(stoploss) + " risks " + str(risk))
    stoploss+= Decimal('0.05')

 

 

risk_ex.thumb.png.1b4d3350227f94167a71903456b875fe.png

 

Edited by PilotFish
  • Like 2

Share this post


Link to post
Share on other sites

Dude! I just wrote a similar program in C++ and came here to post it and saw this lol. 

I think it's a really rare occurrence that'd you'd want to buy as many shares as your account will allow. 

I remember seeing a hotkey where you buy a % of your accounts value. Like you buy as many shares as possible with %25 of your account size. I can see those hotkeys being useful. 

For my program you input the max you're willing to lose on the trade, and then it tells you how many shares you can buy based off of your stop loss (which also goes in .05 increments) 

Here's mine 

 

Edited by Christopher Patterson
  • Like 2

Share this post


Link to post
Share on other sites
36 minutes ago, Christopher Patterson said:

Dude! I just wrote a similar program in C++ and came here to post it and saw this lol. 

I think it's a really rare occurrence that'd you'd want to buy as many shares as your account will allow. 

I remember seeing a hotkey where you buy a % of your accounts value. Like you buy as many shares as possible with %25 of your account size. I can see those hotkeys being useful. 

For my program you input the max you're willing to lose on the trade, and then it tells you how many shares you can buy based off of your stop loss (which also goes in .05 increments) 

Here's mine 

Nice man! Great minds something something. I am under the impression it would be perfectly fine to trade an entire account with strict stop loss/risk management control? Also, have a gander here if you haven't already, Kyle has set up DAS to do all of this for us automagically. (Although we won't get cool readouts like our programs do)

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.