Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is there a way i can take profit and stop it from being reinvested?

My only way to do it is to multiply each of my trades by a float i.e. 0.95 so 5% of my money is "safe". is there any other way to do this?

2 responses

To be honest, I'm a noob at this, but my guess would be to alternatively keep a counter around in one of your schedule_functions()

Then utilize this: cash_to_invest = 0.95*context.portfolio.cash

Although, keeping an int at the top equal to 0.95 seems more appropriate.

Lots of ways -- it's really up to you to program it how you like. Multiplying by a float like you're doing is fine. Do you want a fixed percent reserved in cash? Or a fixed value set aside as cash? Do you want it the cash reserve set aside continuously or monthly or quarterly, or triggered by some event?

Keep in mind that once you start live-trading you can manually sell some shares and withdraw the amount you'd like from your brokerage account. It'll confuse the stats and interpret the withdraw as a "loss", but that's a simple way to do it.