New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edge Positioning #1229
Edge Positioning #1229
Conversation
science project replacement for freqtrade backtest analysis - appprox 300-500x quicker to execute - fixes stop on close take close price bug in FT Bslap is configurable but by default stops are triggerd on low and pay stop price Not implimented dynamic stops or roi
Fixed Index Alignment that was off moving from scratch to FT Fixed Stoploss, its a negative in FT, had been using positve stop -1 in scratch
Bugs Calculating % prof ok, but abs wrong BAT/BTC DF is very broken all OHLC are the same - but exposes a buy after stop on last row "oddness" to be investigated / handled
updated logic added vector fill for abs/profit/duration in single hit on results.
All pass 3 sells 1 stop loss
If self.use_backslap = True Backslap executes If self.use_backslap = False Original Backtest Code executes
Switched Stops to trigger on Low Switched Stops to pay stop-rate not close.
Switched Stops to trigger on Low Switched Stops to pay stop-rate not close.
If true, prints trades ordered by date after summary. Useful for spotting trends.
Seperated save trades and print trades options.
We will never see this, as buy is on close which is the end of backtest e.g there is no next candle OPEN to buy at, or on
when buy opening on Index 1
stop_stops is an int value when number of stops in a pair reached the int the pair is stopped trading. This allows backtest to align with my pre_trade_mgt that does the same in dry and live operations
vector calcs redone.
vector calcs redone.
Dude. No
"
I am saying your total capital at risk is your stake_amount multiplied by
max_open_trades."
Capital at risk is to the stoploss.
It is NOT your stake amount by any amount of trades.
I can invest $1,000,000 over 1 or a hundred trades, if the stoploss on all
of them is %1 my capital at risk is $10,000 not $1,000,000
…On Sat, Nov 10, 2018, 12:52 PM Misagh ***@***.*** wrote:
I am saying your total capital at risk is your stake_amount multiplied by
max_open_trades.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1229 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AhCkwxBM38Qd8RwOo0-O6xZaNiccaPuBks5utq_agaJpZM4W0fHj>
.
|
@creslinux a different approach where we're applying Edge and its calculations to a portion of the total wallet capital would work as well. Does that makes sense ? Instead of using 1% of your total wallet and having to only be able to support a single trade, applying the risk calculations and hence the max amount per trade with a ceiling at total_wallet/number_of_max_trades |
I am sorry I meant your total capital. |
No makes no sense.
Position mgt can and will also give many many smaller positions. Not only
large.
To limit to three will severally hamper how effective you can be at putting
TC to work.
The way to scale down a position is to keep edge as is, and scale any
position that comes out down under a ceiling the same way it must also
scale under available free balance.
TC remains the same, it has to.
…On Sat, Nov 10, 2018, 1:03 PM doftorul ***@***.*** wrote:
Guys of course you have to check your wallet to see if you have free
balance and scale into it for new positions. That does not change total
capital for the calcs to get your ratios. How ever capital is spread over X
assets it's still total capital.
… <#m_6732848976521223383_>
On Sat, Nov 10, 2018, 12:52 PM Misagh ***@***.*** wrote: I am saying your
total capital at risk is your stake_amount multiplied by max_open_trades. —
You are receiving this because you were mentioned. Reply to this email
directly, view it on GitHub <#1229 (comment)
<#1229 (comment)>>,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AhCkwxBM38Qd8RwOo0-O6xZaNiccaPuBks5utq_agaJpZM4W0fHj
.
@creslinux <https://github.com/creslinux> a different approach where
we're applying Edge and its calculations to a portion of the total wallet
capital would work as well.
Even taking into account a split of 3 trades, it optimizes the risk
management of the portfolio if we consider the total capital/3 allowed
parallel trades and go with the R/R calculation on each of the trades.
Then, at a later stage when the wallet amount can be fetched from the
exchange one should be able to decide if it wants the capital spread among
4 trades or to increase the stake available for a trade by dividing the new
total wallet value fetched from the exchange to the same 3 max trades in
parallel.
Does that makes sense ?
Instead of using 1% of your total wallet and having to only be able to
support a single trade, applying the risk calculations and hence the max
amount per trade with a ceiling at total_wallet/number_of_max_trades
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1229 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AhCkw-jqfYXEDI1wLlDJUZ3BytM0Ei2Xks5utrJ6gaJpZM4W0fHj>
.
|
total capital = 1500 |
you are talking about scaling down after position sizing. I am saying you can scale down from the beginning. it comes to the exact same result mathematically |
That math works of the asset costs exactly 250 and you bought exactly 1 per
trade.
If you bought 0.5 your risk is $2.5.
How are you entering trade 4.
You want to be able to open 20 positions not 3.
So when stop is %10, you're going to put less capital into position. How
are you investing the remaining capital. Or is it dead money because
entered another trade?
Ditch FT max trades and max per trade, it's not compatible.
…On Sat, Nov 10, 2018, 1:16 PM Misagh ***@***.*** wrote:
you are talking about scaling down after position sizing. I am saying you
can scale down from the beginning. it comes to the exact same result
mathematically
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1229 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AhCkwyaO8E-I69C0NKW3FisEQFu7rUtBks5utrV3gaJpZM4W0fHj>
.
|
Consider the below scenario: ID Pair Since Profit 2 ZIL/BTC 9 h 0.08% The trades are some 4 hours apart from each other, the amounts are 0.07493757, 0.04987999, 0.02501785 from a total of 0.15 BTC made available to Edge. Once the first trade happened, the amount it took limited the other potential trades, i missed on 4 different trades between the first trade and the 2nd one due to Edge setting a higher stake amount for that trade. Between trade 2 and 3 i missed 5 different trades due to the same larger amounts set by the Edge for the stake of a trade. Now, its only logical to consider that the trades Edge enters into after the first one are those where you risk less and less capital and hence tend to have a lower performance. |
yep that's a big problem. if stoploss is 10% then you invest only 50 of 500 then the remaining is dead money ... |
Total capital does not change.
If I have 1000
And invest 200 I still have 1000, which I'm basing my next in parallel
positions max risk on.
Total capital is not free balance in a wallet.
My risk is against my TC not a wallet. Wallet is one limit of how much a
position should be scaled down to using my RR ratio, but the max risk in RR
is based on TC for all Calcs.
This is true untill the 200 exists and I either have 990 or 1010 as
example. Then TC changes.
…On Sat, Nov 10, 2018, 1:31 PM Misagh ***@***.*** wrote:
yep that's a big problem. if stoploss is 10% then you invest only 50 of
500 then the remaining is dead money ...
I can ditch them yep. but then I have to calculate amount of already
invested in open trades then remove it from the total capital ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1229 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AhCkw0OEl3F-iJRzC1FCVo2oN_Nh88qcks5utrkLgaJpZM4W0fHj>
.
|
But when would you stop opening a trade ? simply when you don't have enough remaining free capital ? |
Use the RR ratio based on full TC and scale down
…On Sat, Nov 10, 2018, 2:41 PM Misagh ***@***.*** wrote:
But when would you stop opening a trade ? simply when you don't have
enough remaining free capital ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1229 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AhCkw1mJEd3FLNI5kOyicl0lTk-6ZeP1ks5utsmWgaJpZM4W0fHj>
.
|
Went and supplemented the total wallet amount without changing in config the total_capital_in_stake_currency amount. |
After discussion with @xmatthias we decided to do the following:
The advantage is that it won't break the native functioning in FT and it allows to have more eyes on different parts of Edge. It then will be relatively easy to refactor for real position sizing. @doftorul Thanks a lot for testing and finding the problem ! I will probably ask you again to test if you can once position sizing will be repaired. @creslinux thanks a lot for challenging me. I will consider total capital and fetch balance on exchange for the next version and max_open_trades will be probably ignored (unless we find a compatibility somehow) |
docs/edge.md
Outdated
|
||
#### allowed_risk | ||
Percentage of allowed risk per trade<br/> | ||
(default to 1%) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you should say 0.01 here - this is confusing if i need to set 1 (%) - or 0.01 ...
docs/index.md
Outdated
@@ -25,6 +25,7 @@ Pull-request. Do not hesitate to reach us on | |||
- [Change your strategy](https://github.com/freqtrade/freqtrade/blob/develop/docs/bot-optimization.md#change-your-strategy) | |||
- [Add more Indicator](https://github.com/freqtrade/freqtrade/blob/develop/docs/bot-optimization.md#add-more-indicator) | |||
- [Test your strategy with Backtesting](https://github.com/freqtrade/freqtrade/blob/develop/docs/backtesting.md) | |||
- [Edge positionning](https://github.com/mishaker/freqtrade/blob/money_mgt/docs/edge.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
positioning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
will leave this around til tomorrow evening so @creslinux and @doftorul can comment should they not agree to take the "left open" points (#1319 ) in seperate followup-PR's
Summary
Currently FT analyzes pairs in whitelist randomly (or by order in config.json) and takes a position as soon as it finds a buy signal with a fixed stake_amount. a better approach would be:
This PR addresses the above issues by adding a package called "Edge". Edge will run a process every X minutes (default 30 min) using the mainloop to go through all pairs in order to:
The process uses the backtesting download script to fetch historical data. and cache a matrix of [pair, stoploss, win_rate, expected_risk_reward, required_risk_reward]. an example of the cached matrix:
WinRate is the number of winning trades divided by number of trades (e.x. if 4 trades out of 10 are profitable then the winrate is 40%).
Risk Reward Ratio is the ratio between your loss and your take profit. as an example lets say you take a position with an entry price of 100$. you put your stoploss at 90$ (i.e. 10%) and your take profit (sell point) is 120$. your risk reward would be 2 (your profit would be two times your loss).
While going through historical data we are only interested in finding two and only two things:
TODO list before merging the PR:
Will replace #1147 and #1114