backtesting balance after roundtrip - Printable Version +- Gekko Forum (https://forum.gekko.wizb.it) +-- Forum: Gekko (https://forum.gekko.wizb.it/forum-13.html) +--- Forum: Strategy Development (https://forum.gekko.wizb.it/forum-12.html) +--- Thread: backtesting balance after roundtrip (/thread-57716.html) |
backtesting balance after roundtrip - slav - 10-14-2018 Hi, I'm wondering how, during backtest, can I keep track of the current balance so i can put it in a variable and use it for other calculations? RE: backtesting balance after roundtrip - askmike - 10-19-2018 That's currently not exposed unfortunately. What kind of balance do you want? The raw values (like 0 USD and 1 btc) or the value as measured in currency (eg in USD with BTC/USD)? RE: backtesting balance after roundtrip - slav - 10-22-2018 I need the value measured in currency, potfolioValueChange (or event.balance?) or in other words the "PaperTrader.getBalance()" functions result. The idea is: whenever the position is long, fetch the current potfolioValueChange and make it available in my strategy. So then i could do for example if(portfolioValueChange === (0.98 * portfolioValueFromBeforeLongPosition) { // < == Funny i know, but you get the idea XD this.advice('short'); } I tried to listen to this event in my own plugin, but I can't export the value. Tried listening inside the strategy itself. Tried listening to GekkoEventEmitter etc. When I don't somehow get errors i keep getting "undefined" as a result. I'm new to Javascript and Node, but I've been trying for like a week now. Is it possible at all to do something like this? Regards RE: backtesting balance after roundtrip - askmike - 10-23-2018 Quote:if(portfolioValueChange === (0.98 * portfolioValueFromBeforeLongPosition) { // < == Funny i know, but you get the idea XD Well the idea is that you want to have a stop that if you lose 2% of your money you want out. Do you really need the precise portfolio information to determine this? If when you buy the price is 100, you can know roughly the same by simply watching whether the price goes below 98 (assuming you got a good execution price). --------- Though if you want to use portfolio values, you can do it but you need to change some Gekko code around: As you have figured out Gekko has a concept of events that are broadcasted whenever things happen. The portfolioValueChange is an event that gets broadcasted to all plugins that are interested in it ( https://gekko.wizb.it/docs/internals/events.html#portfolioValueChange-event ). The problem is now that your strategy is wrapped inside a plugin called the tradingAdvisor, as long as this plugin is not listening to the portfolioValueChange event it will be hard to get this data inside your strategy. The code is currently split up like this: Code: [ gekko stream, which has all events ] => [ tradingAdvisor plugin ] => [baseTradingMethod] => [your strategy] So if we want the event to show up in your strategy we need to relay it a few times: - in the tradingAdvisor subscribe to the event, just like this one: https://github.com/askmike/gekko/blob/develop/plugins/tradingAdvisor/tradingAdvisor.js#L106-L108 - in the baseTradingMethod relay the event, just like here (but skip these if checks): https://github.com/askmike/gekko/blob/develop/plugins/tradingAdvisor/baseTradingMethod.js#L206-L219 - add a new function to your strategy to handle the event. |