Can I code this polynomial equation with unknown parameter?
Can I code this polynomial equation with unknown parameter?
Loading saved threads...
Andy Thompson · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Andy Thompson
Original post: https://stackoverflow.com/questions/67162541
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I am trying to code an equation series as follows:
Starting with Value[0],
the first result (Return[1]) = RR * Riskpc * Value[0], Value[1] = Value[0] + Return[1]
Return[2] = RR * ((k * Riskpc * Value[1]) + Return[1]), Value[2] = Value[1] + Return[2]
...
Return[n] = RR * ((k * Riskpc * Value[n-1]) + Return[n-1]), Value[n] = Value[n-1] + Return[n]
this is effectively limiting the loss of the whole series to Riskpc*Value while adding (a multiplier (k) * the whole of the previous return) to the amount risked.
I need to be able to code this in python and in mql4 and mql5 so that regardless of n, Value[n] == m * Value[0], m being a constant > 1. In the current problem m = 1.101, RR = 3 and Riskpc = 1.
I understand that the solution is a geometric equation such that for any given series of length n (n > 1) with constants RR Riskpc and m, k is a function of RR, Riskpc, n and m but this is way beyond my 30 yr old A level maths.
I have tried to explore matlab and sympy but have got lost...
Edit
Sorry I realise the original question was too vague.
My colab file is
here
.
It works for
compoundLength = 2
as per the defaults in that file, but for
compoundLength = 3+
it will only reduce risk on the last trade.
In there I am trying to program the
calcRisk()
function to replace the logic in lines 56 and 51 such that the partial preservation of previous returns is spread across the series (not including the first trade) rather than only occurring on the last trade.
The original problem was:
with a reward:risk ratio of 3, by adding the return on the first trade to the 1% of the new account value as the risk for the second trade (so as to increase upside potential whilst not losing more than the initial 1% across the 2 trades), how do I limit the risk placed on the second trade to that neccessary to hit the target of 10.1%?
This is achieved in a series of 2 by the logic at line 56 and preserves around 50% (depending on previous drawdown) of the returns from trade 1.
The object is to extend this to n (
compoundLength
) trades. The monte-carlo simulator runs 1,000,000 possible trade series, calculating the reduced cumulative risk on the next trade after every profitable trade, but on series of 3+, as it stands, all the benefit of the reduced risk is only realised on the last trade.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Andy Thompson Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/67162541 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I am trying to code an equation series as follows: Starting with Value[0], the first result (Return[1]) = RR * Riskpc * Value[0], Value[1] = Value[0] + Return[1] Return[2] = RR * ((k * Riskpc * Value[1]) + Return[1]), Value[2] = Value[1] + Return[2] ... Return[n] = RR * ((k * Riskpc * Value[n-1]) + Return[n-1]), Value[n] = Value[n-1] + Return[n] this is effectively limiting the loss of the whole series to Riskpc*Value while adding (a multiplier (k) * the whole of the previous return) to the amount risked. I need to be able to code this in python and in mql4 and mql5 so that regardless of n, Value[n] == m * Value[0], m being a constant > 1. In the current problem m = 1.101, RR = 3 and Riskpc = 1. I understand that the solution is a geometric equation such that for any given series of length n (n > 1) with constants RR Riskpc and m, k is a function of RR, Riskpc, n and m but this is way beyond my 30 yr old A level maths. I have tried to explore matlab and sympy but have got lost... Edit Sorry I realise the original question was too vague. My colab file is here . It works for compoundLength = 2 as per the defaults in that file, but for compoundLength = 3+ it will only reduce risk on the last trade. In there I am trying to program the calcRisk() function to replace the logic in lines 56 and 51 such that the partial preservation of previous returns is spread across the series (not including the first trade) rather than only occurring on the last trade. The original problem was: with a reward:risk ratio of 3, by adding the return on the first trade to the 1% of the new account value as the risk for the second trade (so as to increase upside potential whilst not losing more than the initial 1% across the 2 trades), how do I limit the risk placed on the second trade to that neccessary to hit the target of 10.1%? This is achieved in a series of 2 by the logic at line 56 and preserves around 50% (depending on previous drawdown) of the returns from trade 1. The object is to extend this to n ( compoundLength ) trades. The monte-carlo simulator runs 1,000,000 possible trade series, calculating the reduced cumulative risk on the next trade after every profitable trade, but on series of 3+, as it stands, all the benefit of the reduced risk is only realised on the last trade.
Checking account access…